func handleRegisterApp(w http.ResponseWriter, r *http.Request) { remoteIP := strings.Split(r.RemoteAddr, ":")[0] if _, ok := metadataByIP[remoteIP]; ok { // not allowed from container IP w.WriteHeader(http.StatusForbidden) return } uid, err := types.NewUUID(mux.Vars(r)["uid"]) if err != nil { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "UUID is missing or mulformed: %v", err) return } m, ok := metadataByUID[*uid] if !ok { w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "Container with given UUID not found") return } an := mux.Vars(r)["app"] app := &schema.AppManifest{} if err := json.NewDecoder(r.Body).Decode(&app); err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "JSON-decoding failed: %v", err) return } m.apps[an] = app w.WriteHeader(http.StatusOK) }
func appGet(h func(w http.ResponseWriter, r *http.Request, m *metadata, am *schema.AppManifest)) func(http.ResponseWriter, *http.Request) { return containerGet(func(w http.ResponseWriter, r *http.Request, m *metadata) { appname := mux.Vars(r)["app"] if am, ok := m.apps[appname]; ok { h(w, r, m, am) } else { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "App (%v) not found", appname) } }) }
func handleContainerAnnotation(w http.ResponseWriter, r *http.Request, m *metadata) { k, err := types.NewACName(mux.Vars(r)["name"]) if err != nil { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "Container annotation is not a valid AC Label") return } v, ok := m.manifest.Annotations[*k] if !ok { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "Container annotation (%v) not found", k) return } w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) w.Write([]byte(v)) }
func handleAppAnnotation(w http.ResponseWriter, r *http.Request, m *metadata, am *schema.AppManifest) { k, err := types.NewACName(mux.Vars(r)["name"]) if err != nil { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "App annotation is not a valid AC Label") return } merged := mergeAppAnnotations(am, &m.manifest) v, ok := merged[*k] if !ok { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "App annotation (%v) not found", k) return } w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) w.Write([]byte(v)) }