(w http.ResponseWriter, r *http.Request)
| 40 | } |
| 41 | |
| 42 | func scriptHandler(w http.ResponseWriter, r *http.Request) { |
| 43 | switch r.Method { |
| 44 | case http.MethodPost: |
| 45 | const maxBodySize = 1024 // must be larger than protojson serialized [data.ShardMetadata] |
| 46 | r.Body = http.MaxBytesReader(w, r.Body, maxBodySize) |
| 47 | jsonBytes, err := io.ReadAll(r.Body) |
| 48 | if err != nil { |
| 49 | http.Error(w, fmt.Sprintf("unable to read request body: %v", err), |
| 50 | http.StatusInternalServerError) |
| 51 | return |
| 52 | } |
| 53 | var metadata data.ShardMetadata |
| 54 | if err := protojson.Unmarshal(jsonBytes, &metadata); err != nil { |
| 55 | http.Error(w, fmt.Sprintf("unable to parse request as ShardMetadata proto: %v", err), |
| 56 | http.StatusBadRequest) |
| 57 | return |
| 58 | } |
| 59 | authn, err := google.NewEnvAuthenticator(r.Context()) |
| 60 | if err != nil { |
| 61 | http.Error(w, fmt.Sprintf("error in NewEnvAuthenticator: %v", err), http.StatusInternalServerError) |
| 62 | return |
| 63 | } |
| 64 | for _, image := range images { |
| 65 | if err := crane.Tag( |
| 66 | fmt.Sprintf("%s:%s", image, metadata.GetCommitSha()), stableTag, |
| 67 | crane.WithAuth(authn)); err != nil { |
| 68 | http.Error(w, fmt.Sprintf("crane.Tag: %v", err), http.StatusInternalServerError) |
| 69 | return |
| 70 | } |
| 71 | } |
| 72 | w.WriteHeader(http.StatusOK) |
| 73 | if _, err := w.Write([]byte("successfully tagged images\n")); err != nil { |
| 74 | log.Panic(fmt.Errorf("error during Write: %w", err)) |
| 75 | } |
| 76 | default: |
| 77 | http.Error(w, "only POST method is allowed", http.StatusMethodNotAllowed) |
| 78 | return |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func main() { |
| 83 | http.HandleFunc("/", scriptHandler) |
nothing calls this directly
no test coverage detected