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.
This commit is contained in:
Simone Gotti 2019-07-31 15:17:54 +02:00
parent d0c5621201
commit fd26e617b3
66 changed files with 312 additions and 309 deletions

View File

@ -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")

View File

@ -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)
}

View File

@ -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,

View File

@ -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")

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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{

View File

@ -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{

View File

@ -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
}

View File

@ -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
}

View File

@ -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"

View File

@ -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 {

View File

@ -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"}},
},
},
},

View File

@ -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)

View File

@ -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 {

View File

@ -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",

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"
)

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"
)

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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
}

View File

@ -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)

View File

@ -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))

View File

@ -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) {

View File

@ -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")
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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) {

View File

@ -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)
}

View File

@ -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"))

View File

@ -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,
}

View File

@ -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"
@ -30,7 +30,7 @@ import (
type CreateOrgRequest struct {
Name string `json:"name"`
Visibility types.Visibility `json:"visibility"`
Visibility cstypes.Visibility `json:"visibility"`
}
type CreateOrgHandler struct {
@ -130,10 +130,10 @@ 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"`
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,
@ -206,10 +206,10 @@ type OrgMembersResponse struct {
type OrgMemberResponse struct {
User *UserResponse `json:"user"`
Role types.MemberRole `json:"role"`
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 {

View File

@ -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"
@ -31,7 +31,7 @@ import (
type CreateProjectRequest struct {
Name string `json:"name,omitempty"`
ParentRef string `json:"parent_ref,omitempty"`
Visibility types.Visibility `json:"visibility,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"`
@ -79,7 +79,7 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type UpdateProjectRequest struct {
Name string `json:"name,omitempty"`
Visibility types.Visibility `json:"visibility,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
}
type UpdateProjectHandler struct {
@ -244,7 +244,7 @@ type ProjectResponse struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
ParentPath string `json:"parent_path,omitempty"`
Visibility types.Visibility `json:"visibility,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
GlobalVisibility string `json:"global_visibility,omitempty"`
}

View File

@ -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"
@ -32,7 +32,7 @@ import (
type CreateProjectGroupRequest struct {
Name string `json:"name"`
ParentRef string `json:"parent_ref"`
Visibility types.Visibility `json:"visibility"`
Visibility cstypes.Visibility `json:"visibility"`
}
type CreateProjectGroupHandler struct {
@ -82,7 +82,7 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
type UpdateProjectGroupRequest struct {
Name string `json:"name,omitempty"`
Visibility types.Visibility `json:"visibility,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
}
type UpdateProjectGroupHandler struct {
@ -258,7 +258,7 @@ type ProjectGroupResponse struct {
Name string `json:"name"`
Path string `json:"path"`
ParentPath string `json:"parent_path"`
Visibility types.Visibility `json:"visibility"`
Visibility cstypes.Visibility `json:"visibility"`
GlobalVisibility string `json:"global_visibility"`
}

View File

@ -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

View File

@ -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,

View File

@ -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"`

View File

@ -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,7 +256,7 @@ type CreateUserLARequest struct {
}
type CreateUserLAResponse struct {
LinkedAccount *types.LinkedAccount `json:"linked_account"`
LinkedAccount *cstypes.LinkedAccount `json:"linked_account"`
Oauth2Redirect string `json:"oauth2_redirect"`
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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)