Example #1
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
}
Example #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
}
Example #3
0
func getCredential(w http.ResponseWriter, r *http.Request, handler string) *repo.Credential {
	util.LogHandlerEntry(handler, r)
	t := &repo.Credential{}
	if err := httputil.Decode(w, r, t); err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}
	return t
}
Example #4
0
func getDeploymentRequest(w http.ResponseWriter, r *http.Request, handler string) *common.DeploymentRequest {
	util.LogHandlerEntry(handler, r)
	depReq := &common.DeploymentRequest{}
	if err := httputil.Decode(w, r, depReq); err != nil {
		httputil.BadRequest(w, r, err)
		return nil
	}

	return depReq
}
Example #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
}
Example #6
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
}
Example #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
}
Example #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
}
Example #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
}
Example #10
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
}
Example #11
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
}
Example #12
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
}
Example #13
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
}