Пример #1
0
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)
}
Пример #2
0
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)
}
Пример #3
0
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)
}
Пример #4
0
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)
}
Пример #5
0
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
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
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
}