Skip to content

Commit

Permalink
fix(sdk): import project vcs interface (#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored Sep 28, 2022
1 parent dfb0e98 commit 007aeae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
17 changes: 11 additions & 6 deletions cli/cdsctl/experimental_project_vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

yaml "github.com/ghodss/yaml"
"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/cdsclient"
)

Expand Down Expand Up @@ -71,18 +72,22 @@ var projectVCSImportCmd = cli.Command{
}

func projectVCSImportFunc(v cli.Values) error {
f, err := os.Open(v.GetString("filename"))
var mods []cdsclient.RequestModifier
if v.GetBool("force") {
mods = append(mods, cdsclient.Force())
}

btes, err := os.ReadFile(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())
var content sdk.VCSProject
if err := yaml.Unmarshal(btes, &content); err != nil {
return cli.WrapError(err, "unable to parse file %s", v.GetString("filename"))
}

_, err = client.ProjectVCSImport(context.Background(), v.GetString(_ProjectKey), f, mods...)
_, err = client.ProjectVCSImport(context.Background(), v.GetString(_ProjectKey), content, mods...)
return err
}

Expand Down
16 changes: 1 addition & 15 deletions sdk/cdsclient/client_project_vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package cdsclient
import (
"context"
"fmt"
"io"
"net/url"

"github.com/ghodss/yaml"

"github.com/ovh/cds/sdk"
)

Expand Down Expand Up @@ -38,18 +35,7 @@ func (c *client) ProjectVCSDelete(ctx context.Context, projectKey string, vcsNam
return nil
}

func (c *client) ProjectVCSImport(ctx context.Context, projectKey string, content io.Reader, mods ...RequestModifier) (sdk.VCSProject, error) {
var vcsProject sdk.VCSProject

body, err := io.ReadAll(content)
if err != nil {
return vcsProject, err
}

if err := yaml.Unmarshal(body, &vcsProject); err != nil {
return vcsProject, err
}

func (c *client) ProjectVCSImport(ctx context.Context, projectKey string, vcsProject sdk.VCSProject, mods ...RequestModifier) (sdk.VCSProject, error) {
oldvcs, _ := c.ProjectVCSGet(ctx, projectKey, vcsProject.Name)
if oldvcs.Name == "" {
path := fmt.Sprintf("/v2/project/%s/vcs", projectKey)
Expand Down
25 changes: 13 additions & 12 deletions sdk/cdsclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ 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)
ProjectVCSImport(ctx context.Context, projectKey string, vcs sdk.VCSProject, 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, vcsName string) error
Expand Down Expand Up @@ -494,18 +494,19 @@ type GRPCPluginsClient interface {
PluginGetBinaryInfos(name, os, arch string) (*sdk.GRPCPluginBinary, error)
}

/* ProviderClient exposes allowed methods for providers
Usage:
/*
ProviderClient exposes allowed methods for providers
Usage:
cfg := ProviderConfig{
Host: "https://my-cds-api:8081",
Name: "my-provider-name",
Token: "my-very-long-secret-token",
}
client := NewProviderClient(cfg)
//Get the writable projects of a user
projects, err := client.ProjectsList(FilterByUser("a-username"), FilterByWritablePermission())
...
cfg := ProviderConfig{
Host: "https://my-cds-api:8081",
Name: "my-provider-name",
Token: "my-very-long-secret-token",
}
client := NewProviderClient(cfg)
//Get the writable projects of a user
projects, err := client.ProjectsList(FilterByUser("a-username"), FilterByWritablePermission())
...
*/
type ProviderClient interface {
ApplicationsList(projectKey string, opts ...RequestModifier) ([]sdk.Application, error)
Expand Down
16 changes: 8 additions & 8 deletions sdk/cdsclient/mock_cdsclient/interface_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 007aeae

Please sign in to comment.