Merge pull request #77 from sgotti/export_api_client_types

*: export clients and related types
This commit is contained in:
Simone Gotti 2019-08-02 14:41:50 +02:00 committed by GitHub
commit b333b6f423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
137 changed files with 1778 additions and 1202 deletions

View File

@ -36,7 +36,7 @@ local task_build_go(version, arch) = {
{ type: 'run', command: 'golangci-lint run --deadline 5m' }, { type: 'run', command: 'golangci-lint run --deadline 5m' },
{ type: 'run', name: 'build docker/k8s drivers tests binary', command: 'CGO_ENABLED=0 go test -c ./internal/services/executor/driver -o ./bin/docker-tests' }, { type: 'run', name: 'build docker/k8s drivers tests binary', command: 'CGO_ENABLED=0 go test -c ./internal/services/executor/driver -o ./bin/docker-tests' },
{ type: 'run', name: 'build integration tests binary', command: 'go test -tags "sqlite_unlock_notify" -c ./tests -o ./bin/integration-tests' }, { type: 'run', name: 'build integration tests binary', command: 'go test -tags "sqlite_unlock_notify" -c ./tests -o ./bin/integration-tests' },
{ type: 'run', name: 'run tests', command: 'SKIP_DOCKER_TESTS=1 SKIP_K8S_TESTS=1 go test -v -count 1 ./cmd/... ./internal/...' }, { type: 'run', name: 'run tests', command: 'SKIP_DOCKER_TESTS=1 SKIP_K8S_TESTS=1 go test -v -count 1 $(go list ./... | grep -v /tests)' },
{ type: 'run', name: 'fetch gitea binary for integration tests', command: 'curl -L https://github.com/go-gitea/gitea/releases/download/v1.8.3/gitea-1.8.3-linux-amd64 -o ./bin/gitea && chmod +x ./bin/gitea' }, { type: 'run', name: 'fetch gitea binary for integration tests', command: 'curl -L https://github.com/go-gitea/gitea/releases/download/v1.8.3/gitea-1.8.3-linux-amd64 -o ./bin/gitea && chmod +x ./bin/gitea' },
{ type: 'save_to_workspace', contents: [{ source_dir: './bin', dest_dir: '/bin/', paths: ['*'] }] }, { type: 'save_to_workspace', contents: [{ source_dir: './bin', dest_dir: '/bin/', paths: ['*'] }] },
], ],

View File

@ -20,8 +20,9 @@ import (
"path" "path"
gitsave "agola.io/agola/internal/git-save" gitsave "agola.io/agola/internal/git-save"
"agola.io/agola/internal/services/gateway/api"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -62,7 +63,7 @@ func init() {
} }
func directRunStart(cmd *cobra.Command, args []string) error { func directRunStart(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
user, _, err := gwclient.GetCurrentUser(context.TODO()) user, _, err := gwclient.GetCurrentUser(context.TODO())
if err != nil { if err != nil {
@ -102,7 +103,7 @@ func directRunStart(cmd *cobra.Command, args []string) error {
} }
log.Infof("starting direct run") log.Infof("starting direct run")
req := &api.UserCreateRunRequest{ req := &gwapitypes.UserCreateRunRequest{
RepoUUID: repoUUID, RepoUUID: repoUUID,
RepoPath: repoPath, RepoPath: repoPath,
Branch: branch, Branch: branch,

View File

@ -17,8 +17,8 @@ package cmd
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -55,16 +55,16 @@ func init() {
} }
func orgCreate(cmd *cobra.Command, args []string) error { func orgCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// TODO(sgotti) make this a custom pflag Value? // TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(orgCreateOpts.visibility)) { if !IsValidVisibility(orgCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", orgCreateOpts.visibility) return errors.Errorf("invalid visibility %q", orgCreateOpts.visibility)
} }
req := &api.CreateOrgRequest{ req := &gwapitypes.CreateOrgRequest{
Name: orgCreateOpts.name, Name: orgCreateOpts.name,
Visibility: cstypes.Visibility(orgCreateOpts.visibility), Visibility: gwapitypes.Visibility(orgCreateOpts.visibility),
} }
log.Infof("creating org") log.Infof("creating org")

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
} }
func orgDelete(cmd *cobra.Command, args []string) error { func orgDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting organization %q", orgDeleteOpts.name) log.Infof("deleting organization %q", orgDeleteOpts.name)
if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil { if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil {

View File

@ -17,8 +17,8 @@ package cmd
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -60,10 +60,10 @@ func init() {
} }
func orgMemberAdd(cmd *cobra.Command, args []string) error { func orgMemberAdd(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role) 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, cstypes.MemberRole(orgMemberAddOpts.role)) _, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, gwapitypes.MemberRole(orgMemberAddOpts.role))
if err != nil { if err != nil {
return errors.Errorf("failed to add/update organization member: %w", err) return errors.Errorf("failed to add/update organization member: %w", err)
} }

View File

@ -19,7 +19,7 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -54,7 +54,7 @@ func init() {
} }
func orgMemberList(cmd *cobra.Command, args []string) error { func orgMemberList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
orgMembers, _, err := gwclient.GetOrgMembers(context.TODO(), orgMemberListOpts.orgname) orgMembers, _, err := gwclient.GetOrgMembers(context.TODO(), orgMemberListOpts.orgname)
if err != nil { if err != nil {

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
} }
func orgMemberRemove(cmd *cobra.Command, args []string) error { func orgMemberRemove(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname) log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname)
_, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username) _, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username)

View File

@ -17,8 +17,8 @@ package cmd
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -71,18 +71,28 @@ func init() {
cmdProject.AddCommand(cmdProjectCreate) cmdProject.AddCommand(cmdProjectCreate)
} }
func IsValidVisibility(v string) bool {
switch gwapitypes.Visibility(v) {
case gwapitypes.VisibilityPublic:
case gwapitypes.VisibilityPrivate:
default:
return false
}
return true
}
func projectCreate(cmd *cobra.Command, args []string) error { func projectCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// TODO(sgotti) make this a custom pflag Value? // TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) { if !IsValidVisibility(projectCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility) return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility)
} }
req := &api.CreateProjectRequest{ req := &gwapitypes.CreateProjectRequest{
Name: projectCreateOpts.name, Name: projectCreateOpts.name,
ParentRef: projectCreateOpts.parentPath, ParentRef: projectCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility), Visibility: gwapitypes.Visibility(projectCreateOpts.visibility),
RepoPath: projectCreateOpts.repoPath, RepoPath: projectCreateOpts.repoPath,
RemoteSourceName: projectCreateOpts.remoteSourceName, RemoteSourceName: projectCreateOpts.remoteSourceName,
SkipSSHHostKeyCheck: projectCreateOpts.skipSSHHostKeyCheck, SkipSSHHostKeyCheck: projectCreateOpts.skipSSHHostKeyCheck,

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
} }
func projectDelete(cmd *cobra.Command, args []string) error { func projectDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting project") log.Infof("deleting project")

View File

@ -17,8 +17,8 @@ package cmd
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -60,17 +60,17 @@ func init() {
} }
func projectGroupCreate(cmd *cobra.Command, args []string) error { func projectGroupCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// TODO(sgotti) make this a custom pflag Value? // TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) { if !IsValidVisibility(projectGroupCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility) return errors.Errorf("invalid visibility %q", projectGroupCreateOpts.visibility)
} }
req := &api.CreateProjectGroupRequest{ req := &gwapitypes.CreateProjectGroupRequest{
Name: projectGroupCreateOpts.name, Name: projectGroupCreateOpts.name,
ParentRef: projectGroupCreateOpts.parentPath, ParentRef: projectGroupCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility), Visibility: gwapitypes.Visibility(projectGroupCreateOpts.visibility),
} }
log.Infof("creating project group") log.Infof("creating project group")

View File

