Пример #1
0
func expanderSuccessHandler(w http.ResponseWriter, r *http.Request) {
	handler := "expandybird: expand"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		status := fmt.Sprintf("cannot read request body:%s", err)
		http.Error(w, status, http.StatusInternalServerError)
		return
	}

	svcReq := &expansion.ServiceRequest{}
	if err := json.Unmarshal(body, svcReq); err != nil {
		status := fmt.Sprintf("cannot unmarshal request body:%s\n%s\n", err, body)
		http.Error(w, status, http.StatusInternalServerError)
		return
	}

	/*
		if !reflect.DeepEqual(validRequestTestCaseData, *svcReq) {
			status := fmt.Sprintf("error in http handler:\nwant:%s\nhave:%s\n",
				util.ToJSONOrError(validRequestTestCaseData), util.ToJSONOrError(template))
			http.Error(w, status, http.StatusInternalServerError)
			return
		}
	*/

	svcResp := getValidServiceResponse()
	util.LogHandlerExitWithJSON(handler, w, svcResp, http.StatusOK)
}
Пример #2
0
func listRepoChartsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list repository charts"
	util.LogHandlerEntry(handler, r)
	repoURL, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	values, err := url.ParseQuery(r.URL.RawQuery)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	var regex *regexp.Regexp
	regexString := values.Get("regex")
	if regexString != "" {
		regex, err = regexp.Compile(regexString)
		if err != nil {
			httputil.BadRequest(w, r, err)
			return nil
		}
	}

	repoCharts, err := c.Manager.ListRepoCharts(repoURL, regex)
	if err != nil {
		return err
	}

	util.LogHandlerExitWithJSON(handler, w, repoCharts, http.StatusOK)
	return nil
}
Пример #3
0
func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: add chart repository"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	cr := &repo.Repo{}
	if err := httputil.Decode(w, r, cr); err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	if string(cr.Format) == "" {
		cr.Format = repo.GCSRepoFormat
	}

	if string(cr.Type) == "" {
		cr.Type = repo.GCSRepoType
	}

	if err := c.Manager.AddRepo(cr); err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	msg, _ := json.Marshal(cr.Name + " has been added to the list of chart repositories.")
	util.LogHandlerExitWithJSON(handler, w, msg, http.StatusCreated)
	return nil
}
Пример #4
0
func listChartReposHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list chart repositories"
	repos, err := c.Manager.ListRepos()
	if err != nil {
		return err
	}

	util.LogHandlerExitWithJSON(handler, w, repos, http.StatusOK)
	return nil
}
Пример #5
0
// Putting Type handlers here for now because deployments.go
// currently owns its own Manager backend and doesn't like to share.
func listChartsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list charts"
	util.LogHandlerEntry(handler, r)
	types, err := c.Manager.ListCharts()
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, types, http.StatusOK)
	return nil
}
Пример #6
0
func listDeploymentsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list deployments"
	util.LogHandlerEntry(handler, r)
	l, err := c.Manager.ListDeployments()
	if err != nil {
		util.LogAndReturnError(handler, http.StatusInternalServerError, err, w)
		return nil
	}
	var names []string
	for _, d := range l {
		names = append(names, d.Name)
	}

	util.LogHandlerExitWithJSON(handler, w, names, http.StatusOK)
	return nil
}
Пример #7
0
func getMetadataForChartHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get chart metadata"
	util.LogHandlerEntry(handler, r)
	chartName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	metadata, err := c.Manager.GetMetadataForChart(chartName)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, metadata, http.StatusOK)
	return nil
}
Пример #8
0
func listChartInstancesHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list chart instances"
	util.LogHandlerEntry(handler, r)
	chartName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	instances, err := c.Manager.ListChartInstances(chartName)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, instances, http.StatusOK)
	return nil
}
Пример #9
0
func expandHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: expand config"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	depReq := getDeploymentRequest(w, r, handler)
	if depReq != nil {
		c, err := c.Manager.Expand(depReq)
		if err != nil {
			httputil.BadRequest(w, r, err)
			return nil
		}

		util.LogHandlerExitWithJSON(handler, w, c, http.StatusCreated)
	}

	return nil
}
Пример #10
0
func getCredentialHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get credential"
	util.LogHandlerEntry(handler, r)
	credentialName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	cr, err := c.Manager.GetCredential(credentialName)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, cr, http.StatusOK)
	return nil
}
Пример #11
0
func deleteDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: delete deployment"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	name, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	d, err := c.Manager.DeleteDeployment(name, true)
	if err != nil {
		return err
	}

	util.LogHandlerExitWithJSON(handler, w, d, http.StatusOK)
	return nil
}
Пример #12
0
func getDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get deployment"
	util.LogHandlerEntry(handler, r)
	name, err := pos(w, r, 2)
	if err != nil {
		return nil
	}

	d, err := c.Manager.GetDeployment(name)
	if err != nil {
		util.LogAndReturnError(handler, http.StatusBadRequest, err, w)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, d, http.StatusOK)
	return nil
}
Пример #13
0
func getChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get repository"
	util.LogHandlerEntry(handler, r)
	repoURL, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	cr, err := c.Manager.GetRepo(repoURL)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, cr, http.StatusOK)
	return nil
}
Пример #14
0
func removeChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: remove chart repository"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	name, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	err = c.Manager.RemoveRepo(name)
	if err != nil {
		return err
	}

	msg, _ := json.Marshal(name + " has been removed from the list of chart repositories.")
	util.LogHandlerExitWithJSON(handler, w, msg, http.StatusOK)
	return nil
}
Пример #15
0
func getRepoChartHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get repository charts"
	util.LogHandlerEntry(handler, r)
	repoURL, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	chartName, err := pos(w, r, 4)
	if err != nil {
		return err
	}

	repoChart, err := c.Manager.GetChartForRepo(repoURL, chartName)
	if err != nil {
		return err
	}

	util.LogHandlerExitWithJSON(handler, w, repoChart, http.StatusOK)
	return nil
}
Пример #16
0
func createCredentialHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: create credential"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	credentialName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	cr := getCredential(w, r, handler)
	if cr != nil {
		err = c.Manager.CreateCredential(credentialName, cr)
		if err != nil {
			httputil.BadRequest(w, r, err)
			return nil
		}
	}

	util.LogHandlerExitWithJSON(handler, w, c, http.StatusOK)
	return nil
}
Пример #17
0
func listManifestsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: list manifests"
	util.LogHandlerEntry(handler, r)
	deploymentName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	m, err := c.Manager.ListManifests(deploymentName)
	if err != nil {
		return err
	}

	var manifestNames []string
	for _, manifest := range m {
		manifestNames = append(manifestNames, manifest.Name)
	}

	util.LogHandlerExitWithJSON(handler, w, manifestNames, http.StatusOK)
	return nil
}
Пример #18
0
func putDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: update deployment"
	util.LogHandlerEntry(handler, r)
	defer r.Body.Close()
	name, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	depReq := getDeploymentRequest(w, r, handler)
	if depReq != nil {
		d, err := c.Manager.PutDeployment(name, depReq)
		if err != nil {
			httputil.BadRequest(w, r, err)
			return nil
		}

		util.LogHandlerExitWithJSON(handler, w, d, http.StatusCreated)
	}

	return nil
}
Пример #19
0
func getManifestHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
	handler := "manager: get manifest"
	util.LogHandlerEntry(handler, r)
	deploymentName, err := pos(w, r, 2)
	if err != nil {
		return err
	}

	manifestName, err := pos(w, r, 4)
	if err != nil {
		return err
	}

	m, err := c.Manager.GetManifest(deploymentName, manifestName)
	if err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	util.LogHandlerExitWithJSON(handler, w, m, http.StatusOK)
	return nil
}