diff --git a/Makefile b/Makefile index be2b82e080..47a25903b7 100644 --- a/Makefile +++ b/Makefile @@ -115,3 +115,5 @@ tidy: done; @echo "Running tidy on tests/fixtures/04SCWorkflowRunSimplePlugin" @(cd tests/fixtures/04SCWorkflowRunSimplePlugin && go mod tidy) + @(cd sdk/interpolate && go mod tidy) + @(cd tools/smtpmock && go mod tidy) diff --git a/cli/cdsctl/experimental.go b/cli/cdsctl/experimental.go new file mode 100644 index 0000000000..a615d152a4 --- /dev/null +++ b/cli/cdsctl/experimental.go @@ -0,0 +1,24 @@ +package main + +import ( + "github.com/spf13/cobra" + + "github.com/ovh/cds/cli" +) + +var experimentalCmd = cli.Command{ + Name: "experimental", + Aliases: []string{"exp"}, + Short: "CDS Experimental commands", + Hidden: true, +} + +func experimentalCommands() []*cobra.Command { + return []*cobra.Command{ + experimentalProject(), + } +} + +func experimental() *cobra.Command { + return cli.NewCommand(experimentalCmd, nil, experimentalCommands()) +} diff --git a/cli/cdsctl/experimental_project.go b/cli/cdsctl/experimental_project.go new file mode 100644 index 0000000000..b080d9a0c1 --- /dev/null +++ b/cli/cdsctl/experimental_project.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/spf13/cobra" + + "github.com/ovh/cds/cli" +) + +var experimentalProjectCmd = cli.Command{ + Name: "project", + Short: "CDS Experimental project commands", +} + +func experimentalProject() *cobra.Command { + return cli.NewCommand(experimentalProjectCmd, nil, []*cobra.Command{ + projectVCS(), + }) +} diff --git a/cli/cdsctl/experimental_project_vcs.go b/cli/cdsctl/experimental_project_vcs.go new file mode 100644 index 0000000000..e9b58a2339 --- /dev/null +++ b/cli/cdsctl/experimental_project_vcs.go @@ -0,0 +1,114 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/spf13/cobra" + + yaml "github.com/ghodss/yaml" + "github.com/ovh/cds/cli" + "github.com/ovh/cds/sdk/cdsclient" +) + +var projectVCSCmd = cli.Command{ + Name: "vcs", + Aliases: []string{"vcs"}, + Short: "Manage VCS on a CDS project", +} + +func projectVCS() *cobra.Command { + return cli.NewCommand(projectVCSCmd, nil, []*cobra.Command{ + cli.NewListCommand(projectVCSListCmd, projectVCSListFunc, nil, withAllCommandModifiers()...), + cli.NewDeleteCommand(projectVCSDeleteCmd, projectVCSDeleteFunc, nil, withAllCommandModifiers()...), + cli.NewCommand(projectVCSImportCmd, projectVCSImportFunc, nil, withAllCommandModifiers()...), + cli.NewCommand(projectVCSExportCmd, projectVCSExportFunc, nil, withAllCommandModifiers()...), + }) +} + +var projectVCSListCmd = cli.Command{ + Name: "list", + Short: "List VCS available on a project", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + }, +} + +func projectVCSListFunc(v cli.Values) (cli.ListResult, error) { + pfs, err := client.ProjectVCSList(context.Background(), v.GetString(_ProjectKey)) + return cli.AsListResult(pfs), err +} + +var projectVCSDeleteCmd = cli.Command{ + Name: "delete", + Short: "Delete a VCS configuration on a project", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + }, + Args: []cli.Arg{ + {Name: "name"}, + }, +} + +func projectVCSDeleteFunc(v cli.Values) error { + return client.ProjectVCSDelete(context.Background(), v.GetString(_ProjectKey), v.GetString("name")) +} + +var projectVCSImportCmd = cli.Command{ + Name: "import", + Short: "Import a VCS configuration on a project from a yaml file", + Example: "cdsctl project vcs import MY-PROJECT file.yml", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + }, + Args: []cli.Arg{ + {Name: "filename"}, + }, + Flags: []cli.Flag{ + {Name: "force", Type: cli.FlagBool}, + }, +} + +func projectVCSImportFunc(v cli.Values) error { + f, err := os.Open(v.GetString("filename")) + if err != nil { + return cli.WrapError(err, "unable to open file %s", v.GetString("filename")) + } + defer f.Close() + + var mods []cdsclient.RequestModifier + if v.GetBool("force") { + mods = append(mods, cdsclient.Force()) + } + + _, err = client.ProjectVCSImport(context.Background(), v.GetString(_ProjectKey), f, mods...) + return err +} + +var projectVCSExportCmd = cli.Command{ + Name: "export", + Short: "Export a VCS configuration from a project to stdout", + Example: "cdsctl vcs export MY-PROJECT MY-VCS-SERVER-NAME > file.yaml", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + }, + Args: []cli.Arg{ + {Name: "name"}, + }, +} + +func projectVCSExportFunc(v cli.Values) error { + pf, err := client.ProjectVCSGet(context.Background(), v.GetString(_ProjectKey), v.GetString("name")) + if err != nil { + return err + } + + btes, err := yaml.Marshal(pf) + if err != nil { + return err + } + + fmt.Println(string(btes)) + return nil +} diff --git a/cli/cdsctl/main.go b/cli/cdsctl/main.go index 29313c74e3..419fd07623 100644 --- a/cli/cdsctl/main.go +++ b/cli/cdsctl/main.go @@ -28,6 +28,7 @@ func main() { encrypt(), contexts(), environment(), + experimental(), events(), group(), health(), diff --git a/cli/cdsctl/project_integration.go b/cli/cdsctl/project_integration.go index 2339336d00..9807b2342d 100644 --- a/cli/cdsctl/project_integration.go +++ b/cli/cdsctl/project_integration.go @@ -62,7 +62,7 @@ func projectIntegrationDeleteFunc(v cli.Values) error { var projectIntegrationImportCmd = cli.Command{ Name: "import", Short: "Import a integration configuration on a project from a yaml file", - Example: "cdsctl integration import MY-PROJECT file.yml", + Example: "cdsctl project integration import MY-PROJECT file.yml", Ctx: []cli.Arg{ {Name: _ProjectKey}, }, @@ -93,7 +93,7 @@ func projectIntegrationImportFunc(v cli.Values) error { var projectIntegrationExportCmd = cli.Command{ Name: "export", Short: "Export a integration configuration from a project to stdout", - Example: "cdsctl integration export MY-PROJECT MY-INTEGRATION-NAME > file.yaml", + Example: "cdsctl project integration export MY-PROJECT MY-INTEGRATION-NAME > file.yaml", Ctx: []cli.Arg{ {Name: _ProjectKey}, }, diff --git a/contrib/grpcplugins/action/plugin-archive/go.sum b/contrib/grpcplugins/action/plugin-archive/go.sum index 77e04ce489..da476fafa5 100644 --- a/contrib/grpcplugins/action/plugin-archive/go.sum +++ b/contrib/grpcplugins/action/plugin-archive/go.sum @@ -112,7 +112,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-artifactory-release-bundle-create/go.sum b/contrib/grpcplugins/action/plugin-artifactory-release-bundle-create/go.sum index 20b933f5ff..16879e5301 100644 --- a/contrib/grpcplugins/action/plugin-artifactory-release-bundle-create/go.sum +++ b/contrib/grpcplugins/action/plugin-artifactory-release-bundle-create/go.sum @@ -113,7 +113,6 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v0.0.0-20180910192245-6acdf747ae99/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= diff --git a/contrib/grpcplugins/action/plugin-artifactory-release-bundle-distribute/go.sum b/contrib/grpcplugins/action/plugin-artifactory-release-bundle-distribute/go.sum index b5843c7d08..3270d5a93b 100644 --- a/contrib/grpcplugins/action/plugin-artifactory-release-bundle-distribute/go.sum +++ b/contrib/grpcplugins/action/plugin-artifactory-release-bundle-distribute/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-download/go.sum b/contrib/grpcplugins/action/plugin-download/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/contrib/grpcplugins/action/plugin-download/go.sum +++ b/contrib/grpcplugins/action/plugin-download/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-group-tmpl/go.sum b/contrib/grpcplugins/action/plugin-group-tmpl/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/contrib/grpcplugins/action/plugin-group-tmpl/go.sum +++ b/contrib/grpcplugins/action/plugin-group-tmpl/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-kafka-publish/go.sum b/contrib/grpcplugins/action/plugin-kafka-publish/go.sum index 618a3e80ec..6c7bd90456 100644 --- a/contrib/grpcplugins/action/plugin-kafka-publish/go.sum +++ b/contrib/grpcplugins/action/plugin-kafka-publish/go.sum @@ -122,7 +122,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-marathon/go.mod b/contrib/grpcplugins/action/plugin-marathon/go.mod index 43392d2e29..0a4e7ead22 100644 --- a/contrib/grpcplugins/action/plugin-marathon/go.mod +++ b/contrib/grpcplugins/action/plugin-marathon/go.mod @@ -32,6 +32,7 @@ require ( github.com/emirpasic/gods v1.12.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsamin/go-dump v1.0.9 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-git/gcfg v1.5.0 // indirect github.com/go-git/go-billy/v5 v5.3.1 // indirect github.com/go-git/go-git/v5 v5.4.2 // indirect diff --git a/contrib/grpcplugins/action/plugin-marathon/go.sum b/contrib/grpcplugins/action/plugin-marathon/go.sum index 4457a36e8c..849fc684e7 100644 --- a/contrib/grpcplugins/action/plugin-marathon/go.sum +++ b/contrib/grpcplugins/action/plugin-marathon/go.sum @@ -116,7 +116,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -213,6 +212,7 @@ github.com/fujiwara/shapeio v0.0.0-20170602072123-c073257dd745/go.mod h1:/WpqsrS github.com/gambol99/go-marathon v0.0.0-20170922093320-ec4a50170df7/go.mod h1:GLyXJD41gBO/NPKVPGQbhyyC06eugGy15QEZyUkE2/s= github.com/gambol99/go-marathon v0.7.1 h1:/dnwXQ0W0UDScpvmcdjzRz3ssnJ/5ieX/q4Xi/QHOn4= github.com/gambol99/go-marathon v0.7.1/go.mod h1:GLyXJD41gBO/NPKVPGQbhyyC06eugGy15QEZyUkE2/s= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= diff --git a/contrib/grpcplugins/action/plugin-npm-audit-parser/go.sum b/contrib/grpcplugins/action/plugin-npm-audit-parser/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/contrib/grpcplugins/action/plugin-npm-audit-parser/go.sum +++ b/contrib/grpcplugins/action/plugin-npm-audit-parser/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-ssh-cmd/go.sum b/contrib/grpcplugins/action/plugin-ssh-cmd/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/contrib/grpcplugins/action/plugin-ssh-cmd/go.sum +++ b/contrib/grpcplugins/action/plugin-ssh-cmd/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-tmpl/go.sum b/contrib/grpcplugins/action/plugin-tmpl/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/contrib/grpcplugins/action/plugin-tmpl/go.sum +++ b/contrib/grpcplugins/action/plugin-tmpl/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/contrib/grpcplugins/action/plugin-venom/go.sum b/contrib/grpcplugins/action/plugin-venom/go.sum index de2264eb19..dee68fee59 100644 --- a/contrib/grpcplugins/action/plugin-venom/go.sum +++ b/contrib/grpcplugins/action/plugin-venom/go.sum @@ -116,7 +116,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A= github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= diff --git a/engine/api/v2_project.go b/engine/api/v2_project.go index 80ccedbb35..cc0ca8785d 100644 --- a/engine/api/v2_project.go +++ b/engine/api/v2_project.go @@ -80,6 +80,8 @@ func (api *API) putVCSProjectHandler() ([]service.RbacChecker, service.Handler) } vcsProject.ID = vcsOld.ID + vcsProject.Created = vcsOld.Created + vcsProject.CreatedBy = vcsOld.CreatedBy if err := vcs.Update(ctx, tx, &vcsProject); err != nil { return err diff --git a/sdk/cdsclient/client_project_vcs.go b/sdk/cdsclient/client_project_vcs.go new file mode 100644 index 0000000000..822d6055d2 --- /dev/null +++ b/sdk/cdsclient/client_project_vcs.go @@ -0,0 +1,66 @@ +package cdsclient + +import ( + "context" + "fmt" + "io" + + "github.com/ghodss/yaml" + + "github.com/ovh/cds/sdk" +) + +func (c *client) ProjectVCSGet(ctx context.Context, projectKey string, vcsName string) (sdk.VCSProject, error) { + path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, vcsName) + var pf sdk.VCSProject + if _, err := c.GetJSON(ctx, path, &pf); err != nil { + return pf, err + } + return pf, nil +} + +func (c *client) ProjectVCSList(ctx context.Context, projectKey string) ([]sdk.VCSProject, error) { + path := fmt.Sprintf("/v2/project/%s/vcs", projectKey) + var pfs []sdk.VCSProject + if _, err := c.GetJSON(ctx, path, &pfs); err != nil { + return pfs, err + } + return pfs, nil +} + +func (c *client) ProjectVCSDelete(ctx context.Context, projectKey string, vcsName string) error { + path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, vcsName) + var pf sdk.VCSProject + if _, err := c.DeleteJSON(ctx, path, &pf); err != nil { + return err + } + return nil +} + +func (c *client) ProjectVCSImport(ctx context.Context, projectKey string, content io.Reader, mods ...RequestModifier) (sdk.VCSProject, error) { + var pf sdk.VCSProject + + body, err := io.ReadAll(content) + if err != nil { + return pf, err + } + + if err := yaml.Unmarshal(body, &pf); err != nil { + return pf, err + } + + oldvcs, _ := c.ProjectVCSGet(ctx, projectKey, pf.Name) + if oldvcs.Name == "" { + path := fmt.Sprintf("/v2/project/%s/vcs", projectKey) + if _, err := c.PostJSON(ctx, path, &pf, &pf, mods...); err != nil { + return pf, err + } + return pf, nil + } + + path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, pf.Name) + if _, err := c.PutJSON(ctx, path, &pf, &pf, mods...); err != nil { + return pf, err + } + return pf, nil +} diff --git a/sdk/cdsclient/interface.go b/sdk/cdsclient/interface.go index efc8ba7e52..d64450e101 100644 --- a/sdk/cdsclient/interface.go +++ b/sdk/cdsclient/interface.go @@ -226,6 +226,10 @@ type ProjectClient interface { ProjectAccess(ctx context.Context, projectKey, sessionID string, itemType sdk.CDNItemType) error ProjectIntegrationWorkerHookGet(projectKey string, integrationName string) (*sdk.WorkerHookProjectIntegrationModel, error) ProjectIntegrationWorkerHooksImport(projectKey string, integrationName string, hook sdk.WorkerHookProjectIntegrationModel) error + ProjectVCSImport(ctx context.Context, projectKey string, content io.Reader, mods ...RequestModifier) (sdk.VCSProject, error) + ProjectVCSGet(ctx context.Context, projectKey string, integrationName string) (sdk.VCSProject, error) + ProjectVCSList(ctx context.Context, projectKey string) ([]sdk.VCSProject, error) + ProjectVCSDelete(ctx context.Context, projectKey string, integrationName string) error } // ProjectKeysClient exposes project keys related functions diff --git a/sdk/cdsclient/mock_cdsclient/interface_mock.go b/sdk/cdsclient/mock_cdsclient/interface_mock.go index 43e5aaefc3..8fc2046fac 100644 --- a/sdk/cdsclient/mock_cdsclient/interface_mock.go +++ b/sdk/cdsclient/mock_cdsclient/interface_mock.go @@ -2687,6 +2687,70 @@ func (mr *MockProjectClientMockRecorder) ProjectUpdate(key, project interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectUpdate", reflect.TypeOf((*MockProjectClient)(nil).ProjectUpdate), key, project) } +// ProjectVCSDelete mocks base method. +func (m *MockProjectClient) ProjectVCSDelete(ctx context.Context, projectKey, integrationName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSDelete", ctx, projectKey, integrationName) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProjectVCSDelete indicates an expected call of ProjectVCSDelete. +func (mr *MockProjectClientMockRecorder) ProjectVCSDelete(ctx, projectKey, integrationName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSDelete", reflect.TypeOf((*MockProjectClient)(nil).ProjectVCSDelete), ctx, projectKey, integrationName) +} + +// ProjectVCSGet mocks base method. +func (m *MockProjectClient) ProjectVCSGet(ctx context.Context, projectKey, integrationName string) (sdk.VCSProject, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSGet", ctx, projectKey, integrationName) + ret0, _ := ret[0].(sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSGet indicates an expected call of ProjectVCSGet. +func (mr *MockProjectClientMockRecorder) ProjectVCSGet(ctx, projectKey, integrationName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSGet", reflect.TypeOf((*MockProjectClient)(nil).ProjectVCSGet), ctx, projectKey, integrationName) +} + +// ProjectVCSImport mocks base method. +func (m *MockProjectClient) ProjectVCSImport(ctx context.Context, projectKey string, content io.Reader, mods ...cdsclient.RequestModifier) (sdk.VCSProject, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, projectKey, content} + for _, a := range mods { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ProjectVCSImport", varargs...) + ret0, _ := ret[0].(sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSImport indicates an expected call of ProjectVCSImport. +func (mr *MockProjectClientMockRecorder) ProjectVCSImport(ctx, projectKey, content interface{}, mods ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, projectKey, content}, mods...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSImport", reflect.TypeOf((*MockProjectClient)(nil).ProjectVCSImport), varargs...) +} + +// ProjectVCSList mocks base method. +func (m *MockProjectClient) ProjectVCSList(ctx context.Context, projectKey string) ([]sdk.VCSProject, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSList", ctx, projectKey) + ret0, _ := ret[0].([]sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSList indicates an expected call of ProjectVCSList. +func (mr *MockProjectClientMockRecorder) ProjectVCSList(ctx, projectKey interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSList", reflect.TypeOf((*MockProjectClient)(nil).ProjectVCSList), ctx, projectKey) +} + // ProjectVariableCreate mocks base method. func (m *MockProjectClient) ProjectVariableCreate(projectKey string, variable *sdk.Variable) error { m.ctrl.T.Helper() @@ -6788,6 +6852,70 @@ func (mr *MockInterfaceMockRecorder) ProjectUpdate(key, project interface{}) *go return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectUpdate", reflect.TypeOf((*MockInterface)(nil).ProjectUpdate), key, project) } +// ProjectVCSDelete mocks base method. +func (m *MockInterface) ProjectVCSDelete(ctx context.Context, projectKey, integrationName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSDelete", ctx, projectKey, integrationName) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProjectVCSDelete indicates an expected call of ProjectVCSDelete. +func (mr *MockInterfaceMockRecorder) ProjectVCSDelete(ctx, projectKey, integrationName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSDelete", reflect.TypeOf((*MockInterface)(nil).ProjectVCSDelete), ctx, projectKey, integrationName) +} + +// ProjectVCSGet mocks base method. +func (m *MockInterface) ProjectVCSGet(ctx context.Context, projectKey, integrationName string) (sdk.VCSProject, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSGet", ctx, projectKey, integrationName) + ret0, _ := ret[0].(sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSGet indicates an expected call of ProjectVCSGet. +func (mr *MockInterfaceMockRecorder) ProjectVCSGet(ctx, projectKey, integrationName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSGet", reflect.TypeOf((*MockInterface)(nil).ProjectVCSGet), ctx, projectKey, integrationName) +} + +// ProjectVCSImport mocks base method. +func (m *MockInterface) ProjectVCSImport(ctx context.Context, projectKey string, content io.Reader, mods ...cdsclient.RequestModifier) (sdk.VCSProject, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, projectKey, content} + for _, a := range mods { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ProjectVCSImport", varargs...) + ret0, _ := ret[0].(sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSImport indicates an expected call of ProjectVCSImport. +func (mr *MockInterfaceMockRecorder) ProjectVCSImport(ctx, projectKey, content interface{}, mods ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, projectKey, content}, mods...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSImport", reflect.TypeOf((*MockInterface)(nil).ProjectVCSImport), varargs...) +} + +// ProjectVCSList mocks base method. +func (m *MockInterface) ProjectVCSList(ctx context.Context, projectKey string) ([]sdk.VCSProject, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectVCSList", ctx, projectKey) + ret0, _ := ret[0].([]sdk.VCSProject) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectVCSList indicates an expected call of ProjectVCSList. +func (mr *MockInterfaceMockRecorder) ProjectVCSList(ctx, projectKey interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectVCSList", reflect.TypeOf((*MockInterface)(nil).ProjectVCSList), ctx, projectKey) +} + // ProjectVariableCreate mocks base method. func (m *MockInterface) ProjectVariableCreate(projectKey string, variable *sdk.Variable) error { m.ctrl.T.Helper() diff --git a/sdk/vcs.go b/sdk/vcs.go index cbdf7f6f71..c93af6039d 100644 --- a/sdk/vcs.go +++ b/sdk/vcs.go @@ -180,7 +180,7 @@ type BuildNumberAndHash struct { type VCSProject struct { ID string `json:"id" db:"id"` - Name string `json:"name" db:"name"` + Name string `json:"name" db:"name" cli:"name,key"` Type string `json:"type" db:"type"` Created time.Time `json:"created" db:"created"` LastModified time.Time `json:"last_modified" db:"last_modified"` diff --git a/tests/03_clictl_project_vcs.yml b/tests/03_clictl_project_vcs.yml new file mode 100644 index 0000000000..740a994a08 --- /dev/null +++ b/tests/03_clictl_project_vcs.yml @@ -0,0 +1,27 @@ +name: Project VCS Command TestSuite +testcases: +- name: prepare test + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} project remove --force ITCLIPRJVCS + - script: {{.cdsctl}} -f {{.cdsctl.config}} group remove ITCLIPRJVCS --force + - script: {{.cdsctl}} -f {{.cdsctl.config}} group add ITCLIPRJVCS + - script: {{.cdsctl}} -f {{.cdsctl.config}} project create ITCLIPRJVCS "Test Project" ITCLIPRJVCS + +- name: import / export vcs server + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} experimental project vcs import ITCLIPRJVCS ./fixtures/my_vcs_project.yml + - script: {{.cdsctl}} -f {{.cdsctl.config}} experimental project vcs list ITCLIPRJVCS --format json + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.systemoutjson0.name ShouldEqual "my_vcs_server" + - script: {{.cdsctl}} -f {{.cdsctl.config}} experimental project vcs export ITCLIPRJVCS my_vcs_server > my_vcs_project_exported.yml + - script: grep 'my_vcs_server' my_vcs_project_exported.yml + +- name: delete vcs project + steps: + - script: rm my_vcs_project_exported.yml + - script: {{.cdsctl}} -f {{.cdsctl.config}} experimental project vcs delete ITCLIPRJVCS my_vcs_server --force + - script: {{.cdsctl}} -f {{.cdsctl.config}} experimental project vcs list ITCLIPRJVCS --format json + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.systemoutjson0.name ShouldNotEqual "my_vcs_server" diff --git a/tests/fixtures/04SCWorkflowRunSimplePlugin/go.sum b/tests/fixtures/04SCWorkflowRunSimplePlugin/go.sum index 13f877387c..2f2f4b6ec3 100644 --- a/tests/fixtures/04SCWorkflowRunSimplePlugin/go.sum +++ b/tests/fixtures/04SCWorkflowRunSimplePlugin/go.sum @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/tests/fixtures/my_vcs_project.yml b/tests/fixtures/my_vcs_project.yml new file mode 100644 index 0000000000..c0a15e2b9b --- /dev/null +++ b/tests/fixtures/my_vcs_project.yml @@ -0,0 +1,8 @@ +version: v1.0 +name: my_vcs_server +type: bitbucketserver +description: "it's the test vcs server on project" +url: "http://my-vcs-server.localhost" +auth: + user: the-username + password: the-password \ No newline at end of file