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', 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: '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: 'save_to_workspace', contents: [{ source_dir: './bin', dest_dir: '/bin/', paths: ['*'] }] },
],

View File

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

View File

@ -17,8 +17,8 @@ package cmd
import (
"context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -55,16 +55,16 @@ func init() {
}
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?
if !cstypes.IsValidVisibility(cstypes.Visibility(orgCreateOpts.visibility)) {
if !IsValidVisibility(orgCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", orgCreateOpts.visibility)
}
req := &api.CreateOrgRequest{
req := &gwapitypes.CreateOrgRequest{
Name: orgCreateOpts.name,
Visibility: cstypes.Visibility(orgCreateOpts.visibility),
Visibility: gwapitypes.Visibility(orgCreateOpts.visibility),
}
log.Infof("creating org")

View File

@ -17,7 +17,7 @@ package cmd
import (
"context"
"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
}
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)
if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil {

View File

@ -17,8 +17,8 @@ package cmd
import (
"context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -60,10 +60,10 @@ func init() {
}
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)
_, _, 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 {
return errors.Errorf("failed to add/update organization member: %w", err)
}

View File

@ -19,7 +19,7 @@ import (
"encoding/json"
"os"
"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -54,7 +54,7 @@ func init() {
}
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)
if err != nil {

View File

@ -17,7 +17,7 @@ package cmd
import (
"context"
"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -57,7 +57,7 @@ func init() {
}
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)
_, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username)

View File

