cmd: implement project/projectgroup variable create
This commit is contained in:
parent
99a6c12f98
commit
f0e7ce4a96
|
@ -50,7 +50,7 @@ func init() {
|
|||
flags.StringVar(&projectCreateOpts.repoURL, "repo-url", "", "repository url")
|
||||
flags.StringVar(&projectCreateOpts.remoteSourceName, "remote-source", "", "remote source name")
|
||||
flags.BoolVarP(&projectCreateOpts.skipSSHHostKeyCheck, "skip-ssh-host-key-check", "s", false, "skip ssh host key check")
|
||||
flags.StringVar(&projectCreateOpts.parentPath, "parent", "", `parent project group path (i.e "org/org01" for root project group in org01, "/user/user01/group01/subgroub01") or project group id where the project should be created`)
|
||||
flags.StringVar(&projectCreateOpts.parentPath, "parent", "", `parent project group path (i.e "org/org01" for root project group in org01, "user/user01/group01/subgroub01") or project group id where the project should be created`)
|
||||
|
||||
cmdProjectCreate.MarkFlagRequired("name")
|
||||
cmdProjectCreate.MarkFlagRequired("parent")
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
var cmdProjectGroupCreate = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create a project",
|
||||
Short: "create a project group",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := projectGroupCreate(cmd, args); err != nil {
|
||||
log.Fatalf("err: %v", err)
|
||||
|
@ -43,8 +43,8 @@ var projectGroupCreateOpts projectGroupCreateOptions
|
|||
func init() {
|
||||
flags := cmdProjectGroupCreate.Flags()
|
||||
|
||||
flags.StringVarP(&projectGroupCreateOpts.name, "name", "n", "", "project name")
|
||||
flags.StringVar(&projectGroupCreateOpts.parentPath, "parent", "", `parent project group path (i.e "org/org01" for root project group in org01, "/user/user01/group01/subgroub01") or project group id where the project group should be created`)
|
||||
flags.StringVarP(&projectGroupCreateOpts.name, "name", "n", "", "project group name")
|
||||
flags.StringVar(&projectGroupCreateOpts.parentPath, "parent", "", `parent project group path (i.e "org/org01" for root project group in org01, "user/user01/group01/subgroub01") or project group id where the project group should be created`)
|
||||
|
||||
cmdProjectGroupCreate.MarkFlagRequired("name")
|
||||
cmdProjectGroupCreate.MarkFlagRequired("parent")
|
||||
|
@ -64,9 +64,9 @@ func projectGroupCreate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
project, _, err := gwclient.CreateProjectGroup(context.TODO(), req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create project")
|
||||
return errors.Wrapf(err, "failed to create project group")
|
||||
}
|
||||
log.Infof("project %s created, ID: %s", project.Name, project.ID)
|
||||
log.Infof("project group %s created, ID: %s", project.Name, project.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2019 Sorint.lab
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdProjectGroupSecret = &cobra.Command{
|
||||
Use: "secret",
|
||||
Short: "secret",
|
||||
}
|
||||
|
||||
func init() {
|
||||
cmdProjectGroup.AddCommand(cmdProjectGroupSecret)
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2019 Sorint.lab
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdProjectGroupSecretCreate = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create a project group secret",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := secretCreate(cmd, "projectgroup", args); err != nil {
|
||||
log.Fatalf("err: %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
flags := cmdProjectGroupSecretCreate.Flags()
|
||||
|
||||
flags.StringVar(&secretCreateOpts.projectRef, "project", "", "project id or full path")
|
||||
flags.StringVarP(&secretCreateOpts.name, "name", "n", "", "secret name")
|
||||
|
||||
cmdProjectGroupSecretCreate.MarkFlagRequired("project")
|
||||
cmdProjectGroupSecretCreate.MarkFlagRequired("name")
|
||||
|
||||
cmdProjectGroupSecret.AddCommand(cmdProjectGroupSecretCreate)
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2019 Sorint.lab
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdProjectGroupVariable = &cobra.Command{
|
||||
Use: "variable",
|
||||
Short: "variable",
|
||||
}
|
||||
|
||||
func init() {
|
||||
cmdProjectGroup.AddCommand(cmdProjectGroupVariable)
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2019 Sorint.lab
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdProjectGroupVariableCreate = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create a project variable",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := variableCreate(cmd, "projectgroup", args); err != nil {
|
||||
log.Fatalf("err: %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
flags := cmdProjectGroupVariableCreate.Flags()
|
||||
|
||||
flags.StringVar(&variableCreateOpts.parentRef, "projectgroup", "", "project group id or full path")
|
||||
flags.StringVarP(&variableCreateOpts.name, "name", "n", "", "variable name")
|
||||
flags.StringVar(&variableCreateOpts.values, "values", "", "json list of values and conditions")
|
||||
|
||||
cmdProjectGroupVariableCreate.MarkFlagRequired("project")
|
||||
cmdProjectGroupVariableCreate.MarkFlagRequired("name")
|
||||
cmdProjectGroupVariableCreate.MarkFlagRequired("values")
|
||||
|
||||
cmdProjectGroupVariable.AddCommand(cmdProjectGroupVariableCreate)
|
||||
}
|
|
@ -16,7 +16,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sorintlab/agola/internal/services/gateway/api"
|
||||
|
@ -27,24 +26,24 @@ var cmdProjectSecretCreate = &cobra.Command{
|
|||
Use: "create",
|
||||
Short: "create a project secret",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := projectSecretCreate(cmd, args); err != nil {
|
||||
if err := secretCreate(cmd, "project", args); err != nil {
|
||||
log.Fatalf("err: %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
type projectSecretCreateOptions struct {
|
||||
projectID string
|
||||
type secretCreateOptions struct {
|
||||
projectRef string
|
||||
name string
|
||||
}
|
||||
|
||||
var projectSecretCreateOpts projectSecretCreateOptions
|
||||
var secretCreateOpts secretCreateOptions
|
||||
|
||||
func init() {
|
||||
flags := cmdProjectSecretCreate.Flags()
|
||||
|
||||
flags.StringVar(&projectSecretCreateOpts.projectID, "project", "", "project id or full path)")
|
||||
flags.StringVarP(&projectSecretCreateOpts.name, "name", "n", "", "secret name")
|
||||
flags.StringVar(&secretCreateOpts.projectRef, "project", "", "project id or full path)")
|
||||
flags.StringVarP(&secretCreateOpts.name, "name", "n", "", "secret name")
|
||||
|
||||
cmdProjectSecretCreate.MarkFlagRequired("project")
|
||||
cmdProjectSecretCreate.MarkFlagRequired("name")
|
||||
|
@ -52,19 +51,29 @@ func init() {
|
|||
cmdProjectSecret.AddCommand(cmdProjectSecretCreate)
|
||||
}
|
||||
|
||||
func projectSecretCreate(cmd *cobra.Command, args []string) error {
|
||||
func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||
gwclient := api.NewClient(gatewayURL, token)
|
||||
|
||||
req := &api.CreateSecretRequest{
|
||||
Name: projectSecretCreateOpts.name,
|
||||
Name: secretCreateOpts.name,
|
||||
}
|
||||
|
||||
switch ownertype {
|
||||
case "project":
|
||||
log.Infof("creating project secret")
|
||||
secret, _, err := gwclient.CreateProjectSecret(context.TODO(), url.PathEscape(projectSecretCreateOpts.projectID), req)
|
||||
secret, _, err := gwclient.CreateProjectSecret(context.TODO(), secretCreateOpts.projectRef, req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create project secret")
|
||||
}
|
||||
log.Infof("project secret %q created, ID: %q", secret.Name, secret.ID)
|
||||
case "projectgroup":
|
||||
log.Infof("creating project group secret")
|
||||
secret, _, err := gwclient.CreateProjectGroupSecret(context.TODO(), secretCreateOpts.projectRef, req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create project group secret")
|
||||
}
|
||||
log.Infof("project group secret %q created, ID: %q", secret.Name, secret.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,5 +24,5 @@ var cmdProjectVariable = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
cmdUser.AddCommand(cmdProjectVariable)
|
||||
cmdProject.AddCommand(cmdProjectVariable)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright 2019 Sorint.lab
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sorintlab/agola/internal/services/gateway/api"
|
||||
"github.com/sorintlab/agola/internal/services/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdProjectVariableCreate = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create a project variable",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := variableCreate(cmd, "project", args); err != nil {
|
||||
log.Fatalf("err: %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
type variableCreateOptions struct {
|
||||
parentRef string
|
||||
name string
|
||||
values string
|
||||
}
|
||||
|
||||
var variableCreateOpts variableCreateOptions
|
||||
|
||||
func init() {
|
||||
flags := cmdProjectVariableCreate.Flags()
|
||||
|
||||
flags.StringVar(&variableCreateOpts.parentRef, "project", "", "project id or full path")
|
||||
flags.StringVarP(&variableCreateOpts.name, "name", "n", "", "variable name")
|
||||
flags.StringVar(&variableCreateOpts.values, "values", "", "json list of values and conditions")
|
||||
|
||||
cmdProjectVariableCreate.MarkFlagRequired("project")
|
||||
cmdProjectVariableCreate.MarkFlagRequired("name")
|
||||
cmdProjectVariableCreate.MarkFlagRequired("values")
|
||||
|
||||
cmdProjectVariable.AddCommand(cmdProjectVariableCreate)
|
||||
}
|
||||
|
||||
func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||
gwclient := api.NewClient(gatewayURL, token)
|
||||
|
||||
var values []types.VariableValue
|
||||
if err := json.Unmarshal([]byte(variableCreateOpts.values), &values); err != nil {
|
||||
log.Fatalf("failed to unmarshall values: %v", err)
|
||||
}
|
||||
req := &api.CreateVariableRequest{
|
||||
Name: variableCreateOpts.name,
|
||||
Values: values,
|
||||
}
|
||||
|
||||
switch ownertype {
|
||||
case "project":
|
||||
log.Infof("creating project variable")
|
||||
variable, _, err := gwclient.CreateProjectVariable(context.TODO(), variableCreateOpts.parentRef, req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create project variable")
|
||||
}
|
||||
log.Infof("project variable %q created, ID: %q", variable.Name, variable.ID)
|
||||
case "projectgroup":
|
||||
log.Infof("creating project group variable")
|
||||
variable, _, err := gwclient.CreateProjectGroupVariable(context.TODO(), variableCreateOpts.parentRef, req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create project group variable")
|
||||
}
|
||||
log.Infof("project group variable %q created, ID: %q", variable.Name, variable.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -108,21 +108,21 @@ func (c *Client) getParsedResponse(ctx context.Context, method, path string, que
|
|||
return resp, d.Decode(obj)
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupID string) (*types.ProjectGroup, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupRef string) (*types.ProjectGroup, *http.Response, error) {
|
||||
projectGroup := new(types.ProjectGroup)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupID)), nil, jsonContent, nil, projectGroup)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, projectGroup)
|
||||
return projectGroup, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupID string) ([]*types.ProjectGroup, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*types.ProjectGroup, *http.Response, error) {
|
||||
projectGroups := []*types.ProjectGroup{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/subgroups", url.PathEscape(projectGroupID)), nil, jsonContent, nil, &projectGroups)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/subgroups", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projectGroups)
|
||||
return projectGroups, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupID string) ([]*types.Project, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*types.Project, *http.Response, error) {
|
||||
projects := []*types.Project{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/projects", url.PathEscape(projectGroupID)), nil, jsonContent, nil, &projects)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/projects", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projects)
|
||||
return projects, resp, err
|
||||
}
|
||||
|
||||
|
@ -137,9 +137,9 @@ func (c *Client) CreateProjectGroup(ctx context.Context, projectGroup *types.Pro
|
|||
return projectGroup, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProject(ctx context.Context, projectID string) (*types.Project, *http.Response, error) {
|
||||
func (c *Client) GetProject(ctx context.Context, projectRef string) (*types.Project, *http.Response, error) {
|
||||
project := new(types.Project)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectID)), nil, jsonContent, nil, project)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil, project)
|
||||
return project, resp, err
|
||||
}
|
||||
|
||||
|
@ -154,8 +154,8 @@ func (c *Client) CreateProject(ctx context.Context, project *types.Project) (*ty
|
|||
return project, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteProject(ctx context.Context, projectID string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s", url.PathEscape(projectID)), nil, jsonContent, nil)
|
||||
func (c *Client) DeleteProject(ctx context.Context, projectRef string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupSecrets(ctx context.Context, projectGroupRef string, tree bool) ([]*types.Secret, *http.Response, error) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/sorintlab/agola/internal/services/configstore/command"
|
||||
"github.com/sorintlab/agola/internal/services/configstore/readdb"
|
||||
"github.com/sorintlab/agola/internal/services/types"
|
||||
"github.com/sorintlab/agola/internal/util"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"go.uber.org/zap"
|
||||
|
@ -107,6 +108,8 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
|||
variable.Parent.Type = parentType
|
||||
variable.Parent.ID = parentRef
|
||||
|
||||
h.log.Infof("variable: %s", util.Dump(variable))
|
||||
|
||||
variable, err = h.ch.CreateVariable(ctx, variable)
|
||||
if httpError(w, err) {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
|
|
|
@ -1007,6 +1007,9 @@ func (s *CommandHandler) CreateVariable(ctx context.Context, variable *types.Var
|
|||
if variable.Name == "" {
|
||||
return nil, util.NewErrBadRequest(errors.Errorf("variable name required"))
|
||||
}
|
||||
if len(variable.Values) == 0 {
|
||||
return nil, util.NewErrBadRequest(errors.Errorf("variable values required"))
|
||||
}
|
||||
if variable.Parent.Type == "" {
|
||||
return nil, util.NewErrBadRequest(errors.Errorf("variable parent type required"))
|
||||
}
|
||||
|
|
|
@ -113,27 +113,27 @@ func (c *Client) getParsedResponse(ctx context.Context, method, path string, que
|
|||
return resp, d.Decode(obj)
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupID string) (*ProjectGroupResponse, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupRef string) (*ProjectGroupResponse, *http.Response, error) {
|
||||
projectGroup := new(ProjectGroupResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupID)), nil, jsonContent, nil, projectGroup)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, projectGroup)
|
||||
return projectGroup, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupID string) ([]*ProjectGroupResponse, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*ProjectGroupResponse, *http.Response, error) {
|
||||
projectGroups := []*ProjectGroupResponse{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/subgroups", url.PathEscape(projectGroupID)), nil, jsonContent, nil, &projectGroups)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/subgroups", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projectGroups)
|
||||
return projectGroups, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupID string) ([]*ProjectResponse, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*ProjectResponse, *http.Response, error) {
|
||||
projects := []*ProjectResponse{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/projects", url.PathEscape(projectGroupID)), nil, jsonContent, nil, &projects)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/projects", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projects)
|
||||
return projects, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProject(ctx context.Context, projectID string) (*types.Project, *http.Response, error) {
|
||||
func (c *Client) GetProject(ctx context.Context, projectRef string) (*types.Project, *http.Response, error) {
|
||||
project := new(types.Project)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectID)), nil, jsonContent, nil, project)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil, project)
|
||||
return project, resp, err
|
||||
}
|
||||
|
||||
|
@ -159,65 +159,56 @@ func (c *Client) CreateProject(ctx context.Context, req *CreateProjectRequest) (
|
|||
return project, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupID string, req *CreateSecretRequest) (*SecretResponse, *http.Response, error) {
|
||||
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupRef string, req *CreateSecretRequest) (*SecretResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
secret := new(SecretResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", projectGroupID, "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
||||
return secret, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectSecret(ctx context.Context, projectID string, req *CreateSecretRequest) (*SecretResponse, *http.Response, error) {
|
||||
func (c *Client) CreateProjectSecret(ctx context.Context, projectRef string, req *CreateSecretRequest) (*SecretResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
secret := new(SecretResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", projectID, "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", url.PathEscape(projectRef), "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
||||
return secret, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) createSecret(ctx context.Context, containertype, containerid string, req *CreateSecretRequest) (*SecretResponse, *http.Response, error) {
|
||||
func (c *Client) CreateProjectGroupVariable(ctx context.Context, projectGroupRef string, req *CreateVariableRequest) (*VariableResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var basepath string
|
||||
switch containertype {
|
||||
case "project":
|
||||
basepath = "projects"
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("invalid container type")
|
||||
variable := new(VariableResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "variables"), nil, jsonContent, bytes.NewReader(reqj), variable)
|
||||
return variable, resp, err
|
||||
}
|
||||
|
||||
secret := new(SecretResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/", basepath, containerid, "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
||||
return secret, resp, err
|
||||
func (c *Client) CreateProjectVariable(ctx context.Context, projectRef string, req *CreateVariableRequest) (*VariableResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteCurrentUserProject(ctx context.Context, projectName string) (*http.Response, error) {
|
||||
return c.deleteProject(ctx, "user", "", projectName)
|
||||
variable := new(VariableResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", url.PathEscape(projectRef), "variables"), nil, jsonContent, bytes.NewReader(reqj), variable)
|
||||
return variable, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteUserProject(ctx context.Context, username, projectName string) (*http.Response, error) {
|
||||
return c.deleteProject(ctx, "user", username, projectName)
|
||||
func (c *Client) DeleteProject(ctx context.Context, projectRef string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteOrgProject(ctx context.Context, orgname, projectName string) (*http.Response, error) {
|
||||
return c.deleteProject(ctx, "org", orgname, projectName)
|
||||
}
|
||||
|
||||
func (c *Client) deleteProject(ctx context.Context, ownertype, ownername, projectName string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "DELETE", path.Join("/projects", ownertype, ownername, projectName), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) ReconfigProject(ctx context.Context, projectName string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "POST", fmt.Sprintf("/projects/%s/reconfig", projectName), nil, jsonContent, nil)
|
||||
func (c *Client) ReconfigProject(ctx context.Context, projectRef string) (*http.Response, error) {
|
||||
return c.getResponse(ctx, "POST", fmt.Sprintf("/projects/%s/reconfig", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetUser(ctx context.Context, userID string) (*types.User, *http.Response, error) {
|
||||
|
|
|
@ -141,10 +141,7 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
type CreateVariableRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
SecretName string `json:"secret_name,omitempty"`
|
||||
SecretVar string `json:"secret_var,omitempty"`
|
||||
|
||||
When *types.When `json:"when,omitempty"`
|
||||
Values []types.VariableValue `json:"values,omitempty"`
|
||||
}
|
||||
|
||||
type CreateVariableHandler struct {
|
||||
|
@ -177,12 +174,19 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
|||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(req.Values) == 0 {
|
||||
err := errors.Errorf("empty variable values")
|
||||
h.log.Errorf("err: %+v", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
v := &types.Variable{
|
||||
Name: req.Name,
|
||||
Parent: types.Parent{
|
||||
Type: parentType,
|
||||
ID: parentRef,
|
||||
},
|
||||
Values: req.Values,
|
||||
}
|
||||
|
||||
var cssecrets []*types.Secret
|
||||
|
|
Loading…
Reference in New Issue