@ -18,7 +18,9 @@ import (
"context" "context"
"fmt" "fmt"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -50,14 +52,14 @@ func init() {
cmdProject.AddCommand(cmdProjectList) cmdProject.AddCommand(cmdProjectList)
} }
func printProjects(projects []*api.ProjectResponse) { func printProjects(projects []*gwapitypes.ProjectResponse) {
for _, project := range projects { for _, project := range projects {
fmt.Printf("%s: Name: %s\n", project.ID, project.Name) fmt.Printf("%s: Name: %s\n", project.ID, project.Name)
} }
} }
func projectList(cmd *cobra.Command, args []string) error { func projectList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
projects, _, err := gwclient.GetProjectGroupProjects(context.TODO(), projectListOpts.parentPath) projects, _, err := gwclient.GetProjectGroupProjects(context.TODO(), projectListOpts.parentPath)
if err != nil { if err != nil {

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
} }
func projectReconfig(cmd *cobra.Command, args []string) error { func projectReconfig(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("reconfiguring remote project") log.Infof("reconfiguring remote project")
if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil { if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil {

View File

@ -19,8 +19,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -73,7 +73,7 @@ func init() {
} }
func secretCreate(cmd *cobra.Command, ownertype string, args []string) error { func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// "github.com/ghodss/yaml" doesn't provide a streaming decoder // "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte var data []byte
@ -94,9 +94,9 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &secretData); err != nil { if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err) log.Fatalf("failed to unmarshal secret: %v", err)
} }
req := &api.CreateSecretRequest{ req := &gwapitypes.CreateSecretRequest{
Name: secretCreateOpts.name, Name: secretCreateOpts.name,
Type: cstypes.SecretTypeInternal, Type: gwapitypes.SecretTypeInternal,
Data: secretData, Data: secretData,
} }

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
} }
func secretDelete(cmd *cobra.Command, ownertype string, args []string) error { func secretDelete(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
switch ownertype { switch ownertype {
case "project": case "project":

View File

@ -19,8 +19,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -75,7 +75,7 @@ func init() {
} }
func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error { func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// "github.com/ghodss/yaml" doesn't provide a streaming decoder // "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte var data []byte
@ -96,9 +96,9 @@ func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &secretData); err != nil { if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err) log.Fatalf("failed to unmarshal secret: %v", err)
} }
req := &api.UpdateSecretRequest{ req := &gwapitypes.UpdateSecretRequest{
Name: secretUpdateOpts.name, Name: secretUpdateOpts.name,
Type: cstypes.SecretTypeInternal, Type: gwapitypes.SecretTypeInternal,
Data: secretData, Data: secretData,
} }

View File

@ -19,9 +19,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"agola.io/agola/internal/config" gwapitypes "agola.io/agola/services/gateway/api/types"
cstypes "agola.io/agola/internal/services/configstore/types" gwclient "agola.io/agola/services/gateway/client"
"agola.io/agola/internal/services/gateway/api"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -92,11 +91,11 @@ type VariableValue struct {
SecretName string `json:"secret_name,omitempty"` SecretName string `json:"secret_name,omitempty"`
SecretVar string `json:"secret_var,omitempty"` SecretVar string `json:"secret_var,omitempty"`
When *config.When `json:"when,omitempty"` When *gwapitypes.When `json:"when,omitempty"`
} }
func variableCreate(cmd *cobra.Command, ownertype string, args []string) error { func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// "github.com/ghodss/yaml" doesn't provide a streaming decoder // "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte var data []byte
@ -117,15 +116,15 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &values); err != nil { if err := yaml.Unmarshal(data, &values); err != nil {
log.Fatalf("failed to unmarshal values: %v", err) log.Fatalf("failed to unmarshal values: %v", err)
} }
rvalues := []cstypes.VariableValue{} rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values { for _, value := range values {
rvalues = append(rvalues, cstypes.VariableValue{ rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName, SecretName: value.SecretName,
SecretVar: value.SecretVar, SecretVar: value.SecretVar,
When: (*cstypes.When)(value.When), When: value.When,
}) })
} }
req := &api.CreateVariableRequest{ req := &gwapitypes.CreateVariableRequest{
Name: variableCreateOpts.name, Name: variableCreateOpts.name,
Values: rvalues, Values: rvalues,
} }

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
} }
func variableDelete(cmd *cobra.Command, ownertype string, args []string) error { func variableDelete(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
switch ownertype { switch ownertype {
case "project": case "project":

View File

@ -19,8 +19,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -68,7 +68,7 @@ func init() {
} }
func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error { func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// "github.com/ghodss/yaml" doesn't provide a streaming decoder // "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte var data []byte
@ -89,15 +89,15 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &values); err != nil { if err := yaml.Unmarshal(data, &values); err != nil {
log.Fatalf("failed to unmarshall values: %v", err) log.Fatalf("failed to unmarshall values: %v", err)
} }
rvalues := []cstypes.VariableValue{} rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values { for _, value := range values {
rvalues = append(rvalues, cstypes.VariableValue{ rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName, SecretName: value.SecretName,
SecretVar: value.SecretVar, SecretVar: value.SecretVar,
When: (*cstypes.When)(value.When), When: value.When,
}) })
} }
req := &api.UpdateVariableRequest{ req := &gwapitypes.UpdateVariableRequest{
Name: variableUpdateOpts.name, Name: variableUpdateOpts.name,
Values: rvalues, Values: rvalues,
} }

View File

@ -18,9 +18,9 @@ import (
"context" "context"
"agola.io/agola/internal/gitsources/github" "agola.io/agola/internal/gitsources/github"
cstypes "agola.io/agola/internal/services/configstore/types" gwapitypes "agola.io/agola/services/gateway/api/types"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"agola.io/agola/internal/util" "agola.io/agola/util"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -81,10 +81,10 @@ func init() {
} }
func remoteSourceCreate(cmd *cobra.Command, args []string) error { func remoteSourceCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
// for github remote source type, set defaults for github.com // for github remote source type, set defaults for github.com
if remoteSourceCreateOpts.rsType == string(cstypes.RemoteSourceTypeGithub) { if remoteSourceCreateOpts.rsType == "github" {
remoteSourceCreateOpts.apiURL = github.GitHubAPIURL remoteSourceCreateOpts.apiURL = github.GitHubAPIURL
remoteSourceCreateOpts.sshHostKey = github.GitHubSSHHostKey remoteSourceCreateOpts.sshHostKey = github.GitHubSSHHostKey
} }
@ -93,7 +93,7 @@ func remoteSourceCreate(cmd *cobra.Command, args []string) error {
return errors.Errorf(`required flag "api-url" not set`) return errors.Errorf(`required flag "api-url" not set`)
} }
req := &api.CreateRemoteSourceRequest{ req := &gwapitypes.CreateRemoteSourceRequest{
Name: remoteSourceCreateOpts.name, Name: remoteSourceCreateOpts.name,
Type: remoteSourceCreateOpts.rsType, Type: remoteSourceCreateOpts.rsType,
AuthType: remoteSourceCreateOpts.authType, AuthType: remoteSourceCreateOpts.authType,

View File

@ -18,7 +18,9 @@ import (
"context" "context"
"fmt" "fmt"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -48,14 +50,14 @@ func init() {
cmdRemoteSource.AddCommand(cmdRemoteSourceList) cmdRemoteSource.AddCommand(cmdRemoteSourceList)
} }
func printRemoteSources(remoteSources []*api.RemoteSourceResponse) { func printRemoteSources(remoteSources []*gwapitypes.RemoteSourceResponse) {
for _, rs := range remoteSources { for _, rs := range remoteSources {
fmt.Printf("%s: Name: %s\n", rs.ID, rs.Name) fmt.Printf("%s: Name: %s\n", rs.ID, rs.Name)
} }
} }
func remoteSourceList(cmd *cobra.Command, args []string) error { func remoteSourceList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
remouteSources, _, err := gwclient.GetRemoteSources(context.TODO(), remoteSourceListOpts.start, remoteSourceListOpts.limit, false) remouteSources, _, err := gwclient.GetRemoteSources(context.TODO(), remoteSourceListOpts.start, remoteSourceListOpts.limit, false)
if err != nil { if err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -71,9 +72,9 @@ func init() {
} }
func remoteSourceUpdate(cmd *cobra.Command, args []string) error { func remoteSourceUpdate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
req := &api.UpdateRemoteSourceRequest{} req := &gwapitypes.UpdateRemoteSourceRequest{}
flags := cmd.Flags() flags := cmd.Flags()
if flags.Changed("new-name") { if flags.Changed("new-name") {

View File

@ -19,7 +19,8 @@ import (
"fmt" "fmt"
"path" "path"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -59,7 +60,7 @@ func init() {
cmdRun.AddCommand(cmdRunList) cmdRun.AddCommand(cmdRunList)
} }
func printRuns(runs []*api.RunResponse) { func printRuns(runs []*gwapitypes.RunResponse) {
for _, run := range runs { for _, run := range runs {
fmt.Printf("%s: Phase: %s, Result: %s\n", run.ID, run.Phase, run.Result) fmt.Printf("%s: Phase: %s, Result: %s\n", run.ID, run.Phase, run.Result)
for _, task := range run.Tasks { for _, task := range run.Tasks {
@ -69,7 +70,7 @@ func printRuns(runs []*api.RunResponse) {
} }
func runList(cmd *cobra.Command, args []string) error { func runList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
project, _, err := gwclient.GetProject(context.TODO(), runListOpts.projectRef) project, _, err := gwclient.GetProject(context.TODO(), runListOpts.projectRef)
if err != nil { if err != nil {
@ -81,7 +82,7 @@ func runList(cmd *cobra.Command, args []string) error {
return err return err
} }
runs := make([]*api.RunResponse, len(runsResp)) runs := make([]*gwapitypes.RunResponse, len(runsResp))
for i, runResponse := range runsResp { for i, runResponse := range runsResp {
run, _, err := gwclient.GetRun(context.TODO(), runResponse.ID) run, _, err := gwclient.GetRun(context.TODO(), runResponse.ID)
if err != nil { if err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -52,9 +53,9 @@ func init() {
} }
func userCreate(cmd *cobra.Command, args []string) error { func userCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
req := &api.CreateUserRequest{ req := &gwapitypes.CreateUserRequest{
UserName: userCreateOpts.username, UserName: userCreateOpts.username,
} }

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
} }
func userDelete(cmd *cobra.Command, args []string) error { func userDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting user %q", userDeleteOpts.username) log.Infof("deleting user %q", userDeleteOpts.username)
if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil { if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -61,9 +62,9 @@ func init() {
} }
func userLACreate(cmd *cobra.Command, args []string) error { func userLACreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
req := &api.CreateUserLARequest{ req := &gwapitypes.CreateUserLARequest{
RemoteSourceName: userLACreateOpts.remoteSourceName, RemoteSourceName: userLACreateOpts.remoteSourceName,
RemoteSourceLoginName: userLACreateOpts.remoteSourceLoginName, RemoteSourceLoginName: userLACreateOpts.remoteSourceLoginName,
RemoteSourceLoginPassword: userLACreateOpts.remoteSourceLoginPassword, RemoteSourceLoginPassword: userLACreateOpts.remoteSourceLoginPassword,

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
} }
func userLADelete(cmd *cobra.Command, args []string) error { func userLADelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
userName := userLADeleteOpts.userName userName := userLADeleteOpts.userName
laID := userLADeleteOpts.laID laID := userLADeleteOpts.laID

View File

@ -18,7 +18,9 @@ import (
"context" "context"
"fmt" "fmt"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -48,14 +50,14 @@ func init() {
cmdUser.AddCommand(cmdUserList) cmdUser.AddCommand(cmdUserList)
} }
func printUsers(users []*api.UserResponse) { func printUsers(users []*gwapitypes.UserResponse) {
for _, user := range users { for _, user := range users {
fmt.Printf("%s: Name: %s\n", user.ID, user.UserName) fmt.Printf("%s: Name: %s\n", user.ID, user.UserName)
} }
} }
func userList(cmd *cobra.Command, args []string) error { func userList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
users, _, err := gwclient.GetUsers(context.TODO(), userListOpts.start, userListOpts.limit, false) users, _, err := gwclient.GetUsers(context.TODO(), userListOpts.start, userListOpts.limit, false)
if err != nil { if err != nil {

View File

@ -18,7 +18,8 @@ import (
"context" "context"
"fmt" "fmt"
"agola.io/agola/internal/services/gateway/api" gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -58,9 +59,9 @@ func init() {
} }
func userTokenCreate(cmd *cobra.Command, args []string) error { func userTokenCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
req := &api.CreateUserTokenRequest{ req := &gwapitypes.CreateUserTokenRequest{
TokenName: userTokenCreateOpts.tokenName, TokenName: userTokenCreateOpts.tokenName,
} }

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"context" "context"
"agola.io/agola/internal/services/gateway/api" gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
} }
func userTokenDelete(cmd *cobra.Command, args []string) error { func userTokenDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token) gwclient := gwclient.NewClient(gatewayURL, token)
userName := userTokenDeleteOpts.userName userName := userTokenDeleteOpts.userName
tokenName := userTokenDeleteOpts.tokenName tokenName := userTokenDeleteOpts.tokenName

View File

@ -20,9 +20,9 @@ import (
"regexp" "regexp"
"strings" "strings"
"agola.io/agola/internal/common"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
"agola.io/agola/services/types"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/google/go-jsonnet" "github.com/google/go-jsonnet"
@ -83,7 +83,7 @@ type DockerRegistryAuth struct {
type Runtime struct { type Runtime struct {
Type RuntimeType `json:"type,omitempty"` Type RuntimeType `json:"type,omitempty"`
Arch common.Arch `json:"arch,omitempty"` Arch types.Arch `json:"arch,omitempty"`
Containers []*Container `json:"containers,omitempty"` Containers []*Container `json:"containers,omitempty"`
} }
@ -702,7 +702,7 @@ func checkConfig(config *Config) error {
return errors.Errorf("task %q runtime: at least one container must be defined", task.Name) return errors.Errorf("task %q runtime: at least one container must be defined", task.Name)
} }
if r.Arch != "" { if r.Arch != "" {
if !common.IsValidArch(r.Arch) { if !types.IsValidArch(r.Arch) {
return errors.Errorf("task %q runtime: invalid arch %q", task.Name, r.Arch) return errors.Errorf("task %q runtime: invalid arch %q", task.Name, r.Arch)
} }
} }

View File

@ -18,8 +18,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -35,7 +35,6 @@ var (
tagRefPrefix = "refs/tags/" tagRefPrefix = "refs/tags/"
) )
// Client represents a Gogs API client.
type Client struct { type Client struct {
url string url string
client *http.Client client *http.Client

View File

@ -19,9 +19,9 @@ import (
"strings" "strings"
"agola.io/agola/internal/config" "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/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
rstypes "agola.io/agola/services/runservice/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -20,9 +20,9 @@ import (
"testing" "testing"
"agola.io/agola/internal/config" "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/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
rstypes "agola.io/agola/services/runservice/types"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -19,7 +19,7 @@ import (
"agola.io/agola/internal/gitsources/gitea" "agola.io/agola/internal/gitsources/gitea"
"agola.io/agola/internal/gitsources/github" "agola.io/agola/internal/gitsources/github"
"agola.io/agola/internal/gitsources/gitlab" "agola.io/agola/internal/gitsources/gitlab"
cstypes "agola.io/agola/internal/services/configstore/types" cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -15,20 +15,20 @@
package common package common
import ( import (
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
) )
func FilterOverriddenVariables(variables []*csapi.Variable) []*csapi.Variable { func FilterOverriddenVariables(variables []*csapitypes.Variable) []*csapitypes.Variable {
variablesMap := map[string]*csapi.Variable{} variablesMap := map[string]*csapitypes.Variable{}
for _, v := range variables { for _, v := range variables {
if _, ok := variablesMap[v.Name]; !ok { if _, ok := variablesMap[v.Name]; !ok {
variablesMap[v.Name] = v variablesMap[v.Name] = v
} }
} }
filteredVariables := make([]*csapi.Variable, len(variablesMap)) filteredVariables := make([]*csapitypes.Variable, len(variablesMap))
i := 0 i := 0
// keep the original order // keep the original order
for _, v := range variables { for _, v := range variables {
@ -43,9 +43,9 @@ func FilterOverriddenVariables(variables []*csapi.Variable) []*csapi.Variable {
return filteredVariables return filteredVariables
} }
func GetVarValueMatchingSecret(varval cstypes.VariableValue, varParentPath string, secrets []*csapi.Secret) *csapi.Secret { func GetVarValueMatchingSecret(varval cstypes.VariableValue, varParentPath string, secrets []*csapitypes.Secret) *csapitypes.Secret {
// get the secret value referenced by the variable, it must be a secret at the same level or a lower level // 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 var secret *csapitypes.Secret
for _, s := range secrets { for _, s := range secrets {
// we assume the root path will be the same // we assume the root path will be the same
if s.Name != varval.SecretName { if s.Name != varval.SecretName {

View File

@ -17,84 +17,85 @@ package common
import ( import (
"testing" "testing"
csapi "agola.io/agola/internal/services/configstore/api" csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/internal/services/configstore/types" cstypes "agola.io/agola/services/configstore/types"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
) )
func TestFilterOverriddenVariables(t *testing.T) { func TestFilterOverriddenVariables(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
variables []*csapi.Variable variables []*csapitypes.Variable
out []*csapi.Variable out []*csapitypes.Variable
}{ }{
{ {
name: "test empty variables", name: "test empty variables",
variables: []*csapi.Variable{}, variables: []*csapitypes.Variable{},
out: []*csapi.Variable{}, out: []*csapitypes.Variable{},
}, },
{ {
name: "test variable overrides", name: "test variable overrides",
variables: []*csapi.Variable{ variables: []*csapitypes.Variable{
// variables must be in depth (from leaves to root) order as returned by the // variables must be in depth (from leaves to root) order as returned by the
// configstore apis // configstore apis
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var04", Name: "var04",
}, },
ParentPath: "org/org01/projectgroup02/projectgroup03/project02", ParentPath: "org/org01/projectgroup02/projectgroup03/project02",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var03", Name: "var03",
}, },
ParentPath: "org/org01/projectgroup01/project01", ParentPath: "org/org01/projectgroup01/project01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var02", Name: "var02",
}, },
ParentPath: "org/org01/projectgroup01/project01", ParentPath: "org/org01/projectgroup01/project01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var02", Name: "var02",
}, },
ParentPath: "org/org01/projectgroup01", ParentPath: "org/org01/projectgroup01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var01", Name: "var01",
}, },
ParentPath: "org/org01/projectgroup01", ParentPath: "org/org01/projectgroup01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var01", Name: "var01",
}, },
ParentPath: "org/org01", ParentPath: "org/org01",
}, },
}, },
out: []*csapi.Variable{ out: []*csapitypes.Variable{
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var04", Name: "var04",
}, },
ParentPath: "org/org01/projectgroup02/projectgroup03/project02", ParentPath: "org/org01/projectgroup02/projectgroup03/project02",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var03", Name: "var03",
}, },
ParentPath: "org/org01/projectgroup01/project01", ParentPath: "org/org01/projectgroup01/project01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var02", Name: "var02",
}, },
ParentPath: "org/org01/projectgroup01/project01", ParentPath: "org/org01/projectgroup01/project01",
}, },
&csapi.Variable{ &csapitypes.Variable{
Variable: &cstypes.Variable{ Variable: &cstypes.Variable{
Name: "var01", Name: "var01",
}, },
@ -120,8 +121,8 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
name string name string
varValue cstypes.VariableValue varValue cstypes.VariableValue
varParentPath string varParentPath string
secrets []*csapi.Secret secrets []*csapitypes.Secret
out *csapi.Secret out *csapitypes.Secret
}{ }{
{ {
name: "test empty secrets", name: "test empty secrets",
@ -130,7 +131,7 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/project01", varParentPath: "org/org01/projectgroup01/project01",
secrets: []*csapi.Secret{}, secrets: []*csapitypes.Secret{},
out: nil, out: nil,
}, },
{ {
@ -140,8 +141,8 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret02", Name: "secret02",
}, },
@ -157,8 +158,8 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret02", Name: "secret02",
}, },
@ -174,8 +175,8 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
@ -191,21 +192,21 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01/projectgroup02/project01", ParentPath: "org/org01/projectgroup01/projectgroup02/project01",
}, },
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01/projectgroup02", ParentPath: "org/org01/projectgroup01/projectgroup02",
}, },
}, },
out: &csapi.Secret{ out: &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
@ -219,15 +220,15 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01", ParentPath: "org/org01/projectgroup01",
}, },
}, },
out: &csapi.Secret{ out: &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
@ -241,29 +242,29 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
SecretVar: "secretvar01", SecretVar: "secretvar01",
}, },
varParentPath: "org/org01/projectgroup01/projectgroup02", varParentPath: "org/org01/projectgroup01/projectgroup02",
secrets: []*csapi.Secret{ secrets: []*csapitypes.Secret{
// secrets must be in depth (from leaves to root) order as returned by the // secrets must be in depth (from leaves to root) order as returned by the
// configstore apis // configstore apis
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01/projectgroup02/project01", ParentPath: "org/org01/projectgroup01/projectgroup02/project01",
}, },
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01/projectgroup02", ParentPath: "org/org01/projectgroup01/projectgroup02",
}, },
&csapi.Secret{ &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },
ParentPath: "org/org01/projectgroup01", ParentPath: "org/org01/projectgroup01",
}, },
}, },
out: &csapi.Secret{ out: &csapitypes.Secret{
Secret: &cstypes.Secret{ Secret: &cstypes.Secret{
Name: "secret01", Name: "secret01",
}, },

View File

@ -23,8 +23,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -21,8 +21,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -21,8 +21,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -20,8 +20,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -20,8 +20,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -22,8 +22,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -20,8 +20,8 @@ import (
"agola.io/agola/internal/datamanager" "agola.io/agola/internal/datamanager"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -19,8 +19,9 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -22,12 +22,13 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
errors "golang.org/x/xerrors" csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type OrgHandler struct { type OrgHandler struct {
@ -180,10 +181,6 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type AddOrgMemberRequest struct {
Role types.MemberRole
}
type AddOrgMemberHandler struct { type AddOrgMemberHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -200,7 +197,7 @@ func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
orgRef := vars["orgref"] orgRef := vars["orgref"]
userRef := vars["userref"] userRef := vars["userref"]
var req AddOrgMemberRequest var req csapitypes.AddOrgMemberRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -245,13 +242,8 @@ func (h *RemoveOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
} }
} }
type OrgMemberResponse struct { func orgMemberResponse(orgUser *action.OrgMemberResponse) *csapitypes.OrgMemberResponse {
User *types.User return &csapitypes.OrgMemberResponse{
Role types.MemberRole
}
func orgMemberResponse(orgUser *action.OrgMemberResponse) *OrgMemberResponse {
return &OrgMemberResponse{
User: orgUser.User, User: orgUser.User,
Role: orgUser.Role, Role: orgUser.Role,
} }
@ -277,7 +269,7 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
res := make([]*OrgMemberResponse, len(orgUsers)) res := make([]*csapitypes.OrgMemberResponse, len(orgUsers))
for i, orgUser := range orgUsers { for i, orgUser := range orgUsers {
res[i] = orgMemberResponse(orgUser) res[i] = orgMemberResponse(orgUser)
} }

View File

@ -24,27 +24,16 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
errors "golang.org/x/xerrors" csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
// Project augments types.Project with dynamic data func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.Project) (*csapitypes.Project, error) {
type Project struct {
*types.Project
// dynamic data
OwnerType types.ConfigType
OwnerID string
Path string
ParentPath string
GlobalVisibility types.Visibility
}
func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.Project) (*Project, error) {
r, err := projectsResponse(ctx, readDB, []*types.Project{project}) r, err := projectsResponse(ctx, readDB, []*types.Project{project})
if err != nil { if err != nil {
return nil, err return nil, err
@ -52,8 +41,8 @@ func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.
return r[0], nil return r[0], nil
} }
func projectsResponse(ctx context.Context, readDB *readdb.ReadDB, projects []*types.Project) ([]*Project, error) { func projectsResponse(ctx context.Context, readDB *readdb.ReadDB, projects []*types.Project) ([]*csapitypes.Project, error) {
resProjects := make([]*Project, len(projects)) resProjects := make([]*csapitypes.Project, len(projects))
err := readDB.Do(ctx, func(tx *db.Tx) error { err := readDB.Do(ctx, func(tx *db.Tx) error {
for i, project := range projects { for i, project := range projects {
@ -75,7 +64,7 @@ func projectsResponse(ctx context.Context, readDB *readdb.ReadDB, projects []*ty
// we calculate the path here from parent path since the db could not yet be // we calculate the path here from parent path since the db could not yet be
// updated on create // updated on create
resProjects[i] = &Project{ resProjects[i] = &csapitypes.Project{
Project: project, Project: project,
OwnerType: ownerType, OwnerType: ownerType,
OwnerID: ownerID, OwnerID: ownerID,

View File

@ -24,27 +24,16 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
errors "golang.org/x/xerrors" csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
// ProjectGroup augments types.ProjectGroup with dynamic data func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroup *types.ProjectGroup) (*csapitypes.ProjectGroup, error) {
type ProjectGroup struct {
*types.ProjectGroup
// dynamic data
OwnerType types.ConfigType
OwnerID string
Path string
ParentPath string
GlobalVisibility types.Visibility
}
func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroup *types.ProjectGroup) (*ProjectGroup, error) {
r, err := projectGroupsResponse(ctx, readDB, []*types.ProjectGroup{projectGroup}) r, err := projectGroupsResponse(ctx, readDB, []*types.ProjectGroup{projectGroup})
if err != nil { if err != nil {
return nil, err return nil, err
@ -52,8 +41,8 @@ func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGro
return r[0], nil return r[0], nil
} }
func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroups []*types.ProjectGroup) ([]*ProjectGroup, error) { func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroups []*types.ProjectGroup) ([]*csapitypes.ProjectGroup, error) {
resProjectGroups := make([]*ProjectGroup, len(projectGroups)) resProjectGroups := make([]*csapitypes.ProjectGroup, len(projectGroups))
err := readDB.Do(ctx, func(tx *db.Tx) error { err := readDB.Do(ctx, func(tx *db.Tx) error {
for i, projectGroup := range projectGroups { for i, projectGroup := range projectGroups {
@ -75,7 +64,7 @@ func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGr
// we calculate the path here from parent path since the db could not yet be // we calculate the path here from parent path since the db could not yet be
// updated on create // updated on create
resProjectGroups[i] = &ProjectGroup{ resProjectGroups[i] = &csapitypes.ProjectGroup{
ProjectGroup: projectGroup, ProjectGroup: projectGroup,
OwnerType: ownerType, OwnerType: ownerType,
OwnerID: ownerID, OwnerID: ownerID,

View File

@ -22,12 +22,12 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
errors "golang.org/x/xerrors" "agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type RemoteSourceHandler struct { type RemoteSourceHandler struct {

View File

@ -21,21 +21,14 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
) )
// Secret augments types.Secret with dynamic data
type Secret struct {
*types.Secret
// dynamic data
ParentPath string
}
type SecretHandler struct { type SecretHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -89,9 +82,9 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
resSecrets := make([]*Secret, len(secrets)) resSecrets := make([]*csapitypes.Secret, len(secrets))
for i, s := range secrets { for i, s := range secrets {
resSecrets[i] = &Secret{Secret: s} resSecrets[i] = &csapitypes.Secret{Secret: s}
} }
err = h.readDB.Do(ctx, func(tx *db.Tx) error { err = h.readDB.Do(ctx, func(tx *db.Tx) error {

View File

@ -18,17 +18,17 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"strconv" "strconv"
"time"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
action "agola.io/agola/internal/services/configstore/action" action "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
errors "golang.org/x/xerrors" csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type UserHandler struct { type UserHandler struct {
@ -67,12 +67,6 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type CreateUserRequest struct {
UserName string `json:"user_name"`
CreateUserLARequest *CreateUserLARequest `json:"create_user_la_request"`
}
type CreateUserHandler struct { type CreateUserHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -85,7 +79,7 @@ func NewCreateUserHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateU
func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req *CreateUserRequest var req *csapitypes.CreateUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -118,10 +112,6 @@ func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type UpdateUserRequest struct {
UserName string `json:"user_name"`
}
type UpdateUserHandler struct { type UpdateUserHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -137,7 +127,7 @@ func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
userRef := vars["userref"] userRef := vars["userref"]
var req *UpdateUserRequest var req *csapitypes.UpdateUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -305,16 +295,6 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type CreateUserLARequest struct {
RemoteSourceName string `json:"remote_source_name"`
RemoteUserID string `json:"remote_user_id"`
RemoteUserName string `json:"remote_user_name"`
UserAccessToken string `json:"user_access_token"`
Oauth2AccessToken string `json:"oauth2_access_token"`
Oauth2RefreshToken string `json:"oauth2_refresh_token"`
Oauth2AccessTokenExpiresAt time.Time `json:"oauth_2_access_token_expires_at"`
}
type CreateUserLAHandler struct { type CreateUserLAHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -329,7 +309,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
vars := mux.Vars(r) vars := mux.Vars(r)
userRef := vars["userref"] userRef := vars["userref"]
var req CreateUserLARequest var req csapitypes.CreateUserLARequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -381,15 +361,6 @@ func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
type UpdateUserLARequest struct {
RemoteUserID string `json:"remote_user_id"`
RemoteUserName string `json:"remote_user_name"`
UserAccessToken string `json:"user_access_token"`
Oauth2AccessToken string `json:"oauth2_access_token"`
Oauth2RefreshToken string `json:"oauth2_refresh_token"`
Oauth2AccessTokenExpiresAt time.Time `json:"oauth_2_access_token_expires_at"`
}
type UpdateUserLAHandler struct { type UpdateUserLAHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -405,7 +376,7 @@ func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
userRef := vars["userref"] userRef := vars["userref"]
linkedAccountID := vars["laid"] linkedAccountID := vars["laid"]
var req UpdateUserLARequest var req csapitypes.UpdateUserLARequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -433,14 +404,6 @@ func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
type CreateUserTokenRequest struct {
TokenName string `json:"token_name"`
}
type CreateUserTokenResponse struct {
Token string `json:"token"`
}
type CreateUserTokenHandler struct { type CreateUserTokenHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -455,7 +418,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r) vars := mux.Vars(r)
userRef := vars["userref"] userRef := vars["userref"]
var req CreateUserTokenRequest var req csapitypes.CreateUserTokenRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -468,7 +431,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return return
} }
resp := &CreateUserTokenResponse{ resp := &csapitypes.CreateUserTokenResponse{
Token: token, Token: token,
} }
if err := httpResponse(w, http.StatusCreated, resp); err != nil { if err := httpResponse(w, http.StatusCreated, resp); err != nil {
@ -501,13 +464,8 @@ func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
} }
} }
type UserOrgsResponse struct { func userOrgsResponse(userOrg *action.UserOrgsResponse) *csapitypes.UserOrgsResponse {
Organization *types.Organization return &csapitypes.UserOrgsResponse{
Role types.MemberRole
}
func userOrgsResponse(userOrg *action.UserOrgsResponse) *UserOrgsResponse {
return &UserOrgsResponse{
Organization: userOrg.Organization, Organization: userOrg.Organization,
Role: userOrg.Role, Role: userOrg.Role,
} }
@ -533,7 +491,7 @@ func (h *UserOrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
res := make([]*UserOrgsResponse, len(userOrgs)) res := make([]*csapitypes.UserOrgsResponse, len(userOrgs))
for i, userOrg := range userOrgs { for i, userOrg := range userOrgs {
res[i] = userOrgsResponse(userOrg) res[i] = userOrgsResponse(userOrg)
} }

View File

@ -21,21 +21,14 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action" "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
) )
// Variable augments types.Variable with dynamic data
type Variable struct {
*types.Variable
// dynamic data
ParentPath string
}
type VariablesHandler struct { type VariablesHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -63,9 +56,9 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
resVariables := make([]*Variable, len(variables)) resVariables := make([]*csapitypes.Variable, len(variables))
for i, v := range variables { for i, v := range variables {
resVariables[i] = &Variable{Variable: v} resVariables[i] = &csapitypes.Variable{Variable: v}
} }
err = h.readDB.Do(ctx, func(tx *db.Tx) error { err = h.readDB.Do(ctx, func(tx *db.Tx) error {
// populate parent path // populate parent path

View File

@ -32,8 +32,8 @@ import (
"agola.io/agola/internal/services/configstore/api" "agola.io/agola/internal/services/configstore/api"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/readdb" "agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
etcdclientv3 "go.etcd.io/etcd/clientv3" etcdclientv3 "go.etcd.io/etcd/clientv3"

View File

@ -30,9 +30,9 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/config" "agola.io/agola/internal/services/config"
action "agola.io/agola/internal/services/configstore/action" action "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/testutil" "agola.io/agola/internal/testutil"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
) )

View File

@ -20,8 +20,8 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -22,8 +22,8 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -22,8 +22,8 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -30,8 +30,8 @@ import (
"agola.io/agola/internal/objectstorage" "agola.io/agola/internal/objectstorage"
ostypes "agola.io/agola/internal/objectstorage/types" ostypes "agola.io/agola/internal/objectstorage/types"
"agola.io/agola/internal/sequence" "agola.io/agola/internal/sequence"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -21,8 +21,8 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -18,8 +18,8 @@ import (
"path" "path"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -19,8 +19,8 @@ import (
"encoding/json" "encoding/json"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -20,8 +20,8 @@ import (
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/common" "agola.io/agola/internal/services/configstore/common"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -19,8 +19,8 @@ import (
"encoding/json" "encoding/json"
"agola.io/agola/internal/db" "agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -23,7 +23,7 @@ import (
"strconv" "strconv"
"time" "time"
"agola.io/agola/internal/services/runservice/types" "agola.io/agola/services/runservice/types"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -28,11 +28,11 @@ import (
"strings" "strings"
"time" "time"
"agola.io/agola/internal/common"
"agola.io/agola/internal/services/executor/registry" "agola.io/agola/internal/services/executor/registry"
"agola.io/agola/services/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
"github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client" "github.com/docker/docker/client"
@ -47,7 +47,7 @@ type DockerDriver struct {
initVolumeHostDir string initVolumeHostDir string
toolboxPath string toolboxPath string
executorID string executorID string
arch common.Arch arch types.Arch
} }
func NewDockerDriver(logger *zap.Logger, executorID, initVolumeHostDir, toolboxPath string) (*DockerDriver, error) { func NewDockerDriver(logger *zap.Logger, executorID, initVolumeHostDir, toolboxPath string) (*DockerDriver, error) {
@ -62,7 +62,7 @@ func NewDockerDriver(logger *zap.Logger, executorID, initVolumeHostDir, toolboxP
initVolumeHostDir: initVolumeHostDir, initVolumeHostDir: initVolumeHostDir,
toolboxPath: toolboxPath, toolboxPath: toolboxPath,
executorID: executorID, executorID: executorID,
arch: common.ArchFromString(runtime.GOARCH), arch: types.ArchFromString(runtime.GOARCH),
}, nil }, nil
} }
@ -76,7 +76,7 @@ func (d *DockerDriver) Setup(ctx context.Context) error {
func (d *DockerDriver) CopyToolbox(ctx context.Context) error { func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
// by default always try to pull the image so we are sure only authorized users can fetch them // by default always try to pull the image so we are sure only authorized users can fetch them
// see https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#alwayspullimages // see https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#alwayspullimages
reader, err := d.client.ImagePull(ctx, "busybox", types.ImagePullOptions{}) reader, err := d.client.ImagePull(ctx, "busybox", dockertypes.ImagePullOptions{})
if err != nil { if err != nil {
return err return err
} }
@ -97,7 +97,7 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
containerID := resp.ID containerID := resp.ID
if err := d.client.ContainerStart(ctx, containerID, types.ContainerStartOptions{}); err != nil { if err := d.client.ContainerStart(ctx, containerID, dockertypes.ContainerStartOptions{}); err != nil {
return err return err
} }
@ -117,7 +117,7 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
} }
defer srcArchive.Close() defer srcArchive.Close()
options := types.CopyToContainerOptions{ options := dockertypes.CopyToContainerOptions{
AllowOverwriteDirWithFile: false, AllowOverwriteDirWithFile: false,
CopyUIDGID: false, CopyUIDGID: false,
} }
@ -127,14 +127,14 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
} }
// ignore remove error // ignore remove error
_ = d.client.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{Force: true}) _ = d.client.ContainerRemove(ctx, containerID, dockertypes.ContainerRemoveOptions{Force: true})
return nil return nil
} }
func (d *DockerDriver) Archs(ctx context.Context) ([]common.Arch, error) { func (d *DockerDriver) Archs(ctx context.Context) ([]types.Arch, error) {
// since we are using the local docker driver we can return our go arch information // since we are using the local docker driver we can return our go arch information
return []common.Arch{d.arch}, nil return []types.Arch{d.arch}, nil
} }
func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Writer) (Pod, error) { func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Writer) (Pod, error) {
@ -155,7 +155,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
mainContainerID = containerID mainContainerID = containerID
} }
if err := d.client.ContainerStart(ctx, containerID, types.ContainerStartOptions{}); err != nil { if err := d.client.ContainerStart(ctx, containerID, dockertypes.ContainerStartOptions{}); err != nil {
return nil, err return nil, err
} }
} }
@ -171,7 +171,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
} }
containers, err := d.client.ContainerList(ctx, containers, err := d.client.ContainerList(ctx,
types.ContainerListOptions{ dockertypes.ContainerListOptions{
Filters: args, Filters: args,
}) })
if err != nil { if err != nil {
@ -241,7 +241,7 @@ func (d *DockerDriver) fetchImage(ctx context.Context, image string, registryCon
// by default always try to pull the image so we are sure only authorized users can fetch them // by default always try to pull the image so we are sure only authorized users can fetch them
// see https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#alwayspullimages // see https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#alwayspullimages
reader, err := d.client.ImagePull(ctx, image, types.ImagePullOptions{RegistryAuth: registryAuthEnc}) reader, err := d.client.ImagePull(ctx, image, dockertypes.ImagePullOptions{RegistryAuth: registryAuthEnc})
if err != nil { if err != nil {
return err return err
} }
@ -307,7 +307,7 @@ func (d *DockerDriver) GetPods(ctx context.Context, all bool) ([]Pod, error) {
args := filters.NewArgs() args := filters.NewArgs()
containers, err := d.client.ContainerList(ctx, containers, err := d.client.ContainerList(ctx,
types.ContainerListOptions{ dockertypes.ContainerListOptions{
Filters: args, Filters: args,
All: all, All: all,
}) })
@ -401,7 +401,7 @@ type DockerPod struct {
type DockerContainer struct { type DockerContainer struct {
Index int Index int
types.Container dockertypes.Container
} }
type ContainerSlice []*DockerContainer type ContainerSlice []*DockerContainer
@ -439,7 +439,7 @@ func (dp *DockerPod) Stop(ctx context.Context) error {
func (dp *DockerPod) Remove(ctx context.Context) error { func (dp *DockerPod) Remove(ctx context.Context) error {
errs := []error{} errs := []error{}
for _, container := range dp.containers { for _, container := range dp.containers {
if err := dp.client.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{Force: true}); err != nil { if err := dp.client.ContainerRemove(ctx, container.ID, dockertypes.ContainerRemoveOptions{Force: true}); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
} }
@ -451,7 +451,7 @@ func (dp *DockerPod) Remove(ctx context.Context) error {
type DockerContainerExec struct { type DockerContainerExec struct {
execID string execID string
hresp *types.HijackedResponse hresp *dockertypes.HijackedResponse
client *client.Client client *client.Client
endCh chan error endCh chan error
@ -461,7 +461,7 @@ type DockerContainerExec struct {
// Stdin is a wrapped HikackedResponse implementing io.WriteCloser so users can // Stdin is a wrapped HikackedResponse implementing io.WriteCloser so users can
// easily close stdin. Internally it will close only the write side of the conn. // easily close stdin. Internally it will close only the write side of the conn.
type Stdin struct { type Stdin struct {
hresp *types.HijackedResponse hresp *dockertypes.HijackedResponse
} }
func (s *Stdin) Write(p []byte) (int, error) { func (s *Stdin) Write(p []byte) (int, error) {
@ -475,7 +475,7 @@ func (s *Stdin) Close() error {
func (dp *DockerPod) Exec(ctx context.Context, execConfig *ExecConfig) (ContainerExec, error) { func (dp *DockerPod) Exec(ctx context.Context, execConfig *ExecConfig) (ContainerExec, error) {
endCh := make(chan error) endCh := make(chan error)
dockerExecConfig := types.ExecConfig{ dockerExecConfig := dockertypes.ExecConfig{
Cmd: execConfig.Cmd, Cmd: execConfig.Cmd,
Env: makeEnvSlice(execConfig.Env), Env: makeEnvSlice(execConfig.Env),
Tty: execConfig.Tty, Tty: execConfig.Tty,
@ -490,7 +490,7 @@ func (dp *DockerPod) Exec(ctx context.Context, execConfig *ExecConfig) (Containe
if err != nil { if err != nil {
return nil, err return nil, err
} }
execStartCheck := types.ExecStartCheck{ execStartCheck := dockertypes.ExecStartCheck{
Detach: dockerExecConfig.Detach, Detach: dockerExecConfig.Detach,
Tty: dockerExecConfig.Tty, Tty: dockerExecConfig.Tty,
} }

View File

@ -21,8 +21,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"agola.io/agola/internal/common"
"agola.io/agola/internal/services/executor/registry" "agola.io/agola/internal/services/executor/registry"
"agola.io/agola/services/types"
) )
const ( const (
@ -53,7 +53,7 @@ type Driver interface {
GetPods(ctx context.Context, all bool) ([]Pod, error) GetPods(ctx context.Context, all bool) ([]Pod, error)
ExecutorGroup(ctx context.Context) (string, error) ExecutorGroup(ctx context.Context) (string, error)
GetExecutors(ctx context.Context) ([]string, error) GetExecutors(ctx context.Context) ([]string, error)
Archs(ctx context.Context) ([]common.Arch, error) Archs(ctx context.Context) ([]types.Arch, error)
} }
type Pod interface { type Pod interface {
@ -80,7 +80,7 @@ type PodConfig struct {
ID string ID string
TaskID string TaskID string
Containers []*ContainerConfig Containers []*ContainerConfig
Arch common.Arch Arch types.Arch
// The container dir where the init volume will be mounted // The container dir where the init volume will be mounted
InitVolumeDir string InitVolumeDir string
DockerConfig *registry.DockerConfig DockerConfig *registry.DockerConfig
@ -106,7 +106,7 @@ type ExecConfig struct {
Tty bool Tty bool
} }
func toolboxExecPath(toolboxDir string, arch common.Arch) (string, error) { func toolboxExecPath(toolboxDir string, arch types.Arch) (string, error) {
toolboxPath := filepath.Join(toolboxDir, fmt.Sprintf("%s-linux-%s", toolboxPrefix, arch)) toolboxPath := filepath.Join(toolboxDir, fmt.Sprintf("%s-linux-%s", toolboxPrefix, arch))
_, err := os.Stat(toolboxPath) _, err := os.Stat(toolboxPath)
if err != nil { if err != nil {

View File

@ -26,8 +26,8 @@ import (
"strings" "strings"
"time" "time"
"agola.io/agola/internal/common"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/types"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
@ -248,16 +248,16 @@ func (d *K8sDriver) Setup(ctx context.Context) error {
return nil return nil
} }
func (d *K8sDriver) Archs(ctx context.Context) ([]common.Arch, error) { func (d *K8sDriver) Archs(ctx context.Context) ([]types.Arch, error) {
// TODO(sgotti) use go client listers instead of querying every time // TODO(sgotti) use go client listers instead of querying every time
nodes, err := d.nodeLister.List(apilabels.SelectorFromSet(nil)) nodes, err := d.nodeLister.List(apilabels.SelectorFromSet(nil))
if err != nil { if err != nil {
return nil, err return nil, err
} }
archsMap := map[common.Arch]struct{}{} archsMap := map[types.Arch]struct{}{}
archs := []common.Arch{} archs := []types.Arch{}
for _, node := range nodes { for _, node := range nodes {
archsMap[common.ArchFromString(node.Status.NodeInfo.Architecture)] = struct{}{} archsMap[types.ArchFromString(node.Status.NodeInfo.Architecture)] = struct{}{}
} }
for arch := range archsMap { for arch := range archsMap {
archs = append(archs, arch) archs = append(archs, arch)
@ -489,12 +489,12 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
} }
osArch := strings.TrimSpace(stdout.String()) osArch := strings.TrimSpace(stdout.String())
var arch common.Arch var arch types.Arch
switch osArch { switch osArch {
case "x86_64": case "x86_64":
arch = common.ArchAMD64 arch = types.ArchAMD64
case "aarch64": case "aarch64":
arch = common.ArchARM64 arch = types.ArchARM64
default: default:
return nil, errors.Errorf("unsupported pod arch %q", osArch) return nil, errors.Errorf("unsupported pod arch %q", osArch)
} }

View File

@ -35,9 +35,9 @@ import (
"agola.io/agola/internal/services/config" "agola.io/agola/internal/services/config"
"agola.io/agola/internal/services/executor/driver" "agola.io/agola/internal/services/executor/driver"
"agola.io/agola/internal/services/executor/registry" "agola.io/agola/internal/services/executor/registry"
rsapi "agola.io/agola/internal/services/runservice/api"
"agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
rsclient "agola.io/agola/services/runservice/client"
"agola.io/agola/services/runservice/types"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -1304,7 +1304,7 @@ func (e *Executor) saveExecutorID(id string) error {
type Executor struct { type Executor struct {
c *config.Executor c *config.Executor
runserviceClient *rsapi.Client runserviceClient *rsclient.Client
id string id string
runningTasks *runningTasks runningTasks *runningTasks
driver driver.Driver driver driver.Driver
@ -1325,7 +1325,7 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
e := &Executor{ e := &Executor{
c: c, c: c,
runserviceClient: rsapi.NewClient(c.RunserviceURL), runserviceClient: rsclient.NewClient(c.RunserviceURL),
runningTasks: &runningTasks{ runningTasks: &runningTasks{
tasks: make(map[string]*runningTask), tasks: make(map[string]*runningTask),
}, },

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"agola.io/agola/internal/services/runservice/types" "agola.io/agola/services/runservice/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
"github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/name"

View File

@ -18,9 +18,9 @@ import (
"net/http" "net/http"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
csapi "agola.io/agola/internal/services/configstore/api"
rsapi "agola.io/agola/internal/services/runservice/api"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -28,14 +28,14 @@ import (
type ActionHandler struct { type ActionHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
sd *common.TokenSigningData sd *common.TokenSigningData
configstoreClient *csapi.Client configstoreClient *csclient.Client
runserviceClient *rsapi.Client runserviceClient *rsclient.Client
agolaID string agolaID string
apiExposedURL string apiExposedURL string
webExposedURL string webExposedURL string
} }
func NewActionHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csapi.Client, runserviceClient *rsapi.Client, agolaID, apiExposedURL, webExposedURL string) *ActionHandler { func NewActionHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csclient.Client, runserviceClient *rsclient.Client, agolaID, apiExposedURL, webExposedURL string) *ActionHandler {
return &ActionHandler{ return &ActionHandler{
log: logger.Sugar(), log: logger.Sugar(),
sd: sd, sd: sd,

View File

@ -18,7 +18,7 @@ import (
"context" "context"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
cstypes "agola.io/agola/internal/services/configstore/types" cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -20,7 +20,7 @@ import (
"path" "path"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
rstypes "agola.io/agola/internal/services/runservice/types" rstypes "agola.io/agola/services/runservice/types"
) )
// GetBadge return a badge for a project branch // GetBadge return a badge for a project branch

View File

@ -17,8 +17,8 @@ package action
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -22,15 +22,15 @@ import (
"path" "path"
gitsource "agola.io/agola/internal/gitsources" 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/services/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csapi.Project, error) { func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csapitypes.Project, error) {
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef) project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -59,7 +59,7 @@ type CreateProjectRequest struct {
SkipSSHHostKeyCheck bool SkipSSHHostKeyCheck bool
} }
func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectRequest) (*csapi.Project, error) { func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectRequest) (*csapitypes.Project, error) {
curUserID := h.CurrentUserID(ctx) curUserID := h.CurrentUserID(ctx)
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID) user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
@ -184,7 +184,7 @@ type UpdateProjectRequest struct {
Visibility cstypes.Visibility Visibility cstypes.Visibility
} }
func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, req *UpdateProjectRequest) (*csapi.Project, error) { func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, req *UpdateProjectRequest) (*csapitypes.Project, error) {
p, resp, err := h.configstoreClient.GetProject(ctx, projectRef) p, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to get project %q: %w", projectRef, ErrFromRemote(resp, err)) return nil, errors.Errorf("failed to get project %q: %w", projectRef, ErrFromRemote(resp, err))
@ -211,7 +211,7 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, re
return rp, nil return rp, nil
} }
func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, projectRef string) (*csapi.Project, error) { func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, projectRef string) (*csapitypes.Project, error) {
curUserID := h.CurrentUserID(ctx) curUserID := h.CurrentUserID(ctx)
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID) user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
@ -270,7 +270,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
return rp, nil return rp, nil
} }
func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapi.Project) error { func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapitypes.Project) error {
gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
return errors.Errorf("failed to create gitsource client: %w", err) return errors.Errorf("failed to create gitsource client: %w", err)
@ -306,7 +306,7 @@ func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *cstypes.Remo
return nil return nil
} }
func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapi.Project) error { func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *cstypes.RemoteSource, user *cstypes.User, la *cstypes.LinkedAccount, project *csapitypes.Project) error {
gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
return errors.Errorf("failed to create gitsource client: %w", err) return errors.Errorf("failed to create gitsource client: %w", err)
@ -333,7 +333,7 @@ func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *cstypes.Re
return nil return nil
} }
func (h *ActionHandler) genWebhookURL(project *csapi.Project) (string, error) { func (h *ActionHandler) genWebhookURL(project *csapitypes.Project) (string, error) {
baseWebhookURL := fmt.Sprintf("%s/webhooks", h.apiExposedURL) baseWebhookURL := fmt.Sprintf("%s/webhooks", h.apiExposedURL)
webhookURL, err := url.Parse(baseWebhookURL) webhookURL, err := url.Parse(baseWebhookURL)
if err != nil { if err != nil {

View File

@ -18,14 +18,14 @@ import (
"context" "context"
"path" "path"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetProjectGroup(ctx context.Context, projectGroupRef string) (*csapi.ProjectGroup, error) { func (h *ActionHandler) GetProjectGroup(ctx context.Context, projectGroupRef string) (*csapitypes.ProjectGroup, error) {
projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef) projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -33,7 +33,7 @@ func (h *ActionHandler) GetProjectGroup(ctx context.Context, projectGroupRef str
return projectGroup, nil return projectGroup, nil
} }
func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*csapi.ProjectGroup, error) { func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*csapitypes.ProjectGroup, error) {
projectGroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupRef) projectGroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -41,7 +41,7 @@ func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGro
return projectGroups, nil return projectGroups, nil
} }
func (h *ActionHandler) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*csapi.Project, error) { func (h *ActionHandler) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*csapitypes.Project, error) {
projects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupRef) projects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -56,7 +56,7 @@ type CreateProjectGroupRequest struct {
Visibility cstypes.Visibility Visibility cstypes.Visibility
} }
func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProjectGroupRequest) (*csapi.ProjectGroup, error) { func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProjectGroupRequest) (*csapitypes.ProjectGroup, error) {
if !util.ValidateName(req.Name) { if !util.ValidateName(req.Name) {
return nil, util.NewErrBadRequest(errors.Errorf("invalid projectGroup name %q", req.Name)) return nil, util.NewErrBadRequest(errors.Errorf("invalid projectGroup name %q", req.Name))
} }
@ -109,7 +109,7 @@ type UpdateProjectGroupRequest struct {
Visibility cstypes.Visibility Visibility cstypes.Visibility
} }
func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef string, req *UpdateProjectGroupRequest) (*csapi.ProjectGroup, error) { func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef string, req *UpdateProjectGroupRequest) (*csapitypes.ProjectGroup, error) {
pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef) pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to get project group %q: %w", projectGroupRef, ErrFromRemote(resp, err)) return nil, errors.Errorf("failed to get project group %q: %w", projectGroupRef, ErrFromRemote(resp, err))

View File

@ -17,8 +17,8 @@ package action
import ( import (
"context" "context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -24,11 +24,11 @@ import (
gitsource "agola.io/agola/internal/gitsources" gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/runconfig" "agola.io/agola/internal/runconfig"
"agola.io/agola/internal/services/common" "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" "agola.io/agola/internal/services/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
rsapitypes "agola.io/agola/services/runservice/api/types"
rstypes "agola.io/agola/services/runservice/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
@ -65,7 +65,7 @@ const (
AnnotationPullRequestLink = "pull_request_link" AnnotationPullRequestLink = "pull_request_link"
) )
func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapi.RunResponse, error) { func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapitypes.RunResponse, error) {
runResp, resp, err := h.runserviceClient.GetRun(ctx, runID, nil) runResp, resp, err := h.runserviceClient.GetRun(ctx, runID, nil)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -92,7 +92,7 @@ type GetRunsRequest struct {
Asc bool Asc bool
} }
func (h *ActionHandler) GetRuns(ctx context.Context, req *GetRunsRequest) (*rsapi.GetRunsResponse, error) { func (h *ActionHandler) GetRuns(ctx context.Context, req *GetRunsRequest) (*rsapitypes.GetRunsResponse, error) {
canGetRun, err := h.CanGetRun(ctx, req.Group) canGetRun, err := h.CanGetRun(ctx, req.Group)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to determine permissions: %w", err) return nil, errors.Errorf("failed to determine permissions: %w", err)
@ -155,7 +155,7 @@ type RunActionsRequest struct {
FromStart bool FromStart bool
} }
func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (*rsapi.RunResponse, error) { func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (*rsapitypes.RunResponse, error) {
runResp, resp, err := h.runserviceClient.GetRun(ctx, req.RunID, nil) runResp, resp, err := h.runserviceClient.GetRun(ctx, req.RunID, nil)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, err) return nil, ErrFromRemote(resp, err)
@ -170,7 +170,7 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
switch req.ActionType { switch req.ActionType {
case RunActionTypeRestart: case RunActionTypeRestart:
rsreq := &rsapi.RunCreateRequest{ rsreq := &rsapitypes.RunCreateRequest{
RunID: req.RunID, RunID: req.RunID,
FromStart: req.FromStart, FromStart: req.FromStart,
} }
@ -181,8 +181,8 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
} }
case RunActionTypeCancel: case RunActionTypeCancel:
rsreq := &rsapi.RunActionsRequest{ rsreq := &rsapitypes.RunActionsRequest{
ActionType: rsapi.RunActionTypeChangePhase, ActionType: rsapitypes.RunActionTypeChangePhase,
Phase: rstypes.RunPhaseCancelled, Phase: rstypes.RunPhaseCancelled,
} }
@ -192,8 +192,8 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
} }
case RunActionTypeStop: case RunActionTypeStop:
rsreq := &rsapi.RunActionsRequest{ rsreq := &rsapitypes.RunActionsRequest{
ActionType: rsapi.RunActionTypeStop, ActionType: rsapitypes.RunActionTypeStop,
} }
resp, err = h.runserviceClient.RunActions(ctx, req.RunID, rsreq) resp, err = h.runserviceClient.RunActions(ctx, req.RunID, rsreq)
@ -271,8 +271,8 @@ func (h *ActionHandler) RunTaskAction(ctx context.Context, req *RunTaskActionsRe
annotations[common.ApproversAnnotation] = string(approversj) annotations[common.ApproversAnnotation] = string(approversj)
rsreq := &rsapi.RunTaskActionsRequest{ rsreq := &rsapitypes.RunTaskActionsRequest{
ActionType: rsapi.RunTaskActionTypeSetAnnotations, ActionType: rsapitypes.RunTaskActionTypeSetAnnotations,
Annotations: annotations, Annotations: annotations,
ChangeGroupsUpdateToken: runResp.ChangeGroupsUpdateToken, ChangeGroupsUpdateToken: runResp.ChangeGroupsUpdateToken,
} }
@ -461,7 +461,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
// create a run (per config file) with a generic error since we cannot parse // create a run (per config file) with a generic error since we cannot parse
// it and know how many runs are defined // it and know how many runs are defined
setupErrors = append(setupErrors, err.Error()) setupErrors = append(setupErrors, err.Error())
createRunReq := &rsapi.RunCreateRequest{ createRunReq := &rsapitypes.RunCreateRequest{
RunConfigTasks: nil, RunConfigTasks: nil,
Group: runGroup, Group: runGroup,
SetupErrors: setupErrors, SetupErrors: setupErrors,
@ -480,7 +480,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
for _, run := range config.Runs { for _, run := range config.Runs {
rcts := runconfig.GenRunConfigTasks(util.DefaultUUIDGenerator{}, config, run.Name, variables, req.Branch, req.Tag, req.Ref) rcts := runconfig.GenRunConfigTasks(util.DefaultUUIDGenerator{}, config, run.Name, variables, req.Branch, req.Tag, req.Ref)
createRunReq := &rsapi.RunCreateRequest{ createRunReq := &rsapitypes.RunCreateRequest{
RunConfigTasks: rcts, RunConfigTasks: rcts,
Group: runGroup, Group: runGroup,
SetupErrors: setupErrors, SetupErrors: setupErrors,

View File

@ -18,9 +18,9 @@ import (
"context" "context"
"net/http" "net/http"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
@ -32,8 +32,8 @@ type GetSecretsRequest struct {
Tree bool Tree bool
} }
func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) ([]*csapi.Secret, error) { func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) ([]*csapitypes.Secret, error) {
var cssecrets []*csapi.Secret var cssecrets []*csapitypes.Secret
var resp *http.Response var resp *http.Response
var err error var err error
switch req.ParentType { switch req.ParentType {
@ -65,7 +65,7 @@ type CreateSecretRequest struct {
Path string Path string
} }
func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretRequest) (*csapi.Secret, error) { func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretRequest) (*csapitypes.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to determine ownership: %w", err) return nil, errors.Errorf("failed to determine ownership: %w", err)
@ -85,7 +85,7 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque
} }
var resp *http.Response var resp *http.Response
var rs *csapi.Secret var rs *csapitypes.Secret
switch req.ParentType { switch req.ParentType {
case cstypes.ConfigTypeProjectGroup: case cstypes.ConfigTypeProjectGroup:
h.log.Infof("creating project group secret") h.log.Infof("creating project group secret")
@ -120,7 +120,7 @@ type UpdateSecretRequest struct {
Path string Path string
} }
func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretRequest) (*csapi.Secret, error) { func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretRequest) (*csapitypes.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to determine ownership: %w", err) return nil, errors.Errorf("failed to determine ownership: %w", err)
@ -140,7 +140,7 @@ func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretReque
} }
var resp *http.Response var resp *http.Response
var rs *csapi.Secret var rs *csapitypes.Secret
switch req.ParentType { switch req.ParentType {
case cstypes.ConfigTypeProjectGroup: case cstypes.ConfigTypeProjectGroup:
h.log.Infof("updating project group secret") h.log.Infof("updating project group secret")

View File

@ -24,10 +24,10 @@ import (
gitsource "agola.io/agola/internal/gitsources" gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/gitsources/agolagit" "agola.io/agola/internal/gitsources/agolagit"
"agola.io/agola/internal/services/common" "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/services/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -90,7 +90,7 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
return nil, util.NewErrBadRequest(errors.Errorf("invalid user name %q", req.UserName)) return nil, util.NewErrBadRequest(errors.Errorf("invalid user name %q", req.UserName))
} }
creq := &csapi.CreateUserRequest{ creq := &csapitypes.CreateUserRequest{
UserName: req.UserName, UserName: req.UserName,
} }
@ -137,7 +137,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
} }
h.log.Infof("creating user token") h.log.Infof("creating user token")
creq := &csapi.CreateUserTokenRequest{ creq := &csapitypes.CreateUserTokenRequest{
TokenName: req.TokenName, TokenName: req.TokenName,
} }
res, resp, err := h.configstoreClient.CreateUserToken(ctx, userRef, creq) res, resp, err := h.configstoreClient.CreateUserToken(ctx, userRef, creq)
@ -197,7 +197,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
} }
creq := &csapi.CreateUserLARequest{ creq := &csapitypes.CreateUserLARequest{
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
RemoteUserID: remoteUserInfo.ID, RemoteUserID: remoteUserInfo.ID,
RemoteUserName: remoteUserInfo.LoginName, RemoteUserName: remoteUserInfo.LoginName,
@ -233,7 +233,7 @@ func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *cs
return util.NewErrBadRequest(errors.Errorf("user %q doesn't have a linked account with id %q", userRef, la.ID)) return util.NewErrBadRequest(errors.Errorf("user %q doesn't have a linked account with id %q", userRef, la.ID))
} }
creq := &csapi.UpdateUserLARequest{ creq := &csapitypes.UpdateUserLARequest{
RemoteUserID: la.RemoteUserID, RemoteUserID: la.RemoteUserID,
RemoteUserName: la.RemoteUserName, RemoteUserName: la.RemoteUserName,
UserAccessToken: la.UserAccessToken, UserAccessToken: la.UserAccessToken,
@ -333,9 +333,9 @@ func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserReque
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
} }
creq := &csapi.CreateUserRequest{ creq := &csapitypes.CreateUserRequest{
UserName: req.UserName, UserName: req.UserName,
CreateUserLARequest: &csapi.CreateUserLARequest{ CreateUserLARequest: &csapitypes.CreateUserLARequest{
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
RemoteUserID: remoteUserInfo.ID, RemoteUserID: remoteUserInfo.ID,
RemoteUserName: remoteUserInfo.LoginName, RemoteUserName: remoteUserInfo.LoginName,
@ -420,7 +420,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
la.Oauth2RefreshToken = req.Oauth2RefreshToken la.Oauth2RefreshToken = req.Oauth2RefreshToken
la.UserAccessToken = req.UserAccessToken la.UserAccessToken = req.UserAccessToken
creq := &csapi.UpdateUserLARequest{ creq := &csapitypes.UpdateUserLARequest{
RemoteUserID: la.RemoteUserID, RemoteUserID: la.RemoteUserID,
RemoteUserName: la.RemoteUserName, RemoteUserName: la.RemoteUserName,
UserAccessToken: la.UserAccessToken, UserAccessToken: la.UserAccessToken,

View File

@ -19,9 +19,9 @@ import (
"net/http" "net/http"
"agola.io/agola/internal/services/common" "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/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
@ -33,9 +33,9 @@ type GetVariablesRequest struct {
RemoveOverridden bool RemoveOverridden bool
} }
func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesRequest) ([]*csapi.Variable, []*csapi.Secret, error) { func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesRequest) ([]*csapitypes.Variable, []*csapitypes.Secret, error) {
var csvars []*csapi.Variable var csvars []*csapitypes.Variable
var cssecrets []*csapi.Secret var cssecrets []*csapitypes.Secret
switch req.ParentType { switch req.ParentType {
case cstypes.ConfigTypeProjectGroup: case cstypes.ConfigTypeProjectGroup:
@ -79,7 +79,7 @@ type CreateVariableRequest struct {
Values []cstypes.VariableValue Values []cstypes.VariableValue
} }
func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) { func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableRequest) (*csapitypes.Variable, []*csapitypes.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, nil, errors.Errorf("failed to determine ownership: %w", err) return nil, nil, errors.Errorf("failed to determine ownership: %w", err)
@ -105,8 +105,8 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR
Values: req.Values, Values: req.Values,
} }
var cssecrets []*csapi.Secret var cssecrets []*csapitypes.Secret
var rv *csapi.Variable var rv *csapitypes.Variable
switch req.ParentType { switch req.ParentType {
case cstypes.ConfigTypeProjectGroup: case cstypes.ConfigTypeProjectGroup:
@ -152,7 +152,7 @@ type UpdateVariableRequest struct {
Values []cstypes.VariableValue Values []cstypes.VariableValue
} }
func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) { func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableRequest) (*csapitypes.Variable, []*csapitypes.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, nil, errors.Errorf("failed to determine ownership: %w", err) return nil, nil, errors.Errorf("failed to determine ownership: %w", err)
@ -178,8 +178,8 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR
Values: req.Values, Values: req.Values,
} }
var cssecrets []*csapi.Secret var cssecrets []*csapitypes.Secret
var rv *csapi.Variable var rv *csapitypes.Variable
switch req.ParentType { switch req.ParentType {
case cstypes.ConfigTypeProjectGroup: case cstypes.ConfigTypeProjectGroup:

View File

@ -19,8 +19,8 @@ import (
"net/http" "net/http"
"net/url" "net/url"
cstypes "agola.io/agola/internal/services/configstore/types" util "agola.io/agola/internal/util"
"agola.io/agola/internal/util" cstypes "agola.io/agola/services/configstore/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -24,10 +24,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
type BadgeRequest struct {
Name string `json:"name"`
}
type BadgeHandler struct { type BadgeHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler

View File

@ -19,6 +19,7 @@ import (
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -28,11 +29,6 @@ type OAuth2CallbackHandler struct {
ah *action.ActionHandler ah *action.ActionHandler
} }
type RemoteSourceAuthResult struct {
RequestType string `json:"request_type,omitempty"`
Response interface{} `json:"response,omitempty"`
}
func NewOAuth2CallbackHandler(logger *zap.Logger, ah *action.ActionHandler) *OAuth2CallbackHandler { func NewOAuth2CallbackHandler(logger *zap.Logger, ah *action.ActionHandler) *OAuth2CallbackHandler {
return &OAuth2CallbackHandler{log: logger.Sugar(), ah: ah} return &OAuth2CallbackHandler{log: logger.Sugar(), ah: ah}
} }
@ -54,29 +50,39 @@ func (h *OAuth2CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
switch cresp.RequestType { switch cresp.RequestType {
case action.RemoteSourceRequestTypeCreateUserLA: case action.RemoteSourceRequestTypeCreateUserLA:
authresp := cresp.Response.(*action.CreateUserLAResponse) authresp := cresp.Response.(*action.CreateUserLAResponse)
response = &CreateUserLAResponse{ response = &gwapitypes.CreateUserLAResponse{
LinkedAccount: authresp.LinkedAccount, LinkedAccount: &gwapitypes.LinkedAccount{
ID: authresp.LinkedAccount.ID,
RemoteUserID: authresp.LinkedAccount.RemoteUserID,
RemoteUserName: authresp.LinkedAccount.RemoteUserName,
RemoteUserAvatarURL: authresp.LinkedAccount.RemoteUserAvatarURL,
RemoteSourceID: authresp.LinkedAccount.RemoteUserID,
},
} }
case action.RemoteSourceRequestTypeLoginUser: case action.RemoteSourceRequestTypeLoginUser:
authresp := cresp.Response.(*action.LoginUserResponse) authresp := cresp.Response.(*action.LoginUserResponse)
response = &LoginUserResponse{ response = &gwapitypes.LoginUserResponse{
Token: authresp.Token, Token: authresp.Token,
User: createUserResponse(authresp.User), User: createUserResponse(authresp.User),
} }
case action.RemoteSourceRequestTypeAuthorize: case action.RemoteSourceRequestTypeAuthorize:
authresp := cresp.Response.(*action.AuthorizeResponse) authresp := cresp.Response.(*action.AuthorizeResponse)
response = &AuthorizeResponse{ response = &gwapitypes.AuthorizeResponse{
RemoteUserInfo: authresp.RemoteUserInfo, RemoteUserInfo: &gwapitypes.UserInfo{
ID: authresp.RemoteUserInfo.ID,
LoginName: authresp.RemoteUserInfo.LoginName,
Email: authresp.RemoteUserInfo.Email,
},
RemoteSourceName: authresp.RemoteSourceName, RemoteSourceName: authresp.RemoteSourceName,
} }
case action.RemoteSourceRequestTypeRegisterUser: case action.RemoteSourceRequestTypeRegisterUser:
response = &RegisterUserResponse{} response = &gwapitypes.RegisterUserResponse{}
} }
res := RemoteSourceAuthResult{ res := gwapitypes.RemoteSourceAuthResult{
RequestType: string(cresp.RequestType), RequestType: string(cresp.RequestType),
Response: response, Response: response,
} }

View File

@ -19,20 +19,16 @@ import (
"net/http" "net/http"
"strconv" "strconv"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
type CreateOrgRequest struct {
Name string `json:"name"`
Visibility cstypes.Visibility `json:"visibility"`
}
type CreateOrgHandler struct { type CreateOrgHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -51,7 +47,7 @@ func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
userID = userIDVal.(string) userID = userIDVal.(string)
} }
var req CreateOrgRequest var req gwapitypes.CreateOrgRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -60,7 +56,7 @@ func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
creq := &action.CreateOrgRequest{ creq := &action.CreateOrgRequest{
Name: req.Name, Name: req.Name,
Visibility: req.Visibility, Visibility: cstypes.Visibility(req.Visibility),
CreatorUserID: userID, CreatorUserID: userID,
} }
@ -127,17 +123,11 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type OrgResponse struct { func createOrgResponse(o *cstypes.Organization) *gwapitypes.OrgResponse {
ID string `json:"id"` org := &gwapitypes.OrgResponse{
Name string `json:"name"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
}
func createOrgResponse(o *cstypes.Organization) *OrgResponse {
org := &OrgResponse{
ID: o.ID, ID: o.ID,
Name: o.Name, Name: o.Name,
Visibility: o.Visibility, Visibility: gwapitypes.Visibility(o.Visibility),
} }
return org return org
} }
@ -190,7 +180,7 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
orgs := make([]*OrgResponse, len(csorgs)) orgs := make([]*gwapitypes.OrgResponse, len(csorgs))
for i, p := range csorgs { for i, p := range csorgs {
orgs[i] = createOrgResponse(p) orgs[i] = createOrgResponse(p)
} }
@ -199,20 +189,10 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type OrgMembersResponse struct { func createOrgMemberResponse(user *cstypes.User, role cstypes.MemberRole) *gwapitypes.OrgMemberResponse {
Organization *OrgResponse `json:"organization"` return &gwapitypes.OrgMemberResponse{
Members []*OrgMemberResponse `json:"members"`
}
type OrgMemberResponse struct {
User *UserResponse `json:"user"`
Role cstypes.MemberRole `json:"role"`
}
func createOrgMemberResponse(user *cstypes.User, role cstypes.MemberRole) *OrgMemberResponse {
return &OrgMemberResponse{
User: createUserResponse(user), User: createUserResponse(user),
Role: role, Role: gwapitypes.MemberRole(role),
} }
} }
@ -237,9 +217,9 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
res := &OrgMembersResponse{ res := &gwapitypes.OrgMembersResponse{
Organization: createOrgResponse(ares.Organization), Organization: createOrgResponse(ares.Organization),
Members: make([]*OrgMemberResponse, len(ares.Members)), Members: make([]*gwapitypes.OrgMemberResponse, len(ares.Members)),
} }
for i, m := range ares.Members { for i, m := range ares.Members {
res.Members[i] = createOrgMemberResponse(m.User, m.Role) res.Members[i] = createOrgMemberResponse(m.User, m.Role)
@ -249,25 +229,16 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type AddOrgMemberResponse struct { func createAddOrgMemberResponse(org *cstypes.Organization, user *cstypes.User, role cstypes.MemberRole) *gwapitypes.AddOrgMemberResponse {
Organization *OrgResponse `json:"organization"` return &gwapitypes.AddOrgMemberResponse{
OrgMemberResponse
}
func createAddOrgMemberResponse(org *cstypes.Organization, user *cstypes.User, role cstypes.MemberRole) *AddOrgMemberResponse {
return &AddOrgMemberResponse{
Organization: createOrgResponse(org), Organization: createOrgResponse(org),
OrgMemberResponse: OrgMemberResponse{ OrgMemberResponse: gwapitypes.OrgMemberResponse{
User: createUserResponse(user), User: createUserResponse(user),
Role: role, Role: gwapitypes.MemberRole(role),
}, },
} }
} }
type AddOrgMemberRequest struct {
Role cstypes.MemberRole `json:"role"`
}
type AddOrgMemberHandler struct { type AddOrgMemberHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -284,14 +255,14 @@ func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
orgRef := vars["orgref"] orgRef := vars["orgref"]
userRef := vars["userref"] userRef := vars["userref"]
var req AddOrgMemberRequest var req gwapitypes.AddOrgMemberRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
return return
} }
ares, err := h.ah.AddOrgMember(ctx, orgRef, userRef, req.Role) ares, err := h.ah.AddOrgMember(ctx, orgRef, userRef, cstypes.MemberRole(req.Role))
if httpError(w, err) { if httpError(w, err) {
h.log.Errorf("err: %+v", err) h.log.Errorf("err: %+v", err)
return return

View File

@ -19,24 +19,16 @@ import (
"net/http" "net/http"
"net/url" "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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
) )
type CreateProjectRequest struct {
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 { type CreateProjectHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -49,7 +41,7 @@ func NewCreateProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *Crea
func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req CreateProjectRequest var req gwapitypes.CreateProjectRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -59,7 +51,7 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
areq := &action.CreateProjectRequest{ areq := &action.CreateProjectRequest{
Name: req.Name, Name: req.Name,
ParentRef: req.ParentRef, ParentRef: req.ParentRef,
Visibility: req.Visibility, Visibility: cstypes.Visibility(req.Visibility),
RepoPath: req.RepoPath, RepoPath: req.RepoPath,
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
SkipSSHHostKeyCheck: req.SkipSSHHostKeyCheck, SkipSSHHostKeyCheck: req.SkipSSHHostKeyCheck,
@ -77,11 +69,6 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
type UpdateProjectRequest struct {
Name string `json:"name,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
}
type UpdateProjectHandler struct { type UpdateProjectHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -100,7 +87,7 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return return
} }
var req UpdateProjectRequest var req gwapitypes.UpdateProjectRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -109,7 +96,7 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
areq := &action.UpdateProjectRequest{ areq := &action.UpdateProjectRequest{
Name: req.Name, Name: req.Name,
Visibility: req.Visibility, Visibility: cstypes.Visibility(req.Visibility),
} }
project, err := h.ah.UpdateProject(ctx, projectRef, areq) project, err := h.ah.UpdateProject(ctx, projectRef, areq)
if httpError(w, err) { if httpError(w, err) {
@ -239,35 +226,19 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type ProjectResponse struct { func createProjectResponse(r *csapitypes.Project) *gwapitypes.ProjectResponse {
ID string `json:"id,omitempty"` res := &gwapitypes.ProjectResponse{
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 {
res := &ProjectResponse{
ID: r.ID, ID: r.ID,
Name: r.Name, Name: r.Name,
Path: r.Path, Path: r.Path,
ParentPath: r.ParentPath, ParentPath: r.ParentPath,
Visibility: r.Visibility, Visibility: gwapitypes.Visibility(r.Visibility),
GlobalVisibility: string(r.GlobalVisibility), GlobalVisibility: string(r.GlobalVisibility),
} }
return res return res
} }
type ProjectCreateRunRequest struct {
Branch string `json:"branch,omitempty"`
Tag string `json:"tag,omitempty"`
Ref string `json:"ref,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
}
type ProjectCreateRunHandler struct { type ProjectCreateRunHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -286,7 +257,7 @@ func (h *ProjectCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
return return
} }
var req ProjectCreateRunRequest var req gwapitypes.ProjectCreateRunRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))

View File

@ -19,22 +19,17 @@ import (
"net/http" "net/http"
"net/url" "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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
) )
type CreateProjectGroupRequest struct {
Name string `json:"name"`
ParentRef string `json:"parent_ref"`
Visibility cstypes.Visibility `json:"visibility"`
}
type CreateProjectGroupHandler struct { type CreateProjectGroupHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -47,7 +42,7 @@ func NewCreateProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler)
func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req CreateProjectGroupRequest var req gwapitypes.CreateProjectGroupRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -64,7 +59,7 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
creq := &action.CreateProjectGroupRequest{ creq := &action.CreateProjectGroupRequest{
Name: req.Name, Name: req.Name,
ParentRef: req.ParentRef, ParentRef: req.ParentRef,
Visibility: req.Visibility, Visibility: cstypes.Visibility(req.Visibility),
CurrentUserID: userID, CurrentUserID: userID,
} }
@ -80,11 +75,6 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
} }
} }
type UpdateProjectGroupRequest struct {
Name string `json:"name,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
}
type UpdateProjectGroupHandler struct { type UpdateProjectGroupHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -103,7 +93,7 @@ func (h *UpdateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
return return
} }
var req UpdateProjectGroupRequest var req gwapitypes.UpdateProjectGroupRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -112,7 +102,7 @@ func (h *UpdateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
areq := &action.UpdateProjectGroupRequest{ areq := &action.UpdateProjectGroupRequest{
Name: req.Name, Name: req.Name,
Visibility: req.Visibility, Visibility: cstypes.Visibility(req.Visibility),
} }
projectGroup, err := h.ah.UpdateProjectGroup(ctx, projectGroupRef, areq) projectGroup, err := h.ah.UpdateProjectGroup(ctx, projectGroupRef, areq)
if httpError(w, err) { if httpError(w, err) {
@ -209,7 +199,7 @@ func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.R
return return
} }
projects := make([]*ProjectResponse, len(csprojects)) projects := make([]*gwapitypes.ProjectResponse, len(csprojects))
for i, p := range csprojects { for i, p := range csprojects {
projects[i] = createProjectResponse(p) projects[i] = createProjectResponse(p)
} }
@ -243,7 +233,7 @@ func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.
return return
} }
subgroups := make([]*ProjectGroupResponse, len(cssubgroups)) subgroups := make([]*gwapitypes.ProjectGroupResponse, len(cssubgroups))
for i, g := range cssubgroups { for i, g := range cssubgroups {
subgroups[i] = createProjectGroupResponse(g) subgroups[i] = createProjectGroupResponse(g)
} }
@ -253,22 +243,13 @@ func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.
} }
} }
type ProjectGroupResponse struct { func createProjectGroupResponse(r *csapitypes.ProjectGroup) *gwapitypes.ProjectGroupResponse {
ID string `json:"id"` run := &gwapitypes.ProjectGroupResponse{
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 {
run := &ProjectGroupResponse{
ID: r.ID, ID: r.ID,
Name: r.Name, Name: r.Name,
Path: r.Path, Path: r.Path,
ParentPath: r.ParentPath, ParentPath: r.ParentPath,
Visibility: r.Visibility, Visibility: gwapitypes.Visibility(r.Visibility),
GlobalVisibility: string(r.GlobalVisibility), GlobalVisibility: string(r.GlobalVisibility),
} }

View File

@ -18,23 +18,19 @@ import (
"net/http" "net/http"
gitsource "agola.io/agola/internal/gitsources" 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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csclient "agola.io/agola/services/configstore/client"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
type RemoteRepoResponse struct { func createRemoteRepoResponse(r *gitsource.RepoInfo) *gwapitypes.RemoteRepoResponse {
ID string `json:"id,omitempty"` rr := &gwapitypes.RemoteRepoResponse{
Path string `json:"path,omitempty"`
}
func createRemoteRepoResponse(r *gitsource.RepoInfo) *RemoteRepoResponse {
rr := &RemoteRepoResponse{
ID: r.ID, ID: r.ID,
Path: r.Path, Path: r.Path,
} }
@ -45,10 +41,10 @@ func createRemoteRepoResponse(r *gitsource.RepoInfo) *RemoteRepoResponse {
type UserRemoteReposHandler struct { type UserRemoteReposHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
configstoreClient *csapi.Client configstoreClient *csclient.Client
} }
func NewUserRemoteReposHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csapi.Client) *UserRemoteReposHandler { func NewUserRemoteReposHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csclient.Client) *UserRemoteReposHandler {
return &UserRemoteReposHandler{log: logger.Sugar(), ah: ah, configstoreClient: configstoreClient} return &UserRemoteReposHandler{log: logger.Sugar(), ah: ah, configstoreClient: configstoreClient}
} }
@ -105,7 +101,7 @@ func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return return
} }
repos := make([]*RemoteRepoResponse, len(remoteRepos)) repos := make([]*gwapitypes.RemoteRepoResponse, len(remoteRepos))
for i, r := range remoteRepos { for i, r := range remoteRepos {
repos[i] = createRemoteRepoResponse(r) repos[i] = createRemoteRepoResponse(r)
} }

View File

@ -19,29 +19,16 @@ import (
"net/http" "net/http"
"strconv" "strconv"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/gorilla/mux" "github.com/gorilla/mux"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
type CreateRemoteSourceRequest struct {
Name string `json:"name"`
APIURL string `json:"apiurl"`
Type string `json:"type"`
AuthType string `json:"auth_type"`
SkipVerify bool `json:"skip_verify"`
Oauth2ClientID string `json:"oauth_2_client_id"`
Oauth2ClientSecret string `json:"oauth_2_client_secret"`
SSHHostKey string `json:"ssh_host_key"`
SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check"`
RegistrationEnabled *bool `json:"registration_enabled"`
LoginEnabled *bool `json:"login_enabled"`
}
type CreateRemoteSourceHandler struct { type CreateRemoteSourceHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -54,7 +41,7 @@ func NewCreateRemoteSourceHandler(logger *zap.Logger, ah *action.ActionHandler)
func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req CreateRemoteSourceRequest var req gwapitypes.CreateRemoteSourceRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -86,18 +73,6 @@ func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
} }
} }
type UpdateRemoteSourceRequest struct {
Name *string `json:"name"`
APIURL *string `json:"apiurl"`
SkipVerify *bool `json:"skip_verify"`
Oauth2ClientID *string `json:"oauth_2_client_id"`
Oauth2ClientSecret *string `json:"oauth_2_client_secret"`
SSHHostKey *string `json:"ssh_host_key"`
SkipSSHHostKeyCheck *bool `json:"skip_ssh_host_key_check"`
RegistrationEnabled *bool `json:"registration_enabled"`
LoginEnabled *bool `json:"login_enabled"`
}
type UpdateRemoteSourceHandler struct { type UpdateRemoteSourceHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -112,7 +87,7 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
vars := mux.Vars(r) vars := mux.Vars(r)
rsRef := vars["remotesourceref"] rsRef := vars["remotesourceref"]
var req UpdateRemoteSourceRequest var req gwapitypes.UpdateRemoteSourceRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -144,16 +119,8 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
} }
} }
type RemoteSourceResponse struct { func createRemoteSourceResponse(r *cstypes.RemoteSource) *gwapitypes.RemoteSourceResponse {
ID string `json:"id"` rs := &gwapitypes.RemoteSourceResponse{
Name string `json:"name"`
AuthType string `json:"auth_type"`
RegistrationEnabled bool `json:"registration_enabled"`
LoginEnabled bool `json:"login_enabled"`
}
func createRemoteSourceResponse(r *cstypes.RemoteSource) *RemoteSourceResponse {
rs := &RemoteSourceResponse{
ID: r.ID, ID: r.ID,
Name: r.Name, Name: r.Name,
AuthType: string(r.AuthType), AuthType: string(r.AuthType),
@ -237,7 +204,7 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return return
} }
remoteSources := make([]*RemoteSourceResponse, len(csRemoteSources)) remoteSources := make([]*gwapitypes.RemoteSourceResponse, len(csRemoteSources))
for i, rs := range csRemoteSources { for i, rs := range csRemoteSources {
remoteSources[i] = createRemoteSourceResponse(rs) remoteSources[i] = createRemoteSourceResponse(rs)
} }

View File

@ -19,103 +19,19 @@ import (
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
"time"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
rstypes "agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"go.uber.org/zap" gwapitypes "agola.io/agola/services/gateway/api/types"
errors "golang.org/x/xerrors" rstypes "agola.io/agola/services/runservice/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type RunsResponse struct { func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *gwapitypes.RunResponse {
ID string `json:"id"` run := &gwapitypes.RunResponse{
Counter uint64 `json:"counter"`
Name string `json:"name"`
Annotations map[string]string `json:"annotations"`
Phase rstypes.RunPhase `json:"phase"`
Result rstypes.RunResult `json:"result"`
TasksWaitingApproval []string `json:"tasks_waiting_approval"`
EnqueueTime *time.Time `json:"enqueue_time"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
}
type RunResponse struct {
ID string `json:"id"`
Counter uint64 `json:"counter"`
Name string `json:"name"`
Annotations map[string]string `json:"annotations"`
Phase rstypes.RunPhase `json:"phase"`
Result rstypes.RunResult `json:"result"`
SetupErrors []string `json:"setup_errors"`
Stopping bool `json:"stopping"`
Tasks map[string]*RunResponseTask `json:"tasks"`
TasksWaitingApproval []string `json:"tasks_waiting_approval"`
EnqueueTime *time.Time `json:"enqueue_time"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
CanRestartFromScratch bool `json:"can_restart_from_scratch"`
CanRestartFromFailedTasks bool `json:"can_restart_from_failed_tasks"`
}
type RunResponseTask struct {
ID string `json:"id"`
Name string `json:"name"`
Status rstypes.RunTaskStatus `json:"status"`
Level int `json:"level"`
Depends map[string]*rstypes.RunConfigTaskDepend `json:"depends"`
WaitingApproval bool `json:"waiting_approval"`
Approved bool `json:"approved"`
ApprovalAnnotations map[string]string `json:"approval_annotations"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
}
type RunTaskResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Status rstypes.RunTaskStatus `json:"status"`
WaitingApproval bool `json:"waiting_approval"`
Approved bool `json:"approved"`
ApprovalAnnotations map[string]string `json:"approval_annotations"`
SetupStep *RunTaskResponseSetupStep `json:"setup_step"`
Steps []*RunTaskResponseStep `json:"steps"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
}
type RunTaskResponseSetupStep struct {
Phase rstypes.ExecutorTaskPhase `json:"phase"`
Name string `json:"name"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
}
type RunTaskResponseStep struct {
Phase rstypes.ExecutorTaskPhase `json:"phase"`
Name string `json:"name"`
Command string `json:"command"`
StartTime *time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time"`
}
func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *RunResponse {
run := &RunResponse{
ID: r.ID, ID: r.ID,
Counter: r.Counter, Counter: r.Counter,
Name: r.Name, Name: r.Name,
@ -125,7 +41,7 @@ func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *RunResponse {
Stopping: r.Stop, Stopping: r.Stop,
SetupErrors: rc.SetupErrors, SetupErrors: rc.SetupErrors,
Tasks: make(map[string]*RunResponseTask), Tasks: make(map[string]*gwapitypes.RunResponseTask),
TasksWaitingApproval: r.TasksWaitingApproval(), TasksWaitingApproval: r.TasksWaitingApproval(),
EnqueueTime: r.EnqueueTime, EnqueueTime: r.EnqueueTime,
@ -144,8 +60,8 @@ func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *RunResponse {
return run return run
} }
func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *RunResponseTask { func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *gwapitypes.RunResponseTask {
t := &RunResponseTask{ t := &gwapitypes.RunResponseTask{
ID: rt.ID, ID: rt.ID,
Name: rct.Name, Name: rct.Name,
Status: rt.Status, Status: rt.Status,
@ -164,8 +80,8 @@ func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.Run
return t return t
} }
func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *RunTaskResponse { func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *gwapitypes.RunTaskResponse {
t := &RunTaskResponse{ t := &gwapitypes.RunTaskResponse{
ID: rt.ID, ID: rt.ID,
Name: rct.Name, Name: rct.Name,
Status: rt.Status, Status: rt.Status,
@ -174,13 +90,13 @@ func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *Run
Approved: rt.Approved, Approved: rt.Approved,
ApprovalAnnotations: rt.Annotations, ApprovalAnnotations: rt.Annotations,
Steps: make([]*RunTaskResponseStep, len(rt.Steps)), Steps: make([]*gwapitypes.RunTaskResponseStep, len(rt.Steps)),
StartTime: rt.StartTime, StartTime: rt.StartTime,
EndTime: rt.EndTime, EndTime: rt.EndTime,
} }
t.SetupStep = &RunTaskResponseSetupStep{ t.SetupStep = &gwapitypes.RunTaskResponseSetupStep{
Name: "Task setup", Name: "Task setup",
Phase: rt.SetupStep.Phase, Phase: rt.SetupStep.Phase,
StartTime: rt.SetupStep.StartTime, StartTime: rt.SetupStep.StartTime,
@ -188,7 +104,7 @@ func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *Run
} }
for i := 0; i < len(t.Steps); i++ { for i := 0; i < len(t.Steps); i++ {
s := &RunTaskResponseStep{ s := &gwapitypes.RunTaskResponseStep{
Phase: rt.Steps[i].Phase, Phase: rt.Steps[i].Phase,
StartTime: rt.Steps[i].StartTime, StartTime: rt.Steps[i].StartTime,
EndTime: rt.Steps[i].EndTime, EndTime: rt.Steps[i].EndTime,
@ -282,8 +198,8 @@ const (
MaxRunsLimit = 40 MaxRunsLimit = 40
) )
func createRunsResponse(r *rstypes.Run) *RunsResponse { func createRunsResponse(r *rstypes.Run) *gwapitypes.RunsResponse {
run := &RunsResponse{ run := &gwapitypes.RunsResponse{
ID: r.ID, ID: r.ID,
Counter: r.Counter, Counter: r.Counter,
Name: r.Name, Name: r.Name,
@ -368,7 +284,7 @@ func (h *RunsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
runs := make([]*RunsResponse, len(runsResp.Runs)) runs := make([]*gwapitypes.RunsResponse, len(runsResp.Runs))
for i, r := range runsResp.Runs { for i, r := range runsResp.Runs {
runs[i] = createRunsResponse(r) runs[i] = createRunsResponse(r)
} }
@ -377,13 +293,6 @@ func (h *RunsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type RunActionsRequest struct {
ActionType action.RunActionType `json:"action_type"`
// Restart
FromStart bool `json:"from_start"`
}
type RunActionsHandler struct { type RunActionsHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -398,7 +307,7 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
runID := vars["runid"] runID := vars["runid"]
var req RunActionsRequest var req gwapitypes.RunActionsRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -407,7 +316,7 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
areq := &action.RunActionsRequest{ areq := &action.RunActionsRequest{
RunID: runID, RunID: runID,
ActionType: req.ActionType, ActionType: action.RunActionType(req.ActionType),
FromStart: req.FromStart, FromStart: req.FromStart,
} }
@ -423,10 +332,6 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type RunTaskActionsRequest struct {
ActionType action.RunTaskActionType `json:"action_type"`
}
type RunTaskActionsHandler struct { type RunTaskActionsHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -442,7 +347,7 @@ func (h *RunTaskActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
runID := vars["runid"] runID := vars["runid"]
taskID := vars["taskid"] taskID := vars["taskid"]
var req RunTaskActionsRequest var req gwapitypes.RunTaskActionsRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -452,7 +357,7 @@ func (h *RunTaskActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
areq := &action.RunTaskActionsRequest{ areq := &action.RunTaskActionsRequest{
RunID: runID, RunID: runID,
TaskID: taskID, TaskID: taskID,
ActionType: req.ActionType, ActionType: action.RunTaskActionType(req.ActionType),
} }
err := h.ah.RunTaskAction(ctx, areq) err := h.ah.RunTaskAction(ctx, areq)

View File

@ -18,23 +18,18 @@ import (
"encoding/json" "encoding/json"
"net/http" "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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
) )
type SecretResponse struct { func createSecretResponse(s *csapitypes.Secret) *gwapitypes.SecretResponse {
ID string `json:"id"` return &gwapitypes.SecretResponse{
Name string `json:"name"`
ParentPath string `json:"parent_path"`
}
func createSecretResponse(s *csapi.Secret) *SecretResponse {
return &SecretResponse{
ID: s.ID, ID: s.ID,
Name: s.Name, Name: s.Name,
ParentPath: s.ParentPath, ParentPath: s.ParentPath,
@ -72,7 +67,7 @@ func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
secrets := make([]*SecretResponse, len(cssecrets)) secrets := make([]*gwapitypes.SecretResponse, len(cssecrets))
for i, s := range cssecrets { for i, s := range cssecrets {
secrets[i] = createSecretResponse(s) secrets[i] = createSecretResponse(s)
} }
@ -82,19 +77,6 @@ func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type CreateSecretRequest struct {
Name string `json:"name,omitempty"`
Type cstypes.SecretType `json:"type,omitempty"`
// internal secret
Data map[string]string `json:"data,omitempty"`
// external secret
SecretProviderID string `json:"secret_provider_id,omitempty"`
Path string `json:"path,omitempty"`
}
type CreateSecretHandler struct { type CreateSecretHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -111,7 +93,7 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return return
} }
var req CreateSecretRequest var req gwapitypes.CreateSecretRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -122,7 +104,7 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
Name: req.Name, Name: req.Name,
ParentType: parentType, ParentType: parentType,
ParentRef: parentRef, ParentRef: parentRef,
Type: req.Type, Type: cstypes.SecretType(req.Type),
Data: req.Data, Data: req.Data,
SecretProviderID: req.SecretProviderID, SecretProviderID: req.SecretProviderID,
Path: req.Path, Path: req.Path,
@ -139,19 +121,6 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
type UpdateSecretRequest struct {
Name string `json:"name,omitempty"`
Type cstypes.SecretType `json:"type,omitempty"`
// internal secret
Data map[string]string `json:"data,omitempty"`
// external secret
SecretProviderID string `json:"secret_provider_id,omitempty"`
Path string `json:"path,omitempty"`
}
type UpdateSecretHandler struct { type UpdateSecretHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -172,7 +141,7 @@ func (h *UpdateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return return
} }
var req UpdateSecretRequest var req gwapitypes.UpdateSecretRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -184,7 +153,7 @@ func (h *UpdateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
Name: req.Name, Name: req.Name,
ParentType: parentType, ParentType: parentType,
ParentRef: parentRef, ParentRef: parentRef,
Type: req.Type, Type: cstypes.SecretType(req.Type),
Data: req.Data, Data: req.Data,
SecretProviderID: req.SecretProviderID, SecretProviderID: req.SecretProviderID,
Path: req.Path, Path: req.Path,

View File

@ -21,20 +21,16 @@ import (
"sort" "sort"
"strconv" "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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )
type CreateUserRequest struct {
UserName string `json:"username"`
}
type CreateUserHandler struct { type CreateUserHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -47,7 +43,7 @@ func NewCreateUserHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateU
func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req CreateUserRequest var req gwapitypes.CreateUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -152,26 +148,12 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type UserResponse struct { func createUserResponse(u *cstypes.User) *gwapitypes.UserResponse {
ID string `json:"id"` user := &gwapitypes.UserResponse{
UserName string `json:"username"`
Tokens []string `json:"tokens"`
LinkedAccounts []*LinkedAccountResponse `json:"linked_accounts"`
}
type LinkedAccountResponse struct {
ID string `json:"id"`
RemoteSourceID string `json:"remote_source_id"`
RemoteUserName string `json:"remote_user_name"`
RemoteUserAvatarURL string `json:"remote_user_avatar_url"`
}
func createUserResponse(u *cstypes.User) *UserResponse {
user := &UserResponse{
ID: u.ID, ID: u.ID,
UserName: u.Name, UserName: u.Name,
Tokens: make([]string, 0, len(u.Tokens)), Tokens: make([]string, 0, len(u.Tokens)),
LinkedAccounts: make([]*LinkedAccountResponse, 0, len(u.LinkedAccounts)), LinkedAccounts: make([]*gwapitypes.LinkedAccountResponse, 0, len(u.LinkedAccounts)),
} }
for tokenName := range u.Tokens { for tokenName := range u.Tokens {
user.Tokens = append(user.Tokens, tokenName) user.Tokens = append(user.Tokens, tokenName)
@ -179,7 +161,7 @@ func createUserResponse(u *cstypes.User) *UserResponse {
sort.Strings(user.Tokens) sort.Strings(user.Tokens)
for _, la := range u.LinkedAccounts { for _, la := range u.LinkedAccounts {
user.LinkedAccounts = append(user.LinkedAccounts, &LinkedAccountResponse{ user.LinkedAccounts = append(user.LinkedAccounts, &gwapitypes.LinkedAccountResponse{
ID: la.ID, ID: la.ID,
RemoteSourceID: la.RemoteSourceID, RemoteSourceID: la.RemoteSourceID,
RemoteUserName: la.RemoteUserName, RemoteUserName: la.RemoteUserName,
@ -239,7 +221,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
users := make([]*UserResponse, len(csusers)) users := make([]*gwapitypes.UserResponse, len(csusers))
for i, p := range csusers { for i, p := range csusers {
users[i] = createUserResponse(p) users[i] = createUserResponse(p)
} }
@ -249,17 +231,6 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type CreateUserLARequest struct {
RemoteSourceName string `json:"remote_source_name"`
RemoteSourceLoginName string `json:"remote_source_login_name"`
RemoteSourceLoginPassword string `json:"remote_source_login_password"`
}
type CreateUserLAResponse struct {
LinkedAccount *cstypes.LinkedAccount `json:"linked_account"`
Oauth2Redirect string `json:"oauth2_redirect"`
}
type CreateUserLAHandler struct { type CreateUserLAHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -274,7 +245,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
vars := mux.Vars(r) vars := mux.Vars(r)
userRef := vars["userref"] userRef := vars["userref"]
var req *CreateUserLARequest var req *gwapitypes.CreateUserLARequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -292,7 +263,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userRef string, req *CreateUserLARequest) (*CreateUserLAResponse, error) { func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userRef string, req *gwapitypes.CreateUserLARequest) (*gwapitypes.CreateUserLAResponse, error) {
creq := &action.CreateUserLARequest{ creq := &action.CreateUserLARequest{
UserRef: userRef, UserRef: userRef,
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
@ -304,14 +275,20 @@ func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userRef string,
return nil, err return nil, err
} }
if cresp.Oauth2Redirect != "" { if cresp.Oauth2Redirect != "" {
return &CreateUserLAResponse{ return &gwapitypes.CreateUserLAResponse{
Oauth2Redirect: cresp.Oauth2Redirect, Oauth2Redirect: cresp.Oauth2Redirect,
}, nil }, nil
} }
authresp := cresp.Response.(*action.CreateUserLAResponse) authresp := cresp.Response.(*action.CreateUserLAResponse)
resp := &CreateUserLAResponse{ resp := &gwapitypes.CreateUserLAResponse{
LinkedAccount: authresp.LinkedAccount, LinkedAccount: &gwapitypes.LinkedAccount{
ID: authresp.LinkedAccount.ID,
RemoteUserID: authresp.LinkedAccount.RemoteUserID,
RemoteUserName: authresp.LinkedAccount.RemoteUserName,
RemoteUserAvatarURL: authresp.LinkedAccount.RemoteUserAvatarURL,
RemoteSourceID: authresp.LinkedAccount.RemoteUserID,
},
} }
h.log.Infof("linked account %q for user %q created", resp.LinkedAccount.ID, userRef) h.log.Infof("linked account %q for user %q created", resp.LinkedAccount.ID, userRef)
return resp, nil return resp, nil
@ -343,14 +320,6 @@ func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
type CreateUserTokenRequest struct {
TokenName string `json:"token_name"`
}
type CreateUserTokenResponse struct {
Token string `json:"token"`
}
type CreateUserTokenHandler struct { type CreateUserTokenHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -365,7 +334,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r) vars := mux.Vars(r)
userRef := vars["userref"] userRef := vars["userref"]
var req CreateUserTokenRequest var req gwapitypes.CreateUserTokenRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -383,7 +352,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return return
} }
res := &CreateUserTokenResponse{ res := &gwapitypes.CreateUserTokenResponse{
Token: token, Token: token,
} }
@ -419,20 +388,11 @@ func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
} }
} }
type RegisterUserRequest struct {
CreateUserRequest
CreateUserLARequest
}
type RegisterUserHandler struct { type RegisterUserHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
} }
type RegisterUserResponse struct {
Oauth2Redirect string `json:"oauth2_redirect"`
}
func NewRegisterUserHandler(logger *zap.Logger, ah *action.ActionHandler) *RegisterUserHandler { func NewRegisterUserHandler(logger *zap.Logger, ah *action.ActionHandler) *RegisterUserHandler {
return &RegisterUserHandler{log: logger.Sugar(), ah: ah} return &RegisterUserHandler{log: logger.Sugar(), ah: ah}
} }
@ -440,7 +400,7 @@ func NewRegisterUserHandler(logger *zap.Logger, ah *action.ActionHandler) *Regis
func (h *RegisterUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *RegisterUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req *RegisterUserRequest var req *gwapitypes.RegisterUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -458,7 +418,7 @@ func (h *RegisterUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
} }
} }
func (h *RegisterUserHandler) registerUser(ctx context.Context, req *RegisterUserRequest) (*RegisterUserResponse, error) { func (h *RegisterUserHandler) registerUser(ctx context.Context, req *gwapitypes.RegisterUserRequest) (*gwapitypes.RegisterUserResponse, error) {
creq := &action.RegisterUserRequest{ creq := &action.RegisterUserRequest{
UserName: req.CreateUserRequest.UserName, UserName: req.CreateUserRequest.UserName,
RemoteSourceName: req.CreateUserLARequest.RemoteSourceName, RemoteSourceName: req.CreateUserLARequest.RemoteSourceName,
@ -469,13 +429,13 @@ func (h *RegisterUserHandler) registerUser(ctx context.Context, req *RegisterUse
return nil, err return nil, err
} }
if cresp.Oauth2Redirect != "" { if cresp.Oauth2Redirect != "" {
return &RegisterUserResponse{ return &gwapitypes.RegisterUserResponse{
Oauth2Redirect: cresp.Oauth2Redirect, Oauth2Redirect: cresp.Oauth2Redirect,
}, nil }, nil
} }
//authresp := cresp.Response.(*action.RegisterUserResponse) //authresp := cresp.Response.(*action.RegisterUserResponse)
resp := &RegisterUserResponse{} resp := &gwapitypes.RegisterUserResponse{}
return resp, nil return resp, nil
} }
@ -484,12 +444,6 @@ type AuthorizeHandler struct {
ah *action.ActionHandler ah *action.ActionHandler
} }
type AuthorizeResponse struct {
Oauth2Redirect string `json:"oauth2_redirect"`
RemoteUserInfo *gitsource.UserInfo `json:"remote_user_info"`
RemoteSourceName string `json:"remote_source_name"`
}
func NewAuthorizeHandler(logger *zap.Logger, ah *action.ActionHandler) *AuthorizeHandler { func NewAuthorizeHandler(logger *zap.Logger, ah *action.ActionHandler) *AuthorizeHandler {
return &AuthorizeHandler{log: logger.Sugar(), ah: ah} return &AuthorizeHandler{log: logger.Sugar(), ah: ah}
} }
@ -497,7 +451,7 @@ func NewAuthorizeHandler(logger *zap.Logger, ah *action.ActionHandler) *Authoriz
func (h *AuthorizeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *AuthorizeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req *LoginUserRequest var req *gwapitypes.LoginUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -515,7 +469,7 @@ func (h *AuthorizeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
func (h *AuthorizeHandler) authorize(ctx context.Context, req *LoginUserRequest) (*AuthorizeResponse, error) { func (h *AuthorizeHandler) authorize(ctx context.Context, req *gwapitypes.LoginUserRequest) (*gwapitypes.AuthorizeResponse, error) {
creq := &action.LoginUserRequest{ creq := &action.LoginUserRequest{
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
} }
@ -525,31 +479,23 @@ func (h *AuthorizeHandler) authorize(ctx context.Context, req *LoginUserRequest)
return nil, err return nil, err
} }
if cresp.Oauth2Redirect != "" { if cresp.Oauth2Redirect != "" {
return &AuthorizeResponse{ return &gwapitypes.AuthorizeResponse{
Oauth2Redirect: cresp.Oauth2Redirect, Oauth2Redirect: cresp.Oauth2Redirect,
}, nil }, nil
} }
authresp := cresp.Response.(*action.AuthorizeResponse) authresp := cresp.Response.(*action.AuthorizeResponse)
resp := &AuthorizeResponse{ resp := &gwapitypes.AuthorizeResponse{
RemoteUserInfo: authresp.RemoteUserInfo, RemoteUserInfo: &gwapitypes.UserInfo{
ID: authresp.RemoteUserInfo.ID,
LoginName: authresp.RemoteUserInfo.LoginName,
Email: authresp.RemoteUserInfo.Email,
},
RemoteSourceName: authresp.RemoteSourceName, RemoteSourceName: authresp.RemoteSourceName,
} }
return resp, nil return resp, nil
} }
type LoginUserRequest struct {
RemoteSourceName string `json:"remote_source_name"`
LoginName string `json:"login_name"`
LoginPassword string `json:"password"`
}
type LoginUserResponse struct {
Oauth2Redirect string `json:"oauth2_redirect"`
Token string `json:"token"`
User *UserResponse `json:"user"`
}
type LoginUserHandler struct { type LoginUserHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -562,7 +508,7 @@ func NewLoginUserHandler(logger *zap.Logger, ah *action.ActionHandler) *LoginUse
func (h *LoginUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *LoginUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req *LoginUserRequest var req *gwapitypes.LoginUserRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -580,7 +526,7 @@ func (h *LoginUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
func (h *LoginUserHandler) loginUser(ctx context.Context, req *LoginUserRequest) (*LoginUserResponse, error) { func (h *LoginUserHandler) loginUser(ctx context.Context, req *gwapitypes.LoginUserRequest) (*gwapitypes.LoginUserResponse, error) {
creq := &action.LoginUserRequest{ creq := &action.LoginUserRequest{
RemoteSourceName: req.RemoteSourceName, RemoteSourceName: req.RemoteSourceName,
} }
@ -591,27 +537,19 @@ func (h *LoginUserHandler) loginUser(ctx context.Context, req *LoginUserRequest)
return nil, err return nil, err
} }
if cresp.Oauth2Redirect != "" { if cresp.Oauth2Redirect != "" {
return &LoginUserResponse{ return &gwapitypes.LoginUserResponse{
Oauth2Redirect: cresp.Oauth2Redirect, Oauth2Redirect: cresp.Oauth2Redirect,
}, nil }, nil
} }
authresp := cresp.Response.(*action.LoginUserResponse) authresp := cresp.Response.(*action.LoginUserResponse)
resp := &LoginUserResponse{ resp := &gwapitypes.LoginUserResponse{
Token: authresp.Token, Token: authresp.Token,
User: createUserResponse(authresp.User), User: createUserResponse(authresp.User),
} }
return resp, nil return resp, nil
} }
type UserCreateRunRequest struct {
RepoUUID string `json:"repo_uuid,omitempty"`
RepoPath string `json:"repo_path,omitempty"`
Branch string `json:"branch,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
Message string `json:"message,omitempty"`
}
type UserCreateRunHandler struct { type UserCreateRunHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -624,7 +562,7 @@ func NewUserCreateRunHandler(logger *zap.Logger, ah *action.ActionHandler) *User
func (h *UserCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *UserCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
var req UserCreateRunRequest var req gwapitypes.UserCreateRunRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))

View File

@ -19,43 +19,29 @@ import (
"net/http" "net/http"
"agola.io/agola/internal/services/common" "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/gateway/action"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"go.uber.org/zap" csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap"
) )
type VariableValue struct { func createVariableResponse(v *csapitypes.Variable, secrets []*csapitypes.Secret) *gwapitypes.VariableResponse {
SecretName string `json:"secret_name"` nv := &gwapitypes.VariableResponse{
SecretVar string `json:"secret_var"`
MatchingSecretParentPath string `json:"matching_secret_parent_path"`
When *cstypes.When `json:"when"`
}
type VariableResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Values []VariableValue `json:"values"`
ParentPath string `json:"parent_path"`
}
func createVariableResponse(v *csapi.Variable, secrets []*csapi.Secret) *VariableResponse {
nv := &VariableResponse{
ID: v.ID, ID: v.ID,
Name: v.Name, Name: v.Name,
Values: make([]VariableValue, len(v.Values)), Values: make([]gwapitypes.VariableValue, len(v.Values)),
ParentPath: v.ParentPath, ParentPath: v.ParentPath,
} }
for i, varvalue := range v.Values { for i, varvalue := range v.Values {
nv.Values[i] = VariableValue{ nv.Values[i] = gwapitypes.VariableValue{
SecretName: varvalue.SecretName, SecretName: varvalue.SecretName,
SecretVar: varvalue.SecretVar, SecretVar: varvalue.SecretVar,
When: varvalue.When, When: fromCsWhen(varvalue.When),
} }
// get matching secret for var value // get matching secret for var value
secret := common.GetVarValueMatchingSecret(varvalue, v.ParentPath, secrets) secret := common.GetVarValueMatchingSecret(varvalue, v.ParentPath, secrets)
@ -100,7 +86,7 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
variables := make([]*VariableResponse, len(csvars)) variables := make([]*gwapitypes.VariableResponse, len(csvars))
for i, v := range csvars { for i, v := range csvars {
variables[i] = createVariableResponse(v, cssecrets) variables[i] = createVariableResponse(v, cssecrets)
} }
@ -110,12 +96,6 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
type CreateVariableRequest struct {
Name string `json:"name,omitempty"`
Values []cstypes.VariableValue `json:"values,omitempty"`
}
type CreateVariableHandler struct { type CreateVariableHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -133,7 +113,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
return return
} }
var req CreateVariableRequest var req gwapitypes.CreateVariableRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
@ -143,7 +123,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
Name: req.Name, Name: req.Name,
ParentType: parentType, ParentType: parentType,
ParentRef: parentRef, ParentRef: parentRef,
Values: req.Values, Values: fromApiVariableValues(req.Values),
} }
csvar, cssecrets, err := h.ah.CreateVariable(ctx, areq) csvar, cssecrets, err := h.ah.CreateVariable(ctx, areq)
if httpError(w, err) { if httpError(w, err) {
@ -157,12 +137,6 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
} }
} }
type UpdateVariableRequest struct {
Name string `json:"name,omitempty"`
Values []cstypes.VariableValue `json:"values,omitempty"`
}
type UpdateVariableHandler struct { type UpdateVariableHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
@ -183,19 +157,20 @@ func (h *UpdateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
return return
} }
var req UpdateVariableRequest var req gwapitypes.UpdateVariableRequest
d := json.NewDecoder(r.Body) d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil { if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err)) httpError(w, util.NewErrBadRequest(err))
return return
} }
areq := &action.UpdateVariableRequest{ areq := &action.UpdateVariableRequest{
VariableName: variableName, VariableName: variableName,
Name: req.Name, Name: req.Name,
ParentType: parentType, ParentType: parentType,
ParentRef: parentRef, ParentRef: parentRef,
Values: req.Values, Values: fromApiVariableValues(req.Values),
} }
csvar, cssecrets, err := h.ah.UpdateVariable(ctx, areq) csvar, cssecrets, err := h.ah.UpdateVariable(ctx, areq)
if httpError(w, err) { if httpError(w, err) {
@ -239,3 +214,75 @@ func (h *DeleteVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
h.log.Errorf("err: %+v", err) h.log.Errorf("err: %+v", err)
} }
} }
func fromApiVariableValues(apivalues []gwapitypes.VariableValueRequest) []cstypes.VariableValue {
values := make([]cstypes.VariableValue, len(apivalues))
for i, v := range apivalues {
values[i] = cstypes.VariableValue{
SecretName: v.SecretName,
SecretVar: v.SecretVar,
When: fromApiWhen(v.When),
}
}
return values
}
func fromApiWhenCondition(apiwc gwapitypes.WhenCondition) cstypes.WhenCondition {
return cstypes.WhenCondition{
Type: cstypes.WhenConditionType(apiwc.Type),
Match: apiwc.Match,
}
}
func fromApiWhenConditions(apiwcs *gwapitypes.WhenConditions) *cstypes.WhenConditions {
wcs := &cstypes.WhenConditions{
Include: make([]cstypes.WhenCondition, len(apiwcs.Include)),
Exclude: make([]cstypes.WhenCondition, len(apiwcs.Exclude)),
}
for i, include := range apiwcs.Include {
wcs.Include[i] = fromApiWhenCondition(include)
}
for i, exclude := range apiwcs.Exclude {
wcs.Exclude[i] = fromApiWhenCondition(exclude)
}
return wcs
}
func fromApiWhen(apiwhen *gwapitypes.When) *cstypes.When {
return &cstypes.When{
Branch: fromApiWhenConditions(apiwhen.Branch),
Tag: fromApiWhenConditions(apiwhen.Tag),
Ref: fromApiWhenConditions(apiwhen.Ref),
}
}
func fromCsWhenCondition(apiwc cstypes.WhenCondition) gwapitypes.WhenCondition {
return gwapitypes.WhenCondition{
Type: gwapitypes.WhenConditionType(apiwc.Type),
Match: apiwc.Match,
}
}
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
wcs := &gwapitypes.WhenConditions{
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),
}
for i, include := range apiwcs.Include {
wcs.Include[i] = fromCsWhenCondition(include)
}
for i, exclude := range apiwcs.Exclude {
wcs.Exclude[i] = fromCsWhenCondition(exclude)
}
return wcs
}
func fromCsWhen(apiwhen *cstypes.When) *gwapitypes.When {
return &gwapitypes.When{
Branch: fromCsWhenConditions(apiwhen.Branch),
Tag: fromCsWhenConditions(apiwhen.Tag),
Ref: fromCsWhenConditions(apiwhen.Ref),
}
}

View File

@ -18,11 +18,11 @@ import (
"net/http" "net/http"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
csapi "agola.io/agola/internal/services/configstore/api"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
rsapi "agola.io/agola/internal/services/runservice/api"
"agola.io/agola/internal/services/types" "agola.io/agola/internal/services/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
@ -31,12 +31,12 @@ import (
type webhooksHandler struct { type webhooksHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
ah *action.ActionHandler ah *action.ActionHandler
configstoreClient *csapi.Client configstoreClient *csclient.Client
runserviceClient *rsapi.Client runserviceClient *rsclient.Client
apiExposedURL string apiExposedURL string
} }
func NewWebhooksHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csapi.Client, runserviceClient *rsapi.Client, apiExposedURL string) *webhooksHandler { func NewWebhooksHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csclient.Client, runserviceClient *rsclient.Client, apiExposedURL string) *webhooksHandler {
return &webhooksHandler{ return &webhooksHandler{
log: logger.Sugar(), log: logger.Sugar(),
ah: ah, ah: ah,

View File

@ -25,12 +25,12 @@ import (
"agola.io/agola/internal/objectstorage" "agola.io/agola/internal/objectstorage"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
"agola.io/agola/internal/services/config" "agola.io/agola/internal/services/config"
csapi "agola.io/agola/internal/services/configstore/api"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
"agola.io/agola/internal/services/gateway/api" "agola.io/agola/internal/services/gateway/api"
"agola.io/agola/internal/services/gateway/handlers" "agola.io/agola/internal/services/gateway/handlers"
rsapi "agola.io/agola/internal/services/runservice/api"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
ghandlers "github.com/gorilla/handlers" ghandlers "github.com/gorilla/handlers"
@ -52,8 +52,8 @@ type Gateway struct {
c *config.Gateway c *config.Gateway
ost *objectstorage.ObjStorage ost *objectstorage.ObjStorage
runserviceClient *rsapi.Client runserviceClient *rsclient.Client
configstoreClient *csapi.Client configstoreClient *csclient.Client
ah *action.ActionHandler ah *action.ActionHandler
sd *common.TokenSigningData sd *common.TokenSigningData
} }
@ -121,8 +121,8 @@ func NewGateway(gc *config.Config) (*Gateway, error) {
return nil, err return nil, err
} }
configstoreClient := csapi.NewClient(c.ConfigstoreURL) configstoreClient := csclient.NewClient(c.ConfigstoreURL)
runserviceClient := rsapi.NewClient(c.RunserviceURL) runserviceClient := rsclient.NewClient(c.RunserviceURL)
ah := action.NewActionHandler(logger, sd, configstoreClient, runserviceClient, gc.ID, c.APIExposedURL, c.WebExposedURL) ah := action.NewActionHandler(logger, sd, configstoreClient, runserviceClient, gc.ID, c.APIExposedURL, c.WebExposedURL)

View File

@ -20,7 +20,7 @@ import (
"strings" "strings"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
csapi "agola.io/agola/internal/services/configstore/api" csclient "agola.io/agola/services/configstore/client"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
jwtrequest "github.com/dgrijalva/jwt-go/request" jwtrequest "github.com/dgrijalva/jwt-go/request"
@ -32,7 +32,7 @@ type AuthHandler struct {
log *zap.SugaredLogger log *zap.SugaredLogger
next http.Handler next http.Handler
configstoreClient *csapi.Client configstoreClient *csclient.Client
adminToken string adminToken string
sd *common.TokenSigningData sd *common.TokenSigningData
@ -40,7 +40,7 @@ type AuthHandler struct {
required bool required bool
} }
func NewAuthHandler(logger *zap.Logger, configstoreClient *csapi.Client, adminToken string, sd *common.TokenSigningData, required bool) func(http.Handler) http.Handler { func NewAuthHandler(logger *zap.Logger, configstoreClient *csclient.Client, adminToken string, sd *common.TokenSigningData, required bool) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler { return func(h http.Handler) http.Handler {
return &AuthHandler{ return &AuthHandler{
log: logger.Sugar(), log: logger.Sugar(),

View File

@ -22,7 +22,7 @@ import (
gitsource "agola.io/agola/internal/gitsources" gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/services/common" "agola.io/agola/internal/services/common"
"agola.io/agola/internal/services/gateway/action" "agola.io/agola/internal/services/gateway/action"
rstypes "agola.io/agola/internal/services/runservice/types" rstypes "agola.io/agola/services/runservice/types"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"
) )

View File

@ -21,8 +21,8 @@ import (
"agola.io/agola/internal/etcd" "agola.io/agola/internal/etcd"
slog "agola.io/agola/internal/log" slog "agola.io/agola/internal/log"
"agola.io/agola/internal/services/config" "agola.io/agola/internal/services/config"
csapi "agola.io/agola/internal/services/configstore/api" csclient "agola.io/agola/services/configstore/client"
rsapi "agola.io/agola/internal/services/runservice/api" rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -38,8 +38,8 @@ type NotificationService struct {
e *etcd.Store e *etcd.Store
runserviceClient *rsapi.Client runserviceClient *rsclient.Client
configstoreClient *csapi.Client configstoreClient *csclient.Client
} }
func NewNotificationService(gc *config.Config) (*NotificationService, error) { func NewNotificationService(gc *config.Config) (*NotificationService, error) {
@ -53,8 +53,8 @@ func NewNotificationService(gc *config.Config) (*NotificationService, error) {
return nil, err return nil, err
} }
configstoreClient := csapi.NewClient(c.ConfigstoreURL) configstoreClient := csclient.NewClient(c.ConfigstoreURL)
runserviceClient := rsapi.NewClient(c.RunserviceURL) runserviceClient := rsclient.NewClient(c.RunserviceURL)
return &NotificationService{ return &NotificationService{
gc: gc, gc: gc,

View File

@ -24,7 +24,7 @@ import (
"path" "path"
"time" "time"
rstypes "agola.io/agola/internal/services/runservice/types" rstypes "agola.io/agola/services/runservice/types"
"go.etcd.io/etcd/clientv3/concurrency" "go.etcd.io/etcd/clientv3/concurrency"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -29,8 +29,8 @@ import (
"agola.io/agola/internal/services/runservice/common" "agola.io/agola/internal/services/runservice/common"
"agola.io/agola/internal/services/runservice/readdb" "agola.io/agola/internal/services/runservice/readdb"
"agola.io/agola/internal/services/runservice/store" "agola.io/agola/internal/services/runservice/store"
"agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/runservice/types"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors" errors "golang.org/x/xerrors"

View File

@ -17,8 +17,8 @@ package action
import ( import (
"testing" "testing"
"agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util" "agola.io/agola/internal/util"
"agola.io/agola/services/runservice/types"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
) )

Some files were not shown because too many files have changed in this diff Show More