@ -17,8 +17,8 @@ package cmd
import (
"context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -71,18 +71,28 @@ func init() {
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 {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)
// 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)
}
req := &api.CreateProjectRequest{
req := &gwapitypes.CreateProjectRequest{
Name: projectCreateOpts.name,
ParentRef: projectCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility),
Visibility: gwapitypes.Visibility(projectCreateOpts.visibility),
RepoPath: projectCreateOpts.repoPath,
RemoteSourceName: projectCreateOpts.remoteSourceName,
SkipSSHHostKeyCheck: projectCreateOpts.skipSSHHostKeyCheck,

View File

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

View File

@ -17,8 +17,8 @@ package cmd
import (
"context"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -60,17 +60,17 @@ func init() {
}
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?
if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) {
return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility)
if !IsValidVisibility(projectGroupCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", projectGroupCreateOpts.visibility)
}
req := &api.CreateProjectGroupRequest{
req := &gwapitypes.CreateProjectGroupRequest{
Name: projectGroupCreateOpts.name,
ParentRef: projectGroupCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility),
Visibility: gwapitypes.Visibility(projectGroupCreateOpts.visibility),
}
log.Infof("creating project group")

View File

@ -18,7 +18,9 @@ import (
"context"
"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"
)
@ -50,14 +52,14 @@ func init() {
cmdProject.AddCommand(cmdProjectList)
}
func printProjects(projects []*api.ProjectResponse) {
func printProjects(projects []*gwapitypes.ProjectResponse) {
for _, project := range projects {
fmt.Printf("%s: Name: %s\n", project.ID, project.Name)
}
}
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)
if err != nil {

View File

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

View File

@ -19,8 +19,8 @@ import (
"io/ioutil"
"os"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@ -73,7 +73,7 @@ func init() {
}
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
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 {
log.Fatalf("failed to unmarshal secret: %v", err)
}
req := &api.CreateSecretRequest{
req := &gwapitypes.CreateSecretRequest{
Name: secretCreateOpts.name,
Type: cstypes.SecretTypeInternal,
Type: gwapitypes.SecretTypeInternal,
Data: secretData,
}

View File

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

View File

@ -19,8 +19,8 @@ import (
"io/ioutil"
"os"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@ -75,7 +75,7 @@ func init() {
}
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
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 {
log.Fatalf("failed to unmarshal secret: %v", err)
}
req := &api.UpdateSecretRequest{
req := &gwapitypes.UpdateSecretRequest{
Name: secretUpdateOpts.name,
Type: cstypes.SecretTypeInternal,
Type: gwapitypes.SecretTypeInternal,
Data: secretData,
}

View File

@ -19,9 +19,8 @@ import (
"io/ioutil"
"os"
"agola.io/agola/internal/config"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@ -92,11 +91,11 @@ type VariableValue struct {
SecretName string `json:"secret_name,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 {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)
// "github.com/ghodss/yaml" doesn't provide a streaming decoder
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 {
log.Fatalf("failed to unmarshal values: %v", err)
}
rvalues := []cstypes.VariableValue{}
rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values {
rvalues = append(rvalues, cstypes.VariableValue{
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName,
SecretVar: value.SecretVar,
When: (*cstypes.When)(value.When),
When: value.When,
})
}
req := &api.CreateVariableRequest{
req := &gwapitypes.CreateVariableRequest{
Name: variableCreateOpts.name,
Values: rvalues,
}

View File

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

View File

@ -19,8 +19,8 @@ import (
"io/ioutil"
"os"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
@ -68,7 +68,7 @@ func init() {
}
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
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 {
log.Fatalf("failed to unmarshall values: %v", err)
}
rvalues := []cstypes.VariableValue{}
rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values {
rvalues = append(rvalues, cstypes.VariableValue{
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName,
SecretVar: value.SecretVar,
When: (*cstypes.When)(value.When),
When: value.When,
})
}
req := &api.UpdateVariableRequest{
req := &gwapitypes.UpdateVariableRequest{
Name: variableUpdateOpts.name,
Values: rvalues,
}

View File

@ -18,9 +18,9 @@ import (
"context"
"agola.io/agola/internal/gitsources/github"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
"agola.io/agola/internal/util"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"agola.io/agola/util"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -81,10 +81,10 @@ func init() {
}
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
if remoteSourceCreateOpts.rsType == string(cstypes.RemoteSourceTypeGithub) {
if remoteSourceCreateOpts.rsType == "github" {
remoteSourceCreateOpts.apiURL = github.GitHubAPIURL
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`)
}
req := &api.CreateRemoteSourceRequest{
req := &gwapitypes.CreateRemoteSourceRequest{
Name: remoteSourceCreateOpts.name,
Type: remoteSourceCreateOpts.rsType,
AuthType: remoteSourceCreateOpts.authType,

View File

@ -18,7 +18,9 @@ import (
"context"
"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"
)
@ -48,14 +50,14 @@ func init() {
cmdRemoteSource.AddCommand(cmdRemoteSourceList)
}
func printRemoteSources(remoteSources []*api.RemoteSourceResponse) {
func printRemoteSources(remoteSources []*gwapitypes.RemoteSourceResponse) {
for _, rs := range remoteSources {
fmt.Printf("%s: Name: %s\n", rs.ID, rs.Name)
}
}
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)
if err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import (
"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"
errors "golang.org/x/xerrors"
@ -71,9 +72,9 @@ func init() {
}
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()
if flags.Changed("new-name") {

View File

@ -19,7 +19,8 @@ import (
"fmt"
"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"
"github.com/spf13/cobra"
@ -59,7 +60,7 @@ func init() {
cmdRun.AddCommand(cmdRunList)
}
func printRuns(runs []*api.RunResponse) {
func printRuns(runs []*gwapitypes.RunResponse) {
for _, run := range runs {
fmt.Printf("%s: Phase: %s, Result: %s\n", run.ID, run.Phase, run.Result)
for _, task := range run.Tasks {
@ -69,7 +70,7 @@ func printRuns(runs []*api.RunResponse) {
}
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)
if err != nil {
@ -81,7 +82,7 @@ func runList(cmd *cobra.Command, args []string) error {
return err
}
runs := make([]*api.RunResponse, len(runsResp))
runs := make([]*gwapitypes.RunResponse, len(runsResp))
for i, runResponse := range runsResp {
run, _, err := gwclient.GetRun(context.TODO(), runResponse.ID)
if err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import (
"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"
errors "golang.org/x/xerrors"
@ -52,9 +53,9 @@ func init() {
}
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,
}

View File

@ -17,7 +17,7 @@ package cmd
import (
"context"
"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
@ -52,7 +52,7 @@ func init() {
}
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)
if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil {

View File

@ -17,7 +17,8 @@ package cmd
import (
"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"
errors "golang.org/x/xerrors"
@ -61,9 +62,9 @@ func init() {
}
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,
RemoteSourceLoginName: userLACreateOpts.remoteSourceLoginName,
RemoteSourceLoginPassword: userLACreateOpts.remoteSourceLoginPassword,

View File

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

View File

@ -18,7 +18,9 @@ import (
"context"
"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"
)
@ -48,14 +50,14 @@ func init() {
cmdUser.AddCommand(cmdUserList)
}
func printUsers(users []*api.UserResponse) {
func printUsers(users []*gwapitypes.UserResponse) {
for _, user := range users {
fmt.Printf("%s: Name: %s\n", user.ID, user.UserName)
}
}
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)
if err != nil {

View File

@ -18,7 +18,8 @@ import (
"context"
"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"
errors "golang.org/x/xerrors"
@ -58,9 +59,9 @@ func init() {
}
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,
}

View File

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

View File

@ -20,9 +20,9 @@ import (
"regexp"
"strings"
"agola.io/agola/internal/common"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
"agola.io/agola/services/types"
"github.com/ghodss/yaml"
"github.com/google/go-jsonnet"
@ -83,7 +83,7 @@ type DockerRegistryAuth struct {
type Runtime struct {
Type RuntimeType `json:"type,omitempty"`
Arch common.Arch `json:"arch,omitempty"`
Arch types.Arch `json:"arch,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)
}
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)
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@ import (
"agola.io/agola/internal/gitsources/gitea"
"agola.io/agola/internal/gitsources/github"
"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"
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,27 +24,16 @@ import (
"agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"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"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
// Project augments types.Project with dynamic data
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) {
func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.Project) (*csapitypes.Project, error) {
r, err := projectsResponse(ctx, readDB, []*types.Project{project})
if err != nil {
return nil, err
@ -52,8 +41,8 @@ func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.
return r[0], nil
}
func projectsResponse(ctx context.Context, readDB *readdb.ReadDB, projects []*types.Project) ([]*Project, error) {
resProjects := make([]*Project, len(projects))
func projectsResponse(ctx context.Context, readDB *readdb.ReadDB, projects []*types.Project) ([]*csapitypes.Project, error) {
resProjects := make([]*csapitypes.Project, len(projects))
err := readDB.Do(ctx, func(tx *db.Tx) error {
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
// updated on create
resProjects[i] = &Project{
resProjects[i] = &csapitypes.Project{
Project: project,
OwnerType: ownerType,
OwnerID: ownerID,

View File

@ -24,27 +24,16 @@ import (
"agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"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"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
// ProjectGroup augments types.ProjectGroup with dynamic data
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) {
func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroup *types.ProjectGroup) (*csapitypes.ProjectGroup, error) {
r, err := projectGroupsResponse(ctx, readDB, []*types.ProjectGroup{projectGroup})
if err != nil {
return nil, err
@ -52,8 +41,8 @@ func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGro
return r[0], nil
}
func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroups []*types.ProjectGroup) ([]*ProjectGroup, error) {
resProjectGroups := make([]*ProjectGroup, len(projectGroups))
func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroups []*types.ProjectGroup) ([]*csapitypes.ProjectGroup, error) {
resProjectGroups := make([]*csapitypes.ProjectGroup, len(projectGroups))
err := readDB.Do(ctx, func(tx *db.Tx) error {
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
// updated on create
resProjectGroups[i] = &ProjectGroup{
resProjectGroups[i] = &csapitypes.ProjectGroup{
ProjectGroup: projectGroup,
OwnerType: ownerType,
OwnerID: ownerID,

View File

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

View File

@ -21,21 +21,14 @@ import (
"agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
)
// Secret augments types.Secret with dynamic data
type Secret struct {
*types.Secret
// dynamic data
ParentPath string
}
type SecretHandler struct {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -89,9 +82,9 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
resSecrets := make([]*Secret, len(secrets))
resSecrets := make([]*csapitypes.Secret, len(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 {

View File

@ -18,17 +18,17 @@ import (
"encoding/json"
"net/http"
"strconv"
"time"
"agola.io/agola/internal/db"
action "agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"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"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
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 {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req *CreateUserRequest
var req *csapitypes.CreateUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -137,7 +127,7 @@ func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userRef := vars["userref"]
var req *UpdateUserRequest
var req *csapitypes.UpdateUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -329,7 +309,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
vars := mux.Vars(r)
userRef := vars["userref"]
var req CreateUserLARequest
var req csapitypes.CreateUserLARequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -405,7 +376,7 @@ func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
userRef := vars["userref"]
linkedAccountID := vars["laid"]
var req UpdateUserLARequest
var req csapitypes.UpdateUserLARequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -455,7 +418,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r)
userRef := vars["userref"]
var req CreateUserTokenRequest
var req csapitypes.CreateUserTokenRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -468,7 +431,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
resp := &CreateUserTokenResponse{
resp := &csapitypes.CreateUserTokenResponse{
Token: token,
}
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 {
Organization *types.Organization
Role types.MemberRole
}
func userOrgsResponse(userOrg *action.UserOrgsResponse) *UserOrgsResponse {
return &UserOrgsResponse{
func userOrgsResponse(userOrg *action.UserOrgsResponse) *csapitypes.UserOrgsResponse {
return &csapitypes.UserOrgsResponse{
Organization: userOrg.Organization,
Role: userOrg.Role,
}
@ -533,7 +491,7 @@ func (h *UserOrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
res := make([]*UserOrgsResponse, len(userOrgs))
res := make([]*csapitypes.UserOrgsResponse, len(userOrgs))
for i, userOrg := range userOrgs {
res[i] = userOrgsResponse(userOrg)
}

View File

@ -21,21 +21,14 @@ import (
"agola.io/agola/internal/db"
"agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/services/configstore/readdb"
"agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
)
// Variable augments types.Variable with dynamic data
type Variable struct {
*types.Variable
// dynamic data
ParentPath string
}
type VariablesHandler struct {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -63,9 +56,9 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
resVariables := make([]*Variable, len(variables))
resVariables := make([]*csapitypes.Variable, len(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 {
// populate parent path

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,11 +28,11 @@ import (
"strings"
"time"
"agola.io/agola/internal/common"
"agola.io/agola/internal/services/executor/registry"
"agola.io/agola/services/types"
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/filters"
"github.com/docker/docker/client"
@ -47,7 +47,7 @@ type DockerDriver struct {
initVolumeHostDir string
toolboxPath string
executorID string
arch common.Arch
arch types.Arch
}
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,
toolboxPath: toolboxPath,
executorID: executorID,
arch: common.ArchFromString(runtime.GOARCH),
arch: types.ArchFromString(runtime.GOARCH),
}, nil
}
@ -76,7 +76,7 @@ func (d *DockerDriver) Setup(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
// 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 {
return err
}
@ -97,7 +97,7 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
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
}
@ -117,7 +117,7 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
}
defer srcArchive.Close()
options := types.CopyToContainerOptions{
options := dockertypes.CopyToContainerOptions{
AllowOverwriteDirWithFile: false,
CopyUIDGID: false,
}
@ -127,14 +127,14 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
}
// ignore remove error
_ = d.client.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{Force: true})
_ = d.client.ContainerRemove(ctx, containerID, dockertypes.ContainerRemoveOptions{Force: true})
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
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) {
@ -155,7 +155,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
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
}
}
@ -171,7 +171,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
}
containers, err := d.client.ContainerList(ctx,
types.ContainerListOptions{
dockertypes.ContainerListOptions{
Filters: args,
})
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
// 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 {
return err
}
@ -307,7 +307,7 @@ func (d *DockerDriver) GetPods(ctx context.Context, all bool) ([]Pod, error) {
args := filters.NewArgs()
containers, err := d.client.ContainerList(ctx,
types.ContainerListOptions{
dockertypes.ContainerListOptions{
Filters: args,
All: all,
})
@ -401,7 +401,7 @@ type DockerPod struct {
type DockerContainer struct {
Index int
types.Container
dockertypes.Container
}
type ContainerSlice []*DockerContainer
@ -439,7 +439,7 @@ func (dp *DockerPod) Stop(ctx context.Context) error {
func (dp *DockerPod) Remove(ctx context.Context) error {
errs := []error{}
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)
}
}
@ -451,7 +451,7 @@ func (dp *DockerPod) Remove(ctx context.Context) error {
type DockerContainerExec struct {
execID string
hresp *types.HijackedResponse
hresp *dockertypes.HijackedResponse
client *client.Client
endCh chan error
@ -461,7 +461,7 @@ type DockerContainerExec struct {
// 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.
type Stdin struct {
hresp *types.HijackedResponse
hresp *dockertypes.HijackedResponse
}
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) {
endCh := make(chan error)
dockerExecConfig := types.ExecConfig{
dockerExecConfig := dockertypes.ExecConfig{
Cmd: execConfig.Cmd,
Env: makeEnvSlice(execConfig.Env),
Tty: execConfig.Tty,
@ -490,7 +490,7 @@ func (dp *DockerPod) Exec(ctx context.Context, execConfig *ExecConfig) (Containe
if err != nil {
return nil, err
}
execStartCheck := types.ExecStartCheck{
execStartCheck := dockertypes.ExecStartCheck{
Detach: dockerExecConfig.Detach,
Tty: dockerExecConfig.Tty,
}

View File

@ -21,8 +21,8 @@ import (
"os"
"path/filepath"
"agola.io/agola/internal/common"
"agola.io/agola/internal/services/executor/registry"
"agola.io/agola/services/types"
)
const (
@ -53,7 +53,7 @@ type Driver interface {
GetPods(ctx context.Context, all bool) ([]Pod, error)
ExecutorGroup(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 {
@ -80,7 +80,7 @@ type PodConfig struct {
ID string
TaskID string
Containers []*ContainerConfig
Arch common.Arch
Arch types.Arch
// The container dir where the init volume will be mounted
InitVolumeDir string
DockerConfig *registry.DockerConfig
@ -106,7 +106,7 @@ type ExecConfig struct {
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))
_, err := os.Stat(toolboxPath)
if err != nil {

View File

@ -26,8 +26,8 @@ import (
"strings"
"time"
"agola.io/agola/internal/common"
"agola.io/agola/internal/util"
"agola.io/agola/services/types"
"github.com/docker/docker/pkg/archive"
uuid "github.com/satori/go.uuid"
@ -248,16 +248,16 @@ func (d *K8sDriver) Setup(ctx context.Context) error {
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
nodes, err := d.nodeLister.List(apilabels.SelectorFromSet(nil))
if err != nil {
return nil, err
}
archsMap := map[common.Arch]struct{}{}
archs := []common.Arch{}
archsMap := map[types.Arch]struct{}{}
archs := []types.Arch{}
for _, node := range nodes {
archsMap[common.ArchFromString(node.Status.NodeInfo.Architecture)] = struct{}{}
archsMap[types.ArchFromString(node.Status.NodeInfo.Architecture)] = struct{}{}
}
for arch := range archsMap {
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())
var arch common.Arch
var arch types.Arch
switch osArch {
case "x86_64":
arch = common.ArchAMD64
arch = types.ArchAMD64
case "aarch64":
arch = common.ArchARM64
arch = types.ArchARM64
default:
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/executor/driver"
"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"
rsclient "agola.io/agola/services/runservice/client"
"agola.io/agola/services/runservice/types"
uuid "github.com/satori/go.uuid"
"github.com/gorilla/mux"
@ -1304,7 +1304,7 @@ func (e *Executor) saveExecutorID(id string) error {
type Executor struct {
c *config.Executor
runserviceClient *rsapi.Client
runserviceClient *rsclient.Client
id string
runningTasks *runningTasks
driver driver.Driver
@ -1325,7 +1325,7 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
e := &Executor{
c: c,
runserviceClient: rsapi.NewClient(c.RunserviceURL),
runserviceClient: rsclient.NewClient(c.RunserviceURL),
runningTasks: &runningTasks{
tasks: make(map[string]*runningTask),
},

View File

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

View File

@ -18,9 +18,9 @@ import (
"net/http"
"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"
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap"
)
@ -28,14 +28,14 @@ import (
type ActionHandler struct {
log *zap.SugaredLogger
sd *common.TokenSigningData
configstoreClient *csapi.Client
runserviceClient *rsapi.Client
configstoreClient *csclient.Client
runserviceClient *rsclient.Client
agolaID string
apiExposedURL 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{
log: logger.Sugar(),
sd: sd,

View File

@ -18,7 +18,7 @@ import (
"context"
"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"
)

View File

@ -20,7 +20,7 @@ import (
"path"
"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

View File

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

View File

@ -22,15 +22,15 @@ import (
"path"
gitsource "agola.io/agola/internal/gitsources"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/types"
"agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -59,7 +59,7 @@ type CreateProjectRequest struct {
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)
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
@ -184,7 +184,7 @@ type UpdateProjectRequest struct {
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)
if err != nil {
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
}
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)
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
@ -270,7 +270,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
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)
if err != nil {
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
}
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)
if err != nil {
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
}
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)
webhookURL, err := url.Parse(baseWebhookURL)
if err != nil {

View File

@ -18,14 +18,14 @@ import (
"context"
"path"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"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"
)
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -33,7 +33,7 @@ func (h *ActionHandler) GetProjectGroup(ctx context.Context, projectGroupRef str
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -41,7 +41,7 @@ func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGro
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -56,7 +56,7 @@ type CreateProjectGroupRequest struct {
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) {
return nil, util.NewErrBadRequest(errors.Errorf("invalid projectGroup name %q", req.Name))
}
@ -109,7 +109,7 @@ type UpdateProjectGroupRequest struct {
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)
if err != nil {
return nil, errors.Errorf("failed to get project group %q: %w", projectGroupRef, ErrFromRemote(resp, err))

View File

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

View File

@ -24,11 +24,11 @@ import (
gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/runconfig"
"agola.io/agola/internal/services/common"
cstypes "agola.io/agola/internal/services/configstore/types"
rsapi "agola.io/agola/internal/services/runservice/api"
rstypes "agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/services/types"
"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"
)
@ -65,7 +65,7 @@ const (
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -92,7 +92,7 @@ type GetRunsRequest struct {
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)
if err != nil {
return nil, errors.Errorf("failed to determine permissions: %w", err)
@ -155,7 +155,7 @@ type RunActionsRequest struct {
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)
if err != nil {
return nil, ErrFromRemote(resp, err)
@ -170,7 +170,7 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
switch req.ActionType {
case RunActionTypeRestart:
rsreq := &rsapi.RunCreateRequest{
rsreq := &rsapitypes.RunCreateRequest{
RunID: req.RunID,
FromStart: req.FromStart,
}
@ -181,8 +181,8 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
}
case RunActionTypeCancel:
rsreq := &rsapi.RunActionsRequest{
ActionType: rsapi.RunActionTypeChangePhase,
rsreq := &rsapitypes.RunActionsRequest{
ActionType: rsapitypes.RunActionTypeChangePhase,
Phase: rstypes.RunPhaseCancelled,
}
@ -192,8 +192,8 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
}
case RunActionTypeStop:
rsreq := &rsapi.RunActionsRequest{
ActionType: rsapi.RunActionTypeStop,
rsreq := &rsapitypes.RunActionsRequest{
ActionType: rsapitypes.RunActionTypeStop,
}
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)
rsreq := &rsapi.RunTaskActionsRequest{
ActionType: rsapi.RunTaskActionTypeSetAnnotations,
rsreq := &rsapitypes.RunTaskActionsRequest{
ActionType: rsapitypes.RunTaskActionTypeSetAnnotations,
Annotations: annotations,
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
// it and know how many runs are defined
setupErrors = append(setupErrors, err.Error())
createRunReq := &rsapi.RunCreateRequest{
createRunReq := &rsapitypes.RunCreateRequest{
RunConfigTasks: nil,
Group: runGroup,
SetupErrors: setupErrors,
@ -480,7 +480,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
for _, run := range config.Runs {
rcts := runconfig.GenRunConfigTasks(util.DefaultUUIDGenerator{}, config, run.Name, variables, req.Branch, req.Tag, req.Ref)
createRunReq := &rsapi.RunCreateRequest{
createRunReq := &rsapitypes.RunCreateRequest{
RunConfigTasks: rcts,
Group: runGroup,
SetupErrors: setupErrors,

View File

@ -18,9 +18,9 @@ import (
"context"
"net/http"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"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"
)
@ -32,8 +32,8 @@ type GetSecretsRequest struct {
Tree bool
}
func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) ([]*csapi.Secret, error) {
var cssecrets []*csapi.Secret
func (h *ActionHandler) GetSecrets(ctx context.Context, req *GetSecretsRequest) ([]*csapitypes.Secret, error) {
var cssecrets []*csapitypes.Secret
var resp *http.Response
var err error
switch req.ParentType {
@ -65,7 +65,7 @@ type CreateSecretRequest struct {
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)
if err != nil {
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 rs *csapi.Secret
var rs *csapitypes.Secret
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("creating project group secret")
@ -120,7 +120,7 @@ type UpdateSecretRequest struct {
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)
if err != nil {
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 rs *csapi.Secret
var rs *csapitypes.Secret
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("updating project group secret")

View File

@ -24,10 +24,10 @@ import (
gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/gitsources/agolagit"
"agola.io/agola/internal/services/common"
csapi "agola.io/agola/internal/services/configstore/api"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/types"
"agola.io/agola/internal/util"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
jwt "github.com/dgrijalva/jwt-go"
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))
}
creq := &csapi.CreateUserRequest{
creq := &csapitypes.CreateUserRequest{
UserName: req.UserName,
}
@ -137,7 +137,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
}
h.log.Infof("creating user token")
creq := &csapi.CreateUserTokenRequest{
creq := &csapitypes.CreateUserTokenRequest{
TokenName: req.TokenName,
}
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)
}
creq := &csapi.CreateUserLARequest{
creq := &csapitypes.CreateUserLARequest{
RemoteSourceName: req.RemoteSourceName,
RemoteUserID: remoteUserInfo.ID,
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))
}
creq := &csapi.UpdateUserLARequest{
creq := &csapitypes.UpdateUserLARequest{
RemoteUserID: la.RemoteUserID,
RemoteUserName: la.RemoteUserName,
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)
}
creq := &csapi.CreateUserRequest{
creq := &csapitypes.CreateUserRequest{
UserName: req.UserName,
CreateUserLARequest: &csapi.CreateUserLARequest{
CreateUserLARequest: &csapitypes.CreateUserLARequest{
RemoteSourceName: req.RemoteSourceName,
RemoteUserID: remoteUserInfo.ID,
RemoteUserName: remoteUserInfo.LoginName,
@ -420,7 +420,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
la.Oauth2RefreshToken = req.Oauth2RefreshToken
la.UserAccessToken = req.UserAccessToken
creq := &csapi.UpdateUserLARequest{
creq := &csapitypes.UpdateUserLARequest{
RemoteUserID: la.RemoteUserID,
RemoteUserName: la.RemoteUserName,
UserAccessToken: la.UserAccessToken,

View File

@ -19,9 +19,9 @@ import (
"net/http"
"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"
csapitypes "agola.io/agola/services/configstore/api/types"
cstypes "agola.io/agola/services/configstore/types"
errors "golang.org/x/xerrors"
)
@ -33,9 +33,9 @@ type GetVariablesRequest struct {
RemoveOverridden bool
}
func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesRequest) ([]*csapi.Variable, []*csapi.Secret, error) {
var csvars []*csapi.Variable
var cssecrets []*csapi.Secret
func (h *ActionHandler) GetVariables(ctx context.Context, req *GetVariablesRequest) ([]*csapitypes.Variable, []*csapitypes.Secret, error) {
var csvars []*csapitypes.Variable
var cssecrets []*csapitypes.Secret
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
@ -79,7 +79,7 @@ type CreateVariableRequest struct {
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)
if err != nil {
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,
}
var cssecrets []*csapi.Secret
var rv *csapi.Variable
var cssecrets []*csapitypes.Secret
var rv *csapitypes.Variable
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
@ -152,7 +152,7 @@ type UpdateVariableRequest struct {
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)
if err != nil {
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,
}
var cssecrets []*csapi.Secret
var rv *csapi.Variable
var cssecrets []*csapitypes.Secret
var rv *csapitypes.Variable
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:

View File

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

View File

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

View File

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

View File

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

View File

@ -19,24 +19,16 @@ import (
"net/http"
"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/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"
"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 {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req CreateProjectRequest
var req gwapitypes.CreateProjectRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -59,7 +51,7 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
areq := &action.CreateProjectRequest{
Name: req.Name,
ParentRef: req.ParentRef,
Visibility: req.Visibility,
Visibility: cstypes.Visibility(req.Visibility),
RepoPath: req.RepoPath,
RemoteSourceName: req.RemoteSourceName,
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -100,7 +87,7 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return
}
var req UpdateProjectRequest
var req gwapitypes.UpdateProjectRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -109,7 +96,7 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
areq := &action.UpdateProjectRequest{
Name: req.Name,
Visibility: req.Visibility,
Visibility: cstypes.Visibility(req.Visibility),
}
project, err := h.ah.UpdateProject(ctx, projectRef, areq)
if httpError(w, err) {
@ -239,35 +226,19 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
type ProjectResponse struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
ParentPath string `json:"parent_path,omitempty"`
Visibility cstypes.Visibility `json:"visibility,omitempty"`
GlobalVisibility string `json:"global_visibility,omitempty"`
}
func createProjectResponse(r *csapi.Project) *ProjectResponse {
res := &ProjectResponse{
func createProjectResponse(r *csapitypes.Project) *gwapitypes.ProjectResponse {
res := &gwapitypes.ProjectResponse{
ID: r.ID,
Name: r.Name,
Path: r.Path,
ParentPath: r.ParentPath,
Visibility: r.Visibility,
Visibility: gwapitypes.Visibility(r.Visibility),
GlobalVisibility: string(r.GlobalVisibility),
}
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -286,7 +257,7 @@ func (h *ProjectCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
return
}
var req ProjectCreateRunRequest
var req gwapitypes.ProjectCreateRunRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))

View File

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

View File

@ -18,23 +18,19 @@ import (
"net/http"
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/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"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
type RemoteRepoResponse struct {
ID string `json:"id,omitempty"`
Path string `json:"path,omitempty"`
}
func createRemoteRepoResponse(r *gitsource.RepoInfo) *RemoteRepoResponse {
rr := &RemoteRepoResponse{
func createRemoteRepoResponse(r *gitsource.RepoInfo) *gwapitypes.RemoteRepoResponse {
rr := &gwapitypes.RemoteRepoResponse{
ID: r.ID,
Path: r.Path,
}
@ -45,10 +41,10 @@ func createRemoteRepoResponse(r *gitsource.RepoInfo) *RemoteRepoResponse {
type UserRemoteReposHandler struct {
log *zap.SugaredLogger
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}
}
@ -105,7 +101,7 @@ func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
repos := make([]*RemoteRepoResponse, len(remoteRepos))
repos := make([]*gwapitypes.RemoteRepoResponse, len(remoteRepos))
for i, r := range remoteRepos {
repos[i] = createRemoteRepoResponse(r)
}

View File

@ -19,29 +19,16 @@ import (
"net/http"
"strconv"
cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/action"
"agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap"
"github.com/gorilla/mux"
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 {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req CreateRemoteSourceRequest
var req gwapitypes.CreateRemoteSourceRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -112,7 +87,7 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
vars := mux.Vars(r)
rsRef := vars["remotesourceref"]
var req UpdateRemoteSourceRequest
var req gwapitypes.UpdateRemoteSourceRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -144,16 +119,8 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
}
}
type RemoteSourceResponse struct {
ID string `json:"id"`
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{
func createRemoteSourceResponse(r *cstypes.RemoteSource) *gwapitypes.RemoteSourceResponse {
rs := &gwapitypes.RemoteSourceResponse{
ID: r.ID,
Name: r.Name,
AuthType: string(r.AuthType),
@ -237,7 +204,7 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return
}
remoteSources := make([]*RemoteSourceResponse, len(csRemoteSources))
remoteSources := make([]*gwapitypes.RemoteSourceResponse, len(csRemoteSources))
for i, rs := range csRemoteSources {
remoteSources[i] = createRemoteSourceResponse(rs)
}

View File

@ -19,103 +19,19 @@ import (
"io"
"net/http"
"strconv"
"time"
"agola.io/agola/internal/services/gateway/action"
rstypes "agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
gwapitypes "agola.io/agola/services/gateway/api/types"
rstypes "agola.io/agola/services/runservice/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
type RunsResponse 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"`
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{
func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *gwapitypes.RunResponse {
run := &gwapitypes.RunResponse{
ID: r.ID,
Counter: r.Counter,
Name: r.Name,
@ -125,7 +41,7 @@ func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *RunResponse {
Stopping: r.Stop,
SetupErrors: rc.SetupErrors,
Tasks: make(map[string]*RunResponseTask),
Tasks: make(map[string]*gwapitypes.RunResponseTask),
TasksWaitingApproval: r.TasksWaitingApproval(),
EnqueueTime: r.EnqueueTime,
@ -144,8 +60,8 @@ func createRunResponse(r *rstypes.Run, rc *rstypes.RunConfig) *RunResponse {
return run
}
func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *RunResponseTask {
t := &RunResponseTask{
func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *gwapitypes.RunResponseTask {
t := &gwapitypes.RunResponseTask{
ID: rt.ID,
Name: rct.Name,
Status: rt.Status,
@ -164,8 +80,8 @@ func createRunResponseTask(r *rstypes.Run, rt *rstypes.RunTask, rct *rstypes.Run
return t
}
func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *RunTaskResponse {
t := &RunTaskResponse{
func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *gwapitypes.RunTaskResponse {
t := &gwapitypes.RunTaskResponse{
ID: rt.ID,
Name: rct.Name,
Status: rt.Status,
@ -174,13 +90,13 @@ func createRunTaskResponse(rt *rstypes.RunTask, rct *rstypes.RunConfigTask) *Run
Approved: rt.Approved,
ApprovalAnnotations: rt.Annotations,
Steps: make([]*RunTaskResponseStep, len(rt.Steps)),
Steps: make([]*gwapitypes.RunTaskResponseStep, len(rt.Steps)),
StartTime: rt.StartTime,
EndTime: rt.EndTime,
}
t.SetupStep = &RunTaskResponseSetupStep{
t.SetupStep = &gwapitypes.RunTaskResponseSetupStep{
Name: "Task setup",
Phase: rt.SetupStep.Phase,
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++ {
s := &RunTaskResponseStep{
s := &gwapitypes.RunTaskResponseStep{
Phase: rt.Steps[i].Phase,
StartTime: rt.Steps[i].StartTime,
EndTime: rt.Steps[i].EndTime,
@ -282,8 +198,8 @@ const (
MaxRunsLimit = 40
)
func createRunsResponse(r *rstypes.Run) *RunsResponse {
run := &RunsResponse{
func createRunsResponse(r *rstypes.Run) *gwapitypes.RunsResponse {
run := &gwapitypes.RunsResponse{
ID: r.ID,
Counter: r.Counter,
Name: r.Name,
@ -368,7 +284,7 @@ func (h *RunsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
runs := make([]*RunsResponse, len(runsResp.Runs))
runs := make([]*gwapitypes.RunsResponse, len(runsResp.Runs))
for i, r := range runsResp.Runs {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -398,7 +307,7 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
runID := vars["runid"]
var req RunActionsRequest
var req gwapitypes.RunActionsRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -407,7 +316,7 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
areq := &action.RunActionsRequest{
RunID: runID,
ActionType: req.ActionType,
ActionType: action.RunActionType(req.ActionType),
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -442,7 +347,7 @@ func (h *RunTaskActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
runID := vars["runid"]
taskID := vars["taskid"]
var req RunTaskActionsRequest
var req gwapitypes.RunTaskActionsRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -452,7 +357,7 @@ func (h *RunTaskActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
areq := &action.RunTaskActionsRequest{
RunID: runID,
TaskID: taskID,
ActionType: req.ActionType,
ActionType: action.RunTaskActionType(req.ActionType),
}
err := h.ah.RunTaskAction(ctx, areq)

View File

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

View File

@ -21,20 +21,16 @@ import (
"sort"
"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/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
type CreateUserRequest struct {
UserName string `json:"username"`
}
type CreateUserHandler struct {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req CreateUserRequest
var req gwapitypes.CreateUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -152,26 +148,12 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
type UserResponse struct {
ID string `json:"id"`
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{
func createUserResponse(u *cstypes.User) *gwapitypes.UserResponse {
user := &gwapitypes.UserResponse{
ID: u.ID,
UserName: u.Name,
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 {
user.Tokens = append(user.Tokens, tokenName)
@ -179,7 +161,7 @@ func createUserResponse(u *cstypes.User) *UserResponse {
sort.Strings(user.Tokens)
for _, la := range u.LinkedAccounts {
user.LinkedAccounts = append(user.LinkedAccounts, &LinkedAccountResponse{
user.LinkedAccounts = append(user.LinkedAccounts, &gwapitypes.LinkedAccountResponse{
ID: la.ID,
RemoteSourceID: la.RemoteSourceID,
RemoteUserName: la.RemoteUserName,
@ -239,7 +221,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
users := make([]*UserResponse, len(csusers))
users := make([]*gwapitypes.UserResponse, len(csusers))
for i, p := range csusers {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -274,7 +245,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
vars := mux.Vars(r)
userRef := vars["userref"]
var req *CreateUserLARequest
var req *gwapitypes.CreateUserLARequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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{
UserRef: userRef,
RemoteSourceName: req.RemoteSourceName,
@ -304,14 +275,20 @@ func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userRef string,
return nil, err
}
if cresp.Oauth2Redirect != "" {
return &CreateUserLAResponse{
return &gwapitypes.CreateUserLAResponse{
Oauth2Redirect: cresp.Oauth2Redirect,
}, nil
}
authresp := cresp.Response.(*action.CreateUserLAResponse)
resp := &CreateUserLAResponse{
LinkedAccount: authresp.LinkedAccount,
resp := &gwapitypes.CreateUserLAResponse{
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)
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -365,7 +334,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r)
userRef := vars["userref"]
var req CreateUserTokenRequest
var req gwapitypes.CreateUserTokenRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -383,7 +352,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
res := &CreateUserTokenResponse{
res := &gwapitypes.CreateUserTokenResponse{
Token: token,
}
@ -419,20 +388,11 @@ func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
}
}
type RegisterUserRequest struct {
CreateUserRequest
CreateUserLARequest
}
type RegisterUserHandler struct {
log *zap.SugaredLogger
ah *action.ActionHandler
}
type RegisterUserResponse struct {
Oauth2Redirect string `json:"oauth2_redirect"`
}
func NewRegisterUserHandler(logger *zap.Logger, ah *action.ActionHandler) *RegisterUserHandler {
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) {
ctx := r.Context()
var req *RegisterUserRequest
var req *gwapitypes.RegisterUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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{
UserName: req.CreateUserRequest.UserName,
RemoteSourceName: req.CreateUserLARequest.RemoteSourceName,
@ -469,13 +429,13 @@ func (h *RegisterUserHandler) registerUser(ctx context.Context, req *RegisterUse
return nil, err
}
if cresp.Oauth2Redirect != "" {
return &RegisterUserResponse{
return &gwapitypes.RegisterUserResponse{
Oauth2Redirect: cresp.Oauth2Redirect,
}, nil
}
//authresp := cresp.Response.(*action.RegisterUserResponse)
resp := &RegisterUserResponse{}
resp := &gwapitypes.RegisterUserResponse{}
return resp, nil
}
@ -484,12 +444,6 @@ type AuthorizeHandler struct {
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 {
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) {
ctx := r.Context()
var req *LoginUserRequest
var req *gwapitypes.LoginUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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{
RemoteSourceName: req.RemoteSourceName,
}
@ -525,31 +479,23 @@ func (h *AuthorizeHandler) authorize(ctx context.Context, req *LoginUserRequest)
return nil, err
}
if cresp.Oauth2Redirect != "" {
return &AuthorizeResponse{
return &gwapitypes.AuthorizeResponse{
Oauth2Redirect: cresp.Oauth2Redirect,
}, nil
}
authresp := cresp.Response.(*action.AuthorizeResponse)
resp := &AuthorizeResponse{
RemoteUserInfo: authresp.RemoteUserInfo,
resp := &gwapitypes.AuthorizeResponse{
RemoteUserInfo: &gwapitypes.UserInfo{
ID: authresp.RemoteUserInfo.ID,
LoginName: authresp.RemoteUserInfo.LoginName,
Email: authresp.RemoteUserInfo.Email,
},
RemoteSourceName: authresp.RemoteSourceName,
}
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 {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req *LoginUserRequest
var req *gwapitypes.LoginUserRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
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{
RemoteSourceName: req.RemoteSourceName,
}
@ -591,27 +537,19 @@ func (h *LoginUserHandler) loginUser(ctx context.Context, req *LoginUserRequest)
return nil, err
}
if cresp.Oauth2Redirect != "" {
return &LoginUserResponse{
return &gwapitypes.LoginUserResponse{
Oauth2Redirect: cresp.Oauth2Redirect,
}, nil
}
authresp := cresp.Response.(*action.LoginUserResponse)
resp := &LoginUserResponse{
resp := &gwapitypes.LoginUserResponse{
Token: authresp.Token,
User: createUserResponse(authresp.User),
}
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 {
log *zap.SugaredLogger
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) {
ctx := r.Context()
var req UserCreateRunRequest
var req gwapitypes.UserCreateRunRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))

View File

@ -19,43 +19,29 @@ import (
"net/http"
"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/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"
"go.uber.org/zap"
)
type VariableValue struct {
SecretName string `json:"secret_name"`
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{
func createVariableResponse(v *csapitypes.Variable, secrets []*csapitypes.Secret) *gwapitypes.VariableResponse {
nv := &gwapitypes.VariableResponse{
ID: v.ID,
Name: v.Name,
Values: make([]VariableValue, len(v.Values)),
Values: make([]gwapitypes.VariableValue, len(v.Values)),
ParentPath: v.ParentPath,
}
for i, varvalue := range v.Values {
nv.Values[i] = VariableValue{
nv.Values[i] = gwapitypes.VariableValue{
SecretName: varvalue.SecretName,
SecretVar: varvalue.SecretVar,
When: varvalue.When,
When: fromCsWhen(varvalue.When),
}
// get matching secret for var value
secret := common.GetVarValueMatchingSecret(varvalue, v.ParentPath, secrets)
@ -100,7 +86,7 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
variables := make([]*VariableResponse, len(csvars))
variables := make([]*gwapitypes.VariableResponse, len(csvars))
for i, v := range csvars {
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -133,7 +113,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
return
}
var req CreateVariableRequest
var req gwapitypes.CreateVariableRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
@ -143,7 +123,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
Name: req.Name,
ParentType: parentType,
ParentRef: parentRef,
Values: req.Values,
Values: fromApiVariableValues(req.Values),
}
csvar, cssecrets, err := h.ah.CreateVariable(ctx, areq)
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 {
log *zap.SugaredLogger
ah *action.ActionHandler
@ -183,19 +157,20 @@ func (h *UpdateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
return
}
var req UpdateVariableRequest
var req gwapitypes.UpdateVariableRequest
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
httpError(w, util.NewErrBadRequest(err))
return
}
areq := &action.UpdateVariableRequest{
VariableName: variableName,
Name: req.Name,
ParentType: parentType,
ParentRef: parentRef,
Values: req.Values,
Values: fromApiVariableValues(req.Values),
}
csvar, cssecrets, err := h.ah.UpdateVariable(ctx, areq)
if httpError(w, err) {
@ -239,3 +214,75 @@ func (h *DeleteVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
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"
"agola.io/agola/internal/services/common"
csapi "agola.io/agola/internal/services/configstore/api"
"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/util"
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
@ -31,12 +31,12 @@ import (
type webhooksHandler struct {
log *zap.SugaredLogger
ah *action.ActionHandler
configstoreClient *csapi.Client
runserviceClient *rsapi.Client
configstoreClient *csclient.Client
runserviceClient *rsclient.Client
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{
log: logger.Sugar(),
ah: ah,

View File

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

View File

@ -20,7 +20,7 @@ import (
"strings"
"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"
jwtrequest "github.com/dgrijalva/jwt-go/request"
@ -32,7 +32,7 @@ type AuthHandler struct {
log *zap.SugaredLogger
next http.Handler
configstoreClient *csapi.Client
configstoreClient *csclient.Client
adminToken string
sd *common.TokenSigningData
@ -40,7 +40,7 @@ type AuthHandler struct {
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 &AuthHandler{
log: logger.Sugar(),

View File

@ -22,7 +22,7 @@ import (
gitsource "agola.io/agola/internal/gitsources"
"agola.io/agola/internal/services/common"
"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"
)

View File

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

View File

@ -24,7 +24,7 @@ import (
"path"
"time"
rstypes "agola.io/agola/internal/services/runservice/types"
rstypes "agola.io/agola/services/runservice/types"
"go.etcd.io/etcd/clientv3/concurrency"
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/readdb"
"agola.io/agola/internal/services/runservice/store"
"agola.io/agola/internal/services/runservice/types"
"agola.io/agola/internal/util"
"agola.io/agola/services/runservice/types"
"go.uber.org/zap"
errors "golang.org/x/xerrors"

View File

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

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