From fd26e617b37d8edea92a261e8a2cccffc4942601 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 31 Jul 2019 15:17:54 +0200 Subject: [PATCH] configstore: move configstore types inside configstore package Since they're not types common to all the services but belongs to the configstore. Next step will be to make them local to the configstore and not directly used by other services since these types are also stored. --- cmd/agola/cmd/orgcreate.go | 6 +- cmd/agola/cmd/orgmemberadd.go | 4 +- cmd/agola/cmd/projectcreate.go | 6 +- cmd/agola/cmd/projectgroupcreate.go | 6 +- cmd/agola/cmd/projectsecretcreate.go | 4 +- cmd/agola/cmd/projectsecretupdate.go | 4 +- cmd/agola/cmd/projectvariablecreate.go | 8 +-- cmd/agola/cmd/projectvariableupdate.go | 8 +-- cmd/agola/cmd/remotesourcecreate.go | 4 +- internal/config/config.go | 20 +++--- internal/config/config_test.go | 2 +- internal/runconfig/runconfig.go | 8 +-- internal/runconfig/runconfig_test.go | 12 ++-- internal/services/common/gitsource.go | 40 ++++++------ internal/services/common/variables.go | 4 +- internal/services/common/variables_test.go | 62 +++++++++---------- internal/services/configstore/action/org.go | 2 +- .../services/configstore/action/project.go | 2 +- .../configstore/action/projectgroup.go | 2 +- .../configstore/action/remotesource.go | 2 +- .../services/configstore/action/secret.go | 2 +- internal/services/configstore/action/user.go | 2 +- .../services/configstore/action/variable.go | 2 +- internal/services/configstore/api/api.go | 2 +- internal/services/configstore/api/client.go | 2 +- internal/services/configstore/api/org.go | 2 +- internal/services/configstore/api/project.go | 2 +- .../services/configstore/api/projectgroup.go | 2 +- .../services/configstore/api/remotesource.go | 2 +- internal/services/configstore/api/secret.go | 2 +- internal/services/configstore/api/user.go | 2 +- internal/services/configstore/api/variable.go | 2 +- internal/services/configstore/configstore.go | 2 +- .../services/configstore/configstore_test.go | 2 +- internal/services/configstore/readdb/org.go | 2 +- .../services/configstore/readdb/project.go | 2 +- .../configstore/readdb/projectgroup.go | 2 +- .../services/configstore/readdb/readdb.go | 2 +- .../configstore/readdb/remotesource.go | 2 +- .../services/configstore/readdb/resolve.go | 2 +- .../services/configstore/readdb/secret.go | 2 +- internal/services/configstore/readdb/user.go | 2 +- .../services/configstore/readdb/variable.go | 2 +- .../services/{ => configstore}/types/types.go | 0 .../{ => configstore}/types/types_test.go | 0 internal/services/gateway/action/auth.go | 40 ++++++------ internal/services/gateway/action/org.go | 26 ++++---- internal/services/gateway/action/project.go | 27 ++++---- .../services/gateway/action/projectgroup.go | 12 ++-- .../services/gateway/action/remotesource.go | 20 +++--- internal/services/gateway/action/run.go | 9 +-- internal/services/gateway/action/secret.go | 34 +++++----- internal/services/gateway/action/user.go | 33 +++++----- internal/services/gateway/action/variable.go | 38 ++++++------ internal/services/gateway/api/api.go | 8 +-- internal/services/gateway/api/client.go | 4 +- internal/services/gateway/api/org.go | 24 +++---- internal/services/gateway/api/project.go | 30 ++++----- internal/services/gateway/api/projectgroup.go | 24 +++---- internal/services/gateway/api/remoterepo.go | 4 +- internal/services/gateway/api/remotesource.go | 6 +- internal/services/gateway/api/secret.go | 8 +-- internal/services/gateway/api/user.go | 8 +-- internal/services/gateway/api/variable.go | 8 +-- internal/util/backoff.go | 2 +- tests/setup_test.go | 4 +- 66 files changed, 312 insertions(+), 309 deletions(-) rename internal/services/{ => configstore}/types/types.go (100%) rename internal/services/{ => configstore}/types/types_test.go (100%) diff --git a/cmd/agola/cmd/orgcreate.go b/cmd/agola/cmd/orgcreate.go index 97b43c9..e2dff6e 100644 --- a/cmd/agola/cmd/orgcreate.go +++ b/cmd/agola/cmd/orgcreate.go @@ -17,8 +17,8 @@ package cmd import ( "context" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/spf13/cobra" errors "golang.org/x/xerrors" @@ -58,13 +58,13 @@ func orgCreate(cmd *cobra.Command, args []string) error { gwclient := api.NewClient(gatewayURL, token) // TODO(sgotti) make this a custom pflag Value? - if !types.IsValidVisibility(types.Visibility(orgCreateOpts.visibility)) { + if !cstypes.IsValidVisibility(cstypes.Visibility(orgCreateOpts.visibility)) { return errors.Errorf("invalid visibility %q", orgCreateOpts.visibility) } req := &api.CreateOrgRequest{ Name: orgCreateOpts.name, - Visibility: types.Visibility(orgCreateOpts.visibility), + Visibility: cstypes.Visibility(orgCreateOpts.visibility), } log.Infof("creating org") diff --git a/cmd/agola/cmd/orgmemberadd.go b/cmd/agola/cmd/orgmemberadd.go index d9362d6..30d9ef2 100644 --- a/cmd/agola/cmd/orgmemberadd.go +++ b/cmd/agola/cmd/orgmemberadd.go @@ -17,8 +17,8 @@ package cmd import ( "context" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/spf13/cobra" errors "golang.org/x/xerrors" @@ -63,7 +63,7 @@ func orgMemberAdd(cmd *cobra.Command, args []string) error { gwclient := api.NewClient(gatewayURL, token) log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role) - _, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, types.MemberRole(orgMemberAddOpts.role)) + _, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, cstypes.MemberRole(orgMemberAddOpts.role)) if err != nil { return errors.Errorf("failed to add/update organization member: %w", err) } diff --git a/cmd/agola/cmd/projectcreate.go b/cmd/agola/cmd/projectcreate.go index 23ceeae..b238e99 100644 --- a/cmd/agola/cmd/projectcreate.go +++ b/cmd/agola/cmd/projectcreate.go @@ -17,8 +17,8 @@ package cmd import ( "context" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/spf13/cobra" errors "golang.org/x/xerrors" @@ -75,14 +75,14 @@ func projectCreate(cmd *cobra.Command, args []string) error { gwclient := api.NewClient(gatewayURL, token) // TODO(sgotti) make this a custom pflag Value? - if !types.IsValidVisibility(types.Visibility(projectCreateOpts.visibility)) { + if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) { return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility) } req := &api.CreateProjectRequest{ Name: projectCreateOpts.name, ParentRef: projectCreateOpts.parentPath, - Visibility: types.Visibility(projectCreateOpts.visibility), + Visibility: cstypes.Visibility(projectCreateOpts.visibility), RepoPath: projectCreateOpts.repoPath, RemoteSourceName: projectCreateOpts.remoteSourceName, SkipSSHHostKeyCheck: projectCreateOpts.skipSSHHostKeyCheck, diff --git a/cmd/agola/cmd/projectgroupcreate.go b/cmd/agola/cmd/projectgroupcreate.go index 2cbb52d..5b5a82f 100644 --- a/cmd/agola/cmd/projectgroupcreate.go +++ b/cmd/agola/cmd/projectgroupcreate.go @@ -17,8 +17,8 @@ package cmd import ( "context" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/spf13/cobra" errors "golang.org/x/xerrors" @@ -63,14 +63,14 @@ func projectGroupCreate(cmd *cobra.Command, args []string) error { gwclient := api.NewClient(gatewayURL, token) // TODO(sgotti) make this a custom pflag Value? - if !types.IsValidVisibility(types.Visibility(projectCreateOpts.visibility)) { + if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) { return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility) } req := &api.CreateProjectGroupRequest{ Name: projectGroupCreateOpts.name, ParentRef: projectGroupCreateOpts.parentPath, - Visibility: types.Visibility(projectCreateOpts.visibility), + Visibility: cstypes.Visibility(projectCreateOpts.visibility), } log.Infof("creating project group") diff --git a/cmd/agola/cmd/projectsecretcreate.go b/cmd/agola/cmd/projectsecretcreate.go index 9facfee..d249b97 100644 --- a/cmd/agola/cmd/projectsecretcreate.go +++ b/cmd/agola/cmd/projectsecretcreate.go @@ -19,8 +19,8 @@ import ( "io/ioutil" "os" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/ghodss/yaml" "github.com/spf13/cobra" @@ -96,7 +96,7 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error { } req := &api.CreateSecretRequest{ Name: secretCreateOpts.name, - Type: types.SecretTypeInternal, + Type: cstypes.SecretTypeInternal, Data: secretData, } diff --git a/cmd/agola/cmd/projectsecretupdate.go b/cmd/agola/cmd/projectsecretupdate.go index edf514d..b483fd9 100644 --- a/cmd/agola/cmd/projectsecretupdate.go +++ b/cmd/agola/cmd/projectsecretupdate.go @@ -19,8 +19,8 @@ import ( "io/ioutil" "os" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/ghodss/yaml" "github.com/spf13/cobra" @@ -98,7 +98,7 @@ func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error { } req := &api.UpdateSecretRequest{ Name: secretUpdateOpts.name, - Type: types.SecretTypeInternal, + Type: cstypes.SecretTypeInternal, Data: secretData, } diff --git a/cmd/agola/cmd/projectvariablecreate.go b/cmd/agola/cmd/projectvariablecreate.go index d219931..f3a2272 100644 --- a/cmd/agola/cmd/projectvariablecreate.go +++ b/cmd/agola/cmd/projectvariablecreate.go @@ -20,8 +20,8 @@ import ( "os" "agola.io/agola/internal/config" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/ghodss/yaml" "github.com/spf13/cobra" @@ -117,12 +117,12 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error { if err := yaml.Unmarshal(data, &values); err != nil { log.Fatalf("failed to unmarshal values: %v", err) } - rvalues := []types.VariableValue{} + rvalues := []cstypes.VariableValue{} for _, value := range values { - rvalues = append(rvalues, types.VariableValue{ + rvalues = append(rvalues, cstypes.VariableValue{ SecretName: value.SecretName, SecretVar: value.SecretVar, - When: (*types.When)(value.When), + When: (*cstypes.When)(value.When), }) } req := &api.CreateVariableRequest{ diff --git a/cmd/agola/cmd/projectvariableupdate.go b/cmd/agola/cmd/projectvariableupdate.go index 6f71219..aee4ae8 100644 --- a/cmd/agola/cmd/projectvariableupdate.go +++ b/cmd/agola/cmd/projectvariableupdate.go @@ -19,8 +19,8 @@ import ( "io/ioutil" "os" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "github.com/ghodss/yaml" "github.com/spf13/cobra" @@ -89,12 +89,12 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error { if err := yaml.Unmarshal(data, &values); err != nil { log.Fatalf("failed to unmarshall values: %v", err) } - rvalues := []types.VariableValue{} + rvalues := []cstypes.VariableValue{} for _, value := range values { - rvalues = append(rvalues, types.VariableValue{ + rvalues = append(rvalues, cstypes.VariableValue{ SecretName: value.SecretName, SecretVar: value.SecretVar, - When: (*types.When)(value.When), + When: (*cstypes.When)(value.When), }) } req := &api.UpdateVariableRequest{ diff --git a/cmd/agola/cmd/remotesourcecreate.go b/cmd/agola/cmd/remotesourcecreate.go index 3ebca9b..7707b9d 100644 --- a/cmd/agola/cmd/remotesourcecreate.go +++ b/cmd/agola/cmd/remotesourcecreate.go @@ -18,8 +18,8 @@ import ( "context" "agola.io/agola/internal/gitsources/github" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/api" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "github.com/spf13/cobra" @@ -84,7 +84,7 @@ func remoteSourceCreate(cmd *cobra.Command, args []string) error { gwclient := api.NewClient(gatewayURL, token) // for github remote source type, set defaults for github.com - if remoteSourceCreateOpts.rsType == string(types.RemoteSourceTypeGithub) { + if remoteSourceCreateOpts.rsType == string(cstypes.RemoteSourceTypeGithub) { remoteSourceCreateOpts.apiURL = github.GitHubAPIURL remoteSourceCreateOpts.sshHostKey = github.GitHubSSHHostKey } diff --git a/internal/config/config.go b/internal/config/config.go index effea09..822dca8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -21,7 +21,7 @@ import ( "strings" "agola.io/agola/internal/common" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/ghodss/yaml" @@ -445,7 +445,7 @@ func (val *Value) UnmarshalJSON(b []byte) error { return nil } -type When types.When +type When cstypes.When type when struct { Branch interface{} `json:"branch"` @@ -485,8 +485,8 @@ func (w *When) UnmarshalJSON(b []byte) error { return nil } -func parseWhenConditions(wi interface{}) (*types.WhenConditions, error) { - w := &types.WhenConditions{} +func parseWhenConditions(wi interface{}) (*cstypes.WhenConditions, error) { + w := &cstypes.WhenConditions{} var err error include := []string{} @@ -534,12 +534,12 @@ func parseWhenConditions(wi interface{}) (*types.WhenConditions, error) { return w, nil } -func parseWhenConditionSlice(conds []string) ([]types.WhenCondition, error) { +func parseWhenConditionSlice(conds []string) ([]cstypes.WhenCondition, error) { if len(conds) == 0 { return nil, nil } - wcs := []types.WhenCondition{} + wcs := []cstypes.WhenCondition{} for _, cond := range conds { wc, err := parseWhenCondition(cond) if err != nil { @@ -551,7 +551,7 @@ func parseWhenConditionSlice(conds []string) ([]types.WhenCondition, error) { return wcs, nil } -func parseWhenCondition(s string) (*types.WhenCondition, error) { +func parseWhenCondition(s string) (*cstypes.WhenCondition, error) { isRegExp := false if len(s) > 2 { for _, d := range regExpDelimiters { @@ -563,15 +563,15 @@ func parseWhenCondition(s string) (*types.WhenCondition, error) { } } - wc := &types.WhenCondition{Match: s} + wc := &cstypes.WhenCondition{Match: s} if isRegExp { if _, err := regexp.Compile(s); err != nil { return nil, errors.Errorf("wrong regular expression: %w", err) } - wc.Type = types.WhenConditionTypeRegExp + wc.Type = cstypes.WhenConditionTypeRegExp } else { - wc.Type = types.WhenConditionTypeSimple + wc.Type = cstypes.WhenConditionTypeSimple } return wc, nil } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 10a3663..6141e74 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -18,7 +18,7 @@ import ( "fmt" "testing" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/google/go-cmp/cmp" diff --git a/internal/runconfig/runconfig.go b/internal/runconfig/runconfig.go index 7981561..49a6d0b 100644 --- a/internal/runconfig/runconfig.go +++ b/internal/runconfig/runconfig.go @@ -19,8 +19,8 @@ import ( "strings" "agola.io/agola/internal/config" + cstypes "agola.io/agola/internal/services/configstore/types" rstypes "agola.io/agola/internal/services/runservice/types" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" @@ -48,11 +48,11 @@ func genRuntime(c *config.Config, ce *config.Runtime, variables map[string]strin } } -func whenFromConfigWhen(cw *config.When) *types.When { +func whenFromConfigWhen(cw *config.When) *cstypes.When { if cw == nil { return nil } - return &types.When{ + return &cstypes.When{ Branch: cw.Branch, Tag: cw.Tag, Ref: cw.Ref, @@ -194,7 +194,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string rcts := map[string]*rstypes.RunConfigTask{} for _, ct := range cr.Tasks { - include := types.MatchWhen(whenFromConfigWhen(ct.When), branch, tag, ref) + include := cstypes.MatchWhen(whenFromConfigWhen(ct.When), branch, tag, ref) steps := make(rstypes.Steps, len(ct.Steps)) for i, cpts := range ct.Steps { diff --git a/internal/runconfig/runconfig_test.go b/internal/runconfig/runconfig_test.go index fb594d7..30839a0 100644 --- a/internal/runconfig/runconfig_test.go +++ b/internal/runconfig/runconfig_test.go @@ -20,8 +20,8 @@ import ( "testing" "agola.io/agola/internal/config" + cstypes "agola.io/agola/internal/services/configstore/types" rstypes "agola.io/agola/internal/services/runservice/types" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "github.com/google/go-cmp/cmp" @@ -706,11 +706,11 @@ func TestGenRunConfig(t *testing.T) { IgnoreFailure: false, Approval: false, When: &config.When{ - Branch: &types.WhenConditions{Include: []types.WhenCondition{{Match: "master"}}}, - Tag: &types.WhenConditions{Include: []types.WhenCondition{{Match: "v1.x"}, {Match: "v2.x"}}}, - Ref: &types.WhenConditions{ - Include: []types.WhenCondition{{Match: "master"}}, - Exclude: []types.WhenCondition{{Match: "branch01", Type: types.WhenConditionTypeRegExp}, {Match: "branch02"}}, + Branch: &cstypes.WhenConditions{Include: []cstypes.WhenCondition{{Match: "master"}}}, + Tag: &cstypes.WhenConditions{Include: []cstypes.WhenCondition{{Match: "v1.x"}, {Match: "v2.x"}}}, + Ref: &cstypes.WhenConditions{ + Include: []cstypes.WhenCondition{{Match: "master"}}, + Exclude: []cstypes.WhenCondition{{Match: "branch01", Type: cstypes.WhenConditionTypeRegExp}, {Match: "branch02"}}, }, }, }, diff --git a/internal/services/common/gitsource.go b/internal/services/common/gitsource.go index 993e11e..7a7aa98 100644 --- a/internal/services/common/gitsource.go +++ b/internal/services/common/gitsource.go @@ -19,12 +19,12 @@ import ( "agola.io/agola/internal/gitsources/gitea" "agola.io/agola/internal/gitsources/github" "agola.io/agola/internal/gitsources/gitlab" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" errors "golang.org/x/xerrors" ) -func newGitea(rs *types.RemoteSource, accessToken string) (*gitea.Client, error) { +func newGitea(rs *cstypes.RemoteSource, accessToken string) (*gitea.Client, error) { return gitea.New(gitea.Opts{ APIURL: rs.APIURL, SkipVerify: rs.SkipVerify, @@ -34,7 +34,7 @@ func newGitea(rs *types.RemoteSource, accessToken string) (*gitea.Client, error) }) } -func newGitlab(rs *types.RemoteSource, accessToken string) (*gitlab.Client, error) { +func newGitlab(rs *cstypes.RemoteSource, accessToken string) (*gitlab.Client, error) { return gitlab.New(gitlab.Opts{ APIURL: rs.APIURL, SkipVerify: rs.SkipVerify, @@ -44,7 +44,7 @@ func newGitlab(rs *types.RemoteSource, accessToken string) (*gitlab.Client, erro }) } -func newGithub(rs *types.RemoteSource, accessToken string) (*github.Client, error) { +func newGithub(rs *cstypes.RemoteSource, accessToken string) (*github.Client, error) { return github.New(github.Opts{ APIURL: rs.APIURL, SkipVerify: rs.SkipVerify, @@ -54,18 +54,18 @@ func newGithub(rs *types.RemoteSource, accessToken string) (*github.Client, erro }) } -func GetAccessToken(rs *types.RemoteSource, userAccessToken, oauth2AccessToken string) (string, error) { +func GetAccessToken(rs *cstypes.RemoteSource, userAccessToken, oauth2AccessToken string) (string, error) { switch rs.AuthType { - case types.RemoteSourceAuthTypePassword: + case cstypes.RemoteSourceAuthTypePassword: return userAccessToken, nil - case types.RemoteSourceAuthTypeOauth2: + case cstypes.RemoteSourceAuthTypeOauth2: return oauth2AccessToken, nil default: return "", errors.Errorf("invalid remote source auth type %q", rs.AuthType) } } -func GetGitSource(rs *types.RemoteSource, la *types.LinkedAccount) (gitsource.GitSource, error) { +func GetGitSource(rs *cstypes.RemoteSource, la *cstypes.LinkedAccount) (gitsource.GitSource, error) { var accessToken string if la != nil { var err error @@ -78,11 +78,11 @@ func GetGitSource(rs *types.RemoteSource, la *types.LinkedAccount) (gitsource.Gi var gitSource gitsource.GitSource var err error switch rs.Type { - case types.RemoteSourceTypeGitea: + case cstypes.RemoteSourceTypeGitea: gitSource, err = newGitea(rs, accessToken) - case types.RemoteSourceTypeGitlab: + case cstypes.RemoteSourceTypeGitlab: gitSource, err = newGitlab(rs, accessToken) - case types.RemoteSourceTypeGithub: + case cstypes.RemoteSourceTypeGithub: gitSource, err = newGithub(rs, accessToken) default: return nil, errors.Errorf("remote source %s isn't a valid git source", rs.Name) @@ -91,13 +91,13 @@ func GetGitSource(rs *types.RemoteSource, la *types.LinkedAccount) (gitsource.Gi return gitSource, err } -func GetUserSource(rs *types.RemoteSource, accessToken string) (gitsource.UserSource, error) { +func GetUserSource(rs *cstypes.RemoteSource, accessToken string) (gitsource.UserSource, error) { var userSource gitsource.UserSource var err error switch rs.AuthType { - case types.RemoteSourceAuthTypeOauth2: + case cstypes.RemoteSourceAuthTypeOauth2: userSource, err = GetOauth2Source(rs, accessToken) - case types.RemoteSourceAuthTypePassword: + case cstypes.RemoteSourceAuthTypePassword: userSource, err = GetPasswordSource(rs, accessToken) default: return nil, errors.Errorf("unknown remote source auth type") @@ -106,15 +106,15 @@ func GetUserSource(rs *types.RemoteSource, accessToken string) (gitsource.UserSo return userSource, err } -func GetOauth2Source(rs *types.RemoteSource, accessToken string) (gitsource.Oauth2Source, error) { +func GetOauth2Source(rs *cstypes.RemoteSource, accessToken string) (gitsource.Oauth2Source, error) { var oauth2Source gitsource.Oauth2Source var err error switch rs.Type { - case types.RemoteSourceTypeGitea: + case cstypes.RemoteSourceTypeGitea: oauth2Source, err = newGitea(rs, accessToken) - case types.RemoteSourceTypeGitlab: + case cstypes.RemoteSourceTypeGitlab: oauth2Source, err = newGitlab(rs, accessToken) - case types.RemoteSourceTypeGithub: + case cstypes.RemoteSourceTypeGithub: oauth2Source, err = newGithub(rs, accessToken) default: return nil, errors.Errorf("remote source %s isn't a valid oauth2 source", rs.Name) @@ -123,11 +123,11 @@ func GetOauth2Source(rs *types.RemoteSource, accessToken string) (gitsource.Oaut return oauth2Source, err } -func GetPasswordSource(rs *types.RemoteSource, accessToken string) (gitsource.PasswordSource, error) { +func GetPasswordSource(rs *cstypes.RemoteSource, accessToken string) (gitsource.PasswordSource, error) { var passwordSource gitsource.PasswordSource var err error switch rs.Type { - case types.RemoteSourceTypeGitea: + case cstypes.RemoteSourceTypeGitea: passwordSource, err = newGitea(rs, accessToken) default: return nil, errors.Errorf("remote source %s isn't a valid oauth2 source", rs.Name) diff --git a/internal/services/common/variables.go b/internal/services/common/variables.go index 331707b..5f6b45d 100644 --- a/internal/services/common/variables.go +++ b/internal/services/common/variables.go @@ -16,7 +16,7 @@ package common import ( csapi "agola.io/agola/internal/services/configstore/api" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" ) @@ -43,7 +43,7 @@ func FilterOverriddenVariables(variables []*csapi.Variable) []*csapi.Variable { return filteredVariables } -func GetVarValueMatchingSecret(varval types.VariableValue, varParentPath string, secrets []*csapi.Secret) *csapi.Secret { +func GetVarValueMatchingSecret(varval cstypes.VariableValue, varParentPath string, secrets []*csapi.Secret) *csapi.Secret { // get the secret value referenced by the variable, it must be a secret at the same level or a lower level var secret *csapi.Secret for _, s := range secrets { diff --git a/internal/services/common/variables_test.go b/internal/services/common/variables_test.go index 1afa6c5..24c76fc 100644 --- a/internal/services/common/variables_test.go +++ b/internal/services/common/variables_test.go @@ -18,7 +18,7 @@ import ( "testing" csapi "agola.io/agola/internal/services/configstore/api" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "github.com/google/go-cmp/cmp" ) @@ -39,37 +39,37 @@ func TestFilterOverriddenVariables(t *testing.T) { // variables must be in depth (from leaves to root) order as returned by the // configstore apis &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var04", }, ParentPath: "org/org01/projectgroup02/projectgroup03/project02", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var03", }, ParentPath: "org/org01/projectgroup01/project01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var02", }, ParentPath: "org/org01/projectgroup01/project01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var02", }, ParentPath: "org/org01/projectgroup01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var01", }, ParentPath: "org/org01/projectgroup01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var01", }, ParentPath: "org/org01", @@ -77,25 +77,25 @@ func TestFilterOverriddenVariables(t *testing.T) { }, out: []*csapi.Variable{ &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var04", }, ParentPath: "org/org01/projectgroup02/projectgroup03/project02", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var03", }, ParentPath: "org/org01/projectgroup01/project01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var02", }, ParentPath: "org/org01/projectgroup01/project01", }, &csapi.Variable{ - Variable: &types.Variable{ + Variable: &cstypes.Variable{ Name: "var01", }, ParentPath: "org/org01/projectgroup01", @@ -118,14 +118,14 @@ func TestFilterOverriddenVariables(t *testing.T) { func TestGetVarValueMatchingSecret(t *testing.T) { tests := []struct { name string - varValue types.VariableValue + varValue cstypes.VariableValue varParentPath string secrets []*csapi.Secret out *csapi.Secret }{ { name: "test empty secrets", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, @@ -135,14 +135,14 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test secret with different name", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, varParentPath: "org/org01/projectgroup01/projectgroup02", secrets: []*csapi.Secret{ &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret02", }, ParentPath: "org/org01/projectgroup01/projectgroup02", @@ -152,14 +152,14 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test secret with tree", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, varParentPath: "org/org01/projectgroup01/projectgroup02", secrets: []*csapi.Secret{ &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret02", }, ParentPath: "org/org01/projectgroup01/projectgroup03", @@ -169,14 +169,14 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test secret in child of variable parent", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, varParentPath: "org/org01/projectgroup01/projectgroup02", secrets: []*csapi.Secret{ &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02/project01", @@ -186,27 +186,27 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test secret in same parent and also child of variable parent", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, varParentPath: "org/org01/projectgroup01/projectgroup02", secrets: []*csapi.Secret{ &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02/project01", }, &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02", }, }, out: &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02", @@ -214,21 +214,21 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test secret in parent", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, varParentPath: "org/org01/projectgroup01/projectgroup02", secrets: []*csapi.Secret{ &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01", }, }, out: &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01", @@ -236,7 +236,7 @@ func TestGetVarValueMatchingSecret(t *testing.T) { }, { name: "test multiple secrets in same branch and also child of variable parent", - varValue: types.VariableValue{ + varValue: cstypes.VariableValue{ SecretName: "secret01", SecretVar: "secretvar01", }, @@ -245,26 +245,26 @@ func TestGetVarValueMatchingSecret(t *testing.T) { // secrets must be in depth (from leaves to root) order as returned by the // configstore apis &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02/project01", }, &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02", }, &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01", }, }, out: &csapi.Secret{ - Secret: &types.Secret{ + Secret: &cstypes.Secret{ Name: "secret01", }, ParentPath: "org/org01/projectgroup01/projectgroup02", diff --git a/internal/services/configstore/action/org.go b/internal/services/configstore/action/org.go index c467356..2698151 100644 --- a/internal/services/configstore/action/org.go +++ b/internal/services/configstore/action/org.go @@ -23,7 +23,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/project.go b/internal/services/configstore/action/project.go index 5afa611..07dc7af 100644 --- a/internal/services/configstore/action/project.go +++ b/internal/services/configstore/action/project.go @@ -21,7 +21,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/projectgroup.go b/internal/services/configstore/action/projectgroup.go index e46cb93..c56bda1 100644 --- a/internal/services/configstore/action/projectgroup.go +++ b/internal/services/configstore/action/projectgroup.go @@ -21,7 +21,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/remotesource.go b/internal/services/configstore/action/remotesource.go index 4dea7b3..49cecfe 100644 --- a/internal/services/configstore/action/remotesource.go +++ b/internal/services/configstore/action/remotesource.go @@ -20,7 +20,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/secret.go b/internal/services/configstore/action/secret.go index f2410ee..fc05c2f 100644 --- a/internal/services/configstore/action/secret.go +++ b/internal/services/configstore/action/secret.go @@ -20,7 +20,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/user.go b/internal/services/configstore/action/user.go index e2dea83..df9cf23 100644 --- a/internal/services/configstore/action/user.go +++ b/internal/services/configstore/action/user.go @@ -22,7 +22,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/action/variable.go b/internal/services/configstore/action/variable.go index d7a5887..078e814 100644 --- a/internal/services/configstore/action/variable.go +++ b/internal/services/configstore/action/variable.go @@ -20,7 +20,7 @@ import ( "agola.io/agola/internal/datamanager" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" uuid "github.com/satori/go.uuid" diff --git a/internal/services/configstore/api/api.go b/internal/services/configstore/api/api.go index 8361ca2..a48b3d8 100644 --- a/internal/services/configstore/api/api.go +++ b/internal/services/configstore/api/api.go @@ -19,7 +19,7 @@ import ( "net/http" "net/url" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/client.go b/internal/services/configstore/api/client.go index 5c0c231..44eff33 100644 --- a/internal/services/configstore/api/client.go +++ b/internal/services/configstore/api/client.go @@ -26,7 +26,7 @@ import ( "strconv" "strings" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" errors "golang.org/x/xerrors" ) diff --git a/internal/services/configstore/api/org.go b/internal/services/configstore/api/org.go index a0d57d8..eb8c169 100644 --- a/internal/services/configstore/api/org.go +++ b/internal/services/configstore/api/org.go @@ -22,7 +22,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/project.go b/internal/services/configstore/api/project.go index 0510792..3f9a58f 100644 --- a/internal/services/configstore/api/project.go +++ b/internal/services/configstore/api/project.go @@ -24,7 +24,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/projectgroup.go b/internal/services/configstore/api/projectgroup.go index 4b025ad..c481955 100644 --- a/internal/services/configstore/api/projectgroup.go +++ b/internal/services/configstore/api/projectgroup.go @@ -24,7 +24,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/remotesource.go b/internal/services/configstore/api/remotesource.go index a3bc0dc..4f5faa7 100644 --- a/internal/services/configstore/api/remotesource.go +++ b/internal/services/configstore/api/remotesource.go @@ -22,7 +22,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/secret.go b/internal/services/configstore/api/secret.go index 38f525d..86f783c 100644 --- a/internal/services/configstore/api/secret.go +++ b/internal/services/configstore/api/secret.go @@ -21,7 +21,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" diff --git a/internal/services/configstore/api/user.go b/internal/services/configstore/api/user.go index 55d8b81..de117d7 100644 --- a/internal/services/configstore/api/user.go +++ b/internal/services/configstore/api/user.go @@ -23,7 +23,7 @@ import ( "agola.io/agola/internal/db" action "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" diff --git a/internal/services/configstore/api/variable.go b/internal/services/configstore/api/variable.go index 4920300..30fb46f 100644 --- a/internal/services/configstore/api/variable.go +++ b/internal/services/configstore/api/variable.go @@ -21,7 +21,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" diff --git a/internal/services/configstore/configstore.go b/internal/services/configstore/configstore.go index 780b359..89cf0ce 100644 --- a/internal/services/configstore/configstore.go +++ b/internal/services/configstore/configstore.go @@ -32,7 +32,7 @@ import ( "agola.io/agola/internal/services/configstore/api" "agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/readdb" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" diff --git a/internal/services/configstore/configstore_test.go b/internal/services/configstore/configstore_test.go index 16cd3da..70b7698 100644 --- a/internal/services/configstore/configstore_test.go +++ b/internal/services/configstore/configstore_test.go @@ -30,7 +30,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/config" action "agola.io/agola/internal/services/configstore/action" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/testutil" "agola.io/agola/internal/util" diff --git a/internal/services/configstore/readdb/org.go b/internal/services/configstore/readdb/org.go index 307c751..b2715dc 100644 --- a/internal/services/configstore/readdb/org.go +++ b/internal/services/configstore/readdb/org.go @@ -20,7 +20,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/common" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/project.go b/internal/services/configstore/readdb/project.go index 8b52fc0..ce2e1b6 100644 --- a/internal/services/configstore/readdb/project.go +++ b/internal/services/configstore/readdb/project.go @@ -22,7 +22,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/common" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/projectgroup.go b/internal/services/configstore/readdb/projectgroup.go index 3ae99d7..4e7138c 100644 --- a/internal/services/configstore/readdb/projectgroup.go +++ b/internal/services/configstore/readdb/projectgroup.go @@ -22,7 +22,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/common" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/readdb.go b/internal/services/configstore/readdb/readdb.go index 5b38131..a4e3f11 100644 --- a/internal/services/configstore/readdb/readdb.go +++ b/internal/services/configstore/readdb/readdb.go @@ -30,7 +30,7 @@ import ( "agola.io/agola/internal/objectstorage" ostypes "agola.io/agola/internal/objectstorage/types" "agola.io/agola/internal/sequence" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/remotesource.go b/internal/services/configstore/readdb/remotesource.go index e210a43..f6be51b 100644 --- a/internal/services/configstore/readdb/remotesource.go +++ b/internal/services/configstore/readdb/remotesource.go @@ -21,7 +21,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/common" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/resolve.go b/internal/services/configstore/readdb/resolve.go index c597bf8..f8fc1cd 100644 --- a/internal/services/configstore/readdb/resolve.go +++ b/internal/services/configstore/readdb/resolve.go @@ -18,7 +18,7 @@ import ( "path" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" ) diff --git a/internal/services/configstore/readdb/secret.go b/internal/services/configstore/readdb/secret.go index 87617ee..c3eaffa 100644 --- a/internal/services/configstore/readdb/secret.go +++ b/internal/services/configstore/readdb/secret.go @@ -19,7 +19,7 @@ import ( "encoding/json" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/user.go b/internal/services/configstore/readdb/user.go index f6d6a70..952fb55 100644 --- a/internal/services/configstore/readdb/user.go +++ b/internal/services/configstore/readdb/user.go @@ -20,7 +20,7 @@ import ( "agola.io/agola/internal/db" "agola.io/agola/internal/services/configstore/common" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/configstore/readdb/variable.go b/internal/services/configstore/readdb/variable.go index 88754a8..de7ba65 100644 --- a/internal/services/configstore/readdb/variable.go +++ b/internal/services/configstore/readdb/variable.go @@ -19,7 +19,7 @@ import ( "encoding/json" "agola.io/agola/internal/db" - "agola.io/agola/internal/services/types" + "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" sq "github.com/Masterminds/squirrel" diff --git a/internal/services/types/types.go b/internal/services/configstore/types/types.go similarity index 100% rename from internal/services/types/types.go rename to internal/services/configstore/types/types.go diff --git a/internal/services/types/types_test.go b/internal/services/configstore/types/types_test.go similarity index 100% rename from internal/services/types/types_test.go rename to internal/services/configstore/types/types_test.go diff --git a/internal/services/gateway/action/auth.go b/internal/services/gateway/action/auth.go index dd53349..e12c1f0 100644 --- a/internal/services/gateway/action/auth.go +++ b/internal/services/gateway/action/auth.go @@ -18,7 +18,7 @@ import ( "context" "agola.io/agola/internal/services/common" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" errors "golang.org/x/xerrors" ) @@ -68,7 +68,7 @@ func (h *ActionHandler) IsOrgOwner(ctx context.Context, orgID string) (bool, err if userOrg.Organization.ID != orgID { continue } - if userOrg.Role == types.MemberRoleOwner { + if userOrg.Role == cstypes.MemberRoleOwner { return true, nil } } @@ -76,7 +76,7 @@ func (h *ActionHandler) IsOrgOwner(ctx context.Context, orgID string) (bool, err return false, nil } -func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType types.ConfigType, ownerID string) (bool, error) { +func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType cstypes.ConfigType, ownerID string) (bool, error) { isAdmin := h.IsUserAdmin(ctx) if isAdmin { return true, nil @@ -87,13 +87,13 @@ func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType types.Conf return false, nil } - if ownerType == types.ConfigTypeUser { + if ownerType == cstypes.ConfigTypeUser { if userID == ownerID { return true, nil } } - if ownerType == types.ConfigTypeOrg { + if ownerType == cstypes.ConfigTypeOrg { userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID) if err != nil { return false, errors.Errorf("failed to get user orgs: %w", ErrFromRemote(resp, err)) @@ -103,7 +103,7 @@ func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType types.Conf if userOrg.Organization.ID != ownerID { continue } - if userOrg.Role == types.MemberRoleOwner { + if userOrg.Role == cstypes.MemberRoleOwner { return true, nil } } @@ -112,7 +112,7 @@ func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType types.Conf return false, nil } -func (h *ActionHandler) IsProjectMember(ctx context.Context, ownerType types.ConfigType, ownerID string) (bool, error) { +func (h *ActionHandler) IsProjectMember(ctx context.Context, ownerType cstypes.ConfigType, ownerID string) (bool, error) { isAdmin := h.IsUserAdmin(ctx) if isAdmin { return true, nil @@ -123,13 +123,13 @@ func (h *ActionHandler) IsProjectMember(ctx context.Context, ownerType types.Con return false, nil } - if ownerType == types.ConfigTypeUser { + if ownerType == cstypes.ConfigTypeUser { if userID == ownerID { return true, nil } } - if ownerType == types.ConfigTypeOrg { + if ownerType == cstypes.ConfigTypeOrg { userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID) if err != nil { return false, errors.Errorf("failed to get user orgs: %w", ErrFromRemote(resp, err)) @@ -146,18 +146,18 @@ func (h *ActionHandler) IsProjectMember(ctx context.Context, ownerType types.Con return false, nil } -func (h *ActionHandler) IsVariableOwner(ctx context.Context, parentType types.ConfigType, parentRef string) (bool, error) { - var ownerType types.ConfigType +func (h *ActionHandler) IsVariableOwner(ctx context.Context, parentType cstypes.ConfigType, parentRef string) (bool, error) { + var ownerType cstypes.ConfigType var ownerID string switch parentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, parentRef) if err != nil { return false, errors.Errorf("failed to get project group %q: %w", parentRef, ErrFromRemote(resp, err)) } ownerType = pg.OwnerType ownerID = pg.OwnerID - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: p, resp, err := h.configstoreClient.GetProject(ctx, parentRef) if err != nil { return false, errors.Errorf("failed to get project %q: %w", parentRef, ErrFromRemote(resp, err)) @@ -175,8 +175,8 @@ func (h *ActionHandler) CanGetRun(ctx context.Context, runGroup string) (bool, e return false, err } - var visibility types.Visibility - var ownerType types.ConfigType + var visibility cstypes.Visibility + var ownerType cstypes.ConfigType var ownerID string switch groupType { case common.GroupTypeProject: @@ -189,12 +189,12 @@ func (h *ActionHandler) CanGetRun(ctx context.Context, runGroup string) (bool, e visibility = p.GlobalVisibility case common.GroupTypeUser: // user direct runs - ownerType = types.ConfigTypeUser + ownerType = cstypes.ConfigTypeUser ownerID = groupID - visibility = types.VisibilityPrivate + visibility = cstypes.VisibilityPrivate } - if visibility == types.VisibilityPublic { + if visibility == cstypes.VisibilityPublic { return true, nil } isProjectMember, err := h.IsProjectMember(ctx, ownerType, ownerID) @@ -213,7 +213,7 @@ func (h *ActionHandler) CanDoRunActions(ctx context.Context, runGroup string) (b return false, err } - var ownerType types.ConfigType + var ownerType cstypes.ConfigType var ownerID string switch groupType { case common.GroupTypeProject: @@ -225,7 +225,7 @@ func (h *ActionHandler) CanDoRunActions(ctx context.Context, runGroup string) (b ownerID = p.OwnerID case common.GroupTypeUser: // user direct runs - ownerType = types.ConfigTypeUser + ownerType = cstypes.ConfigTypeUser ownerID = groupID } diff --git a/internal/services/gateway/action/org.go b/internal/services/gateway/action/org.go index 445c5f8..8816c3c 100644 --- a/internal/services/gateway/action/org.go +++ b/internal/services/gateway/action/org.go @@ -17,13 +17,13 @@ package action import ( "context" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" ) -func (h *ActionHandler) GetOrg(ctx context.Context, orgRef string) (*types.Organization, error) { +func (h *ActionHandler) GetOrg(ctx context.Context, orgRef string) (*cstypes.Organization, error) { org, resp, err := h.configstoreClient.GetOrg(ctx, orgRef) if err != nil { return nil, ErrFromRemote(resp, err) @@ -37,7 +37,7 @@ type GetOrgsRequest struct { Asc bool } -func (h *ActionHandler) GetOrgs(ctx context.Context, req *GetOrgsRequest) ([]*types.Organization, error) { +func (h *ActionHandler) GetOrgs(ctx context.Context, req *GetOrgsRequest) ([]*cstypes.Organization, error) { orgs, resp, err := h.configstoreClient.GetOrgs(ctx, req.Start, req.Limit, req.Asc) if err != nil { return nil, ErrFromRemote(resp, err) @@ -46,13 +46,13 @@ func (h *ActionHandler) GetOrgs(ctx context.Context, req *GetOrgsRequest) ([]*ty } type OrgMembersResponse struct { - Organization *types.Organization + Organization *cstypes.Organization Members []*OrgMemberResponse } type OrgMemberResponse struct { - User *types.User - Role types.MemberRole + User *cstypes.User + Role cstypes.MemberRole } func (h *ActionHandler) GetOrgMembers(ctx context.Context, orgRef string) (*OrgMembersResponse, error) { @@ -81,12 +81,12 @@ func (h *ActionHandler) GetOrgMembers(ctx context.Context, orgRef string) (*OrgM type CreateOrgRequest struct { Name string - Visibility types.Visibility + Visibility cstypes.Visibility CreatorUserID string } -func (h *ActionHandler) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*types.Organization, error) { +func (h *ActionHandler) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*cstypes.Organization, error) { if !h.IsUserLoggedOrAdmin(ctx) { return nil, errors.Errorf("user not logged in") } @@ -98,7 +98,7 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, req *CreateOrgRequest) (* return nil, util.NewErrBadRequest(errors.Errorf("invalid organization name %q", req.Name)) } - org := &types.Organization{ + org := &cstypes.Organization{ Name: req.Name, Visibility: req.Visibility, } @@ -138,12 +138,12 @@ func (h *ActionHandler) DeleteOrg(ctx context.Context, orgRef string) error { } type AddOrgMemberResponse struct { - OrganizationMember *types.OrganizationMember - Org *types.Organization - User *types.User + OrganizationMember *cstypes.OrganizationMember + Org *cstypes.Organization + User *cstypes.User } -func (h *ActionHandler) AddOrgMember(ctx context.Context, orgRef, userRef string, role types.MemberRole) (*AddOrgMemberResponse, error) { +func (h *ActionHandler) AddOrgMember(ctx context.Context, orgRef, userRef string, role cstypes.MemberRole) (*AddOrgMemberResponse, error) { org, resp, err := h.configstoreClient.GetOrg(ctx, orgRef) if err != nil { return nil, ErrFromRemote(resp, err) diff --git a/internal/services/gateway/action/project.go b/internal/services/gateway/action/project.go index 08781b2..cee237b 100644 --- a/internal/services/gateway/action/project.go +++ b/internal/services/gateway/action/project.go @@ -23,6 +23,7 @@ import ( gitsource "agola.io/agola/internal/gitsources" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" @@ -39,7 +40,7 @@ func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csa if err != nil { return nil, errors.Errorf("failed to determine ownership: %w", err) } - if project.GlobalVisibility == types.VisibilityPublic { + if project.GlobalVisibility == cstypes.VisibilityPublic { return project, nil } if !isProjectMember { @@ -52,7 +53,7 @@ func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csa type CreateProjectRequest struct { Name string ParentRef string - Visibility types.Visibility + Visibility cstypes.Visibility RemoteSourceName string RepoPath string SkipSSHHostKeyCheck bool @@ -108,7 +109,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq if err != nil { return nil, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, ErrFromRemote(resp, err)) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -135,14 +136,14 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq return nil, errors.Errorf("failed to generate ssh key pair: %w", err) } - p := &types.Project{ + p := &cstypes.Project{ Name: req.Name, - Parent: types.Parent{ - Type: types.ConfigTypeProjectGroup, + Parent: cstypes.Parent{ + Type: cstypes.ConfigTypeProjectGroup, ID: parentRef, }, Visibility: req.Visibility, - RemoteRepositoryConfigType: types.RemoteRepositoryConfigTypeRemoteSource, + RemoteRepositoryConfigType: cstypes.RemoteRepositoryConfigTypeRemoteSource, RemoteSourceID: rs.ID, LinkedAccountID: la.ID, RepositoryID: repo.ID, @@ -180,7 +181,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq type UpdateProjectRequest struct { Name string - Visibility types.Visibility + Visibility cstypes.Visibility } func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, req *UpdateProjectRequest) (*csapi.Project, error) { @@ -235,7 +236,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj if err != nil { return nil, errors.Errorf("failed to get remote source %q: %w", p.RemoteSourceID, ErrFromRemote(resp, err)) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -269,7 +270,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj return rp, nil } -func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *csapi.Project) error { +func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapi.Project) error { gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) if err != nil { return errors.Errorf("failed to create gitsource client: %w", err) @@ -305,7 +306,7 @@ func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *types.Remote return nil } -func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *csapi.Project) error { +func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapi.Project) error { gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) if err != nil { return errors.Errorf("failed to create gitsource client: %w", err) @@ -436,7 +437,7 @@ func (h *ActionHandler) ProjectCreateRun(ctx context.Context, projectRef, branch if err != nil { return errors.Errorf("failed to get remote source %q: %w", p.RemoteSourceID, ErrFromRemote(resp, err)) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -571,7 +572,7 @@ func (h *ActionHandler) ProjectCreateRun(ctx context.Context, projectRef, branch return h.CreateRuns(ctx, req) } -func (h *ActionHandler) getRemoteRepoAccessData(ctx context.Context, linkedAccountID string) (*types.User, *types.RemoteSource, *types.LinkedAccount, error) { +func (h *ActionHandler) getRemoteRepoAccessData(ctx context.Context, linkedAccountID string) (*cstypes.User, *cstypes.RemoteSource, *cstypes.LinkedAccount, error) { user, resp, err := h.configstoreClient.GetUserByLinkedAccount(ctx, linkedAccountID) if err != nil { return nil, nil, nil, errors.Errorf("failed to get user with linked account id %q: %w", linkedAccountID, ErrFromRemote(resp, err)) diff --git a/internal/services/gateway/action/projectgroup.go b/internal/services/gateway/action/projectgroup.go index 3415b4e..4308cd0 100644 --- a/internal/services/gateway/action/projectgroup.go +++ b/internal/services/gateway/action/projectgroup.go @@ -19,7 +19,7 @@ import ( "path" csapi "agola.io/agola/internal/services/configstore/api" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" @@ -53,7 +53,7 @@ type CreateProjectGroupRequest struct { CurrentUserID string Name string ParentRef string - Visibility types.Visibility + Visibility cstypes.Visibility } func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProjectGroupRequest) (*csapi.ProjectGroup, error) { @@ -85,10 +85,10 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje parentRef = path.Join("user", user.Name) } - p := &types.ProjectGroup{ + p := &cstypes.ProjectGroup{ Name: req.Name, - Parent: types.Parent{ - Type: types.ConfigTypeProjectGroup, + Parent: cstypes.Parent{ + Type: cstypes.ConfigTypeProjectGroup, ID: parentRef, }, Visibility: req.Visibility, @@ -106,7 +106,7 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje type UpdateProjectGroupRequest struct { Name string - Visibility types.Visibility + Visibility cstypes.Visibility } func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef string, req *UpdateProjectGroupRequest) (*csapi.ProjectGroup, error) { diff --git a/internal/services/gateway/action/remotesource.go b/internal/services/gateway/action/remotesource.go index 1791964..2fe724e 100644 --- a/internal/services/gateway/action/remotesource.go +++ b/internal/services/gateway/action/remotesource.go @@ -17,13 +17,13 @@ package action import ( "context" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" ) -func (h *ActionHandler) GetRemoteSource(ctx context.Context, rsRef string) (*types.RemoteSource, error) { +func (h *ActionHandler) GetRemoteSource(ctx context.Context, rsRef string) (*cstypes.RemoteSource, error) { rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, rsRef) if err != nil { return nil, ErrFromRemote(resp, err) @@ -37,7 +37,7 @@ type GetRemoteSourcesRequest struct { Asc bool } -func (h *ActionHandler) GetRemoteSources(ctx context.Context, req *GetRemoteSourcesRequest) ([]*types.RemoteSource, error) { +func (h *ActionHandler) GetRemoteSources(ctx context.Context, req *GetRemoteSourcesRequest) ([]*cstypes.RemoteSource, error) { remoteSources, resp, err := h.configstoreClient.GetRemoteSources(ctx, req.Start, req.Limit, req.Asc) if err != nil { return nil, ErrFromRemote(resp, err) @@ -59,7 +59,7 @@ type CreateRemoteSourceRequest struct { LoginEnabled *bool } -func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemoteSourceRequest) (*types.RemoteSource, error) { +func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemoteSourceRequest) (*cstypes.RemoteSource, error) { if !h.IsUserAdmin(ctx) { return nil, errors.Errorf("user not admin") } @@ -82,11 +82,11 @@ func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemot } // validate if the remote source type supports the required auth type - if !types.SourceSupportsAuthType(types.RemoteSourceType(req.Type), types.RemoteSourceAuthType(req.AuthType)) { + if !cstypes.SourceSupportsAuthType(cstypes.RemoteSourceType(req.Type), cstypes.RemoteSourceAuthType(req.AuthType)) { return nil, util.NewErrBadRequest(errors.Errorf("remotesource type %q doesn't support auth type %q", req.Type, req.AuthType)) } - if req.AuthType == string(types.RemoteSourceAuthTypeOauth2) { + if req.AuthType == string(cstypes.RemoteSourceAuthTypeOauth2) { if req.Oauth2ClientID == "" { return nil, util.NewErrBadRequest(errors.Errorf("remotesource oauth2 clientid required")) } @@ -95,10 +95,10 @@ func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemot } } - rs := &types.RemoteSource{ + rs := &cstypes.RemoteSource{ Name: req.Name, - Type: types.RemoteSourceType(req.Type), - AuthType: types.RemoteSourceAuthType(req.AuthType), + Type: cstypes.RemoteSourceType(req.Type), + AuthType: cstypes.RemoteSourceAuthType(req.AuthType), APIURL: req.APIURL, SkipVerify: req.SkipVerify, Oauth2ClientID: req.Oauth2ClientID, @@ -133,7 +133,7 @@ type UpdateRemoteSourceRequest struct { LoginEnabled *bool } -func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemoteSourceRequest) (*types.RemoteSource, error) { +func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemoteSourceRequest) (*cstypes.RemoteSource, error) { if !h.IsUserAdmin(ctx) { return nil, errors.Errorf("user not admin") } diff --git a/internal/services/gateway/action/run.go b/internal/services/gateway/action/run.go index 534a3c7..5a19541 100644 --- a/internal/services/gateway/action/run.go +++ b/internal/services/gateway/action/run.go @@ -24,6 +24,7 @@ import ( gitsource "agola.io/agola/internal/gitsources" "agola.io/agola/internal/runconfig" "agola.io/agola/internal/services/common" + cstypes "agola.io/agola/internal/services/configstore/types" rsapi "agola.io/agola/internal/services/runservice/api" rstypes "agola.io/agola/internal/services/runservice/types" "agola.io/agola/internal/services/types" @@ -293,8 +294,8 @@ type CreateRunRequest struct { RefType types.RunRefType RunCreationTrigger types.RunCreationTriggerType - Project *types.Project - User *types.User + Project *cstypes.Project + User *cstypes.User RepoPath string GitSource gitsource.GitSource CommitSHA string @@ -537,9 +538,9 @@ func (h *ActionHandler) genRunVariables(ctx context.Context, req *CreateRunReque } for _, pvar := range pvars { // find the value match - var varval types.VariableValue + var varval cstypes.VariableValue for _, varval = range pvar.Values { - match := types.MatchWhen(varval.When, req.Branch, req.Tag, req.Ref) + match := cstypes.MatchWhen(varval.When, req.Branch, req.Tag, req.Ref) if !match { continue } diff --git a/internal/services/gateway/action/secret.go b/internal/services/gateway/action/secret.go index 15ec9d0..29901d2 100644 --- a/internal/services/gateway/action/secret.go +++ b/internal/services/gateway/action/secret.go @@ -19,14 +19,14 @@ import ( "net/http" csapi "agola.io/agola/internal/services/configstore/api" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" ) type GetSecretsRequest struct { - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string Tree bool @@ -37,9 +37,9 @@ func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) var resp *http.Response var err error switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: cssecrets, resp, err = h.configstoreClient.GetProjectGroupSecrets(ctx, req.ParentRef, req.Tree) - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: cssecrets, resp, err = h.configstoreClient.GetProjectSecrets(ctx, req.ParentRef, req.Tree) } if err != nil { @@ -52,10 +52,10 @@ func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) type CreateSecretRequest struct { Name string - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string - Type types.SecretType + Type cstypes.SecretType // internal secret Data map[string]string @@ -78,7 +78,7 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque return nil, util.NewErrBadRequest(errors.Errorf("invalid secret name %q", req.Name)) } - s := &types.Secret{ + s := &cstypes.Secret{ Name: req.Name, Type: req.Type, Data: req.Data, @@ -87,10 +87,10 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque var resp *http.Response var rs *csapi.Secret switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: h.log.Infof("creating project group secret") rs, resp, err = h.configstoreClient.CreateProjectGroupSecret(ctx, req.ParentRef, s) - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: h.log.Infof("creating project secret") rs, resp, err = h.configstoreClient.CreateProjectSecret(ctx, req.ParentRef, s) } @@ -107,10 +107,10 @@ type UpdateSecretRequest struct { Name string - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string - Type types.SecretType + Type cstypes.SecretType // internal secret Data map[string]string @@ -133,7 +133,7 @@ func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretReque return nil, util.NewErrBadRequest(errors.Errorf("invalid secret name %q", req.Name)) } - s := &types.Secret{ + s := &cstypes.Secret{ Name: req.Name, Type: req.Type, Data: req.Data, @@ -142,10 +142,10 @@ func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretReque var resp *http.Response var rs *csapi.Secret switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: h.log.Infof("updating project group secret") rs, resp, err = h.configstoreClient.UpdateProjectGroupSecret(ctx, req.ParentRef, req.SecretName, s) - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: h.log.Infof("updating project secret") rs, resp, err = h.configstoreClient.UpdateProjectSecret(ctx, req.ParentRef, req.SecretName, s) } @@ -157,7 +157,7 @@ func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretReque return rs, nil } -func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType types.ConfigType, parentRef, name string) error { +func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType cstypes.ConfigType, parentRef, name string) error { isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef) if err != nil { return errors.Errorf("failed to determine ownership: %w", err) @@ -168,10 +168,10 @@ func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType types.Confi var resp *http.Response switch parentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: h.log.Infof("deleting project group secret") resp, err = h.configstoreClient.DeleteProjectGroupSecret(ctx, parentRef, name) - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: h.log.Infof("deleting project secret") resp, err = h.configstoreClient.DeleteProjectSecret(ctx, parentRef, name) } diff --git a/internal/services/gateway/action/user.go b/internal/services/gateway/action/user.go index 6d9c2aa..67664e1 100644 --- a/internal/services/gateway/action/user.go +++ b/internal/services/gateway/action/user.go @@ -25,6 +25,7 @@ import ( "agola.io/agola/internal/gitsources/agolagit" "agola.io/agola/internal/services/common" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" @@ -43,7 +44,7 @@ func isAccessTokenExpired(expiresAt time.Time) bool { return expiresAt.Add(-expireTimeRange).Before(time.Now()) } -func (h *ActionHandler) GetUser(ctx context.Context, userRef string) (*types.User, error) { +func (h *ActionHandler) GetUser(ctx context.Context, userRef string) (*cstypes.User, error) { if !h.IsUserLoggedOrAdmin(ctx) { return nil, errors.Errorf("user not logged in") } @@ -61,7 +62,7 @@ type GetUsersRequest struct { Asc bool } -func (h *ActionHandler) GetUsers(ctx context.Context, req *GetUsersRequest) ([]*types.User, error) { +func (h *ActionHandler) GetUsers(ctx context.Context, req *GetUsersRequest) ([]*cstypes.User, error) { if !h.IsUserAdmin(ctx) { return nil, errors.Errorf("user not logged in") } @@ -77,7 +78,7 @@ type CreateUserRequest struct { UserName string } -func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest) (*types.User, error) { +func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest) (*cstypes.User, error) { if !h.IsUserAdmin(ctx) { return nil, errors.Errorf("user not admin") } @@ -158,7 +159,7 @@ type CreateUserLARequest struct { Oauth2AccessTokenExpiresAt time.Time } -func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequest) (*types.LinkedAccount, error) { +func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequest) (*cstypes.LinkedAccount, error) { userRef := req.UserRef user, resp, err := h.configstoreClient.GetUser(ctx, userRef) if err != nil { @@ -168,7 +169,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque if err != nil { return nil, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, ErrFromRemote(resp, err)) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -216,7 +217,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque return la, nil } -func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *types.LinkedAccount) error { +func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *cstypes.LinkedAccount) error { user, resp, err := h.configstoreClient.GetUser(ctx, userRef) if err != nil { return errors.Errorf("failed to get user %q: %w", userRef, ErrFromRemote(resp, err)) @@ -252,9 +253,9 @@ func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *ty } // RefreshLinkedAccount refreshed the linked account oauth2 access token and update linked account in the configstore -func (h *ActionHandler) RefreshLinkedAccount(ctx context.Context, rs *types.RemoteSource, userName string, la *types.LinkedAccount) (*types.LinkedAccount, error) { +func (h *ActionHandler) RefreshLinkedAccount(ctx context.Context, rs *cstypes.RemoteSource, userName string, la *cstypes.LinkedAccount) (*cstypes.LinkedAccount, error) { switch rs.AuthType { - case types.RemoteSourceAuthTypeOauth2: + case cstypes.RemoteSourceAuthTypeOauth2: // refresh access token if expired if isAccessTokenExpired(la.Oauth2AccessTokenExpiresAt) { userSource, err := common.GetOauth2Source(rs, "") @@ -282,7 +283,7 @@ func (h *ActionHandler) RefreshLinkedAccount(ctx context.Context, rs *types.Remo // GetGitSource is a wrapper around common.GetGitSource that will also refresh // the oauth2 access token and update the linked account when needed -func (h *ActionHandler) GetGitSource(ctx context.Context, rs *types.RemoteSource, userName string, la *types.LinkedAccount) (gitsource.GitSource, error) { +func (h *ActionHandler) GetGitSource(ctx context.Context, rs *cstypes.RemoteSource, userName string, la *cstypes.LinkedAccount) (gitsource.GitSource, error) { la, err := h.RefreshLinkedAccount(ctx, rs, userName, la) if err != nil { return nil, err @@ -299,7 +300,7 @@ type RegisterUserRequest struct { Oauth2AccessTokenExpiresAt time.Time } -func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserRequest) (*types.User, error) { +func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserRequest) (*cstypes.User, error) { if req.UserName == "" { return nil, util.NewErrBadRequest(errors.Errorf("user name required")) } @@ -365,7 +366,7 @@ type LoginUserRequest struct { type LoginUserResponse struct { Token string - User *types.User + User *cstypes.User } func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*LoginUserResponse, error) { @@ -399,7 +400,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (* return nil, errors.Errorf("failed to get user for remote user id %q and remote source %q: %w", remoteUserInfo.ID, rs.ID, ErrFromRemote(resp, err)) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -517,7 +518,7 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource return nil, util.NewErrBadRequest(errors.Errorf("logged in user cannot create linked account for another user")) } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v @@ -539,7 +540,7 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource } switch rs.AuthType { - case types.RemoteSourceAuthTypeOauth2: + case cstypes.RemoteSourceAuthTypeOauth2: oauth2Source, err := common.GetOauth2Source(rs, "") if err != nil { return nil, errors.Errorf("failed to create git source: %w", err) @@ -557,7 +558,7 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource Oauth2Redirect: redirect, }, nil - case types.RemoteSourceAuthTypePassword: + case cstypes.RemoteSourceAuthTypePassword: passwordSource, err := common.GetPasswordSource(rs, "") if err != nil { return nil, errors.Errorf("failed to create git source: %w", err) @@ -602,7 +603,7 @@ type RemoteSourceAuthResult struct { } type CreateUserLAResponse struct { - LinkedAccount *types.LinkedAccount + LinkedAccount *cstypes.LinkedAccount } func (h *ActionHandler) HandleRemoteSourceAuthRequest(ctx context.Context, requestType RemoteSourceRequestType, requestString string, userAccessToken, oauth2AccessToken, oauth2RefreshToken string, oauth2AccessTokenExpiresAt time.Time) (*RemoteSourceAuthResult, error) { diff --git a/internal/services/gateway/action/variable.go b/internal/services/gateway/action/variable.go index 97e5e17..e84e889 100644 --- a/internal/services/gateway/action/variable.go +++ b/internal/services/gateway/action/variable.go @@ -20,13 +20,13 @@ import ( "agola.io/agola/internal/services/common" csapi "agola.io/agola/internal/services/configstore/api" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" ) type GetVariablesRequest struct { - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string Tree bool @@ -38,7 +38,7 @@ func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesReque var cssecrets []*csapi.Secret switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: var err error var resp *http.Response csvars, resp, err = h.configstoreClient.GetProjectGroupVariables(ctx, req.ParentRef, req.Tree) @@ -49,7 +49,7 @@ func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesReque if err != nil { return nil, nil, ErrFromRemote(resp, err) } - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: var err error var resp *http.Response csvars, resp, err = h.configstoreClient.GetProjectVariables(ctx, req.ParentRef, req.Tree) @@ -73,10 +73,10 @@ func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesReque type CreateVariableRequest struct { Name string - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string - Values []types.VariableValue + Values []cstypes.VariableValue } func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) { @@ -96,9 +96,9 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR return nil, nil, util.NewErrBadRequest(errors.Errorf("empty variable values")) } - v := &types.Variable{ + v := &cstypes.Variable{ Name: req.Name, - Parent: types.Parent{ + Parent: cstypes.Parent{ Type: req.ParentType, ID: req.ParentRef, }, @@ -109,7 +109,7 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR var rv *csapi.Variable switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: var err error var resp *http.Response cssecrets, resp, err = h.configstoreClient.GetProjectGroupSecrets(ctx, req.ParentRef, true) @@ -122,7 +122,7 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR if err != nil { return nil, nil, errors.Errorf("failed to create variable: %w", ErrFromRemote(resp, err)) } - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: var err error var resp *http.Response cssecrets, resp, err = h.configstoreClient.GetProjectSecrets(ctx, req.ParentRef, true) @@ -146,10 +146,10 @@ type UpdateVariableRequest struct { Name string - ParentType types.ConfigType + ParentType cstypes.ConfigType ParentRef string - Values []types.VariableValue + Values []cstypes.VariableValue } func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) { @@ -169,9 +169,9 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR return nil, nil, util.NewErrBadRequest(errors.Errorf("empty variable values")) } - v := &types.Variable{ + v := &cstypes.Variable{ Name: req.Name, - Parent: types.Parent{ + Parent: cstypes.Parent{ Type: req.ParentType, ID: req.ParentRef, }, @@ -182,7 +182,7 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR var rv *csapi.Variable switch req.ParentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: var err error var resp *http.Response cssecrets, resp, err = h.configstoreClient.GetProjectGroupSecrets(ctx, req.ParentRef, true) @@ -195,7 +195,7 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR if err != nil { return nil, nil, errors.Errorf("failed to create variable: %w", ErrFromRemote(resp, err)) } - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: var err error var resp *http.Response cssecrets, resp, err = h.configstoreClient.GetProjectSecrets(ctx, req.ParentRef, true) @@ -214,7 +214,7 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR return rv, cssecrets, nil } -func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType types.ConfigType, parentRef, name string) error { +func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType cstypes.ConfigType, parentRef, name string) error { isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef) if err != nil { return errors.Errorf("failed to determine ownership: %w", err) @@ -225,10 +225,10 @@ func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType types.Con var resp *http.Response switch parentType { - case types.ConfigTypeProjectGroup: + case cstypes.ConfigTypeProjectGroup: h.log.Infof("deleting project group variable") resp, err = h.configstoreClient.DeleteProjectGroupVariable(ctx, parentRef, name) - case types.ConfigTypeProject: + case cstypes.ConfigTypeProject: h.log.Infof("deleting project variable") resp, err = h.configstoreClient.DeleteProjectVariable(ctx, parentRef, name) } diff --git a/internal/services/gateway/api/api.go b/internal/services/gateway/api/api.go index 9621fbb..8cfee8e 100644 --- a/internal/services/gateway/api/api.go +++ b/internal/services/gateway/api/api.go @@ -19,7 +19,7 @@ import ( "net/http" "net/url" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" @@ -139,14 +139,14 @@ func httpErrorFromRemote(w http.ResponseWriter, resp *http.Response, err error) return false } -func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) { +func GetConfigTypeRef(r *http.Request) (cstypes.ConfigType, string, error) { vars := mux.Vars(r) projectRef, err := url.PathUnescape(vars["projectref"]) if err != nil { return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectref %q: %w", vars["projectref"], err)) } if projectRef != "" { - return types.ConfigTypeProject, projectRef, nil + return cstypes.ConfigTypeProject, projectRef, nil } projectGroupRef, err := url.PathUnescape(vars["projectgroupref"]) @@ -154,7 +154,7 @@ func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) { return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectgroupref %q: %w", vars["projectgroupref"], err)) } if projectGroupRef != "" { - return types.ConfigTypeProjectGroup, projectGroupRef, nil + return cstypes.ConfigTypeProjectGroup, projectGroupRef, nil } return "", "", util.NewErrBadRequest(errors.Errorf("cannot get project or projectgroup ref")) diff --git a/internal/services/gateway/api/client.go b/internal/services/gateway/api/client.go index 8b370d1..8d3715e 100644 --- a/internal/services/gateway/api/client.go +++ b/internal/services/gateway/api/client.go @@ -27,7 +27,7 @@ import ( "strconv" "strings" - "agola.io/agola/internal/services/types" + cstypes "agola.io/agola/internal/services/configstore/types" errors "golang.org/x/xerrors" ) @@ -475,7 +475,7 @@ func (c *Client) DeleteOrg(ctx context.Context, orgRef string) (*http.Response, return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil) } -func (c *Client) AddOrgMember(ctx context.Context, orgRef, userRef string, role types.MemberRole) (*AddOrgMemberResponse, *http.Response, error) { +func (c *Client) AddOrgMember(ctx context.Context, orgRef, userRef string, role cstypes.MemberRole) (*AddOrgMemberResponse, *http.Response, error) { req := &AddOrgMemberRequest{ Role: role, } diff --git a/internal/services/gateway/api/org.go b/internal/services/gateway/api/org.go index abf1841..bfe334b 100644 --- a/internal/services/gateway/api/org.go +++ b/internal/services/gateway/api/org.go @@ -19,8 +19,8 @@ import ( "net/http" "strconv" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "go.uber.org/zap" errors "golang.org/x/xerrors" @@ -29,8 +29,8 @@ import ( ) type CreateOrgRequest struct { - Name string `json:"name"` - Visibility types.Visibility `json:"visibility"` + Name string `json:"name"` + Visibility cstypes.Visibility `json:"visibility"` } type CreateOrgHandler struct { @@ -128,12 +128,12 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } type OrgResponse struct { - ID string `json:"id"` - Name string `json:"name"` - Visibility types.Visibility `json:"visibility,omitempty"` + ID string `json:"id"` + Name string `json:"name"` + Visibility cstypes.Visibility `json:"visibility,omitempty"` } -func createOrgResponse(o *types.Organization) *OrgResponse { +func createOrgResponse(o *cstypes.Organization) *OrgResponse { org := &OrgResponse{ ID: o.ID, Name: o.Name, @@ -205,11 +205,11 @@ type OrgMembersResponse struct { } type OrgMemberResponse struct { - User *UserResponse `json:"user"` - Role types.MemberRole `json:"role"` + User *UserResponse `json:"user"` + Role cstypes.MemberRole `json:"role"` } -func createOrgMemberResponse(user *types.User, role types.MemberRole) *OrgMemberResponse { +func createOrgMemberResponse(user *cstypes.User, role cstypes.MemberRole) *OrgMemberResponse { return &OrgMemberResponse{ User: createUserResponse(user), Role: role, @@ -254,7 +254,7 @@ type AddOrgMemberResponse struct { OrgMemberResponse } -func createAddOrgMemberResponse(org *types.Organization, user *types.User, role types.MemberRole) *AddOrgMemberResponse { +func createAddOrgMemberResponse(org *cstypes.Organization, user *cstypes.User, role cstypes.MemberRole) *AddOrgMemberResponse { return &AddOrgMemberResponse{ Organization: createOrgResponse(org), OrgMemberResponse: OrgMemberResponse{ @@ -265,7 +265,7 @@ func createAddOrgMemberResponse(org *types.Organization, user *types.User, role } type AddOrgMemberRequest struct { - Role types.MemberRole `json:"role"` + Role cstypes.MemberRole `json:"role"` } type AddOrgMemberHandler struct { diff --git a/internal/services/gateway/api/project.go b/internal/services/gateway/api/project.go index 909578b..1f4890d 100644 --- a/internal/services/gateway/api/project.go +++ b/internal/services/gateway/api/project.go @@ -20,8 +20,8 @@ import ( "net/url" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" @@ -29,12 +29,12 @@ import ( ) type CreateProjectRequest struct { - Name string `json:"name,omitempty"` - ParentRef string `json:"parent_ref,omitempty"` - Visibility types.Visibility `json:"visibility,omitempty"` - RepoPath string `json:"repo_path,omitempty"` - RemoteSourceName string `json:"remote_source_name,omitempty"` - SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check,omitempty"` + Name string `json:"name,omitempty"` + ParentRef string `json:"parent_ref,omitempty"` + Visibility cstypes.Visibility `json:"visibility,omitempty"` + RepoPath string `json:"repo_path,omitempty"` + RemoteSourceName string `json:"remote_source_name,omitempty"` + SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check,omitempty"` } type CreateProjectHandler struct { @@ -78,8 +78,8 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) } type UpdateProjectRequest struct { - Name string `json:"name,omitempty"` - Visibility types.Visibility `json:"visibility,omitempty"` + Name string `json:"name,omitempty"` + Visibility cstypes.Visibility `json:"visibility,omitempty"` } type UpdateProjectHandler struct { @@ -240,12 +240,12 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } type ProjectResponse struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - ParentPath string `json:"parent_path,omitempty"` - Visibility types.Visibility `json:"visibility,omitempty"` - GlobalVisibility string `json:"global_visibility,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Path string `json:"path,omitempty"` + ParentPath string `json:"parent_path,omitempty"` + Visibility cstypes.Visibility `json:"visibility,omitempty"` + GlobalVisibility string `json:"global_visibility,omitempty"` } func createProjectResponse(r *csapi.Project) *ProjectResponse { diff --git a/internal/services/gateway/api/projectgroup.go b/internal/services/gateway/api/projectgroup.go index e0dd6eb..f30ec21 100644 --- a/internal/services/gateway/api/projectgroup.go +++ b/internal/services/gateway/api/projectgroup.go @@ -20,8 +20,8 @@ import ( "net/url" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" errors "golang.org/x/xerrors" @@ -30,9 +30,9 @@ import ( ) type CreateProjectGroupRequest struct { - Name string `json:"name"` - ParentRef string `json:"parent_ref"` - Visibility types.Visibility `json:"visibility"` + Name string `json:"name"` + ParentRef string `json:"parent_ref"` + Visibility cstypes.Visibility `json:"visibility"` } type CreateProjectGroupHandler struct { @@ -81,8 +81,8 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req } type UpdateProjectGroupRequest struct { - Name string `json:"name,omitempty"` - Visibility types.Visibility `json:"visibility,omitempty"` + Name string `json:"name,omitempty"` + Visibility cstypes.Visibility `json:"visibility,omitempty"` } type UpdateProjectGroupHandler struct { @@ -254,12 +254,12 @@ func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http. } type ProjectGroupResponse struct { - ID string `json:"id"` - Name string `json:"name"` - Path string `json:"path"` - ParentPath string `json:"parent_path"` - Visibility types.Visibility `json:"visibility"` - GlobalVisibility string `json:"global_visibility"` + ID string `json:"id"` + Name string `json:"name"` + Path string `json:"path"` + ParentPath string `json:"parent_path"` + Visibility cstypes.Visibility `json:"visibility"` + GlobalVisibility string `json:"global_visibility"` } func createProjectGroupResponse(r *csapi.ProjectGroup) *ProjectGroupResponse { diff --git a/internal/services/gateway/api/remoterepo.go b/internal/services/gateway/api/remoterepo.go index 713f2d2..2db303b 100644 --- a/internal/services/gateway/api/remoterepo.go +++ b/internal/services/gateway/api/remoterepo.go @@ -19,8 +19,8 @@ import ( gitsource "agola.io/agola/internal/gitsources" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" @@ -76,7 +76,7 @@ func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques return } - var la *types.LinkedAccount + var la *cstypes.LinkedAccount for _, v := range user.LinkedAccounts { if v.RemoteSourceID == rs.ID { la = v diff --git a/internal/services/gateway/api/remotesource.go b/internal/services/gateway/api/remotesource.go index 421720b..2de0831 100644 --- a/internal/services/gateway/api/remotesource.go +++ b/internal/services/gateway/api/remotesource.go @@ -19,13 +19,13 @@ import ( "net/http" "strconv" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "go.uber.org/zap" - errors "golang.org/x/xerrors" "github.com/gorilla/mux" + errors "golang.org/x/xerrors" ) type CreateRemoteSourceRequest struct { @@ -152,7 +152,7 @@ type RemoteSourceResponse struct { LoginEnabled bool `json:"login_enabled"` } -func createRemoteSourceResponse(r *types.RemoteSource) *RemoteSourceResponse { +func createRemoteSourceResponse(r *cstypes.RemoteSource) *RemoteSourceResponse { rs := &RemoteSourceResponse{ ID: r.ID, Name: r.Name, diff --git a/internal/services/gateway/api/secret.go b/internal/services/gateway/api/secret.go index 2cefc59..4348149 100644 --- a/internal/services/gateway/api/secret.go +++ b/internal/services/gateway/api/secret.go @@ -19,12 +19,12 @@ import ( "net/http" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" - "go.uber.org/zap" "github.com/gorilla/mux" + "go.uber.org/zap" ) type SecretResponse struct { @@ -85,7 +85,7 @@ func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { type CreateSecretRequest struct { Name string `json:"name,omitempty"` - Type types.SecretType `json:"type,omitempty"` + Type cstypes.SecretType `json:"type,omitempty"` // internal secret Data map[string]string `json:"data,omitempty"` @@ -142,7 +142,7 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) type UpdateSecretRequest struct { Name string `json:"name,omitempty"` - Type types.SecretType `json:"type,omitempty"` + Type cstypes.SecretType `json:"type,omitempty"` // internal secret Data map[string]string `json:"data,omitempty"` diff --git a/internal/services/gateway/api/user.go b/internal/services/gateway/api/user.go index bbedb6b..1b1fa38 100644 --- a/internal/services/gateway/api/user.go +++ b/internal/services/gateway/api/user.go @@ -22,8 +22,8 @@ import ( "strconv" gitsource "agola.io/agola/internal/gitsources" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "github.com/gorilla/mux" @@ -166,7 +166,7 @@ type LinkedAccountResponse struct { RemoteUserAvatarURL string `json:"remote_user_avatar_url"` } -func createUserResponse(u *types.User) *UserResponse { +func createUserResponse(u *cstypes.User) *UserResponse { user := &UserResponse{ ID: u.ID, UserName: u.Name, @@ -256,8 +256,8 @@ type CreateUserLARequest struct { } type CreateUserLAResponse struct { - LinkedAccount *types.LinkedAccount `json:"linked_account"` - Oauth2Redirect string `json:"oauth2_redirect"` + LinkedAccount *cstypes.LinkedAccount `json:"linked_account"` + Oauth2Redirect string `json:"oauth2_redirect"` } type CreateUserLAHandler struct { diff --git a/internal/services/gateway/api/variable.go b/internal/services/gateway/api/variable.go index 4234918..fad56c8 100644 --- a/internal/services/gateway/api/variable.go +++ b/internal/services/gateway/api/variable.go @@ -20,8 +20,8 @@ import ( "agola.io/agola/internal/services/common" csapi "agola.io/agola/internal/services/configstore/api" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/gateway/action" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/util" "go.uber.org/zap" @@ -33,7 +33,7 @@ type VariableValue struct { SecretVar string `json:"secret_var"` MatchingSecretParentPath string `json:"matching_secret_parent_path"` - When *types.When `json:"when"` + When *cstypes.When `json:"when"` } type VariableResponse struct { @@ -113,7 +113,7 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { type CreateVariableRequest struct { Name string `json:"name,omitempty"` - Values []types.VariableValue `json:"values,omitempty"` + Values []cstypes.VariableValue `json:"values,omitempty"` } type CreateVariableHandler struct { @@ -160,7 +160,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request type UpdateVariableRequest struct { Name string `json:"name,omitempty"` - Values []types.VariableValue `json:"values,omitempty"` + Values []cstypes.VariableValue `json:"values,omitempty"` } type UpdateVariableHandler struct { diff --git a/internal/util/backoff.go b/internal/util/backoff.go index 2892b37..90e09d8 100644 --- a/internal/util/backoff.go +++ b/internal/util/backoff.go @@ -88,7 +88,7 @@ type Backoff struct { // // If the condition never returns true, ErrWaitTimeout is returned. All other // errors terminate immediately. -func ExponentialBackoff(ctx context.Context,backoff Backoff, condition ConditionFunc) error { +func ExponentialBackoff(ctx context.Context, backoff Backoff, condition ConditionFunc) error { duration := backoff.Duration for i := 0; i < backoff.Steps; i++ { if i != 0 { diff --git a/tests/setup_test.go b/tests/setup_test.go index 307e25d..86bf79f 100644 --- a/tests/setup_test.go +++ b/tests/setup_test.go @@ -28,6 +28,7 @@ import ( slog "agola.io/agola/internal/log" "agola.io/agola/internal/services/config" "agola.io/agola/internal/services/configstore" + cstypes "agola.io/agola/internal/services/configstore/types" "agola.io/agola/internal/services/executor" "agola.io/agola/internal/services/gateway" gwapi "agola.io/agola/internal/services/gateway/api" @@ -36,7 +37,6 @@ import ( rsscheduler "agola.io/agola/internal/services/runservice" rstypes "agola.io/agola/internal/services/runservice/types" "agola.io/agola/internal/services/scheduler" - "agola.io/agola/internal/services/types" "agola.io/agola/internal/testutil" "agola.io/agola/internal/util" @@ -427,7 +427,7 @@ func createProject(ctx context.Context, t *testing.T, giteaClient *gitea.Client, ParentRef: path.Join("user", agolaUser01), RemoteSourceName: "gitea", RepoPath: path.Join(giteaUser01, "repo01"), - Visibility: types.VisibilityPublic, + Visibility: cstypes.VisibilityPublic, }) if err != nil { t.Fatalf("unexpected err: %v", err)