func CreateProfileHandler(w http.ResponseWriter, r *http.Request) { var p Profile if err := httputils.UnmarshalJSONBody(r.Body, &p); err != nil { httputils.JSONError(w, err.Error(), 500) } if err := p.Save(); err != nil { httputils.JSONError(w, err.Error(), 500) } httputils.SetLocationHeader(w, "http://localhost:8080/profiles/"+p.Name) w.WriteHeader(http.StatusCreated) }
func CreateSSHKeyHandler(w http.ResponseWriter, r *http.Request) { var s SSHKey if err := httputils.UnmarshalJSONBody(r.Body, &s); err != nil { httputils.JSONError(w, err.Error(), 500) } if err := s.Save(); err != nil { httputils.JSONError(w, err.Error(), 500) } httputils.SetLocationHeader(w, "http://localhost:8080/sshkeys/"+s.Name) w.WriteHeader(http.StatusCreated) }
func CreateCloudConfigHandler(w http.ResponseWriter, r *http.Request) { var c CloudConfig if err := httputils.UnmarshalJSONBody(r.Body, &c); err != nil { httputils.JSONError(w, err.Error(), 500) } if err := c.Save(); err != nil { httputils.JSONError(w, err.Error(), 500) } httputils.SetLocationHeader(w, "http://localhost:8080/cloudconfigs/"+c.Name) w.WriteHeader(http.StatusCreated) }
func CreateMachineHandler(w http.ResponseWriter, r *http.Request) { var m Machine if err := httputils.UnmarshalJSONBody(r.Body, &m); err != nil { httputils.JSONError(w, err.Error(), 500) } if err := m.Save(); err != nil { httputils.JSONError(w, err.Error(), 500) } httputils.SetLocationHeader(w, "http://localhost:8080/machines/"+m.Name) w.WriteHeader(http.StatusCreated) }
func GetCloudConfigs() ([]CloudConfig, error) { var response CloudConfigsResponse resp, err := http.Get("http://localhost:8080/api/cloudconfigs") if err != nil { return response.CloudConfigs, err } if resp.StatusCode != 200 { return response.CloudConfigs, errors.New(resp.Status) } err = httputils.UnmarshalJSONBody(resp.Body, &response) if err != nil { return response.CloudConfigs, err } return response.CloudConfigs, nil }
func GetCloudConfigByName(name string) (CloudConfig, error) { var c CloudConfig resp, err := http.Get("http://localhost:8080/api/cloudconfigs/" + name) if err != nil { return c, err } if resp.StatusCode != http.StatusOK { return c, errors.New("invalid response") } err = httputils.UnmarshalJSONBody(resp.Body, &c) if err != nil { return c, err } return c, nil }
func GetProfiles() ([]Profile, error) { var response ProfilesResponse resp, err := http.Get("http://localhost:8080/api/profiles") if err != nil { return response.Profiles, err } if resp.StatusCode != 200 { return response.Profiles, errors.New(resp.Status) } err = httputils.UnmarshalJSONBody(resp.Body, &response) if err != nil { return response.Profiles, err } return response.Profiles, nil }
func GetProfileByName(name string) (Profile, error) { var p Profile resp, err := http.Get("http://localhost:8080/api/profiles/" + name) if err != nil { return p, err } if resp.StatusCode != http.StatusOK { return p, errors.New("invalid response") } err = httputils.UnmarshalJSONBody(resp.Body, &p) if err != nil { return p, err } return p, nil }