*: migrate to "golang.org/x/xerrors"

Just a raw replace of "github.com/pkg/errors".

Next steps will improve errors (like remote errors, api errors, not exist errors
etc...) to leverage its functionalities
This commit is contained in:
Simone Gotti 2019-05-23 11:23:14 +02:00
parent 8f1225da76
commit 9b2ce717c7
116 changed files with 670 additions and 643 deletions

View File

@ -20,10 +20,10 @@ import (
"github.com/sorintlab/agola/cmd" "github.com/sorintlab/agola/cmd"
slog "github.com/sorintlab/agola/internal/log" slog "github.com/sorintlab/agola/internal/log"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
errors "golang.org/x/xerrors"
) )
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel) var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)

View File

@ -17,11 +17,11 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdOrgCreate = &cobra.Command{ var cmdOrgCreate = &cobra.Command{
@ -68,7 +68,7 @@ func orgCreate(cmd *cobra.Command, args []string) error {
log.Infof("creating org") log.Infof("creating org")
org, _, err := gwclient.CreateOrg(context.TODO(), req) org, _, err := gwclient.CreateOrg(context.TODO(), req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create org") return errors.Errorf("failed to create org: %w", err)
} }
log.Infof("org %q created, ID: %q", org.Name, org.ID) log.Infof("org %q created, ID: %q", org.Name, org.ID)

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdOrgDelete = &cobra.Command{ var cmdOrgDelete = &cobra.Command{
@ -54,7 +54,7 @@ func orgDelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting organization %q", orgDeleteOpts.name) log.Infof("deleting organization %q", orgDeleteOpts.name)
if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil { if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil {
return errors.Wrapf(err, "failed to delete organization") return errors.Errorf("failed to delete organization: %w", err)
} }
return nil return nil

View File

@ -17,11 +17,11 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdOrgMemberAdd = &cobra.Command{ var cmdOrgMemberAdd = &cobra.Command{
@ -61,7 +61,7 @@ func orgMemberAdd(cmd *cobra.Command, args []string) error {
log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role) log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role)
_, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, types.MemberRole(orgMemberAddOpts.role)) _, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, types.MemberRole(orgMemberAddOpts.role))
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to add/update organization member") return errors.Errorf("failed to add/update organization member: %w", err)
} }
return nil return nil

View File

@ -19,10 +19,10 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdOrgMemberList = &cobra.Command{ var cmdOrgMemberList = &cobra.Command{
@ -58,7 +58,7 @@ func orgMemberList(cmd *cobra.Command, args []string) error {
orgMembers, _, err := gwclient.GetOrgMembers(context.TODO(), orgMemberListOpts.orgname) orgMembers, _, err := gwclient.GetOrgMembers(context.TODO(), orgMemberListOpts.orgname)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get organization member") return errors.Errorf("failed to get organization member: %w", err)
} }
out, err := json.MarshalIndent(orgMembers, "", "\t") out, err := json.MarshalIndent(orgMembers, "", "\t")

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdOrgMemberRemove = &cobra.Command{ var cmdOrgMemberRemove = &cobra.Command{
@ -58,7 +58,7 @@ func orgMemberRemove(cmd *cobra.Command, args []string) error {
log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname) log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname)
_, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username) _, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to remove organization member") return errors.Errorf("failed to remove organization member: %w", err)
} }
return nil return nil

View File

@ -17,11 +17,11 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectCreate = &cobra.Command{ var cmdProjectCreate = &cobra.Command{
@ -84,7 +84,7 @@ func projectCreate(cmd *cobra.Command, args []string) error {
project, _, err := gwclient.CreateProject(context.TODO(), req) project, _, err := gwclient.CreateProject(context.TODO(), req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project") return errors.Errorf("failed to create project: %w", err)
} }
log.Infof("project %s created, ID: %s", project.Name, project.ID) log.Infof("project %s created, ID: %s", project.Name, project.ID)

View File

@ -19,8 +19,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectDelete = &cobra.Command{ var cmdProjectDelete = &cobra.Command{
@ -55,7 +55,7 @@ func projectDelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting project") log.Infof("deleting project")
if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.projectRef); err != nil { if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.projectRef); err != nil {
return errors.Wrapf(err, "failed to delete project") return errors.Errorf("failed to delete project: %w", err)
} }
return nil return nil

View File

@ -17,11 +17,11 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectGroupCreate = &cobra.Command{ var cmdProjectGroupCreate = &cobra.Command{
@ -73,7 +73,7 @@ func projectGroupCreate(cmd *cobra.Command, args []string) error {
project, _, err := gwclient.CreateProjectGroup(context.TODO(), req) project, _, err := gwclient.CreateProjectGroup(context.TODO(), req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project group") return errors.Errorf("failed to create project group: %w", err)
} }
log.Infof("project group %s created, ID: %s", project.Name, project.ID) log.Infof("project group %s created, ID: %s", project.Name, project.ID)

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectReconfig = &cobra.Command{ var cmdProjectReconfig = &cobra.Command{
@ -54,7 +54,7 @@ func projectReconfig(cmd *cobra.Command, args []string) error {
log.Infof("reconfiguring remote project") log.Infof("reconfiguring remote project")
if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil { if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil {
return errors.Wrapf(err, "failed to reconfigure remote project") return errors.Errorf("failed to reconfigure remote project: %w", err)
} }
log.Infof("project reconfigured") log.Infof("project reconfigured")

View File

@ -21,8 +21,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectSecretCreate = &cobra.Command{ var cmdProjectSecretCreate = &cobra.Command{
@ -75,14 +75,14 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
log.Infof("creating project secret") log.Infof("creating project secret")
secret, _, err := gwclient.CreateProjectSecret(context.TODO(), secretCreateOpts.parentRef, req) secret, _, err := gwclient.CreateProjectSecret(context.TODO(), secretCreateOpts.parentRef, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project secret") return errors.Errorf("failed to create project secret: %w", err)
} }
log.Infof("project secret %q created, ID: %q", secret.Name, secret.ID) log.Infof("project secret %q created, ID: %q", secret.Name, secret.ID)
case "projectgroup": case "projectgroup":
log.Infof("creating project group secret") log.Infof("creating project group secret")
secret, _, err := gwclient.CreateProjectGroupSecret(context.TODO(), secretCreateOpts.parentRef, req) secret, _, err := gwclient.CreateProjectGroupSecret(context.TODO(), secretCreateOpts.parentRef, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project group secret") return errors.Errorf("failed to create project group secret: %w", err)
} }
log.Infof("project group secret %q created, ID: %q", secret.Name, secret.ID) log.Infof("project group secret %q created, ID: %q", secret.Name, secret.ID)
} }

View File

@ -19,8 +19,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectSecretDelete = &cobra.Command{ var cmdProjectSecretDelete = &cobra.Command{
@ -60,14 +60,14 @@ func secretDelete(cmd *cobra.Command, ownertype string, args []string) error {
log.Infof("deleting project secret") log.Infof("deleting project secret")
_, err := gwclient.DeleteProjectSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name) _, err := gwclient.DeleteProjectSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete project secret") return errors.Errorf("failed to delete project secret: %w", err)
} }
log.Infof("project secret deleted") log.Infof("project secret deleted")
case "projectgroup": case "projectgroup":
log.Infof("deleting project group secret") log.Infof("deleting project group secret")
_, err := gwclient.DeleteProjectGroupSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name) _, err := gwclient.DeleteProjectGroupSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete project group secret") return errors.Errorf("failed to delete project group secret: %w", err)
} }
log.Infof("project group secret deleted") log.Infof("project group secret deleted")
} }

View File

@ -18,10 +18,11 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectVariableCreate = &cobra.Command{ var cmdProjectVariableCreate = &cobra.Command{
@ -73,14 +74,14 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
log.Infof("creating project variable") log.Infof("creating project variable")
variable, _, err := gwclient.CreateProjectVariable(context.TODO(), variableCreateOpts.parentRef, req) variable, _, err := gwclient.CreateProjectVariable(context.TODO(), variableCreateOpts.parentRef, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project variable") return errors.Errorf("failed to create project variable: %w", err)
} }
log.Infof("project variable %q created, ID: %q", variable.Name, variable.ID) log.Infof("project variable %q created, ID: %q", variable.Name, variable.ID)
case "projectgroup": case "projectgroup":
log.Infof("creating project group variable") log.Infof("creating project group variable")
variable, _, err := gwclient.CreateProjectGroupVariable(context.TODO(), variableCreateOpts.parentRef, req) variable, _, err := gwclient.CreateProjectGroupVariable(context.TODO(), variableCreateOpts.parentRef, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create project group variable") return errors.Errorf("failed to create project group variable: %w", err)
} }
log.Infof("project group variable %q created, ID: %q", variable.Name, variable.ID) log.Infof("project group variable %q created, ID: %q", variable.Name, variable.ID)
} }

View File

@ -19,8 +19,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdProjectVariableDelete = &cobra.Command{ var cmdProjectVariableDelete = &cobra.Command{
@ -60,14 +60,14 @@ func variableDelete(cmd *cobra.Command, ownertype string, args []string) error {
log.Infof("deleting project variable") log.Infof("deleting project variable")
_, err := gwclient.DeleteProjectVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name) _, err := gwclient.DeleteProjectVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete project variable") return errors.Errorf("failed to delete project variable: %w", err)
} }
log.Infof("project variable deleted") log.Infof("project variable deleted")
case "projectgroup": case "projectgroup":
log.Infof("deleting project group variable") log.Infof("deleting project group variable")
_, err := gwclient.DeleteProjectGroupVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name) _, err := gwclient.DeleteProjectGroupVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete project group variable") return errors.Errorf("failed to delete project group variable: %w", err)
} }
log.Infof("project group variable deleted") log.Infof("project group variable deleted")
} }

View File

@ -17,12 +17,12 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/gitsources/github" "github.com/sorintlab/agola/internal/gitsources/github"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdRemoteSourceCreate = &cobra.Command{ var cmdRemoteSourceCreate = &cobra.Command{
@ -94,7 +94,7 @@ func remoteSourceCreate(cmd *cobra.Command, args []string) error {
log.Infof("creating remotesource") log.Infof("creating remotesource")
remoteSource, _, err := gwclient.CreateRemoteSource(context.TODO(), req) remoteSource, _, err := gwclient.CreateRemoteSource(context.TODO(), req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create remotesource") return errors.Errorf("failed to create remotesource: %w", err)
} }
log.Infof("remotesource %s created, ID: %s", remoteSource.Name, remoteSource.ID) log.Infof("remotesource %s created, ID: %s", remoteSource.Name, remoteSource.ID)

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdRemoteSourceUpdate = &cobra.Command{ var cmdRemoteSourceUpdate = &cobra.Command{
@ -95,7 +95,7 @@ func remoteSourceUpdate(cmd *cobra.Command, args []string) error {
log.Infof("updating remotesource") log.Infof("updating remotesource")
remoteSource, _, err := gwclient.UpdateRemoteSource(context.TODO(), remoteSourceUpdateOpts.ref, req) remoteSource, _, err := gwclient.UpdateRemoteSource(context.TODO(), remoteSourceUpdateOpts.ref, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to update remotesource") return errors.Errorf("failed to update remotesource: %w", err)
} }
log.Infof("remotesource %s updated, ID: %s", remoteSource.Name, remoteSource.ID) log.Infof("remotesource %s updated, ID: %s", remoteSource.Name, remoteSource.ID)

View File

@ -30,9 +30,9 @@ import (
"github.com/sorintlab/agola/internal/services/scheduler" "github.com/sorintlab/agola/internal/services/scheduler"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.etcd.io/etcd/embed" "go.etcd.io/etcd/embed"
errors "golang.org/x/xerrors"
) )
var ( var (
@ -132,12 +132,12 @@ func serve(cmd *cobra.Command, args []string) error {
c, err := config.Parse(serveOpts.config) c, err := config.Parse(serveOpts.config)
if err != nil { if err != nil {
return errors.Wrapf(err, "config error") return errors.Errorf("config error: %w", err)
} }
if serveOpts.embeddedEtcd { if serveOpts.embeddedEtcd {
if err := embeddedEtcd(ctx); err != nil { if err := embeddedEtcd(ctx); err != nil {
return errors.Wrapf(err, "failed to start run service scheduler") return errors.Errorf("failed to start run service scheduler: %w", err)
} }
} }
@ -145,7 +145,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("runservice") { if isComponentEnabled("runservice") {
rs, err = rsscheduler.NewRunservice(ctx, &c.Runservice) rs, err = rsscheduler.NewRunservice(ctx, &c.Runservice)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start run service scheduler") return errors.Errorf("failed to start run service scheduler: %w", err)
} }
} }
@ -153,7 +153,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("executor") { if isComponentEnabled("executor") {
ex, err = executor.NewExecutor(&c.Executor) ex, err = executor.NewExecutor(&c.Executor)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start run service executor") return errors.Errorf("failed to start run service executor: %w", err)
} }
} }
@ -161,7 +161,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("configstore") { if isComponentEnabled("configstore") {
cs, err = configstore.NewConfigstore(ctx, &c.Configstore) cs, err = configstore.NewConfigstore(ctx, &c.Configstore)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start config store") return errors.Errorf("failed to start config store: %w", err)
} }
} }
@ -169,7 +169,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("scheduler") { if isComponentEnabled("scheduler") {
sched, err = scheduler.NewScheduler(&c.Scheduler) sched, err = scheduler.NewScheduler(&c.Scheduler)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start scheduler") return errors.Errorf("failed to start scheduler: %w", err)
} }
} }
@ -177,7 +177,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("notification") { if isComponentEnabled("notification") {
ns, err = notification.NewNotificationService(c) ns, err = notification.NewNotificationService(c)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start notification service") return errors.Errorf("failed to start notification service: %w", err)
} }
} }
@ -185,7 +185,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("gateway") { if isComponentEnabled("gateway") {
gw, err = gateway.NewGateway(c) gw, err = gateway.NewGateway(c)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start gateway") return errors.Errorf("failed to start gateway: %w", err)
} }
} }
@ -193,7 +193,7 @@ func serve(cmd *cobra.Command, args []string) error {
if isComponentEnabled("gitserver") { if isComponentEnabled("gitserver") {
gs, err = gitserver.NewGitserver(&c.Gitserver) gs, err = gitserver.NewGitserver(&c.Gitserver)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to start git server") return errors.Errorf("failed to start git server: %w", err)
} }
} }

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserCreate = &cobra.Command{ var cmdUserCreate = &cobra.Command{
@ -59,7 +59,7 @@ func userCreate(cmd *cobra.Command, args []string) error {
log.Infof("creating user") log.Infof("creating user")
user, _, err := gwclient.CreateUser(context.TODO(), req) user, _, err := gwclient.CreateUser(context.TODO(), req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create user") return errors.Errorf("failed to create user: %w", err)
} }
log.Infof("user %q created, ID: %q", user.UserName, user.ID) log.Infof("user %q created, ID: %q", user.UserName, user.ID)

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserDelete = &cobra.Command{ var cmdUserDelete = &cobra.Command{
@ -54,7 +54,7 @@ func userDelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting user %q", userDeleteOpts.username) log.Infof("deleting user %q", userDeleteOpts.username)
if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil { if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil {
return errors.Wrapf(err, "failed to delete user") return errors.Errorf("failed to delete user: %w", err)
} }
return nil return nil

View File

@ -17,10 +17,10 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserLACreate = &cobra.Command{ var cmdUserLACreate = &cobra.Command{
@ -68,7 +68,7 @@ func userLACreate(cmd *cobra.Command, args []string) error {
log.Infof("creating linked account for user %q", userLACreateOpts.username) log.Infof("creating linked account for user %q", userLACreateOpts.username)
resp, _, err := gwclient.CreateUserLA(context.TODO(), userLACreateOpts.username, req) resp, _, err := gwclient.CreateUserLA(context.TODO(), userLACreateOpts.username, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create linked account") return errors.Errorf("failed to create linked account: %w", err)
} }
if resp.Oauth2Redirect != "" { if resp.Oauth2Redirect != "" {
log.Infof("visit %s to continue", resp.Oauth2Redirect) log.Infof("visit %s to continue", resp.Oauth2Redirect)

View File

@ -19,8 +19,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserLADelete = &cobra.Command{ var cmdUserLADelete = &cobra.Command{
@ -61,7 +61,7 @@ func userLADelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting linked account %q for user %q", laID, userName) log.Infof("deleting linked account %q for user %q", laID, userName)
_, err := gwclient.DeleteUserLA(context.TODO(), userName, laID) _, err := gwclient.DeleteUserLA(context.TODO(), userName, laID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete linked account") return errors.Errorf("failed to delete linked account: %w", err)
} }
log.Infof("linked account %q for user %q deleted", laID, userName) log.Infof("linked account %q for user %q deleted", laID, userName)

View File

@ -18,10 +18,10 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserTokenCreate = &cobra.Command{ var cmdUserTokenCreate = &cobra.Command{
@ -63,7 +63,7 @@ func userTokenCreate(cmd *cobra.Command, args []string) error {
log.Infof("creating token for user %q", userTokenCreateOpts.username) log.Infof("creating token for user %q", userTokenCreateOpts.username)
resp, _, err := gwclient.CreateUserToken(context.TODO(), userTokenCreateOpts.username, req) resp, _, err := gwclient.CreateUserToken(context.TODO(), userTokenCreateOpts.username, req)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create token") return errors.Errorf("failed to create token: %w", err)
} }
log.Infof("token for user %q created: %s", userTokenCreateOpts.username, resp.Token) log.Infof("token for user %q created: %s", userTokenCreateOpts.username, resp.Token)
fmt.Println(resp.Token) fmt.Println(resp.Token)

View File

@ -19,8 +19,8 @@ import (
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
errors "golang.org/x/xerrors"
) )
var cmdUserTokenDelete = &cobra.Command{ var cmdUserTokenDelete = &cobra.Command{
@ -61,7 +61,7 @@ func userTokenDelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting token %q for user %q", tokenName, userName) log.Infof("deleting token %q for user %q", tokenName, userName)
_, err := gwclient.DeleteUserToken(context.TODO(), userName, tokenName) _, err := gwclient.DeleteUserToken(context.TODO(), userName, tokenName)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete user token") return errors.Errorf("failed to delete user token: %w", err)
} }
log.Infof("token %q for user %q deleted", tokenName, userName) log.Infof("token %q for user %q deleted", tokenName, userName)

2
go.mod
View File

@ -48,7 +48,6 @@ require (
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect github.com/opencontainers/runc v0.1.1 // indirect
github.com/pkg/errors v0.8.0
github.com/sanity-io/litter v1.1.0 github.com/sanity-io/litter v1.1.0
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.0.0 // indirect github.com/sergi/go-diff v1.0.0 // indirect
@ -61,6 +60,7 @@ require (
go.uber.org/zap v1.9.1 go.uber.org/zap v1.9.1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9 golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522
gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.42.0 // indirect gopkg.in/ini.v1 v1.42.0 // indirect
gopkg.in/yaml.v2 v2.2.2 gopkg.in/yaml.v2 v2.2.2

2
go.sum
View File

@ -246,6 +246,8 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 h1:bhOzK9QyoD0ogCnFro1m2mz41+Ib0oOhfJnBp5MR4K4=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=

View File

@ -21,13 +21,13 @@ import (
"os" "os"
"path" "path"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/etcd" "github.com/sorintlab/agola/internal/etcd"
"github.com/sorintlab/agola/internal/objectstorage" "github.com/sorintlab/agola/internal/objectstorage"
"github.com/sorintlab/agola/internal/objectstorage/posix" "github.com/sorintlab/agola/internal/objectstorage/posix"
"github.com/sorintlab/agola/internal/objectstorage/s3" "github.com/sorintlab/agola/internal/objectstorage/s3"
"github.com/sorintlab/agola/internal/services/config" "github.com/sorintlab/agola/internal/services/config"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
const ( const (
@ -85,7 +85,7 @@ func NewObjectStorage(c *config.ObjectStorage) (*objectstorage.ObjStorage, error
case config.ObjectStorageTypePosix: case config.ObjectStorageTypePosix:
ost, err = posix.New(c.Path) ost, err = posix.New(c.Path)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create posix object storage") return nil, errors.Errorf("failed to create posix object storage: %w", err)
} }
case config.ObjectStorageTypeS3: case config.ObjectStorageTypeS3:
// minio golang client doesn't accept an url as an endpoint // minio golang client doesn't accept an url as an endpoint
@ -104,7 +104,7 @@ func NewObjectStorage(c *config.ObjectStorage) (*objectstorage.ObjStorage, error
} }
ost, err = s3.New(c.Bucket, c.Location, endpoint, c.AccessKey, c.SecretAccessKey, secure) ost, err = s3.New(c.Bucket, c.Location, endpoint, c.AccessKey, c.SecretAccessKey, secure)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create s3 object storage") return nil, errors.Errorf("failed to create s3 object storage: %w", err)
} }
} }
@ -122,7 +122,7 @@ func NewEtcd(c *config.Etcd, logger *zap.Logger, prefix string) (*etcd.Store, er
SkipTLSVerify: c.TLSSkipVerify, SkipTLSVerify: c.TLSSkipVerify,
}) })
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to create etcd store") return nil, errors.Errorf("failed to create etcd store: %w", err)
} }
return e, nil return e, nil

View File

@ -26,7 +26,7 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/google/go-jsonnet" "github.com/google/go-jsonnet"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (
@ -559,7 +559,7 @@ func parseWhenCondition(s string) (*types.WhenCondition, error) {
if isRegExp { if isRegExp {
if _, err := regexp.Compile(s); err != nil { if _, err := regexp.Compile(s); err != nil {
return nil, errors.Wrapf(err, "wrong regular expression") return nil, errors.Errorf("wrong regular expression: %w", err)
} }
wc.Type = types.WhenConditionTypeRegExp wc.Type = types.WhenConditionTypeRegExp
} else { } else {
@ -623,14 +623,14 @@ func ParseConfig(configData []byte, format ConfigFormat) (*Config, error) {
vm := jsonnet.MakeVM() vm := jsonnet.MakeVM()
out, err := vm.EvaluateSnippet("", string(configData)) out, err := vm.EvaluateSnippet("", string(configData))
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to evaluate jsonnet config") return nil, errors.Errorf("failed to evaluate jsonnet config: %w", err)
} }
configData = []byte(out) configData = []byte(out)
} }
config := DefaultConfig config := DefaultConfig
if err := yaml.Unmarshal(configData, &config); err != nil { if err := yaml.Unmarshal(configData, &config); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal config") return nil, errors.Errorf("failed to unmarshal config: %w", err)
} }
return &config, checkConfig(&config) return &config, checkConfig(&config)

View File

@ -22,7 +22,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func TestParseConfig(t *testing.T) { func TestParseConfig(t *testing.T) {

View File

@ -26,9 +26,9 @@ import (
"github.com/sorintlab/agola/internal/etcd" "github.com/sorintlab/agola/internal/etcd"
"github.com/pkg/errors"
etcdclientv3rpc "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes" etcdclientv3rpc "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
"go.etcd.io/etcd/mvcc/mvccpb" "go.etcd.io/etcd/mvcc/mvccpb"
errors "golang.org/x/xerrors"
) )
// TODO(sgotti) rewrite this to use a sqlite local cache // TODO(sgotti) rewrite this to use a sqlite local cache
@ -149,7 +149,7 @@ func (d *DataManager) applyWalChanges(ctx context.Context, walData *WalData, rev
walDataFile, err := d.ost.ReadObject(walDataFilePath) walDataFile, err := d.ost.ReadObject(walDataFilePath)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to read waldata %q", walDataFilePath) return errors.Errorf("failed to read waldata %q: %w", walDataFilePath, err)
} }
defer walDataFile.Close() defer walDataFile.Close()
dec := json.NewDecoder(walDataFile) dec := json.NewDecoder(walDataFile)
@ -165,7 +165,7 @@ func (d *DataManager) applyWalChanges(ctx context.Context, walData *WalData, rev
break break
} }
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to decode wal file") return errors.Errorf("failed to decode wal file: %w", err)
} }
d.applyWalChangesAction(ctx, action, walData.WalSequence, revision) d.applyWalChangesAction(ctx, action, walData.WalSequence, revision)
@ -285,7 +285,7 @@ func (d *DataManager) watcher(ctx context.Context) error {
d.changes.initialized = false d.changes.initialized = false
d.changes.Unlock() d.changes.Unlock()
} }
return errors.Wrapf(err, "watch error") return errors.Errorf("watch error: %w", err)
} }
revision := wresp.Header.Revision revision := wresp.Header.Revision

View File

@ -22,9 +22,9 @@ import (
"io" "io"
"strings" "strings"
"github.com/pkg/errors"
ostypes "github.com/sorintlab/agola/internal/objectstorage/types" ostypes "github.com/sorintlab/agola/internal/objectstorage/types"
"github.com/sorintlab/agola/internal/sequence" "github.com/sorintlab/agola/internal/sequence"
errors "golang.org/x/xerrors"
) )
type DataStatus struct { type DataStatus struct {
@ -145,7 +145,7 @@ func (d *DataManager) writeDataType(ctx context.Context, wals []*WalData, dataty
walFile, err := d.ReadWalData(header.WalDataFileID) walFile, err := d.ReadWalData(header.WalDataFileID)
if err != nil { if err != nil {
return errors.Wrapf(err, "cannot read wal data file %q", header.WalDataFileID) return errors.Errorf("cannot read wal data file %q: %w", header.WalDataFileID, err)
} }
defer walFile.Close() defer walFile.Close()
@ -159,7 +159,7 @@ func (d *DataManager) writeDataType(ctx context.Context, wals []*WalData, dataty
break break
} }
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to decode wal file") return errors.Errorf("failed to decode wal file: %w", err)
} }
if action.DataType != datatype { if action.DataType != datatype {
continue continue
@ -234,7 +234,7 @@ func (d *DataManager) Read(dataType, id string) (io.Reader, error) {
err = dec.Decode(&dataFileIndex) err = dec.Decode(&dataFileIndex)
if err != nil { if err != nil {
dataFileIndexf.Close() dataFileIndexf.Close()
return nil, errors.WithStack(err) return nil, err
} }
dataFileIndexf.Close() dataFileIndexf.Close()
@ -245,11 +245,11 @@ func (d *DataManager) Read(dataType, id string) (io.Reader, error) {
dataf, err := d.ost.ReadObject(dataFilePath(dataType, dataSequence)) dataf, err := d.ost.ReadObject(dataFilePath(dataType, dataSequence))
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if _, err := dataf.Seek(int64(pos), io.SeekStart); err != nil { if _, err := dataf.Seek(int64(pos), io.SeekStart); err != nil {
dataf.Close() dataf.Close()
return nil, errors.WithStack(err) return nil, err
} }
var de *DataEntry var de *DataEntry
dec = json.NewDecoder(dataf) dec = json.NewDecoder(dataf)

View File

@ -23,8 +23,8 @@ import (
"github.com/sorintlab/agola/internal/etcd" "github.com/sorintlab/agola/internal/etcd"
"github.com/sorintlab/agola/internal/objectstorage" "github.com/sorintlab/agola/internal/objectstorage"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
// TODO(sgotti) handle etcd unwanted changes: // TODO(sgotti) handle etcd unwanted changes:

View File

@ -30,12 +30,12 @@ import (
ostypes "github.com/sorintlab/agola/internal/objectstorage/types" ostypes "github.com/sorintlab/agola/internal/objectstorage/types"
"github.com/sorintlab/agola/internal/sequence" "github.com/sorintlab/agola/internal/sequence"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
etcdclientv3 "go.etcd.io/etcd/clientv3" etcdclientv3 "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency" "go.etcd.io/etcd/clientv3/concurrency"
etcdclientv3rpc "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes" etcdclientv3rpc "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
"go.etcd.io/etcd/mvcc/mvccpb" "go.etcd.io/etcd/mvcc/mvccpb"
errors "golang.org/x/xerrors"
) )
func (d *DataManager) storageWalStatusFile(walSeq string) string { func (d *DataManager) storageWalStatusFile(walSeq string) string {
@ -724,7 +724,7 @@ func (d *DataManager) checkpoint(ctx context.Context) error {
} }
if err := d.writeData(ctx, walsData); err != nil { if err := d.writeData(ctx, walsData); err != nil {
return errors.Wrapf(err, "checkpoint function error") return errors.Errorf("checkpoint function error: %w", err)
} }
for _, walData := range walsData { for _, walData := range walsData {

View File

@ -18,7 +18,7 @@ import (
"database/sql" "database/sql"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const dbVersionTableDDLTmpl = ` const dbVersionTableDDLTmpl = `
@ -32,7 +32,7 @@ func (db *DB) Create(stmts []string) error {
err := db.Do(func(tx *Tx) error { err := db.Do(func(tx *Tx) error {
if _, err := tx.Exec(dbVersionTableDDLTmpl); err != nil { if _, err := tx.Exec(dbVersionTableDDLTmpl); err != nil {
return errors.Wrap(err, "failed to create dbversion table") return errors.Errorf("failed to create dbversion table: %w", err)
} }
return nil return nil
}) })
@ -47,7 +47,7 @@ func (db *DB) Create(stmts []string) error {
return err return err
} }
if err := tx.QueryRow(q, args...).Scan(&version); err != nil { if err := tx.QueryRow(q, args...).Scan(&version); err != nil {
return errors.Wrap(err, "cannot get current db version") return errors.Errorf("cannot get current db version: %w", err)
} }
if version.Valid { if version.Valid {
return nil return nil
@ -55,7 +55,7 @@ func (db *DB) Create(stmts []string) error {
for _, stmt := range stmts { for _, stmt := range stmts {
if _, err := tx.Exec(stmt); err != nil { if _, err := tx.Exec(stmt); err != nil {
return errors.Wrapf(err, "creation failed") return errors.Errorf("creation failed: %w", err)
} }
} }
@ -64,7 +64,7 @@ func (db *DB) Create(stmts []string) error {
return err return err
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to update dbversion table") return errors.Errorf("failed to update dbversion table: %w", err)
} }
return nil return nil
}) })

View File

@ -21,7 +21,7 @@ import (
"time" "time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
type Type string type Type string
@ -126,7 +126,7 @@ func NewDB(dbType Type, dbConnString string) (*DB, error) {
sqldb, err := sql.Open(driverName, dbConnString) sqldb, err := sql.Open(driverName, dbConnString)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
db := &DB{ db := &DB{
@ -191,12 +191,12 @@ func (db *DB) Do(f func(tx *Tx) error) error {
func (tx *Tx) Start() error { func (tx *Tx) Start() error {
wtx, err := tx.db.db.Begin() wtx, err := tx.db.db.Begin()
if err != nil { if err != nil {
return errors.WithStack(err) return err
} }
switch tx.db.data.t { switch tx.db.data.t {
case Postgres: case Postgres:
if _, err := wtx.Exec("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"); err != nil { if _, err := wtx.Exec("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"); err != nil {
return errors.WithStack(err) return err
} }
} }
tx.tx = wtx tx.tx = wtx
@ -220,13 +220,13 @@ func (tx *Tx) Rollback() error {
func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error) { func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error) {
query = tx.db.data.translate(query) query = tx.db.data.translate(query)
r, err := tx.tx.Exec(query, tx.db.data.translateArgs(args)...) r, err := tx.tx.Exec(query, tx.db.data.translateArgs(args)...)
return r, errors.WithStack(err) return r, err
} }
func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error) { func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error) {
query = tx.db.data.translate(query) query = tx.db.data.translate(query)
r, err := tx.tx.Query(query, tx.db.data.translateArgs(args)...) r, err := tx.tx.Query(query, tx.db.data.translateArgs(args)...)
return r, errors.WithStack(err) return r, err
} }
func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row { func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row {
@ -239,13 +239,13 @@ func (tx *Tx) CurTime() (time.Time, error) {
case Sqlite3: case Sqlite3:
var timestring string var timestring string
if err := tx.QueryRow("select now()").Scan(&timestring); err != nil { if err := tx.QueryRow("select now()").Scan(&timestring); err != nil {
return time.Time{}, errors.WithStack(err) return time.Time{}, err
} }
return time.ParseInLocation("2006-01-02 15:04:05.999999999", timestring, time.UTC) return time.ParseInLocation("2006-01-02 15:04:05.999999999", timestring, time.UTC)
case Postgres: case Postgres:
var now time.Time var now time.Time
if err := tx.QueryRow("select now()").Scan(&now); err != nil { if err := tx.QueryRow("select now()").Scan(&now); err != nil {
return time.Time{}, errors.WithStack(err) return time.Time{}, err
} }
return now, nil return now, nil
} }

View File

@ -24,12 +24,12 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
"go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/clientv3"
etcdclientv3 "go.etcd.io/etcd/clientv3" etcdclientv3 "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/namespace" "go.etcd.io/etcd/clientv3/namespace"
"go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes" "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
var ( var (
@ -91,7 +91,7 @@ func New(cfg Config) (*Store, error) {
for _, e := range endpoints { for _, e := range endpoints {
u, err := url.Parse(e) u, err := url.Parse(e)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot parse endpoint %q", e) return nil, errors.Errorf("cannot parse endpoint %q: %w", e, err)
} }
if scheme == "" { if scheme == "" {
scheme = u.Scheme scheme = u.Scheme
@ -109,7 +109,7 @@ func New(cfg Config) (*Store, error) {
var err error var err error
tlsConfig, err = util.NewTLSConfig(cfg.CertFile, cfg.KeyFile, cfg.CAFile, cfg.SkipTLSVerify) tlsConfig, err = util.NewTLSConfig(cfg.CertFile, cfg.KeyFile, cfg.CAFile, cfg.SkipTLSVerify)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot create tls config") return nil, errors.Errorf("cannot create tls config: %w", err)
} }
} }

View File

@ -25,8 +25,8 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
var ( var (

View File

@ -23,8 +23,8 @@ import (
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
const ( const (

View File

@ -26,8 +26,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
gitsource "github.com/sorintlab/agola/internal/gitsources" gitsource "github.com/sorintlab/agola/internal/gitsources"
errors "golang.org/x/xerrors"
) )
var jsonContent = http.Header{"content-type": []string{"application/json"}} var jsonContent = http.Header{"content-type": []string{"application/json"}}

View File

@ -26,7 +26,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (

View File

@ -28,10 +28,10 @@ import (
"time" "time"
gitsource "github.com/sorintlab/agola/internal/gitsources" gitsource "github.com/sorintlab/agola/internal/gitsources"
"golang.org/x/oauth2"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
"github.com/pkg/errors" "golang.org/x/oauth2"
errors "golang.org/x/xerrors"
) )
const ( const (
@ -137,7 +137,7 @@ func (c *Client) RequestOauth2Token(callbackURL, code string) (*oauth2.Token, er
var config = c.oauth2Config(callbackURL) var config = c.oauth2Config(callbackURL)
token, err := config.Exchange(context.TODO(), code) token, err := config.Exchange(context.TODO(), code)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot get oauth2 token") return nil, errors.Errorf("cannot get oauth2 token: %w", err)
} }
return token, nil return token, nil
} }
@ -239,13 +239,15 @@ func (c *Client) CreateDeployKey(repopath, title, pubKey string, readonly bool)
if err != nil { if err != nil {
return err return err
} }
_, err = c.client.CreateDeployKey(owner, reponame, gitea.CreateKeyOption{ if _, err = c.client.CreateDeployKey(owner, reponame, gitea.CreateKeyOption{
Title: title, Title: title,
Key: pubKey, Key: pubKey,
ReadOnly: readonly, ReadOnly: readonly,
}) }); err != nil {
return errors.Errorf("error creating deploy key: %w", err)
}
return errors.Wrapf(err, "error creating deploy key") return nil
} }
func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool) error { func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool) error {
@ -259,7 +261,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
// when the public key value has changed // when the public key value has changed
keys, err := c.client.ListDeployKeys(owner, reponame) keys, err := c.client.ListDeployKeys(owner, reponame)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
@ -268,7 +270,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
return nil return nil
} }
if err := c.client.DeleteDeployKey(owner, reponame, key.ID); err != nil { if err := c.client.DeleteDeployKey(owner, reponame, key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -278,7 +280,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
Key: pubKey, Key: pubKey,
ReadOnly: readonly, ReadOnly: readonly,
}); err != nil { }); err != nil {
return errors.Wrapf(err, "error creating deploy key") return errors.Errorf("error creating deploy key: %w", err)
} }
return nil return nil
@ -291,13 +293,13 @@ func (c *Client) DeleteDeployKey(repopath, title string) error {
} }
keys, err := c.client.ListDeployKeys(owner, reponame) keys, err := c.client.ListDeployKeys(owner, reponame)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
if key.Title == title { if key.Title == title {
if err := c.client.DeleteDeployKey(owner, reponame, key.ID); err != nil { if err := c.client.DeleteDeployKey(owner, reponame, key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -322,9 +324,11 @@ func (c *Client) CreateRepoWebhook(repopath, url, secret string) error {
Active: true, Active: true,
} }
_, err = c.client.CreateRepoHook(owner, reponame, opts) if _, err = c.client.CreateRepoHook(owner, reponame, opts); err != nil {
return errors.Errorf("error creating repository webhook: %w", err)
}
return errors.Wrapf(err, "error creating repository webhook") return nil
} }
func (c *Client) DeleteRepoWebhook(repopath, u string) error { func (c *Client) DeleteRepoWebhook(repopath, u string) error {
@ -334,7 +338,7 @@ func (c *Client) DeleteRepoWebhook(repopath, u string) error {
} }
hooks, err := c.client.ListRepoHooks(owner, reponame) hooks, err := c.client.ListRepoHooks(owner, reponame)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving repository webhooks") return errors.Errorf("error retrieving repository webhooks: %w", err)
} }
// match the full url so we can have multiple webhooks for different agola // match the full url so we can have multiple webhooks for different agola
@ -342,7 +346,7 @@ func (c *Client) DeleteRepoWebhook(repopath, u string) error {
for _, hook := range hooks { for _, hook := range hooks {
if hook.Config["url"] == u { if hook.Config["url"] == u {
if err := c.client.DeleteRepoHook(owner, reponame, hook.ID); err != nil { if err := c.client.DeleteRepoHook(owner, reponame, hook.ID); err != nil {
return errors.Wrapf(err, "error deleting existing repository webhook") return errors.Errorf("error deleting existing repository webhook: %w", err)
} }
} }
} }

View File

@ -29,7 +29,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (

View File

@ -30,8 +30,8 @@ import (
gitsource "github.com/sorintlab/agola/internal/gitsources" gitsource "github.com/sorintlab/agola/internal/gitsources"
"github.com/google/go-github/v25/github" "github.com/google/go-github/v25/github"
"github.com/pkg/errors"
"golang.org/x/oauth2" "golang.org/x/oauth2"
errors "golang.org/x/xerrors"
) )
var ( var (
@ -159,7 +159,7 @@ func (c *Client) RequestOauth2Token(callbackURL, code string) (*oauth2.Token, er
var config = c.oauth2Config(callbackURL) var config = c.oauth2Config(callbackURL)
token, err := config.Exchange(context.TODO(), code) token, err := config.Exchange(context.TODO(), code)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot get oauth2 token") return nil, errors.Errorf("cannot get oauth2 token: %w", err)
} }
return token, nil return token, nil
} }
@ -219,7 +219,7 @@ func (c *Client) CreateDeployKey(repopath, title, pubKey string, readonly bool)
Key: github.String(pubKey), Key: github.String(pubKey),
ReadOnly: github.Bool(readonly), ReadOnly: github.Bool(readonly),
}); err != nil { }); err != nil {
return errors.Wrapf(err, "error creating deploy key") return errors.Errorf("error creating deploy key: %w", err)
} }
return nil return nil
} }
@ -235,7 +235,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
// when the public key value has changed // when the public key value has changed
keys, _, err := c.client.Repositories.ListKeys(context.TODO(), owner, reponame, nil) keys, _, err := c.client.Repositories.ListKeys(context.TODO(), owner, reponame, nil)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
@ -244,7 +244,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
return nil return nil
} }
if _, err := c.client.Repositories.DeleteKey(context.TODO(), owner, reponame, *key.ID); err != nil { if _, err := c.client.Repositories.DeleteKey(context.TODO(), owner, reponame, *key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -254,7 +254,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
Key: github.String(pubKey), Key: github.String(pubKey),
ReadOnly: github.Bool(readonly), ReadOnly: github.Bool(readonly),
}); err != nil { }); err != nil {
return errors.Wrapf(err, "error creating deploy key") return errors.Errorf("error creating deploy key: %w", err)
} }
return nil return nil
@ -267,13 +267,13 @@ func (c *Client) DeleteDeployKey(repopath, title string) error {
} }
keys, _, err := c.client.Repositories.ListKeys(context.TODO(), owner, reponame, nil) keys, _, err := c.client.Repositories.ListKeys(context.TODO(), owner, reponame, nil)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
if *key.Title == title { if *key.Title == title {
if _, err := c.client.Repositories.DeleteKey(context.TODO(), owner, reponame, *key.ID); err != nil { if _, err := c.client.Repositories.DeleteKey(context.TODO(), owner, reponame, *key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -298,7 +298,7 @@ func (c *Client) CreateRepoWebhook(repopath, url, secret string) error {
} }
if _, _, err = c.client.Repositories.CreateHook(context.TODO(), owner, reponame, hook); err != nil { if _, _, err = c.client.Repositories.CreateHook(context.TODO(), owner, reponame, hook); err != nil {
return errors.Wrapf(err, "error creating repository webhook") return errors.Errorf("error creating repository webhook: %w", err)
} }
return nil return nil
@ -316,7 +316,7 @@ func (c *Client) DeleteRepoWebhook(repopath, u string) error {
for { for {
pHooks, resp, err := c.client.Repositories.ListHooks(context.TODO(), owner, reponame, opt) pHooks, resp, err := c.client.Repositories.ListHooks(context.TODO(), owner, reponame, opt)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving repository webhooks") return errors.Errorf("error retrieving repository webhooks: %w", err)
} }
hooks = append(hooks, pHooks...) hooks = append(hooks, pHooks...)
if resp.NextPage == 0 { if resp.NextPage == 0 {
@ -330,7 +330,7 @@ func (c *Client) DeleteRepoWebhook(repopath, u string) error {
for _, hook := range hooks { for _, hook := range hooks {
if hook.Config["url"] == u { if hook.Config["url"] == u {
if _, err := c.client.Repositories.DeleteHook(context.TODO(), owner, reponame, *hook.ID); err != nil { if _, err := c.client.Repositories.DeleteHook(context.TODO(), owner, reponame, *hook.ID); err != nil {
return errors.Wrapf(err, "error deleting existing repository webhook") return errors.Errorf("error deleting existing repository webhook: %w", err)
} }
} }
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/google/go-github/v25/github" "github.com/google/go-github/v25/github"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (
@ -40,12 +40,12 @@ const (
func (c *Client) ParseWebhook(r *http.Request, secret string) (*types.WebhookData, error) { func (c *Client) ParseWebhook(r *http.Request, secret string) (*types.WebhookData, error) {
payload, err := github.ValidatePayload(r, []byte(secret)) payload, err := github.ValidatePayload(r, []byte(secret))
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "wrong webhook signature") return nil, errors.Errorf("wrong webhook signature: %w", err)
} }
webHookType := github.WebHookType(r) webHookType := github.WebHookType(r)
event, err := github.ParseWebHook(webHookType, payload) event, err := github.ParseWebHook(webHookType, payload)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to parse webhook") return nil, errors.Errorf("failed to parse webhook: %w", err)
} }
switch event := event.(type) { switch event := event.(type) {
case *github.PushEvent: case *github.PushEvent:

View File

@ -24,10 +24,11 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/pkg/errors"
gitsource "github.com/sorintlab/agola/internal/gitsources" gitsource "github.com/sorintlab/agola/internal/gitsources"
gitlab "github.com/xanzy/go-gitlab" gitlab "github.com/xanzy/go-gitlab"
"golang.org/x/oauth2" "golang.org/x/oauth2"
errors "golang.org/x/xerrors"
) )
var ( var (
@ -114,7 +115,7 @@ func (c *Client) RequestOauth2Token(callbackURL, code string) (*oauth2.Token, er
var config = c.oauth2Config(callbackURL) var config = c.oauth2Config(callbackURL)
token, err := config.Exchange(context.TODO(), code) token, err := config.Exchange(context.TODO(), code)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot get oauth2 token") return nil, errors.Errorf("cannot get oauth2 token: %w", err)
} }
return token, nil return token, nil
} }
@ -156,18 +157,20 @@ func (c *Client) GetFile(repopath, commit, file string) ([]byte, error) {
} }
func (c *Client) CreateDeployKey(repopath, title, pubKey string, readonly bool) error { func (c *Client) CreateDeployKey(repopath, title, pubKey string, readonly bool) error {
_, _, err := c.client.DeployKeys.AddDeployKey(repopath, &gitlab.AddDeployKeyOptions{ if _, _, err := c.client.DeployKeys.AddDeployKey(repopath, &gitlab.AddDeployKeyOptions{
Title: gitlab.String(title), Title: gitlab.String(title),
Key: gitlab.String(pubKey), Key: gitlab.String(pubKey),
}) }); err != nil {
return errors.Errorf("error creating deploy key: %w", err)
}
return errors.Wrapf(err, "error creating deploy key") return nil
} }
func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool) error { func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool) error {
keys, _, err := c.client.DeployKeys.ListProjectDeployKeys(repopath, nil) keys, _, err := c.client.DeployKeys.ListProjectDeployKeys(repopath, nil)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
@ -176,7 +179,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
return nil return nil
} }
if _, err := c.client.DeployKeys.DeleteDeployKey(repopath, key.ID); err != nil { if _, err := c.client.DeployKeys.DeleteDeployKey(repopath, key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -185,7 +188,7 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
Title: &title, Title: &title,
Key: &pubKey, Key: &pubKey,
}); err != nil { }); err != nil {
return errors.Wrapf(err, "error creating deploy key") return errors.Errorf("error creating deploy key: %w", err)
} }
return nil return nil
@ -194,13 +197,13 @@ func (c *Client) UpdateDeployKey(repopath, title, pubKey string, readonly bool)
func (c *Client) DeleteDeployKey(repopath, title string) error { func (c *Client) DeleteDeployKey(repopath, title string) error {
keys, _, err := c.client.DeployKeys.ListProjectDeployKeys(repopath, nil) keys, _, err := c.client.DeployKeys.ListProjectDeployKeys(repopath, nil)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving existing deploy keys") return errors.Errorf("error retrieving existing deploy keys: %w", err)
} }
for _, key := range keys { for _, key := range keys {
if key.Title == title { if key.Title == title {
if _, err := c.client.DeployKeys.DeleteDeployKey(repopath, key.ID); err != nil { if _, err := c.client.DeployKeys.DeleteDeployKey(repopath, key.ID); err != nil {
return errors.Wrapf(err, "error removing existing deploy key") return errors.Errorf("error removing existing deploy key: %w", err)
} }
} }
} }
@ -216,15 +219,17 @@ func (c *Client) CreateRepoWebhook(repopath, url, secret string) error {
MergeRequestsEvents: gitlab.Bool(true), MergeRequestsEvents: gitlab.Bool(true),
Token: gitlab.String(secret), Token: gitlab.String(secret),
} }
_, _, err := c.client.Projects.AddProjectHook(repopath, opts) if _, _, err := c.client.Projects.AddProjectHook(repopath, opts); err != nil {
return errors.Errorf("error creating repository webhook: %w", err)
}
return errors.Wrapf(err, "error creating repository webhook") return nil
} }
func (c *Client) DeleteRepoWebhook(repopath, u string) error { func (c *Client) DeleteRepoWebhook(repopath, u string) error {
hooks, _, err := c.client.Projects.ListProjectHooks(repopath, nil) hooks, _, err := c.client.Projects.ListProjectHooks(repopath, nil)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving repository webhooks") return errors.Errorf("error retrieving repository webhooks: %w", err)
} }
// match the full url so we can have multiple webhooks for different agola // match the full url so we can have multiple webhooks for different agola
@ -232,7 +237,7 @@ func (c *Client) DeleteRepoWebhook(repopath, u string) error {
for _, hook := range hooks { for _, hook := range hooks {
if hook.URL == u { if hook.URL == u {
if _, err := c.client.Projects.DeleteProjectHook(repopath, hook.ID); err != nil { if _, err := c.client.Projects.DeleteProjectHook(repopath, hook.ID); err != nil {
return errors.Wrapf(err, "error deleting existing repository webhook") return errors.Errorf("error deleting existing repository webhook: %w", err)
} }
} }
} }

View File

@ -25,7 +25,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (

View File

@ -21,9 +21,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/objectstorage/common" "github.com/sorintlab/agola/internal/objectstorage/common"
"github.com/sorintlab/agola/internal/objectstorage/types" "github.com/sorintlab/agola/internal/objectstorage/types"
errors "golang.org/x/xerrors"
) )
const ( const (
@ -43,10 +43,10 @@ func New(baseDir string) (*PosixStorage, error) {
dataDir := filepath.Join(baseDir, dataDirName) dataDir := filepath.Join(baseDir, dataDirName)
tmpDir := filepath.Join(baseDir, tmpDirName) tmpDir := filepath.Join(baseDir, tmpDirName)
if err := os.MkdirAll(dataDir, 0770); err != nil { if err := os.MkdirAll(dataDir, 0770); err != nil {
return nil, errors.Wrapf(err, "failed to create data dir") return nil, errors.Errorf("failed to create data dir: %w", err)
} }
if err := os.MkdirAll(tmpDir, 0770); err != nil { if err := os.MkdirAll(tmpDir, 0770); err != nil {
return nil, errors.Wrapf(err, "failed to create tmp dir") return nil, errors.Errorf("failed to create tmp dir: %w", err)
} }
return &PosixStorage{ return &PosixStorage{
dataDir: dataDir, dataDir: dataDir,

View File

@ -26,7 +26,7 @@ import (
"github.com/sorintlab/agola/internal/objectstorage/common" "github.com/sorintlab/agola/internal/objectstorage/common"
"github.com/sorintlab/agola/internal/objectstorage/types" "github.com/sorintlab/agola/internal/objectstorage/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (
@ -218,10 +218,10 @@ func New(baseDir string) (*PosixFlatStorage, error) {
dataDir := filepath.Join(baseDir, dataDirName) dataDir := filepath.Join(baseDir, dataDirName)
tmpDir := filepath.Join(baseDir, tmpDirName) tmpDir := filepath.Join(baseDir, tmpDirName)
if err := os.MkdirAll(dataDir, 0770); err != nil { if err := os.MkdirAll(dataDir, 0770); err != nil {
return nil, errors.Wrapf(err, "failed to create data dir") return nil, errors.Errorf("failed to create data dir: %w", err)
} }
if err := os.MkdirAll(tmpDir, 0770); err != nil { if err := os.MkdirAll(tmpDir, 0770); err != nil {
return nil, errors.Wrapf(err, "failed to create tmp dir") return nil, errors.Errorf("failed to create tmp dir: %w", err)
} }
return &PosixFlatStorage{ return &PosixFlatStorage{
dataDir: dataDir, dataDir: dataDir,

View File

@ -24,7 +24,7 @@ import (
"github.com/sorintlab/agola/internal/objectstorage/types" "github.com/sorintlab/agola/internal/objectstorage/types"
minio "github.com/minio/minio-go" minio "github.com/minio/minio-go"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
type S3Storage struct { type S3Storage struct {
@ -47,11 +47,11 @@ func New(bucket, location, endpoint, accessKeyID, secretAccessKey string, secure
exists, err := minioClient.BucketExists(bucket) exists, err := minioClient.BucketExists(bucket)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot check if bucket %q in location %q exits", bucket, location) return nil, errors.Errorf("cannot check if bucket %q in location %q exits: %w", bucket, location, err)
} }
if !exists { if !exists {
if err := minioClient.MakeBucket(bucket, location); err != nil { if err := minioClient.MakeBucket(bucket, location); err != nil {
return nil, errors.Wrapf(err, "cannot create bucket %q in location %q", bucket, location) return nil, errors.Errorf("cannot create bucket %q in location %q: %w", bucket, location, err)
} }
} }

View File

@ -18,11 +18,11 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/config" "github.com/sorintlab/agola/internal/config"
rstypes "github.com/sorintlab/agola/internal/services/runservice/types" rstypes "github.com/sorintlab/agola/internal/services/runservice/types"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
func genRuntime(c *config.Config, ce *config.Runtime, variables map[string]string) *rstypes.Runtime { func genRuntime(c *config.Config, ce *config.Runtime, variables map[string]string) *rstypes.Runtime {

View File

@ -20,11 +20,11 @@ import (
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/config" "github.com/sorintlab/agola/internal/config"
rstypes "github.com/sorintlab/agola/internal/services/runservice/types" rstypes "github.com/sorintlab/agola/internal/services/runservice/types"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
var uuid = &util.TestUUIDGenerator{} var uuid = &util.TestUUIDGenerator{}

View File

@ -23,8 +23,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/etcd" "github.com/sorintlab/agola/internal/etcd"
errors "golang.org/x/xerrors"
) )
type Sequence struct { type Sequence struct {
@ -51,11 +51,11 @@ func Parse(s string) (*Sequence, error) {
} }
epoch, err := strconv.ParseUint(parts[0], 32, 64) epoch, err := strconv.ParseUint(parts[0], 32, 64)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot parse sequence epoch %q", epoch) return nil, errors.Errorf("cannot parse sequence epoch %q: %w", epoch, err)
} }
c, err := strconv.ParseUint(parts[1], 32, 64) c, err := strconv.ParseUint(parts[1], 32, 64)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot parse sequence count %q", c) return nil, errors.Errorf("cannot parse sequence count %q: %w", c, err)
} }
return &Sequence{ return &Sequence{
Epoch: epoch, Epoch: epoch,

View File

@ -21,7 +21,7 @@ import (
"github.com/sorintlab/agola/internal/gitsources/gitlab" "github.com/sorintlab/agola/internal/gitsources/gitlab"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func newGitea(rs *types.RemoteSource, accessToken string) (*gitea.Client, error) { func newGitea(rs *types.RemoteSource, accessToken string) (*gitea.Client, error) {

View File

@ -20,7 +20,7 @@ import (
"time" "time"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
type TokenSigningData struct { type TokenSigningData struct {

View File

@ -19,9 +19,9 @@ import (
"net/url" "net/url"
"path" "path"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
type GroupType string type GroupType string

View File

@ -18,8 +18,8 @@ import (
"io/ioutil" "io/ioutil"
"time" "time"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
@ -233,12 +233,12 @@ var defaultConfig = Config{
func Parse(configFile string) (*Config, error) { func Parse(configFile string) (*Config, error) {
configData, err := ioutil.ReadFile(configFile) configData, err := ioutil.ReadFile(configFile)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
c := &defaultConfig c := &defaultConfig
if err := yaml.Unmarshal(configData, &c); err != nil { if err := yaml.Unmarshal(configData, &c); err != nil {
return nil, errors.WithStack(err) return nil, err
} }
return c, Validate(c) return c, Validate(c)
@ -284,7 +284,7 @@ func Validate(c *Config) error {
return errors.Errorf("gateway runserviceURL is empty") return errors.Errorf("gateway runserviceURL is empty")
} }
if err := validateWeb(&c.Gateway.Web); err != nil { if err := validateWeb(&c.Gateway.Web); err != nil {
return errors.Wrapf(err, "gateway web configuration error") return errors.Errorf("gateway web configuration error: %w", err)
} }
// Configstore // Configstore
@ -292,7 +292,7 @@ func Validate(c *Config) error {
return errors.Errorf("configstore dataDir is empty") return errors.Errorf("configstore dataDir is empty")
} }
if err := validateWeb(&c.Configstore.Web); err != nil { if err := validateWeb(&c.Configstore.Web); err != nil {
return errors.Wrapf(err, "configstore web configuration error") return errors.Errorf("configstore web configuration error: %w", err)
} }
// Runservice // Runservice
@ -300,7 +300,7 @@ func Validate(c *Config) error {
return errors.Errorf("runservice dataDir is empty") return errors.Errorf("runservice dataDir is empty")
} }
if err := validateWeb(&c.Runservice.Web); err != nil { if err := validateWeb(&c.Runservice.Web); err != nil {
return errors.Wrapf(err, "runservice web configuration error") return errors.Errorf("runservice web configuration error: %w", err)
} }
// Executor // Executor

View File

@ -26,8 +26,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
type OrgMemberResponse struct { type OrgMemberResponse struct {
@ -123,7 +123,7 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, org *types.Organization)
org.CreatedAt = time.Now() org.CreatedAt = time.Now()
orgj, err := json.Marshal(org) orgj, err := json.Marshal(org)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal org") return nil, errors.Errorf("failed to marshal org: %w", err)
} }
actions = append(actions, &datamanager.Action{ actions = append(actions, &datamanager.Action{
ActionType: datamanager.ActionTypePut, ActionType: datamanager.ActionTypePut,
@ -142,7 +142,7 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, org *types.Organization)
} }
orgmemberj, err := json.Marshal(orgmember) orgmemberj, err := json.Marshal(orgmember)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project group") return nil, errors.Errorf("failed to marshal project group: %w", err)
} }
actions = append(actions, &datamanager.Action{ actions = append(actions, &datamanager.Action{
ActionType: datamanager.ActionTypePut, ActionType: datamanager.ActionTypePut,
@ -164,7 +164,7 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, org *types.Organization)
} }
pgj, err := json.Marshal(pg) pgj, err := json.Marshal(pg)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project group") return nil, errors.Errorf("failed to marshal project group: %w", err)
} }
actions = append(actions, &datamanager.Action{ actions = append(actions, &datamanager.Action{
ActionType: datamanager.ActionTypePut, ActionType: datamanager.ActionTypePut,
@ -296,7 +296,7 @@ func (h *ActionHandler) AddOrgMember(ctx context.Context, orgRef, userRef string
actions := []*datamanager.Action{} actions := []*datamanager.Action{}
orgmemberj, err := json.Marshal(orgmember) orgmemberj, err := json.Marshal(orgmember)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project group") return nil, errors.Errorf("failed to marshal project group: %w", err)
} }
actions = append(actions, &datamanager.Action{ actions = append(actions, &datamanager.Action{
ActionType: datamanager.ActionTypePut, ActionType: datamanager.ActionTypePut,

View File

@ -24,8 +24,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) ValidateProject(ctx context.Context, project *types.Project) error { func (h *ActionHandler) ValidateProject(ctx context.Context, project *types.Project) error {
@ -110,7 +110,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, project *types.Projec
// check that the linked account matches the remote source // check that the linked account matches the remote source
user, err := h.readDB.GetUserByLinkedAccount(tx, project.LinkedAccountID) user, err := h.readDB.GetUserByLinkedAccount(tx, project.LinkedAccountID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get user with linked account id %q", project.LinkedAccountID) return errors.Errorf("failed to get user with linked account id %q: %w", project.LinkedAccountID, err)
} }
if user == nil { if user == nil {
return util.NewErrBadRequest(errors.Errorf("user for linked account %q doesn't exist", project.LinkedAccountID)) return util.NewErrBadRequest(errors.Errorf("user for linked account %q doesn't exist", project.LinkedAccountID))
@ -138,7 +138,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, project *types.Projec
pcj, err := json.Marshal(project) pcj, err := json.Marshal(project)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project") return nil, errors.Errorf("failed to marshal project: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -223,7 +223,7 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, req *UpdateProjectReq
// check that the linked account matches the remote source // check that the linked account matches the remote source
user, err := h.readDB.GetUserByLinkedAccount(tx, req.Project.LinkedAccountID) user, err := h.readDB.GetUserByLinkedAccount(tx, req.Project.LinkedAccountID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get user with linked account id %q", req.Project.LinkedAccountID) return errors.Errorf("failed to get user with linked account id %q: %w", req.Project.LinkedAccountID, err)
} }
if user == nil { if user == nil {
return util.NewErrBadRequest(errors.Errorf("user for linked account %q doesn't exist", req.Project.LinkedAccountID)) return util.NewErrBadRequest(errors.Errorf("user for linked account %q doesn't exist", req.Project.LinkedAccountID))
@ -245,7 +245,7 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, req *UpdateProjectReq
pcj, err := json.Marshal(req.Project) pcj, err := json.Marshal(req.Project)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project") return nil, errors.Errorf("failed to marshal project: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -24,8 +24,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*types.ProjectGroup, error) { func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*types.ProjectGroup, error) {
@ -155,7 +155,7 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, projectGroup *ty
pgj, err := json.Marshal(projectGroup) pgj, err := json.Marshal(projectGroup)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal projectGroup") return nil, errors.Errorf("failed to marshal projectGroup: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -247,7 +247,7 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, req *UpdateProje
pgj, err := json.Marshal(req.ProjectGroup) pgj, err := json.Marshal(req.ProjectGroup)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project") return nil, errors.Errorf("failed to marshal project: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -23,8 +23,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) ValidateRemoteSource(ctx context.Context, remoteSource *types.RemoteSource) error { func (h *ActionHandler) ValidateRemoteSource(ctx context.Context, remoteSource *types.RemoteSource) error {
@ -99,7 +99,7 @@ func (h *ActionHandler) CreateRemoteSource(ctx context.Context, remoteSource *ty
rsj, err := json.Marshal(remoteSource) rsj, err := json.Marshal(remoteSource)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal remotesource") return nil, errors.Errorf("failed to marshal remotesource: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -154,7 +154,7 @@ func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemot
rsj, err := json.Marshal(req.RemoteSource) rsj, err := json.Marshal(req.RemoteSource)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal remotesource") return nil, errors.Errorf("failed to marshal remotesource: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -23,8 +23,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetSecret(ctx context.Context, secretID string) (*types.Secret, error) { func (h *ActionHandler) GetSecret(ctx context.Context, secretID string) (*types.Secret, error) {
@ -129,7 +129,7 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, secret *types.Secret)
secretj, err := json.Marshal(secret) secretj, err := json.Marshal(secret)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal secret") return nil, errors.Errorf("failed to marshal secret: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -25,8 +25,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
type CreateUserRequest struct { type CreateUserRequest struct {
@ -76,7 +76,7 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
} }
user, err := h.readDB.GetUserByLinkedAccountRemoteUserIDandSource(tx, req.CreateUserLARequest.RemoteUserID, rs.ID) user, err := h.readDB.GetUserByLinkedAccountRemoteUserIDandSource(tx, req.CreateUserLARequest.RemoteUserID, rs.ID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get user for remote user id %q and remote source %q", req.CreateUserLARequest.RemoteUserID, rs.ID) return errors.Errorf("failed to get user for remote user id %q and remote source %q: %w", req.CreateUserLARequest.RemoteUserID, rs.ID, err)
} }
if user != nil { if user != nil {
return util.NewErrBadRequest(errors.Errorf("user for remote user id %q for remote source %q already exists", req.CreateUserLARequest.RemoteUserID, req.CreateUserLARequest.RemoteSourceName)) return util.NewErrBadRequest(errors.Errorf("user for remote user id %q for remote source %q already exists", req.CreateUserLARequest.RemoteUserID, req.CreateUserLARequest.RemoteSourceName))
@ -114,7 +114,7 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal user") return nil, errors.Errorf("failed to marshal user: %w", err)
} }
// create root user project group // create root user project group
@ -129,7 +129,7 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
} }
pgj, err := json.Marshal(pg) pgj, err := json.Marshal(pg)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal project group") return nil, errors.Errorf("failed to marshal project group: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
@ -247,7 +247,7 @@ func (h *ActionHandler) UpdateUser(ctx context.Context, req *UpdateUserRequest)
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal user") return nil, errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
@ -316,7 +316,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
user, err := h.readDB.GetUserByLinkedAccountRemoteUserIDandSource(tx, req.RemoteUserID, rs.ID) user, err := h.readDB.GetUserByLinkedAccountRemoteUserIDandSource(tx, req.RemoteUserID, rs.ID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get user for remote user id %q and remote source %q", req.RemoteUserID, rs.ID) return errors.Errorf("failed to get user for remote user id %q and remote source %q: %w", req.RemoteUserID, rs.ID, err)
} }
if user != nil { if user != nil {
return util.NewErrBadRequest(errors.Errorf("user for remote user id %q for remote source %q already exists", req.RemoteUserID, req.RemoteSourceName)) return util.NewErrBadRequest(errors.Errorf("user for remote user id %q for remote source %q already exists", req.RemoteUserID, req.RemoteSourceName))
@ -346,7 +346,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal user") return nil, errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -406,7 +406,7 @@ func (h *ActionHandler) DeleteUserLA(ctx context.Context, userRef, laID string)
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to marshal user") return errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -490,7 +490,7 @@ func (h *ActionHandler) UpdateUserLA(ctx context.Context, req *UpdateUserLAReque
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal user") return nil, errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -555,7 +555,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, userRef, tokenName
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "failed to marshal user") return "", errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {
@ -615,7 +615,7 @@ func (h *ActionHandler) DeleteUserToken(ctx context.Context, userRef, tokenName
userj, err := json.Marshal(user) userj, err := json.Marshal(user)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to marshal user") return errors.Errorf("failed to marshal user: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -23,8 +23,8 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetVariables(ctx context.Context, parentType types.ConfigType, parentRef string, tree bool) ([]*types.Variable, error) { func (h *ActionHandler) GetVariables(ctx context.Context, parentType types.ConfigType, parentRef string, tree bool) ([]*types.Variable, error) {
@ -105,7 +105,7 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, variable *types.Vari
variablej, err := json.Marshal(variable) variablej, err := json.Marshal(variable)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal variable") return nil, errors.Errorf("failed to marshal variable: %w", err)
} }
actions := []*datamanager.Action{ actions := []*datamanager.Action{
{ {

View File

@ -20,9 +20,9 @@ import (
"net/url" "net/url"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
type ErrorResponse struct { type ErrorResponse struct {
@ -88,7 +88,7 @@ func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) {
vars := mux.Vars(r) vars := mux.Vars(r)
projectRef, err := url.PathUnescape(vars["projectref"]) projectRef, err := url.PathUnescape(vars["projectref"])
if err != nil { if err != nil {
return "", "", util.NewErrBadRequest(errors.Wrapf(err, "wrong projectref %q", vars["projectref"])) return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectref %q: %w", vars["projectref"], err))
} }
if projectRef != "" { if projectRef != "" {
return types.ConfigTypeProject, projectRef, nil return types.ConfigTypeProject, projectRef, nil
@ -96,7 +96,7 @@ func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) {
projectGroupRef, err := url.PathUnescape(vars["projectgroupref"]) projectGroupRef, err := url.PathUnescape(vars["projectgroupref"])
if err != nil { if err != nil {
return "", "", util.NewErrBadRequest(errors.Wrapf(err, "wrong projectgroupref %q", vars["projectgroupref"])) return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectgroupref %q: %w", vars["projectgroupref"], err))
} }
if projectGroupRef != "" { if projectGroupRef != "" {
return types.ConfigTypeProjectGroup, projectGroupRef, nil return types.ConfigTypeProjectGroup, projectGroupRef, nil

View File

@ -28,7 +28,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var jsonContent = http.Header{"Content-Type": []string{"application/json"}} var jsonContent = http.Header{"Content-Type": []string{"application/json"}}

View File

@ -19,12 +19,12 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/action" "github.com/sorintlab/agola/internal/services/configstore/action"
"github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
@ -144,7 +144,7 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error var err error
limit, err = strconv.Atoi(limitS) limit, err = strconv.Atoi(limitS)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "cannot parse limit"))) httpError(w, util.NewErrBadRequest(errors.Errorf("cannot parse limit: %w", err)))
return return
} }
} }

View File

@ -20,12 +20,12 @@ import (
"net/url" "net/url"
"path" "path"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/action" "github.com/sorintlab/agola/internal/services/configstore/action"
"github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -20,12 +20,12 @@ import (
"net/url" "net/url"
"path" "path"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/action" "github.com/sorintlab/agola/internal/services/configstore/action"
"github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -19,12 +19,12 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/action" "github.com/sorintlab/agola/internal/services/configstore/action"
"github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
@ -181,7 +181,7 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
var err error var err error
limit, err = strconv.Atoi(limitS) limit, err = strconv.Atoi(limitS)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "cannot parse limit"))) httpError(w, util.NewErrBadRequest(errors.Errorf("cannot parse limit: %w", err)))
return return
} }
} }

View File

@ -20,12 +20,12 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
action "github.com/sorintlab/agola/internal/services/configstore/action" action "github.com/sorintlab/agola/internal/services/configstore/action"
"github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"
@ -206,7 +206,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error var err error
limit, err = strconv.Atoi(limitS) limit, err = strconv.Atoi(limitS)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "cannot parse limit"))) httpError(w, util.NewErrBadRequest(errors.Errorf("cannot parse limit: %w", err)))
return return
} }
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -38,7 +38,7 @@ var (
func (r *ReadDB) insertOrg(tx *db.Tx, data []byte) error { func (r *ReadDB) insertOrg(tx *db.Tx, data []byte) error {
org := types.Organization{} org := types.Organization{}
if err := json.Unmarshal(data, &org); err != nil { if err := json.Unmarshal(data, &org); err != nil {
return errors.Wrap(err, "failed to unmarshal org") return errors.Errorf("failed to unmarshal org: %w", err)
} }
r.log.Infof("inserting org: %s", util.Dump(org)) r.log.Infof("inserting org: %s", util.Dump(org))
// poor man insert or update... // poor man insert or update...
@ -47,10 +47,10 @@ func (r *ReadDB) insertOrg(tx *db.Tx, data []byte) error {
} }
q, args, err := orgInsert.Values(org.ID, org.Name, data).ToSql() q, args, err := orgInsert.Values(org.ID, org.Name, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert org") return errors.Errorf("failed to insert org: %w", err)
} }
return nil return nil
@ -58,7 +58,7 @@ func (r *ReadDB) insertOrg(tx *db.Tx, data []byte) error {
func (r *ReadDB) deleteOrg(tx *db.Tx, orgID string) error { func (r *ReadDB) deleteOrg(tx *db.Tx, orgID string) error {
if _, err := tx.Exec("delete from org where id = $1", orgID); err != nil { if _, err := tx.Exec("delete from org where id = $1", orgID); err != nil {
return errors.Wrap(err, "failed to delete org") return errors.Errorf("failed to delete org: %w", err)
} }
return nil return nil
} }
@ -83,12 +83,12 @@ func (r *ReadDB) GetOrgByID(tx *db.Tx, orgID string) (*types.Organization, error
q, args, err := orgSelect.Where(sq.Eq{"id": orgID}).ToSql() q, args, err := orgSelect.Where(sq.Eq{"id": orgID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
orgs, _, err := fetchOrgs(tx, q, args...) orgs, _, err := fetchOrgs(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(orgs) > 1 { if len(orgs) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -103,12 +103,12 @@ func (r *ReadDB) GetOrgByName(tx *db.Tx, name string) (*types.Organization, erro
q, args, err := orgSelect.Where(sq.Eq{"name": name}).ToSql() q, args, err := orgSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
orgs, _, err := fetchOrgs(tx, q, args...) orgs, _, err := fetchOrgs(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(orgs) > 1 { if len(orgs) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -149,7 +149,7 @@ func (r *ReadDB) GetOrgs(tx *db.Tx, startOrgName string, limit int, asc bool) ([
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
rows, err := tx.Query(q, args...) rows, err := tx.Query(q, args...)
@ -174,12 +174,12 @@ func scanOrg(rows *sql.Rows, additionalFields ...interface{}) (*types.Organizati
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
org := types.Organization{} org := types.Organization{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &org); err != nil { if err := json.Unmarshal(data, &org); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal org") return nil, "", errors.Errorf("failed to unmarshal org: %w", err)
} }
} }
@ -207,7 +207,7 @@ func scanOrgs(rows *sql.Rows) ([]*types.Organization, []string, error) {
func (r *ReadDB) insertOrgMember(tx *db.Tx, data []byte) error { func (r *ReadDB) insertOrgMember(tx *db.Tx, data []byte) error {
orgmember := types.OrganizationMember{} orgmember := types.OrganizationMember{}
if err := json.Unmarshal(data, &orgmember); err != nil { if err := json.Unmarshal(data, &orgmember); err != nil {
return errors.Wrap(err, "failed to unmarshal orgmember") return errors.Errorf("failed to unmarshal orgmember: %w", err)
} }
r.log.Infof("inserting orgmember: %s", util.Dump(orgmember)) r.log.Infof("inserting orgmember: %s", util.Dump(orgmember))
// poor man insert or update... // poor man insert or update...
@ -216,10 +216,10 @@ func (r *ReadDB) insertOrgMember(tx *db.Tx, data []byte) error {
} }
q, args, err := orgmemberInsert.Values(orgmember.ID, orgmember.OrganizationID, orgmember.UserID, orgmember.MemberRole, data).ToSql() q, args, err := orgmemberInsert.Values(orgmember.ID, orgmember.OrganizationID, orgmember.UserID, orgmember.MemberRole, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert orgmember") return errors.Errorf("failed to insert orgmember: %w", err)
} }
return nil return nil
@ -227,7 +227,7 @@ func (r *ReadDB) insertOrgMember(tx *db.Tx, data []byte) error {
func (r *ReadDB) deleteOrgMember(tx *db.Tx, orgmemberID string) error { func (r *ReadDB) deleteOrgMember(tx *db.Tx, orgmemberID string) error {
if _, err := tx.Exec("delete from orgmember where id = $1", orgmemberID); err != nil { if _, err := tx.Exec("delete from orgmember where id = $1", orgmemberID); err != nil {
return errors.Wrap(err, "failed to delete orgmember") return errors.Errorf("failed to delete orgmember: %w", err)
} }
return nil return nil
} }
@ -236,12 +236,12 @@ func (r *ReadDB) GetOrgMemberByOrgUserID(tx *db.Tx, orgID, userID string) (*type
q, args, err := orgmemberSelect.Where(sq.Eq{"orgmember.orgid": orgID, "orgmember.userid": userID}).ToSql() q, args, err := orgmemberSelect.Where(sq.Eq{"orgmember.orgid": orgID, "orgmember.userid": userID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
oms, _, err := fetchOrgMembers(tx, q, args...) oms, _, err := fetchOrgMembers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(oms) > 1 { if len(oms) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -265,12 +265,12 @@ func scanOrgMember(rows *sql.Rows, additionalFields ...interface{}) (*types.Orga
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
orgmember := types.OrganizationMember{} orgmember := types.OrganizationMember{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &orgmember); err != nil { if err := json.Unmarshal(data, &orgmember); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal org") return nil, "", errors.Errorf("failed to unmarshal org: %w", err)
} }
} }
@ -309,7 +309,7 @@ func (r *ReadDB) GetOrgUsers(tx *db.Tx, orgID string) ([]*OrgUser, error) {
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
rows, err := tx.Query(q, args...) rows, err := tx.Query(q, args...)
@ -325,13 +325,13 @@ func (r *ReadDB) GetOrgUsers(tx *db.Tx, orgID string) ([]*OrgUser, error) {
var orgmemberdata []byte var orgmemberdata []byte
var userdata []byte var userdata []byte
if err := rows.Scan(&orgmemberdata, &userdata); err != nil { if err := rows.Scan(&orgmemberdata, &userdata); err != nil {
return nil, errors.Wrap(err, "failed to scan rows") return nil, errors.Errorf("failed to scan rows: %w", err)
} }
if err := json.Unmarshal(orgmemberdata, &orgmember); err != nil { if err := json.Unmarshal(orgmemberdata, &orgmember); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal orgmember") return nil, errors.Errorf("failed to unmarshal orgmember: %w", err)
} }
if err := json.Unmarshal(userdata, &user); err != nil { if err := json.Unmarshal(userdata, &user); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal org") return nil, errors.Errorf("failed to unmarshal org: %w", err)
} }
orgusers = append(orgusers, &OrgUser{ orgusers = append(orgusers, &OrgUser{
@ -360,7 +360,7 @@ func (r *ReadDB) GetUserOrgs(tx *db.Tx, userID string) ([]*UserOrg, error) {
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
rows, err := tx.Query(q, args...) rows, err := tx.Query(q, args...)
@ -376,13 +376,13 @@ func (r *ReadDB) GetUserOrgs(tx *db.Tx, userID string) ([]*UserOrg, error) {
var orgmemberdata []byte var orgmemberdata []byte
var orgdata []byte var orgdata []byte
if err := rows.Scan(&orgmemberdata, &orgdata); err != nil { if err := rows.Scan(&orgmemberdata, &orgdata); err != nil {
return nil, errors.Wrap(err, "failed to scan rows") return nil, errors.Errorf("failed to scan rows: %w", err)
} }
if err := json.Unmarshal(orgmemberdata, &orgmember); err != nil { if err := json.Unmarshal(orgmemberdata, &orgmember); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal orgmember") return nil, errors.Errorf("failed to unmarshal orgmember: %w", err)
} }
if err := json.Unmarshal(orgdata, &org); err != nil { if err := json.Unmarshal(orgdata, &org); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal org") return nil, errors.Errorf("failed to unmarshal org: %w", err)
} }
userorgs = append(userorgs, &UserOrg{ userorgs = append(userorgs, &UserOrg{

View File

@ -26,7 +26,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -37,7 +37,7 @@ var (
func (r *ReadDB) insertProject(tx *db.Tx, data []byte) error { func (r *ReadDB) insertProject(tx *db.Tx, data []byte) error {
var project *types.Project var project *types.Project
if err := json.Unmarshal(data, &project); err != nil { if err := json.Unmarshal(data, &project); err != nil {
return errors.Wrap(err, "failed to unmarshal project") return errors.Errorf("failed to unmarshal project: %w", err)
} }
// poor man insert or update... // poor man insert or update...
if err := r.deleteProject(tx, project.ID); err != nil { if err := r.deleteProject(tx, project.ID); err != nil {
@ -45,16 +45,19 @@ func (r *ReadDB) insertProject(tx *db.Tx, data []byte) error {
} }
q, args, err := projectInsert.Values(project.ID, project.Name, project.Parent.ID, data).ToSql() q, args, err := projectInsert.Values(project.ID, project.Name, project.Parent.ID, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
_, err = tx.Exec(q, args...) if _, err = tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert project") return errors.Errorf("failed to insert project: %w", err)
}
return nil
} }
func (r *ReadDB) deleteProject(tx *db.Tx, id string) error { func (r *ReadDB) deleteProject(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from project where id = $1", id); err != nil { if _, err := tx.Exec("delete from project where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete project") return errors.Errorf("failed to delete project: %w", err)
} }
return nil return nil
} }
@ -108,12 +111,12 @@ func (r *ReadDB) GetProjectByID(tx *db.Tx, projectID string) (*types.Project, er
q, args, err := projectSelect.Where(sq.Eq{"id": projectID}).ToSql() q, args, err := projectSelect.Where(sq.Eq{"id": projectID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projects, _, err := fetchProjects(tx, q, args...) projects, _, err := fetchProjects(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(projects) > 1 { if len(projects) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -128,12 +131,12 @@ func (r *ReadDB) GetProjectByName(tx *db.Tx, parentID, name string) (*types.Proj
q, args, err := projectSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql() q, args, err := projectSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projects, _, err := fetchProjects(tx, q, args...) projects, _, err := fetchProjects(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(projects) > 1 { if len(projects) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -153,7 +156,7 @@ func (r *ReadDB) GetProjectByPath(tx *db.Tx, projectPath string) (*types.Project
projectName := path.Base(projectPath) projectName := path.Base(projectPath)
projectGroup, err := r.GetProjectGroupByPath(tx, projectGroupPath) projectGroup, err := r.GetProjectGroupByPath(tx, projectGroupPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get project group %q", projectGroupPath) return nil, errors.Errorf("failed to get project group %q: %w", projectGroupPath, err)
} }
if projectGroup == nil { if projectGroup == nil {
return nil, nil return nil, nil
@ -161,7 +164,7 @@ func (r *ReadDB) GetProjectByPath(tx *db.Tx, projectPath string) (*types.Project
project, err := r.GetProjectByName(tx, projectGroup.ID, projectName) project, err := r.GetProjectByName(tx, projectGroup.ID, projectName)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get project group %q", projectName) return nil, errors.Errorf("failed to get project group %q: %w", projectName, err)
} }
return project, nil return project, nil
} }
@ -172,7 +175,7 @@ func (r *ReadDB) GetProjectGroupProjects(tx *db.Tx, parentID string) ([]*types.P
q, args, err := projectSelect.Where(sq.Eq{"parentid": parentID}).ToSql() q, args, err := projectSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projects, _, err = fetchProjects(tx, q, args...) projects, _, err = fetchProjects(tx, q, args...)
@ -192,12 +195,12 @@ func scanProject(rows *sql.Rows, additionalFields ...interface{}) (*types.Projec
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
project := types.Project{} project := types.Project{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &project); err != nil { if err := json.Unmarshal(data, &project); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal project") return nil, "", errors.Errorf("failed to unmarshal project: %w", err)
} }
} }
@ -230,7 +233,7 @@ func (r *ReadDB) GetAllProjects(tx *db.Tx) ([]*types.Project, error) {
q, args, err := projectSelect.ToSql() q, args, err := projectSelect.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projects, _, err = fetchProjects(tx, q, args...) projects, _, err = fetchProjects(tx, q, args...)

View File

@ -26,7 +26,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -37,7 +37,7 @@ var (
func (r *ReadDB) insertProjectGroup(tx *db.Tx, data []byte) error { func (r *ReadDB) insertProjectGroup(tx *db.Tx, data []byte) error {
var group *types.ProjectGroup var group *types.ProjectGroup
if err := json.Unmarshal(data, &group); err != nil { if err := json.Unmarshal(data, &group); err != nil {
return errors.Wrap(err, "failed to unmarshal group") return errors.Errorf("failed to unmarshal group: %w", err)
} }
// poor man insert or update... // poor man insert or update...
@ -46,16 +46,19 @@ func (r *ReadDB) insertProjectGroup(tx *db.Tx, data []byte) error {
} }
q, args, err := projectgroupInsert.Values(group.ID, group.Name, group.Parent.ID, data).ToSql() q, args, err := projectgroupInsert.Values(group.ID, group.Name, group.Parent.ID, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
_, err = tx.Exec(q, args...) if _, err = tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert group") errors.Errorf("failed to insert group: %w", err)
}
return nil
} }
func (r *ReadDB) deleteProjectGroup(tx *db.Tx, id string) error { func (r *ReadDB) deleteProjectGroup(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from projectgroup where id = $1", id); err != nil { if _, err := tx.Exec("delete from projectgroup where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete group") return errors.Errorf("failed to delete group: %w", err)
} }
return nil return nil
} }
@ -84,7 +87,7 @@ func (r *ReadDB) GetProjectGroupHierarchy(tx *db.Tx, projectGroup *types.Project
var err error var err error
projectGroup, err = r.GetProjectGroup(tx, projectGroupID) projectGroup, err = r.GetProjectGroup(tx, projectGroupID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get project group %q", projectGroupID) return nil, errors.Errorf("failed to get project group %q: %w", projectGroupID, err)
} }
if projectGroup == nil { if projectGroup == nil {
return nil, errors.Errorf("project group %q doesn't exist", projectGroupID) return nil, errors.Errorf("project group %q doesn't exist", projectGroupID)
@ -165,12 +168,12 @@ func (r *ReadDB) GetProjectGroupByID(tx *db.Tx, projectGroupID string) (*types.P
q, args, err := projectgroupSelect.Where(sq.Eq{"id": projectGroupID}).ToSql() q, args, err := projectgroupSelect.Where(sq.Eq{"id": projectGroupID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projectGroups, _, err := fetchProjectGroups(tx, q, args...) projectGroups, _, err := fetchProjectGroups(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(projectGroups) > 1 { if len(projectGroups) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -185,12 +188,12 @@ func (r *ReadDB) GetProjectGroupByName(tx *db.Tx, parentID, name string) (*types
q, args, err := projectgroupSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql() q, args, err := projectgroupSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projectGroups, _, err := fetchProjectGroups(tx, q, args...) projectGroups, _, err := fetchProjectGroups(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(projectGroups) > 1 { if len(projectGroups) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -211,7 +214,7 @@ func (r *ReadDB) GetProjectGroupByPath(tx *db.Tx, projectGroupPath string) (*typ
case "org": case "org":
org, err := r.GetOrgByName(tx, parts[1]) org, err := r.GetOrgByName(tx, parts[1])
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get org %q", parts[1]) return nil, errors.Errorf("failed to get org %q: %w", parts[1], err)
} }
if org == nil { if org == nil {
return nil, errors.Errorf("cannot find org with name %q", parts[1]) return nil, errors.Errorf("cannot find org with name %q", parts[1])
@ -220,7 +223,7 @@ func (r *ReadDB) GetProjectGroupByPath(tx *db.Tx, projectGroupPath string) (*typ
case "user": case "user":
user, err := r.GetUserByName(tx, parts[1]) user, err := r.GetUserByName(tx, parts[1])
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get user %q", parts[1]) return nil, errors.Errorf("failed to get user %q: %w", parts[1], err)
} }
if user == nil { if user == nil {
return nil, errors.Errorf("cannot find user with name %q", parts[1]) return nil, errors.Errorf("cannot find user with name %q", parts[1])
@ -236,7 +239,7 @@ func (r *ReadDB) GetProjectGroupByPath(tx *db.Tx, projectGroupPath string) (*typ
var err error var err error
projectGroup, err = r.GetProjectGroupByName(tx, parentID, projectGroupName) projectGroup, err = r.GetProjectGroupByName(tx, parentID, projectGroupName)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get project group %q", projectGroupName) return nil, errors.Errorf("failed to get project group %q: %w", projectGroupName, err)
} }
if projectGroup == nil { if projectGroup == nil {
return nil, nil return nil, nil
@ -253,7 +256,7 @@ func (r *ReadDB) GetProjectGroupSubgroups(tx *db.Tx, parentID string) ([]*types.
q, args, err := projectgroupSelect.Where(sq.Eq{"parentid": parentID}).ToSql() q, args, err := projectgroupSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
projectGroups, _, err = fetchProjectGroups(tx, q, args...) projectGroups, _, err = fetchProjectGroups(tx, q, args...)
@ -273,12 +276,12 @@ func scanProjectGroup(rows *sql.Rows, additionalFields ...interface{}) (*types.P
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
group := types.ProjectGroup{} group := types.ProjectGroup{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &group); err != nil { if err := json.Unmarshal(data, &group); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal group") return nil, "", errors.Errorf("failed to unmarshal group: %w", err)
} }
} }

View File

@ -34,8 +34,8 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
var ( var (
@ -95,7 +95,7 @@ func NewReadDB(ctx context.Context, logger *zap.Logger, dataDir string, e *etcd.
func (r *ReadDB) Initialize(ctx context.Context) error { func (r *ReadDB) Initialize(ctx context.Context) error {
// sync the rdb // sync the rdb
if err := r.SyncRDB(ctx); err != nil { if err := r.SyncRDB(ctx); err != nil {
return errors.Wrapf(err, "error syncing db") return errors.Errorf("error syncing db: %w", err)
} }
return nil return nil
} }
@ -127,7 +127,7 @@ func (r *ReadDB) ResetDB() error {
func (r *ReadDB) SyncFromDump() (string, error) { func (r *ReadDB) SyncFromDump() (string, error) {
dumpIndex, err := r.dm.GetLastDataStatus() dumpIndex, err := r.dm.GetLastDataStatus()
if err != nil && err != ostypes.ErrNotExist { if err != nil && err != ostypes.ErrNotExist {
return "", errors.WithStack(err) return "", err
} }
if err == ostypes.ErrNotExist { if err == ostypes.ErrNotExist {
return "", nil return "", nil
@ -135,7 +135,7 @@ func (r *ReadDB) SyncFromDump() (string, error) {
for dataType, files := range dumpIndex.Files { for dataType, files := range dumpIndex.Files {
dumpf, err := r.ost.ReadObject(files[0]) dumpf, err := r.ost.ReadObject(files[0])
if err != nil { if err != nil {
return "", errors.WithStack(err) return "", err
} }
dumpEntries := []*datamanager.DataEntry{} dumpEntries := []*datamanager.DataEntry{}
dec := json.NewDecoder(dumpf) dec := json.NewDecoder(dumpf)
@ -300,7 +300,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
var err error var err error
curWalSeq, err = r.SyncFromDump() curWalSeq, err = r.SyncFromDump()
if err != nil { if err != nil {
return errors.WithStack(err) return err
} }
} }
@ -313,7 +313,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
// committedstorage in etcd // committedstorage in etcd
curWalSeq, err = r.SyncFromWals(curWalSeq, lastCommittedStorageWal) curWalSeq, err = r.SyncFromWals(curWalSeq, lastCommittedStorageWal)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to sync from wals") return errors.Errorf("failed to sync from wals: %w", err)
} }
// Get the first available wal from etcd and check that our current walseq // Get the first available wal from etcd and check that our current walseq
@ -322,7 +322,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
// many new wals are written, the next sync should be faster and able to continue // many new wals are written, the next sync should be faster and able to continue
firstAvailableWalData, revision, err := r.dm.FirstAvailableWalData(ctx) firstAvailableWalData, revision, err := r.dm.FirstAvailableWalData(ctx)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get first available wal data") return errors.Errorf("failed to get first available wal data: %w", err)
} }
r.log.Infof("firstAvailableWalData: %s", util.Dump(firstAvailableWalData)) r.log.Infof("firstAvailableWalData: %s", util.Dump(firstAvailableWalData))
r.log.Infof("revision: %d", revision) r.log.Infof("revision: %d", revision)
@ -459,7 +459,7 @@ func (r *ReadDB) HandleEvents(ctx context.Context) error {
r.Initialized = false r.Initialized = false
return nil return nil
} }
return errors.Wrapf(err, "watch error") return errors.Errorf("watch error: %w", err)
} }
// a single transaction for every response (every response contains all the // a single transaction for every response (every response contains all the
@ -551,7 +551,7 @@ func (r *ReadDB) handleWalEvent(tx *db.Tx, we *datamanager.WatchElement) error {
func (r *ReadDB) applyWal(tx *db.Tx, walDataFileID string) error { func (r *ReadDB) applyWal(tx *db.Tx, walDataFileID string) error {
walFile, err := r.dm.ReadWalData(walDataFileID) walFile, err := r.dm.ReadWalData(walDataFileID)
if err != nil { if err != nil {
return errors.Wrapf(err, "cannot read wal data file %q", walDataFileID) return errors.Errorf("cannot read wal data file %q: %w", walDataFileID, err)
} }
defer walFile.Close() defer walFile.Close()
@ -565,7 +565,7 @@ func (r *ReadDB) applyWal(tx *db.Tx, walDataFileID string) error {
break break
} }
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to decode wal file") return errors.Errorf("failed to decode wal file: %w", err)
} }
if err := r.applyAction(tx, action); err != nil { if err := r.applyAction(tx, action); err != nil {
@ -670,16 +670,16 @@ func (r *ReadDB) insertRevision(tx *db.Tx, revision int64) error {
//r.log.Infof("insert revision: %d", revision) //r.log.Infof("insert revision: %d", revision)
// poor man insert or update that works because transaction isolation level is serializable // poor man insert or update that works because transaction isolation level is serializable
if _, err := tx.Exec("delete from revision"); err != nil { if _, err := tx.Exec("delete from revision"); err != nil {
return errors.Wrap(err, "failed to delete revision") return errors.Errorf("failed to delete revision: %w", err)
} }
// TODO(sgotti) go database/sql and mattn/sqlite3 don't support uint64 types... // TODO(sgotti) go database/sql and mattn/sqlite3 don't support uint64 types...
//q, args, err = revisionInsert.Values(int64(wresp.Header.ClusterId), run.Revision).ToSql() //q, args, err = revisionInsert.Values(int64(wresp.Header.ClusterId), run.Revision).ToSql()
q, args, err := revisionInsert.Values(revision).ToSql() q, args, err := revisionInsert.Values(revision).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err = tx.Exec(q, args...); err != nil { if _, err = tx.Exec(q, args...); err != nil {
return errors.WithStack(err) return err
} }
return nil return nil
} }
@ -701,7 +701,7 @@ func (r *ReadDB) getRevision(tx *db.Tx) (int64, error) {
q, args, err := revisionSelect.ToSql() q, args, err := revisionSelect.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return 0, errors.Wrap(err, "failed to build query") return 0, errors.Errorf("failed to build query: %w", err)
} }
err = tx.QueryRow(q, args...).Scan(&revision) err = tx.QueryRow(q, args...).Scan(&revision)
@ -715,14 +715,14 @@ func (r *ReadDB) insertCommittedWalSequence(tx *db.Tx, seq string) error {
r.log.Infof("insert seq: %s", seq) r.log.Infof("insert seq: %s", seq)
// poor man insert or update that works because transaction isolation level is serializable // poor man insert or update that works because transaction isolation level is serializable
if _, err := tx.Exec("delete from committedwalsequence"); err != nil { if _, err := tx.Exec("delete from committedwalsequence"); err != nil {
return errors.Wrap(err, "failed to delete committedwalsequence") return errors.Errorf("failed to delete committedwalsequence: %w", err)
} }
q, args, err := committedwalsequenceInsert.Values(seq).ToSql() q, args, err := committedwalsequenceInsert.Values(seq).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err = tx.Exec(q, args...); err != nil { if _, err = tx.Exec(q, args...); err != nil {
return errors.WithStack(err) return err
} }
return nil return nil
} }
@ -733,7 +733,7 @@ func (r *ReadDB) GetCommittedWalSequence(tx *db.Tx) (string, error) {
q, args, err := committedwalsequenceSelect.OrderBy("seq").Limit(1).ToSql() q, args, err := committedwalsequenceSelect.OrderBy("seq").Limit(1).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return "", errors.Wrap(err, "failed to build query") return "", errors.Errorf("failed to build query: %w", err)
} }
err = tx.QueryRow(q, args...).Scan(&seq) err = tx.QueryRow(q, args...).Scan(&seq)
@ -748,13 +748,13 @@ func (r *ReadDB) insertChangeGroupRevision(tx *db.Tx, changegroup string, revisi
// poor man insert or update that works because transaction isolation level is serializable // poor man insert or update that works because transaction isolation level is serializable
if _, err := tx.Exec("delete from changegrouprevision where id = $1", changegroup); err != nil { if _, err := tx.Exec("delete from changegrouprevision where id = $1", changegroup); err != nil {
return errors.Wrap(err, "failed to delete run") return errors.Errorf("failed to delete run: %w", err)
} }
// insert only if revision > 0 // insert only if revision > 0
if revision > 0 { if revision > 0 {
q, args, err := changegrouprevisionInsert.Values(changegroup, revision).ToSql() q, args, err := changegrouprevisionInsert.Values(changegroup, revision).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err = tx.Exec(q, args...); err != nil { if _, err = tx.Exec(q, args...); err != nil {
return err return err
@ -768,7 +768,7 @@ func (r *ReadDB) GetChangeGroupsUpdateTokens(tx *db.Tx, groups []string) (*datam
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
cgr, err := fetchChangeGroupsRevision(tx, q, args...) cgr, err := fetchChangeGroupsRevision(tx, q, args...)
if err != nil { if err != nil {
@ -807,7 +807,7 @@ func scanChangeGroupsRevision(rows *sql.Rows) (map[string]int64, error) {
revision int64 revision int64
) )
if err := rows.Scan(&id, &revision); err != nil { if err := rows.Scan(&id, &revision); err != nil {
return nil, errors.Wrap(err, "failed to scan rows") return nil, errors.Errorf("failed to scan rows: %w", err)
} }
changegroups[id] = revision changegroups[id] = revision
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -35,7 +35,7 @@ var (
func (r *ReadDB) insertRemoteSource(tx *db.Tx, data []byte) error { func (r *ReadDB) insertRemoteSource(tx *db.Tx, data []byte) error {
remoteSource := types.RemoteSource{} remoteSource := types.RemoteSource{}
if err := json.Unmarshal(data, &remoteSource); err != nil { if err := json.Unmarshal(data, &remoteSource); err != nil {
return errors.Wrap(err, "failed to unmarshal remotesource") return errors.Errorf("failed to unmarshal remotesource: %w", err)
} }
// poor man insert or update... // poor man insert or update...
if err := r.deleteRemoteSource(tx, remoteSource.ID); err != nil { if err := r.deleteRemoteSource(tx, remoteSource.ID); err != nil {
@ -43,16 +43,19 @@ func (r *ReadDB) insertRemoteSource(tx *db.Tx, data []byte) error {
} }
q, args, err := remotesourceInsert.Values(remoteSource.ID, remoteSource.Name, data).ToSql() q, args, err := remotesourceInsert.Values(remoteSource.ID, remoteSource.Name, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
_, err = tx.Exec(q, args...) if _, err = tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert remotesource") return errors.Errorf("failed to insert remotesource: %w", err)
}
return nil
} }
func (r *ReadDB) deleteRemoteSource(tx *db.Tx, id string) error { func (r *ReadDB) deleteRemoteSource(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from remotesource where id = $1", id); err != nil { if _, err := tx.Exec("delete from remotesource where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete remotesource") return errors.Errorf("failed to delete remotesource: %w", err)
} }
return nil return nil
} }
@ -77,12 +80,12 @@ func (r *ReadDB) GetRemoteSourceByID(tx *db.Tx, remoteSourceID string) (*types.R
q, args, err := remotesourceSelect.Where(sq.Eq{"id": remoteSourceID}).ToSql() q, args, err := remotesourceSelect.Where(sq.Eq{"id": remoteSourceID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
remoteSources, _, err := fetchRemoteSources(tx, q, args...) remoteSources, _, err := fetchRemoteSources(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(remoteSources) > 1 { if len(remoteSources) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -97,12 +100,12 @@ func (r *ReadDB) GetRemoteSourceByName(tx *db.Tx, name string) (*types.RemoteSou
q, args, err := remotesourceSelect.Where(sq.Eq{"name": name}).ToSql() q, args, err := remotesourceSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
remoteSources, _, err := fetchRemoteSources(tx, q, args...) remoteSources, _, err := fetchRemoteSources(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(remoteSources) > 1 { if len(remoteSources) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -135,6 +138,7 @@ func getRemoteSourcesFilteredQuery(startRemoteSourceName string, limit int, asc
return s return s
} }
func (r *ReadDB) GetRemoteSources(startRemoteSourceName string, limit int, asc bool) ([]*types.RemoteSource, error) { func (r *ReadDB) GetRemoteSources(startRemoteSourceName string, limit int, asc bool) ([]*types.RemoteSource, error) {
var remoteSources []*types.RemoteSource var remoteSources []*types.RemoteSource
@ -142,7 +146,7 @@ func (r *ReadDB) GetRemoteSources(startRemoteSourceName string, limit int, asc b
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
err = r.rdb.Do(func(tx *db.Tx) error { err = r.rdb.Do(func(tx *db.Tx) error {
@ -154,7 +158,7 @@ func (r *ReadDB) GetRemoteSources(startRemoteSourceName string, limit int, asc b
remoteSources, _, err = scanRemoteSources(rows) remoteSources, _, err = scanRemoteSources(rows)
return err return err
}) })
return remoteSources, errors.WithStack(err) return remoteSources, err
} }
func fetchRemoteSources(tx *db.Tx, q string, args ...interface{}) ([]*types.RemoteSource, []string, error) { func fetchRemoteSources(tx *db.Tx, q string, args ...interface{}) ([]*types.RemoteSource, []string, error) {
@ -170,12 +174,12 @@ func scanRemoteSource(rows *sql.Rows, additionalFields ...interface{}) (*types.R
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
remoteSource := types.RemoteSource{} remoteSource := types.RemoteSource{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &remoteSource); err != nil { if err := json.Unmarshal(data, &remoteSource); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal remotesource") return nil, "", errors.Errorf("failed to unmarshal remotesource: %w", err)
} }
} }

View File

@ -17,10 +17,10 @@ package readdb
import ( import (
"path" "path"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
func (r *ReadDB) ResolveConfigID(tx *db.Tx, configType types.ConfigType, ref string) (string, error) { func (r *ReadDB) ResolveConfigID(tx *db.Tx, configType types.ConfigType, ref string) (string, error) {
@ -80,7 +80,7 @@ func (r *ReadDB) GetPath(tx *db.Tx, configType types.ConfigType, id string) (str
case types.ConfigTypeOrg: case types.ConfigTypeOrg:
org, err := r.GetOrg(tx, id) org, err := r.GetOrg(tx, id)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "failed to get org %q", id) return "", errors.Errorf("failed to get org %q: %w", id, err)
} }
if org == nil { if org == nil {
return "", errors.Errorf("cannot find org with id %q", id) return "", errors.Errorf("cannot find org with id %q", id)
@ -89,7 +89,7 @@ func (r *ReadDB) GetPath(tx *db.Tx, configType types.ConfigType, id string) (str
case types.ConfigTypeUser: case types.ConfigTypeUser:
user, err := r.GetUser(tx, id) user, err := r.GetUser(tx, id)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "failed to get user %q", id) return "", errors.Errorf("failed to get user %q: %w", id, err)
} }
if user == nil { if user == nil {
return "", errors.Errorf("cannot find user with id %q", id) return "", errors.Errorf("cannot find user with id %q", id)

View File

@ -23,7 +23,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -34,7 +34,7 @@ var (
func (r *ReadDB) insertSecret(tx *db.Tx, data []byte) error { func (r *ReadDB) insertSecret(tx *db.Tx, data []byte) error {
secret := types.Secret{} secret := types.Secret{}
if err := json.Unmarshal(data, &secret); err != nil { if err := json.Unmarshal(data, &secret); err != nil {
return errors.Wrap(err, "failed to unmarshal secret") return errors.Errorf("failed to unmarshal secret: %w", err)
} }
// poor man insert or update... // poor man insert or update...
if err := r.deleteSecret(tx, secret.ID); err != nil { if err := r.deleteSecret(tx, secret.ID); err != nil {
@ -42,16 +42,19 @@ func (r *ReadDB) insertSecret(tx *db.Tx, data []byte) error {
} }
q, args, err := secretInsert.Values(secret.ID, secret.Name, secret.Parent.ID, data).ToSql() q, args, err := secretInsert.Values(secret.ID, secret.Name, secret.Parent.ID, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
_, err = tx.Exec(q, args...) if _, err = tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert secret") return errors.Errorf("failed to insert secret: %w", err)
}
return nil
} }
func (r *ReadDB) deleteSecret(tx *db.Tx, id string) error { func (r *ReadDB) deleteSecret(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from secret where id = $1", id); err != nil { if _, err := tx.Exec("delete from secret where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete secret") return errors.Errorf("failed to delete secret: %w", err)
} }
return nil return nil
} }
@ -60,12 +63,12 @@ func (r *ReadDB) GetSecretByID(tx *db.Tx, secretID string) (*types.Secret, error
q, args, err := secretSelect.Where(sq.Eq{"id": secretID}).ToSql() q, args, err := secretSelect.Where(sq.Eq{"id": secretID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
secrets, _, err := fetchSecrets(tx, q, args...) secrets, _, err := fetchSecrets(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(secrets) > 1 { if len(secrets) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -80,12 +83,12 @@ func (r *ReadDB) GetSecretByName(tx *db.Tx, parentID, name string) (*types.Secre
q, args, err := secretSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql() q, args, err := secretSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
secrets, _, err := fetchSecrets(tx, q, args...) secrets, _, err := fetchSecrets(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(secrets) > 1 { if len(secrets) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -100,7 +103,7 @@ func (r *ReadDB) GetSecrets(tx *db.Tx, parentID string) ([]*types.Secret, error)
q, args, err := secretSelect.Where(sq.Eq{"parentid": parentID}).ToSql() q, args, err := secretSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
secrets, _, err := fetchSecrets(tx, q, args...) secrets, _, err := fetchSecrets(tx, q, args...)
@ -111,7 +114,7 @@ func (r *ReadDB) GetSecretTree(tx *db.Tx, parentType types.ConfigType, parentID,
for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject { for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject {
secret, err := r.GetSecretByName(tx, parentID, name) secret, err := r.GetSecretByName(tx, parentID, name)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get secret with name %q", name) return nil, errors.Errorf("failed to get secret with name %q: %w", name, err)
} }
if secret != nil { if secret != nil {
return secret, nil return secret, nil
@ -150,7 +153,7 @@ func (r *ReadDB) GetSecretsTree(tx *db.Tx, parentType types.ConfigType, parentID
for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject { for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject {
secrets, err := r.GetSecrets(tx, parentID) secrets, err := r.GetSecrets(tx, parentID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get secrets for %s %q", parentType, parentID) return nil, errors.Errorf("failed to get secrets for %s %q: %w", parentType, parentID, err)
} }
allSecrets = append(allSecrets, secrets...) allSecrets = append(allSecrets, secrets...)
@ -194,12 +197,12 @@ func scanSecret(rows *sql.Rows, additionalFields ...interface{}) (*types.Secret,
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
secret := types.Secret{} secret := types.Secret{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &secret); err != nil { if err := json.Unmarshal(data, &secret); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal secret") return nil, "", errors.Errorf("failed to unmarshal secret: %w", err)
} }
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -44,7 +44,7 @@ var (
func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error { func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
user := types.User{} user := types.User{}
if err := json.Unmarshal(data, &user); err != nil { if err := json.Unmarshal(data, &user); err != nil {
return errors.Wrap(err, "failed to unmarshal user") return errors.Errorf("failed to unmarshal user: %w", err)
} }
r.log.Infof("inserting user: %s", util.Dump(user)) r.log.Infof("inserting user: %s", util.Dump(user))
// poor man insert or update... // poor man insert or update...
@ -53,10 +53,10 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
} }
q, args, err := userInsert.Values(user.ID, user.Name, data).ToSql() q, args, err := userInsert.Values(user.ID, user.Name, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert user") return errors.Errorf("failed to insert user: %w", err)
} }
// insert linkedaccounts_user // insert linkedaccounts_user
@ -66,10 +66,10 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
} }
q, args, err = linkedaccountuserInsert.Values(la.ID, la.RemoteSourceID, user.ID, la.RemoteUserID).ToSql() q, args, err = linkedaccountuserInsert.Values(la.ID, la.RemoteSourceID, user.ID, la.RemoteUserID).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert user") return errors.Errorf("failed to insert user: %w", err)
} }
} }
// insert user_token // insert user_token
@ -80,10 +80,10 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
} }
q, args, err = usertokenInsert.Values(tokenValue, user.ID).ToSql() q, args, err = usertokenInsert.Values(tokenValue, user.ID).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
if _, err := tx.Exec(q, args...); err != nil { if _, err := tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert user") return errors.Errorf("failed to insert user: %w", err)
} }
} }
@ -93,17 +93,17 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
func (r *ReadDB) deleteUser(tx *db.Tx, userID string) error { func (r *ReadDB) deleteUser(tx *db.Tx, userID string) error {
// delete user linked accounts // delete user linked accounts
if err := r.deleteUserLinkedAccounts(tx, userID); err != nil { if err := r.deleteUserLinkedAccounts(tx, userID); err != nil {
return errors.Wrap(err, "failed to delete user linked accounts") return errors.Errorf("failed to delete user linked accounts: %w", err)
} }
// delete user tokens // delete user tokens
if _, err := tx.Exec("delete from user_token where userid = $1", userID); err != nil { if _, err := tx.Exec("delete from user_token where userid = $1", userID); err != nil {
return errors.Wrap(err, "failed to delete usertokens") return errors.Errorf("failed to delete usertokens: %w", err)
} }
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from user where id = $1", userID); err != nil { if _, err := tx.Exec("delete from user where id = $1", userID); err != nil {
return errors.Wrap(err, "failed to delete user") return errors.Errorf("failed to delete user: %w", err)
} }
return nil return nil
@ -112,10 +112,10 @@ func (r *ReadDB) deleteUser(tx *db.Tx, userID string) error {
func (r *ReadDB) deleteUserLinkedAccounts(tx *db.Tx, userID string) error { func (r *ReadDB) deleteUserLinkedAccounts(tx *db.Tx, userID string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from linkedaccount_user where userid = $1", userID); err != nil { if _, err := tx.Exec("delete from linkedaccount_user where userid = $1", userID); err != nil {
return errors.Wrap(err, "failed to delete linked account") return errors.Errorf("failed to delete linked account: %w", err)
} }
if _, err := tx.Exec("delete from linkedaccount_project where id = $1", userID); err != nil { if _, err := tx.Exec("delete from linkedaccount_project where id = $1", userID); err != nil {
return errors.Wrap(err, "failed to delete linked account") return errors.Errorf("failed to delete linked account: %w", err)
} }
return nil return nil
} }
@ -123,10 +123,10 @@ func (r *ReadDB) deleteUserLinkedAccounts(tx *db.Tx, userID string) error {
func (r *ReadDB) deleteUserLinkedAccount(tx *db.Tx, id string) error { func (r *ReadDB) deleteUserLinkedAccount(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from linkedaccount_user where id = $1", id); err != nil { if _, err := tx.Exec("delete from linkedaccount_user where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete linked account") return errors.Errorf("failed to delete linked account: %w", err)
} }
if _, err := tx.Exec("delete from linkedaccount_project where id = $1", id); err != nil { if _, err := tx.Exec("delete from linkedaccount_project where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete linked account") return errors.Errorf("failed to delete linked account: %w", err)
} }
return nil return nil
} }
@ -134,7 +134,7 @@ func (r *ReadDB) deleteUserLinkedAccount(tx *db.Tx, id string) error {
func (r *ReadDB) deleteAllUserTokens(tx *db.Tx, userID string) error { func (r *ReadDB) deleteAllUserTokens(tx *db.Tx, userID string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from user_token where userid = $1", userID); err != nil { if _, err := tx.Exec("delete from user_token where userid = $1", userID); err != nil {
return errors.Wrap(err, "failed to delete user_token") return errors.Errorf("failed to delete user_token: %w", err)
} }
return nil return nil
} }
@ -142,7 +142,7 @@ func (r *ReadDB) deleteAllUserTokens(tx *db.Tx, userID string) error {
func (r *ReadDB) deleteUserToken(tx *db.Tx, tokenValue string) error { func (r *ReadDB) deleteUserToken(tx *db.Tx, tokenValue string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from user_token where tokenvalue = $1", tokenValue); err != nil { if _, err := tx.Exec("delete from user_token where tokenvalue = $1", tokenValue); err != nil {
return errors.Wrap(err, "failed to delete user_token") return errors.Errorf("failed to delete user_token: %w", err)
} }
return nil return nil
} }
@ -167,12 +167,12 @@ func (r *ReadDB) GetUserByID(tx *db.Tx, userID string) (*types.User, error) {
q, args, err := userSelect.Where(sq.Eq{"id": userID}).ToSql() q, args, err := userSelect.Where(sq.Eq{"id": userID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
users, _, err := fetchUsers(tx, q, args...) users, _, err := fetchUsers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(users) > 1 { if len(users) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -187,12 +187,12 @@ func (r *ReadDB) GetUserByName(tx *db.Tx, name string) (*types.User, error) {
q, args, err := userSelect.Where(sq.Eq{"name": name}).ToSql() q, args, err := userSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
users, _, err := fetchUsers(tx, q, args...) users, _, err := fetchUsers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(users) > 1 { if len(users) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -210,12 +210,12 @@ func (r *ReadDB) GetUserByTokenValue(tx *db.Tx, tokenValue string) (*types.User,
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
users, _, err := fetchUsers(tx, q, args...) users, _, err := fetchUsers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(users) > 1 { if len(users) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -233,12 +233,12 @@ func (r *ReadDB) GetUserByLinkedAccount(tx *db.Tx, linkedAccountID string) (*typ
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
users, _, err := fetchUsers(tx, q, args...) users, _, err := fetchUsers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(users) > 1 { if len(users) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -256,12 +256,12 @@ func (r *ReadDB) GetUserByLinkedAccountRemoteUserIDandSource(tx *db.Tx, remoteUs
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
users, _, err := fetchUsers(tx, q, args...) users, _, err := fetchUsers(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(users) > 1 { if len(users) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -302,7 +302,7 @@ func (r *ReadDB) GetUsers(tx *db.Tx, startUserName string, limit int, asc bool)
q, args, err := s.ToSql() q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
rows, err := tx.Query(q, args...) rows, err := tx.Query(q, args...)
@ -327,12 +327,12 @@ func scanUser(rows *sql.Rows, additionalFields ...interface{}) (*types.User, str
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
user := types.User{} user := types.User{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &user); err != nil { if err := json.Unmarshal(data, &user); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal user") return nil, "", errors.Errorf("failed to unmarshal user: %w", err)
} }
} }
@ -376,7 +376,7 @@ func fetchLinkedAccounts(tx *db.Tx, q string, args ...interface{}) ([]*LinkedAcc
func scanLinkedAccount(rows *sql.Rows, additionalFields ...interface{}) (*LinkedAccountUser, error) { func scanLinkedAccount(rows *sql.Rows, additionalFields ...interface{}) (*LinkedAccountUser, error) {
var id, userid string var id, userid string
if err := rows.Scan(&id, &userid); err != nil { if err := rows.Scan(&id, &userid); err != nil {
return nil, errors.Wrap(err, "failed to scan rows") return nil, errors.Errorf("failed to scan rows: %w", err)
} }
return &LinkedAccountUser{ID: id, UserID: userid}, nil return &LinkedAccountUser{ID: id, UserID: userid}, nil

View File

@ -23,7 +23,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var ( var (
@ -34,7 +34,7 @@ var (
func (r *ReadDB) insertVariable(tx *db.Tx, data []byte) error { func (r *ReadDB) insertVariable(tx *db.Tx, data []byte) error {
variable := types.Variable{} variable := types.Variable{}
if err := json.Unmarshal(data, &variable); err != nil { if err := json.Unmarshal(data, &variable); err != nil {
return errors.Wrap(err, "failed to unmarshal variable") return errors.Errorf("failed to unmarshal variable: %w", err)
} }
// poor man insert or update... // poor man insert or update...
if err := r.deleteVariable(tx, variable.ID); err != nil { if err := r.deleteVariable(tx, variable.ID); err != nil {
@ -42,16 +42,19 @@ func (r *ReadDB) insertVariable(tx *db.Tx, data []byte) error {
} }
q, args, err := variableInsert.Values(variable.ID, variable.Name, variable.Parent.ID, data).ToSql() q, args, err := variableInsert.Values(variable.ID, variable.Name, variable.Parent.ID, data).ToSql()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to build query") return errors.Errorf("failed to build query: %w", err)
} }
_, err = tx.Exec(q, args...) if _, err = tx.Exec(q, args...); err != nil {
return errors.Wrap(err, "failed to insert variable") return errors.Errorf("failed to insert variable: %w", err)
}
return nil
} }
func (r *ReadDB) deleteVariable(tx *db.Tx, id string) error { func (r *ReadDB) deleteVariable(tx *db.Tx, id string) error {
// poor man insert or update... // poor man insert or update...
if _, err := tx.Exec("delete from variable where id = $1", id); err != nil { if _, err := tx.Exec("delete from variable where id = $1", id); err != nil {
return errors.Wrap(err, "failed to delete variable") return errors.Errorf("failed to delete variable: %w", err)
} }
return nil return nil
} }
@ -60,12 +63,12 @@ func (r *ReadDB) GetVariableByID(tx *db.Tx, variableID string) (*types.Variable,
q, args, err := variableSelect.Where(sq.Eq{"id": variableID}).ToSql() q, args, err := variableSelect.Where(sq.Eq{"id": variableID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
variables, _, err := fetchVariables(tx, q, args...) variables, _, err := fetchVariables(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(variables) > 1 { if len(variables) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -80,12 +83,12 @@ func (r *ReadDB) GetVariableByName(tx *db.Tx, parentID, name string) (*types.Var
q, args, err := variableSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql() q, args, err := variableSelect.Where(sq.Eq{"parentid": parentID, "name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
variables, _, err := fetchVariables(tx, q, args...) variables, _, err := fetchVariables(tx, q, args...)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, err
} }
if len(variables) > 1 { if len(variables) > 1 {
return nil, errors.Errorf("too many rows returned") return nil, errors.Errorf("too many rows returned")
@ -100,7 +103,7 @@ func (r *ReadDB) GetVariables(tx *db.Tx, parentID string) ([]*types.Variable, er
q, args, err := variableSelect.Where(sq.Eq{"parentid": parentID}).ToSql() q, args, err := variableSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args)) r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to build query") return nil, errors.Errorf("failed to build query: %w", err)
} }
variables, _, err := fetchVariables(tx, q, args...) variables, _, err := fetchVariables(tx, q, args...)
@ -113,7 +116,7 @@ func (r *ReadDB) GetVariablesTree(tx *db.Tx, parentType types.ConfigType, parent
for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject { for parentType == types.ConfigTypeProjectGroup || parentType == types.ConfigTypeProject {
vars, err := r.GetVariables(tx, parentID) vars, err := r.GetVariables(tx, parentID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get variables for %s %q", parentType, parentID) return nil, errors.Errorf("failed to get variables for %s %q: %w", parentType, parentID, err)
} }
allVariables = append(allVariables, vars...) allVariables = append(allVariables, vars...)
@ -157,12 +160,12 @@ func scanVariable(rows *sql.Rows, additionalFields ...interface{}) (*types.Varia
var id string var id string
var data []byte var data []byte
if err := rows.Scan(&id, &data); err != nil { if err := rows.Scan(&id, &data); err != nil {
return nil, "", errors.Wrap(err, "failed to scan rows") return nil, "", errors.Errorf("failed to scan rows: %w", err)
} }
variable := types.Variable{} variable := types.Variable{}
if len(data) > 0 { if len(data) > 0 {
if err := json.Unmarshal(data, &variable); err != nil { if err := json.Unmarshal(data, &variable); err != nil {
return nil, "", errors.Wrap(err, "failed to unmarshal variable") return nil, "", errors.Errorf("failed to unmarshal variable: %w", err)
} }
} }

View File

@ -23,9 +23,9 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/runservice/types" "github.com/sorintlab/agola/internal/services/runservice/types"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type taskSubmissionHandler struct { type taskSubmissionHandler struct {
@ -154,7 +154,7 @@ func (h *logsHandler) readLogs(taskID string, setup bool, step int, logPath stri
} }
if !flushstop && follow { if !flushstop && follow {
if _, err := f.Seek(-int64(n), io.SeekCurrent); err != nil { if _, err := f.Seek(-int64(n), io.SeekCurrent); err != nil {
return errors.Wrapf(err, "failed to seek in log file %q", logPath) return errors.Errorf("failed to seek in log file %q: %w", logPath, err)
} }
// check if the step is finished, if so flush until EOF and stop // check if the step is finished, if so flush until EOF and stop
rt, ok := h.e.runningTasks.get(taskID) rt, ok := h.e.runningTasks.get(taskID)

View File

@ -28,9 +28,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/common" "github.com/sorintlab/agola/internal/common"
"github.com/sorintlab/agola/internal/services/executor/registry" "github.com/sorintlab/agola/internal/services/executor/registry"
errors "golang.org/x/xerrors"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
@ -101,7 +101,7 @@ func (d *DockerDriver) CopyToolbox(ctx context.Context) error {
toolboxExecPath, err := toolboxExecPath(d.toolboxPath, d.arch) toolboxExecPath, err := toolboxExecPath(d.toolboxPath, d.arch)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get toolbox path for arch %q", d.arch) return errors.Errorf("failed to get toolbox path for arch %q: %w", d.arch, err)
} }
srcInfo, err := archive.CopyInfoSourcePath(toolboxExecPath, false) srcInfo, err := archive.CopyInfoSourcePath(toolboxExecPath, false)
if err != nil { if err != nil {

View File

@ -28,10 +28,10 @@ import (
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/sorintlab/agola/internal/common" "github.com/sorintlab/agola/internal/common"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -457,7 +457,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
exec, err := remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL()) exec, err := remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to generate k8s client spdy executor for url %q, method: POST", req.URL()) return nil, errors.Errorf("failed to generate k8s client spdy executor for url %q, method: POST: %w", req.URL(), err)
} }
stdout := bytes.Buffer{} stdout := bytes.Buffer{}
@ -466,7 +466,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
Stderr: out, Stderr: out,
}) })
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to execute command on initcontainer") return nil, errors.Errorf("failed to execute command on initcontainer: %w", err)
} }
osArch := strings.TrimSpace(stdout.String()) osArch := strings.TrimSpace(stdout.String())
@ -483,7 +483,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
// copy the toolbox for the pod arch // copy the toolbox for the pod arch
toolboxExecPath, err := toolboxExecPath(d.toolboxPath, arch) toolboxExecPath, err := toolboxExecPath(d.toolboxPath, arch)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get toolbox path for arch %q", arch) return nil, errors.Errorf("failed to get toolbox path for arch %q: %w", arch, err)
} }
srcInfo, err := archive.CopyInfoSourcePath(toolboxExecPath, false) srcInfo, err := archive.CopyInfoSourcePath(toolboxExecPath, false)
if err != nil { if err != nil {
@ -514,7 +514,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
exec, err = remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL()) exec, err = remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to generate k8s client spdy executor for url %q, method: POST", req.URL()) return nil, errors.Errorf("failed to generate k8s client spdy executor for url %q, method: POST: %w", req.URL(), err)
} }
fmt.Fprintf(out, "extracting toolbox\n") fmt.Fprintf(out, "extracting toolbox\n")
@ -524,7 +524,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
Stderr: out, Stderr: out,
}) })
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to execute command on initcontainer") return nil, errors.Errorf("failed to execute command on initcontainer: %w", err)
} }
fmt.Fprintf(out, "extracting toolbox done\n") fmt.Fprintf(out, "extracting toolbox done\n")
@ -544,7 +544,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
exec, err = remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL()) exec, err = remotecommand.NewSPDYExecutor(d.restconfig, "POST", req.URL())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to generate k8s client spdy executor for url %q, method: POST", req.URL()) return nil, errors.Errorf("failed to generate k8s client spdy executor for url %q, method: POST: %w", req.URL(), err)
} }
err = exec.Stream(remotecommand.StreamOptions{ err = exec.Stream(remotecommand.StreamOptions{
@ -552,7 +552,7 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri
Stderr: out, Stderr: out,
}) })
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to execute command on initcontainer") return nil, errors.Errorf("failed to execute command on initcontainer: %w", err)
} }
watcher, err = podClient.Watch( watcher, err = podClient.Watch(

View File

@ -19,7 +19,7 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
coordinationv1 "k8s.io/api/coordination/v1" coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"

View File

@ -42,9 +42,9 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
sockaddr "github.com/hashicorp/go-sockaddr" sockaddr "github.com/hashicorp/go-sockaddr"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
errors "golang.org/x/xerrors"
) )
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel) var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
@ -962,7 +962,7 @@ func (e *Executor) executeTaskInternal(ctx context.Context, et *types.ExecutorTa
} else { } else {
rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseFailed rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseFailed
} }
serr = errors.Wrapf(err, "failed to execute step") serr = errors.Errorf("failed to execute step: %w", err)
} else if exitCode != 0 { } else if exitCode != 0 {
rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseFailed rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseFailed
rt.et.Status.Steps[i].ExitCode = exitCode rt.et.Status.Steps[i].ExitCode = exitCode
@ -1238,7 +1238,7 @@ func (e *Executor) getExecutorID() (string, error) {
func (e *Executor) saveExecutorID(id string) error { func (e *Executor) saveExecutorID(id string) error {
if err := common.WriteFileAtomic(e.executorIDPath(), []byte(id), 0660); err != nil { if err := common.WriteFileAtomic(e.executorIDPath(), []byte(id), 0660); err != nil {
return errors.Wrapf(err, "failed to write executor id file") return errors.Errorf("failed to write executor id file: %w", err)
} }
return nil return nil
} }
@ -1261,7 +1261,7 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
var err error var err error
c.ToolboxPath, err = filepath.Abs(c.ToolboxPath) c.ToolboxPath, err = filepath.Abs(c.ToolboxPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot determine \"agola-toolbox\" absolute path") return nil, errors.Errorf("cannot determine \"agola-toolbox\" absolute path: %w", err)
} }
e := &Executor{ e := &Executor{
@ -1291,7 +1291,7 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
addr, err := sockaddr.GetPrivateIP() addr, err := sockaddr.GetPrivateIP()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot discover executor listen address") return nil, errors.Errorf("cannot discover executor listen address: %w", err)
} }
if addr == "" { if addr == "" {
return nil, errors.Errorf("cannot discover executor listen address") return nil, errors.Errorf("cannot discover executor listen address")
@ -1302,7 +1302,7 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
} }
_, port, err := net.SplitHostPort(c.Web.ListenAddress) _, port, err := net.SplitHostPort(c.Web.ListenAddress)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "cannot get web listen port") return nil, errors.Errorf("cannot get web listen port: %w", err)
} }
u.Host = net.JoinHostPort(addr, port) u.Host = net.JoinHostPort(addr, port)
e.listenURL = u.String() e.listenURL = u.String()
@ -1312,12 +1312,12 @@ func NewExecutor(c *config.Executor) (*Executor, error) {
case config.DriverTypeDocker: case config.DriverTypeDocker:
d, err = driver.NewDockerDriver(logger, e.id, "/tmp/agola/bin", e.c.ToolboxPath) d, err = driver.NewDockerDriver(logger, e.id, "/tmp/agola/bin", e.c.ToolboxPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create docker driver") return nil, errors.Errorf("failed to create docker driver: %w", err)
} }
case config.DriverTypeK8s: case config.DriverTypeK8s:
d, err = driver.NewK8sDriver(logger, e.id, c.ToolboxPath) d, err = driver.NewK8sDriver(logger, e.id, c.ToolboxPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create kubernetes driver") return nil, errors.Errorf("failed to create kubernetes driver: %w", err)
} }
e.dynamic = true e.dynamic = true
default: default:

View File

@ -19,8 +19,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/runservice/types" "github.com/sorintlab/agola/internal/services/runservice/types"
errors "golang.org/x/xerrors"
"github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/name"
) )
@ -94,11 +94,11 @@ func ResolveAuth(auths map[string]types.DockerRegistryAuth, regname string) (str
case types.DockerRegistryAuthTypeEncodedAuth: case types.DockerRegistryAuthTypeEncodedAuth:
decoded, err := base64.StdEncoding.DecodeString(auth.Auth) decoded, err := base64.StdEncoding.DecodeString(auth.Auth)
if err != nil { if err != nil {
return "", "", errors.Wrapf(err, "failed to decode docker auth") return "", "", errors.Errorf("failed to decode docker auth: %w", err)
} }
parts := strings.Split(string(decoded), ":") parts := strings.Split(string(decoded), ":")
if len(parts) != 2 { if len(parts) != 2 {
return "", "", errors.Wrapf(err, "wrong docker auth") return "", "", errors.Errorf("wrong docker auth: %w", err)
} }
return parts[0], parts[1], nil return parts[0], parts[1], nil
case types.DockerRegistryAuthTypeBasic: case types.DockerRegistryAuthTypeBasic:
@ -128,7 +128,7 @@ func GenDockerConfig(auths map[string]types.DockerRegistryAuth, images []string)
username, password, err := ResolveAuth(auths, regName) username, password, err := ResolveAuth(auths, regName)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to resolve auth") return nil, errors.Errorf("failed to resolve auth: %w", err)
} }
delimited := fmt.Sprintf("%s:%s", username, password) delimited := fmt.Sprintf("%s:%s", username, password)
auth := base64.StdEncoding.EncodeToString([]byte(delimited)) auth := base64.StdEncoding.EncodeToString([]byte(delimited))

View File

@ -17,7 +17,6 @@ package action
import ( import (
"net/http" "net/http"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/common" "github.com/sorintlab/agola/internal/services/common"
csapi "github.com/sorintlab/agola/internal/services/configstore/api" csapi "github.com/sorintlab/agola/internal/services/configstore/api"
rsapi "github.com/sorintlab/agola/internal/services/runservice/api" rsapi "github.com/sorintlab/agola/internal/services/runservice/api"
@ -55,11 +54,10 @@ func ErrFromRemote(resp *http.Response, err error) error {
if resp != nil { if resp != nil {
switch resp.StatusCode { switch resp.StatusCode {
// remove wrapping from errors sent to client
case http.StatusBadRequest: case http.StatusBadRequest:
return util.NewErrBadRequest(errors.Cause(err)) return util.NewErrBadRequest(err)
case http.StatusNotFound: case http.StatusNotFound:
return util.NewErrNotFound(errors.Cause(err)) return util.NewErrNotFound(err)
} }
} }

View File

@ -20,7 +20,7 @@ import (
"github.com/sorintlab/agola/internal/services/common" "github.com/sorintlab/agola/internal/services/common"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) CurrentUserID(ctx context.Context) string { func (h *ActionHandler) CurrentUserID(ctx context.Context) string {
@ -61,7 +61,7 @@ func (h *ActionHandler) IsOrgOwner(ctx context.Context, orgID string) (bool, err
userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID) userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID)
if err != nil { if err != nil {
return false, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user orgs")) return false, ErrFromRemote(resp, errors.Errorf("failed to get user orgs: %w", err))
} }
for _, userOrg := range userOrgs { for _, userOrg := range userOrgs {
@ -96,7 +96,7 @@ func (h *ActionHandler) IsProjectOwner(ctx context.Context, ownerType types.Conf
if ownerType == types.ConfigTypeOrg { if ownerType == types.ConfigTypeOrg {
userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID) userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID)
if err != nil { if err != nil {
return false, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user orgs")) return false, ErrFromRemote(resp, errors.Errorf("failed to get user orgs: %w", err))
} }
for _, userOrg := range userOrgs { for _, userOrg := range userOrgs {
@ -132,7 +132,7 @@ func (h *ActionHandler) IsProjectMember(ctx context.Context, ownerType types.Con
if ownerType == types.ConfigTypeOrg { if ownerType == types.ConfigTypeOrg {
userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID) userOrgs, resp, err := h.configstoreClient.GetUserOrgs(ctx, userID)
if err != nil { if err != nil {
return false, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user orgs")) return false, ErrFromRemote(resp, errors.Errorf("failed to get user orgs: %w", err))
} }
for _, userOrg := range userOrgs { for _, userOrg := range userOrgs {
@ -153,14 +153,14 @@ func (h *ActionHandler) IsVariableOwner(ctx context.Context, parentType types.Co
case types.ConfigTypeProjectGroup: case types.ConfigTypeProjectGroup:
pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, parentRef) pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, parentRef)
if err != nil { if err != nil {
return false, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project group %q", parentRef)) return false, ErrFromRemote(resp, errors.Errorf("failed to get project group %q: %w", parentRef, err))
} }
ownerType = pg.OwnerType ownerType = pg.OwnerType
ownerID = pg.OwnerID ownerID = pg.OwnerID
case types.ConfigTypeProject: case types.ConfigTypeProject:
p, resp, err := h.configstoreClient.GetProject(ctx, parentRef) p, resp, err := h.configstoreClient.GetProject(ctx, parentRef)
if err != nil { if err != nil {
return false, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", parentRef)) return false, ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", parentRef, err))
} }
ownerType = p.OwnerType ownerType = p.OwnerType
ownerID = p.OwnerID ownerID = p.OwnerID
@ -196,7 +196,7 @@ func (h *ActionHandler) CanGetRun(ctx context.Context, runGroup string) (bool, e
isProjectMember, err := h.IsProjectMember(ctx, ownerType, ownerID) isProjectMember, err := h.IsProjectMember(ctx, ownerType, ownerID)
if err != nil { if err != nil {
return false, errors.Wrapf(err, "failed to determine ownership") return false, errors.Errorf("failed to determine ownership: %w", err)
} }
if visibility == types.VisibilityPublic { if visibility == types.VisibilityPublic {
return true, nil return true, nil
@ -231,7 +231,7 @@ func (h *ActionHandler) CanDoRunActions(ctx context.Context, runGroup string) (b
isProjectOwner, err := h.IsProjectOwner(ctx, ownerType, ownerID) isProjectOwner, err := h.IsProjectOwner(ctx, ownerType, ownerID)
if err != nil { if err != nil {
return false, errors.Wrapf(err, "failed to determine ownership") return false, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return false, nil return false, nil

View File

@ -20,7 +20,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetOrg(ctx context.Context, orgRef string) (*types.Organization, error) { func (h *ActionHandler) GetOrg(ctx context.Context, orgRef string) (*types.Organization, error) {
@ -109,7 +109,7 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*
h.log.Infof("creating organization") h.log.Infof("creating organization")
org, resp, err := h.configstoreClient.CreateOrg(ctx, org) org, resp, err := h.configstoreClient.CreateOrg(ctx, org)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create organization")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create organization: %w", err))
} }
h.log.Infof("organization %s created, ID: %s", org.Name, org.ID) h.log.Infof("organization %s created, ID: %s", org.Name, org.ID)
@ -124,7 +124,7 @@ func (h *ActionHandler) DeleteOrg(ctx context.Context, orgRef string) error {
isOrgOwner, err := h.IsOrgOwner(ctx, org.ID) isOrgOwner, err := h.IsOrgOwner(ctx, org.ID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isOrgOwner { if !isOrgOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -132,7 +132,7 @@ func (h *ActionHandler) DeleteOrg(ctx context.Context, orgRef string) error {
resp, err = h.configstoreClient.DeleteOrg(ctx, orgRef) resp, err = h.configstoreClient.DeleteOrg(ctx, orgRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete org")) return ErrFromRemote(resp, errors.Errorf("failed to delete org: %w", err))
} }
return nil return nil
} }
@ -155,7 +155,7 @@ func (h *ActionHandler) AddOrgMember(ctx context.Context, orgRef, userRef string
isOrgOwner, err := h.IsOrgOwner(ctx, org.ID) isOrgOwner, err := h.IsOrgOwner(ctx, org.ID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isOrgOwner { if !isOrgOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -163,7 +163,7 @@ func (h *ActionHandler) AddOrgMember(ctx context.Context, orgRef, userRef string
orgmember, resp, err := h.configstoreClient.AddOrgMember(ctx, orgRef, userRef, role) orgmember, resp, err := h.configstoreClient.AddOrgMember(ctx, orgRef, userRef, role)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to add/update organization member")) return nil, ErrFromRemote(resp, errors.Errorf("failed to add/update organization member: %w", err))
} }
return &AddOrgMemberResponse{ return &AddOrgMemberResponse{
@ -181,7 +181,7 @@ func (h *ActionHandler) RemoveOrgMember(ctx context.Context, orgRef, userRef str
isOrgOwner, err := h.IsOrgOwner(ctx, org.ID) isOrgOwner, err := h.IsOrgOwner(ctx, org.ID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isOrgOwner { if !isOrgOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -189,7 +189,7 @@ func (h *ActionHandler) RemoveOrgMember(ctx context.Context, orgRef, userRef str
resp, err = h.configstoreClient.RemoveOrgMember(ctx, orgRef, userRef) resp, err = h.configstoreClient.RemoveOrgMember(ctx, orgRef, userRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to remove organization member")) return ErrFromRemote(resp, errors.Errorf("failed to remove organization member: %w", err))
} }
return nil return nil

View File

@ -25,7 +25,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors" 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) (*csapi.Project, error) {
@ -36,7 +36,7 @@ func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csa
isProjectMember, err := h.IsProjectMember(ctx, project.OwnerType, project.OwnerID) isProjectMember, err := h.IsProjectMember(ctx, project.OwnerType, project.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if project.GlobalVisibility == types.VisibilityPublic { if project.GlobalVisibility == types.VisibilityPublic {
return project, nil return project, nil
@ -62,7 +62,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID) user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", curUserID)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", curUserID, err))
} }
parentRef := req.ParentRef parentRef := req.ParentRef
if parentRef == "" { if parentRef == "" {
@ -72,12 +72,12 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, parentRef) pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, parentRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project group %q", parentRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project group %q: %w", parentRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -97,7 +97,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
_, resp, err = h.configstoreClient.GetProject(ctx, projectPath) _, resp, err = h.configstoreClient.GetProject(ctx, projectPath)
if err != nil { if err != nil {
if resp != nil && resp.StatusCode != http.StatusNotFound { if resp != nil && resp.StatusCode != http.StatusNotFound {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", req.Name)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", req.Name, err))
} }
} else { } else {
return nil, util.NewErrBadRequest(errors.Errorf("project %q already exists", projectPath)) return nil, util.NewErrBadRequest(errors.Errorf("project %q already exists", projectPath))
@ -105,7 +105,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
var la *types.LinkedAccount var la *types.LinkedAccount
@ -122,18 +122,18 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create gitsource client") return nil, errors.Errorf("failed to create gitsource client: %w", err)
} }
repo, err := gitsource.GetRepoInfo(req.RepoPath) repo, err := gitsource.GetRepoInfo(req.RepoPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get repository info from gitsource") return nil, errors.Errorf("failed to get repository info from gitsource: %w", err)
} }
h.log.Infof("generating ssh key pairs") h.log.Infof("generating ssh key pairs")
privateKey, _, err := util.GenSSHKeyPair(4096) privateKey, _, err := util.GenSSHKeyPair(4096)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to generate ssh key pair") return nil, errors.Errorf("failed to generate ssh key pair: %w", err)
} }
p := &types.Project{ p := &types.Project{
@ -155,7 +155,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
h.log.Infof("creating project") h.log.Infof("creating project")
rp, resp, err := h.configstoreClient.CreateProject(ctx, p) rp, resp, err := h.configstoreClient.CreateProject(ctx, p)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create project")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create project: %w", err))
} }
h.log.Infof("project %s created, ID: %s", p.Name, p.ID) h.log.Infof("project %s created, ID: %s", p.Name, p.ID)
@ -170,12 +170,12 @@ type UpdateProjectRequest struct {
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) (*csapi.Project, error) {
p, resp, err := h.configstoreClient.GetProject(ctx, projectRef) p, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", projectRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", projectRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -187,7 +187,7 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, re
h.log.Infof("updating project") h.log.Infof("updating project")
rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project) rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update project")) return nil, ErrFromRemote(resp, errors.Errorf("failed to update project: %w", err))
} }
h.log.Infof("project %s updated, ID: %s", p.Name, p.ID) h.log.Infof("project %s updated, ID: %s", p.Name, p.ID)
@ -199,17 +199,17 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID) user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", curUserID)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", curUserID, err))
} }
p, resp, err := h.configstoreClient.GetProject(ctx, projectRef) p, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", projectRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", projectRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -217,7 +217,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, p.RemoteSourceID) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, p.RemoteSourceID)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", p.RemoteSourceID)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", p.RemoteSourceID, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
var la *types.LinkedAccount var la *types.LinkedAccount
@ -234,13 +234,13 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create gitsource client") return nil, errors.Errorf("failed to create gitsource client: %w", err)
} }
// check user has access to the repository // check user has access to the repository
_, err = gitsource.GetRepoInfo(p.RepositoryPath) _, err = gitsource.GetRepoInfo(p.RepositoryPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get repository info from gitsource") return nil, errors.Errorf("failed to get repository info from gitsource: %w", err)
} }
p.LinkedAccountID = la.ID p.LinkedAccountID = la.ID
@ -248,7 +248,7 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
h.log.Infof("updating project") h.log.Infof("updating project")
rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project) rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update project")) return nil, ErrFromRemote(resp, errors.Errorf("failed to update project: %w", err))
} }
h.log.Infof("project %s updated, ID: %s", p.Name, p.ID) h.log.Infof("project %s updated, ID: %s", p.Name, p.ID)
@ -258,17 +258,17 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
func (h *ActionHandler) SetupProject(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *csapi.Project) error { func (h *ActionHandler) SetupProject(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *csapi.Project) error {
gitsource, err := h.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create gitsource client") return errors.Errorf("failed to create gitsource client: %w", err)
} }
pubKey, err := util.ExtractPublicKey([]byte(project.SSHPrivateKey)) pubKey, err := util.ExtractPublicKey([]byte(project.SSHPrivateKey))
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to extract public key") return errors.Errorf("failed to extract public key: %w", err)
} }
webhookURL, err := url.Parse(fmt.Sprintf("%s/webhooks", h.apiExposedURL)) webhookURL, err := url.Parse(fmt.Sprintf("%s/webhooks", h.apiExposedURL))
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to generate webhook url") return errors.Errorf("failed to generate webhook url: %w", err)
} }
q := url.Values{} q := url.Values{}
q.Add("projectid", project.ID) q.Add("projectid", project.ID)
@ -281,15 +281,15 @@ func (h *ActionHandler) SetupProject(ctx context.Context, rs *types.RemoteSource
deployKeyName := fmt.Sprintf("agola deploy key - %s", project.ID) deployKeyName := fmt.Sprintf("agola deploy key - %s", project.ID)
h.log.Infof("creating/updating deploy key: %s", string(pubKey)) h.log.Infof("creating/updating deploy key: %s", string(pubKey))
if err := gitsource.UpdateDeployKey(project.RepositoryPath, deployKeyName, string(pubKey), true); err != nil { if err := gitsource.UpdateDeployKey(project.RepositoryPath, deployKeyName, string(pubKey), true); err != nil {
return errors.Wrapf(err, "failed to create deploy key") return errors.Errorf("failed to create deploy key: %w", err)
} }
h.log.Infof("deleting existing webhooks") h.log.Infof("deleting existing webhooks")
if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL.String()); err != nil { if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL.String()); err != nil {
return errors.Wrapf(err, "failed to delete repository webhook") return errors.Errorf("failed to delete repository webhook: %w", err)
} }
h.log.Infof("creating webhook to url: %s", webhookURL) h.log.Infof("creating webhook to url: %s", webhookURL)
if err := gitsource.CreateRepoWebhook(project.RepositoryPath, webhookURL.String(), project.WebhookSecret); err != nil { if err := gitsource.CreateRepoWebhook(project.RepositoryPath, webhookURL.String(), project.WebhookSecret); err != nil {
return errors.Wrapf(err, "failed to create repository webhook") return errors.Errorf("failed to create repository webhook: %w", err)
} }
return nil return nil
@ -298,12 +298,12 @@ func (h *ActionHandler) SetupProject(ctx context.Context, rs *types.RemoteSource
func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string) error { func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string) error {
p, resp, err := h.configstoreClient.GetProject(ctx, projectRef) p, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", projectRef)) return ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", projectRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -311,7 +311,7 @@ func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string)
user, resp, err := h.configstoreClient.GetUserByLinkedAccount(ctx, p.LinkedAccountID) user, resp, err := h.configstoreClient.GetUserByLinkedAccount(ctx, p.LinkedAccountID)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user with linked account id %q", p.LinkedAccountID)) return ErrFromRemote(resp, errors.Errorf("failed to get user with linked account id %q: %w", p.LinkedAccountID, err))
} }
la := user.LinkedAccounts[p.LinkedAccountID] la := user.LinkedAccounts[p.LinkedAccountID]
@ -322,7 +322,7 @@ func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string)
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", la.RemoteSourceID)) return ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", la.RemoteSourceID, err))
} }
// TODO(sgotti) update project repo path if the remote let us query by repository id // TODO(sgotti) update project repo path if the remote let us query by repository id
@ -333,12 +333,12 @@ func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string)
func (h *ActionHandler) DeleteProject(ctx context.Context, projectRef string) error { func (h *ActionHandler) DeleteProject(ctx context.Context, projectRef string) error {
p, resp, err := h.configstoreClient.GetProject(ctx, projectRef) p, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", projectRef)) return ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", projectRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))

View File

@ -22,7 +22,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors" 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) (*csapi.ProjectGroup, error) {
@ -63,12 +63,12 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje
pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, req.ParentRef) pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, req.ParentRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project group %q", req.ParentRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project group %q: %w", req.ParentRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -76,7 +76,7 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje
user, resp, err := h.configstoreClient.GetUser(ctx, req.CurrentUserID) user, resp, err := h.configstoreClient.GetUser(ctx, req.CurrentUserID)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.CurrentUserID)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", req.CurrentUserID, err))
} }
parentRef := req.ParentRef parentRef := req.ParentRef
@ -97,7 +97,7 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje
h.log.Infof("creating projectGroup") h.log.Infof("creating projectGroup")
rp, resp, err := h.configstoreClient.CreateProjectGroup(ctx, p) rp, resp, err := h.configstoreClient.CreateProjectGroup(ctx, p)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create projectGroup")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create projectGroup: %w", err))
} }
h.log.Infof("projectGroup %s created, ID: %s", rp.Name, rp.ID) h.log.Infof("projectGroup %s created, ID: %s", rp.Name, rp.ID)
@ -112,12 +112,12 @@ type UpdateProjectGroupRequest struct {
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) (*csapi.ProjectGroup, error) {
pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef) pg, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project group %q", projectGroupRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get project group %q: %w", projectGroupRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, pg.OwnerType, pg.OwnerID)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -129,7 +129,7 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef
h.log.Infof("updating project group") h.log.Infof("updating project group")
rp, resp, err := h.configstoreClient.UpdateProjectGroup(ctx, pg.ID, pg.ProjectGroup) rp, resp, err := h.configstoreClient.UpdateProjectGroup(ctx, pg.ID, pg.ProjectGroup)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update project group")) return nil, ErrFromRemote(resp, errors.Errorf("failed to update project group: %w", err))
} }
h.log.Infof("project group %q updated, ID: %s", pg.Name, pg.ID) h.log.Infof("project group %q updated, ID: %s", pg.Name, pg.ID)
@ -139,12 +139,12 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef
func (h *ActionHandler) DeleteProjectGroup(ctx context.Context, projectRef string) error { func (h *ActionHandler) DeleteProjectGroup(ctx context.Context, projectRef string) error {
p, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectRef) p, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q", projectRef)) return ErrFromRemote(resp, errors.Errorf("failed to get project %q: %w", projectRef, err))
} }
isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID) isProjectOwner, err := h.IsProjectOwner(ctx, p.OwnerType, p.OwnerID)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isProjectOwner { if !isProjectOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))

View File

@ -20,7 +20,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetRemoteSource(ctx context.Context, rsRef string) (*types.RemoteSource, error) { func (h *ActionHandler) GetRemoteSource(ctx context.Context, rsRef string) (*types.RemoteSource, error) {
@ -108,7 +108,7 @@ func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemot
h.log.Infof("creating remotesource") h.log.Infof("creating remotesource")
rs, resp, err := h.configstoreClient.CreateRemoteSource(ctx, rs) rs, resp, err := h.configstoreClient.CreateRemoteSource(ctx, rs)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create remotesource")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create remotesource: %w", err))
} }
h.log.Infof("remotesource %s created, ID: %s", rs.Name, rs.ID) h.log.Infof("remotesource %s created, ID: %s", rs.Name, rs.ID)
@ -162,7 +162,7 @@ func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemot
h.log.Infof("updating remotesource") h.log.Infof("updating remotesource")
rs, resp, err = h.configstoreClient.UpdateRemoteSource(ctx, req.RemoteSourceRef, rs) rs, resp, err = h.configstoreClient.UpdateRemoteSource(ctx, req.RemoteSourceRef, rs)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update remotesource")) return nil, ErrFromRemote(resp, errors.Errorf("failed to update remotesource: %w", err))
} }
h.log.Infof("remotesource %s updated", rs.Name) h.log.Infof("remotesource %s updated", rs.Name)
@ -176,7 +176,7 @@ func (h *ActionHandler) DeleteRemoteSource(ctx context.Context, rsRef string) er
resp, err := h.configstoreClient.DeleteRemoteSource(ctx, rsRef) resp, err := h.configstoreClient.DeleteRemoteSource(ctx, rsRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete remote source")) return ErrFromRemote(resp, errors.Errorf("failed to delete remote source: %w", err))
} }
return nil return nil
} }

View File

@ -24,7 +24,7 @@ import (
rstypes "github.com/sorintlab/agola/internal/services/runservice/types" rstypes "github.com/sorintlab/agola/internal/services/runservice/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapi.RunResponse, error) { func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapi.RunResponse, error) {
@ -34,7 +34,7 @@ func (h *ActionHandler) GetRun(ctx context.Context, runID string) (*rsapi.RunRes
} }
canGetRun, err := h.CanGetRun(ctx, runResp.RunConfig.Group) canGetRun, err := h.CanGetRun(ctx, runResp.RunConfig.Group)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine permissions") return nil, errors.Errorf("failed to determine permissions: %w", err)
} }
if !canGetRun { if !canGetRun {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -56,7 +56,7 @@ type GetRunsRequest struct {
func (h *ActionHandler) GetRuns(ctx context.Context, req *GetRunsRequest) (*rsapi.GetRunsResponse, error) { func (h *ActionHandler) GetRuns(ctx context.Context, req *GetRunsRequest) (*rsapi.GetRunsResponse, error) {
canGetRun, err := h.CanGetRun(ctx, req.Group) canGetRun, err := h.CanGetRun(ctx, req.Group)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine permissions") return nil, errors.Errorf("failed to determine permissions: %w", err)
} }
if !canGetRun { if !canGetRun {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -86,7 +86,7 @@ func (h *ActionHandler) GetLogs(ctx context.Context, req *GetLogsRequest) (*http
} }
canGetRun, err := h.CanGetRun(ctx, runResp.RunConfig.Group) canGetRun, err := h.CanGetRun(ctx, runResp.RunConfig.Group)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine permissions") return nil, errors.Errorf("failed to determine permissions: %w", err)
} }
if !canGetRun { if !canGetRun {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -123,7 +123,7 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
} }
canGetRun, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group) canGetRun, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine permissions") return nil, errors.Errorf("failed to determine permissions: %w", err)
} }
if !canGetRun { if !canGetRun {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -189,7 +189,7 @@ func (h *ActionHandler) RunTaskAction(ctx context.Context, req *RunTaskActionsRe
} }
canDoRunAction, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group) canDoRunAction, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine permissions") return errors.Errorf("failed to determine permissions: %w", err)
} }
if !canDoRunAction { if !canDoRunAction {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -214,7 +214,7 @@ func (h *ActionHandler) RunTaskAction(ctx context.Context, req *RunTaskActionsRe
approversAnnotation, ok := annotations[common.ApproversAnnotation] approversAnnotation, ok := annotations[common.ApproversAnnotation]
if ok { if ok {
if err := json.Unmarshal([]byte(approversAnnotation), &approvers); err != nil { if err := json.Unmarshal([]byte(approversAnnotation), &approvers); err != nil {
return errors.Wrapf(err, "failed to unmarshal run task approvers annotation") return errors.Errorf("failed to unmarshal run task approvers annotation: %w", err)
} }
} }
@ -227,7 +227,7 @@ func (h *ActionHandler) RunTaskAction(ctx context.Context, req *RunTaskActionsRe
approversj, err := json.Marshal(approvers) approversj, err := json.Marshal(approvers)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to marshal run task approvers annotation") return errors.Errorf("failed to marshal run task approvers annotation: %w", err)
} }
annotations[common.ApproversAnnotation] = string(approversj) annotations[common.ApproversAnnotation] = string(approversj)

View File

@ -23,7 +23,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
type GetSecretsRequest struct { type GetSecretsRequest struct {
@ -74,7 +74,7 @@ type CreateSecretHandler struct {
func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretRequest) (*csapi.Secret, error) { func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretRequest) (*csapi.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to determine ownership") return nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isVariableOwner { if !isVariableOwner {
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -101,7 +101,7 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque
rs, resp, err = h.configstoreClient.CreateProjectSecret(ctx, req.ParentRef, s) rs, resp, err = h.configstoreClient.CreateProjectSecret(ctx, req.ParentRef, s)
} }
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create secret")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create secret: %w", err))
} }
h.log.Infof("secret %s created, ID: %s", rs.Name, rs.ID) h.log.Infof("secret %s created, ID: %s", rs.Name, rs.ID)
@ -111,7 +111,7 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque
func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType types.ConfigType, parentRef, name string) error { func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType types.ConfigType, parentRef, name string) error {
isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef) isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isVariableOwner { if !isVariableOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -127,7 +127,7 @@ func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType types.Confi
resp, err = h.configstoreClient.DeleteProjectSecret(ctx, parentRef, name) resp, err = h.configstoreClient.DeleteProjectSecret(ctx, parentRef, name)
} }
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete secret")) return ErrFromRemote(resp, errors.Errorf("failed to delete secret: %w", err))
} }
return nil return nil
} }

View File

@ -26,7 +26,7 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
const ( const (
@ -93,7 +93,7 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
h.log.Infof("creating user") h.log.Infof("creating user")
u, resp, err := h.configstoreClient.CreateUser(ctx, creq) u, resp, err := h.configstoreClient.CreateUser(ctx, creq)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create user")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create user: %w", err))
} }
h.log.Infof("user %s created, ID: %s", u.Name, u.ID) h.log.Infof("user %s created, ID: %s", u.Name, u.ID)
@ -121,7 +121,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
userRef := req.UserRef userRef := req.UserRef
user, resp, err := h.configstoreClient.GetUser(ctx, userRef) user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if err != nil { if err != nil {
return "", ErrFromRemote(resp, errors.Wrapf(err, "failed to get user")) return "", ErrFromRemote(resp, errors.Errorf("failed to get user: %w", err))
} }
// only admin or the same logged user can create a token // only admin or the same logged user can create a token
@ -138,7 +138,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
} }
res, resp, err := h.configstoreClient.CreateUserToken(ctx, userRef, creq) res, resp, err := h.configstoreClient.CreateUserToken(ctx, userRef, creq)
if err != nil { if err != nil {
return "", ErrFromRemote(resp, errors.Wrapf(err, "failed to create user token")) return "", ErrFromRemote(resp, errors.Errorf("failed to create user token: %w", err))
} }
h.log.Infof("token %q for user %q created", req.TokenName, userRef) h.log.Infof("token %q for user %q created", req.TokenName, userRef)
@ -159,11 +159,11 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
userRef := req.UserRef userRef := req.UserRef
user, resp, err := h.configstoreClient.GetUser(ctx, userRef) user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", userRef, err))
} }
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
var la *types.LinkedAccount var la *types.LinkedAccount
@ -189,7 +189,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
remoteUserInfo, err := userSource.GetUserInfo() remoteUserInfo, err := userSource.GetUserInfo()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve remote user info for remote source %q", rs.ID) return nil, errors.Errorf("failed to retrieve remote user info for remote source %q: %w", rs.ID, err)
} }
if remoteUserInfo.ID == "" { if remoteUserInfo.ID == "" {
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
@ -208,7 +208,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
h.log.Infof("creating linked account") h.log.Infof("creating linked account")
la, resp, err = h.configstoreClient.CreateUserLA(ctx, userRef, creq) la, resp, err = h.configstoreClient.CreateUserLA(ctx, userRef, creq)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create linked account")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create linked account: %w", err))
} }
h.log.Infof("linked account %q for user %q created", la.ID, userRef) h.log.Infof("linked account %q for user %q created", la.ID, userRef)
@ -218,7 +218,7 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *types.LinkedAccount) error { func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *types.LinkedAccount) error {
user, resp, err := h.configstoreClient.GetUser(ctx, userRef) user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef)) return ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", userRef, err))
} }
laFound := false laFound := false
for _, ula := range user.LinkedAccounts { for _, ula := range user.LinkedAccounts {
@ -244,7 +244,7 @@ func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *ty
h.log.Infof("updating user %q linked account", userRef) h.log.Infof("updating user %q linked account", userRef)
la, resp, err = h.configstoreClient.UpdateUserLA(ctx, userRef, la.ID, creq) la, resp, err = h.configstoreClient.UpdateUserLA(ctx, userRef, la.ID, creq)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to update user")) return ErrFromRemote(resp, errors.Errorf("failed to update user: %w", err))
} }
h.log.Infof("linked account %q for user %q updated", la.ID, userRef) h.log.Infof("linked account %q for user %q updated", la.ID, userRef)
@ -272,7 +272,7 @@ func (h *ActionHandler) RefreshLinkedAccount(ctx context.Context, rs *types.Remo
la.Oauth2AccessTokenExpiresAt = token.Expiry la.Oauth2AccessTokenExpiresAt = token.Expiry
if err := h.UpdateUserLA(ctx, userName, la); err != nil { if err := h.UpdateUserLA(ctx, userName, la); err != nil {
return nil, errors.Wrapf(err, "failed to update linked account") return nil, errors.Errorf("failed to update linked account: %w", err)
} }
} }
} }
@ -309,7 +309,7 @@ func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserReque
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
@ -324,7 +324,7 @@ func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserReque
remoteUserInfo, err := userSource.GetUserInfo() remoteUserInfo, err := userSource.GetUserInfo()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve remote user info for remote source %q", rs.ID) return nil, errors.Errorf("failed to retrieve remote user info for remote source %q: %w", rs.ID, err)
} }
if remoteUserInfo.ID == "" { if remoteUserInfo.ID == "" {
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
@ -346,7 +346,7 @@ func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserReque
h.log.Infof("creating user account") h.log.Infof("creating user account")
u, resp, err := h.configstoreClient.CreateUser(ctx, creq) u, resp, err := h.configstoreClient.CreateUser(ctx, creq)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create linked account")) return nil, ErrFromRemote(resp, errors.Errorf("failed to create linked account: %w", err))
} }
h.log.Infof("user %q created", req.UserName) h.log.Infof("user %q created", req.UserName)
@ -369,7 +369,7 @@ type LoginUserResponse struct {
func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*LoginUserResponse, error) { func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*LoginUserResponse, error) {
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
@ -384,7 +384,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
remoteUserInfo, err := userSource.GetUserInfo() remoteUserInfo, err := userSource.GetUserInfo()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve remote user info for remote source %q", rs.ID) return nil, errors.Errorf("failed to retrieve remote user info for remote source %q: %w", rs.ID, err)
} }
if remoteUserInfo.ID == "" { if remoteUserInfo.ID == "" {
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
@ -392,7 +392,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
user, resp, err := h.configstoreClient.GetUserByLinkedAccountRemoteUserAndSource(ctx, remoteUserInfo.ID, rs.ID) user, resp, err := h.configstoreClient.GetUserByLinkedAccountRemoteUserAndSource(ctx, remoteUserInfo.ID, rs.ID)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user for remote user id %q and remote source %q", remoteUserInfo.ID, rs.ID)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user for remote user id %q and remote source %q: %w", remoteUserInfo.ID, rs.ID, err))
} }
var la *types.LinkedAccount var la *types.LinkedAccount
@ -428,7 +428,7 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
h.log.Infof("updating user %q linked account", user.Name) h.log.Infof("updating user %q linked account", user.Name)
la, resp, err = h.configstoreClient.UpdateUserLA(ctx, user.Name, la.ID, creq) la, resp, err = h.configstoreClient.UpdateUserLA(ctx, user.Name, la.ID, creq)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update user")) return nil, ErrFromRemote(resp, errors.Errorf("failed to update user: %w", err))
} }
h.log.Infof("linked account %q for user %q updated", la.ID, user.Name) h.log.Infof("linked account %q for user %q updated", la.ID, user.Name)
} }
@ -460,7 +460,7 @@ type AuthorizeResponse struct {
func (h *ActionHandler) Authorize(ctx context.Context, req *AuthorizeRequest) (*AuthorizeResponse, error) { func (h *ActionHandler) Authorize(ctx context.Context, req *AuthorizeRequest) (*AuthorizeResponse, error) {
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", req.RemoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
@ -475,7 +475,7 @@ func (h *ActionHandler) Authorize(ctx context.Context, req *AuthorizeRequest) (*
remoteUserInfo, err := userSource.GetUserInfo() remoteUserInfo, err := userSource.GetUserInfo()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve remote user info for remote source %q", rs.ID) return nil, errors.Errorf("failed to retrieve remote user info for remote source %q: %w", rs.ID, err)
} }
if remoteUserInfo.ID == "" { if remoteUserInfo.ID == "" {
return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID) return nil, errors.Errorf("empty remote user id for remote source %q", rs.ID)
@ -495,7 +495,7 @@ type RemoteSourceAuthResponse struct {
func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourceName, loginName, loginPassword string, requestType RemoteSourceRequestType, req interface{}) (*RemoteSourceAuthResponse, error) { func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourceName, loginName, loginPassword string, requestType RemoteSourceRequestType, req interface{}) (*RemoteSourceAuthResponse, error) {
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", remoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", remoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
@ -505,7 +505,7 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource
user, resp, err := h.configstoreClient.GetUser(ctx, req.UserRef) user, resp, err := h.configstoreClient.GetUser(ctx, req.UserRef)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.UserRef)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", req.UserRef, err))
} }
curUserID := h.CurrentUserID(ctx) curUserID := h.CurrentUserID(ctx)
@ -542,7 +542,7 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource
case types.RemoteSourceAuthTypeOauth2: case types.RemoteSourceAuthTypeOauth2:
oauth2Source, err := common.GetOauth2Source(rs, "") oauth2Source, err := common.GetOauth2Source(rs, "")
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create git source") return nil, errors.Errorf("failed to create git source: %w", err)
} }
token, err := common.GenerateOauth2JWTToken(h.sd, rs.Name, string(requestType), req) token, err := common.GenerateOauth2JWTToken(h.sd, rs.Name, string(requestType), req)
if err != nil { if err != nil {
@ -561,15 +561,15 @@ func (h *ActionHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSource
case types.RemoteSourceAuthTypePassword: case types.RemoteSourceAuthTypePassword:
passwordSource, err := common.GetPasswordSource(rs, "") passwordSource, err := common.GetPasswordSource(rs, "")
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create git source") return nil, errors.Errorf("failed to create git source: %w", err)
} }
tokenName := "agola-" + h.agolaID tokenName := "agola-" + h.agolaID
accessToken, err := passwordSource.LoginPassword(loginName, loginPassword, tokenName) accessToken, err := passwordSource.LoginPassword(loginName, loginPassword, tokenName)
if err != nil { if err != nil {
if err == gitsource.ErrUnauthorized { if err == gitsource.ErrUnauthorized {
return nil, util.NewErrUnauthorized(errors.Wrapf(err, "failed to login to remotesource %q", remoteSourceName)) return nil, util.NewErrUnauthorized(errors.Errorf("failed to login to remotesource %q: %w", remoteSourceName, err))
} }
return nil, errors.Wrapf(err, "failed to login to remote source %q with login name %q", rs.Name, loginName) return nil, errors.Errorf("failed to login to remote source %q with login name %q: %w", rs.Name, loginName, err)
} }
h.log.Infof("access token: %s", accessToken) h.log.Infof("access token: %s", accessToken)
requestj, err := json.Marshal(req) requestj, err := json.Marshal(req)
@ -723,7 +723,7 @@ func (h *ActionHandler) HandleOauth2Callback(ctx context.Context, code, state st
return key, nil return key, nil
}) })
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to parse jwt") return nil, errors.Errorf("failed to parse jwt: %w", err)
} }
if !token.Valid { if !token.Valid {
return nil, errors.Errorf("invalid token") return nil, errors.Errorf("invalid token")
@ -736,13 +736,13 @@ func (h *ActionHandler) HandleOauth2Callback(ctx context.Context, code, state st
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceName) rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceName)
if err != nil { if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", remoteSourceName)) return nil, ErrFromRemote(resp, errors.Errorf("failed to get remote source %q: %w", remoteSourceName, err))
} }
h.log.Infof("rs: %s", util.Dump(rs)) h.log.Infof("rs: %s", util.Dump(rs))
oauth2Source, err := common.GetOauth2Source(rs, "") oauth2Source, err := common.GetOauth2Source(rs, "")
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create oauth2 source") return nil, errors.Errorf("failed to create oauth2 source: %w", err)
} }
oauth2Token, err := oauth2Source.RequestOauth2Token(h.webExposedURL+"/oauth2/callback", code) oauth2Token, err := oauth2Source.RequestOauth2Token(h.webExposedURL+"/oauth2/callback", code)
@ -760,7 +760,7 @@ func (h *ActionHandler) DeleteUser(ctx context.Context, userRef string) error {
resp, err := h.configstoreClient.DeleteUser(ctx, userRef) resp, err := h.configstoreClient.DeleteUser(ctx, userRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete user")) return ErrFromRemote(resp, errors.Errorf("failed to delete user: %w", err))
} }
return nil return nil
} }
@ -775,7 +775,7 @@ func (h *ActionHandler) DeleteUserLA(ctx context.Context, userRef, laID string)
user, resp, err := h.configstoreClient.GetUser(ctx, userRef) user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef)) return ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", userRef, err))
} }
// only admin or the same logged user can create a token // only admin or the same logged user can create a token
@ -785,7 +785,7 @@ func (h *ActionHandler) DeleteUserLA(ctx context.Context, userRef, laID string)
resp, err = h.configstoreClient.DeleteUserLA(ctx, userRef, laID) resp, err = h.configstoreClient.DeleteUserLA(ctx, userRef, laID)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete user linked account")) return ErrFromRemote(resp, errors.Errorf("failed to delete user linked account: %w", err))
} }
return nil return nil
} }
@ -800,7 +800,7 @@ func (h *ActionHandler) DeleteUserToken(ctx context.Context, userRef, tokenName
user, resp, err := h.configstoreClient.GetUser(ctx, userRef) user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef)) return ErrFromRemote(resp, errors.Errorf("failed to get user %q: %w", userRef, err))
} }
// only admin or the same logged user can create a token // only admin or the same logged user can create a token
@ -810,7 +810,7 @@ func (h *ActionHandler) DeleteUserToken(ctx context.Context, userRef, tokenName
resp, err = h.configstoreClient.DeleteUserToken(ctx, userRef, tokenName) resp, err = h.configstoreClient.DeleteUserToken(ctx, userRef, tokenName)
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete user token")) return ErrFromRemote(resp, errors.Errorf("failed to delete user token: %w", err))
} }
return nil return nil
} }

View File

@ -18,11 +18,11 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/common" "github.com/sorintlab/agola/internal/services/common"
csapi "github.com/sorintlab/agola/internal/services/configstore/api" csapi "github.com/sorintlab/agola/internal/services/configstore/api"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
) )
type GetVariablesRequest struct { type GetVariablesRequest struct {
@ -82,7 +82,7 @@ type CreateVariableRequest struct {
func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) { func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableRequest) (*csapi.Variable, []*csapi.Secret, error) {
isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef) isVariableOwner, err := h.IsVariableOwner(ctx, req.ParentType, req.ParentRef)
if err != nil { if err != nil {
return nil, nil, errors.Wrapf(err, "failed to determine ownership") return nil, nil, errors.Errorf("failed to determine ownership: %w", err)
} }
if !isVariableOwner { if !isVariableOwner {
return nil, nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -114,26 +114,26 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR
var resp *http.Response var resp *http.Response
cssecrets, resp, err = h.configstoreClient.GetProjectGroupSecrets(ctx, req.ParentRef, true) cssecrets, resp, err = h.configstoreClient.GetProjectGroupSecrets(ctx, req.ParentRef, true)
if err != nil { if err != nil {
return nil, nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project group %q secrets", req.ParentRef)) return nil, nil, ErrFromRemote(resp, errors.Errorf("failed to get project group %q secrets: %w", req.ParentRef, err))
} }
h.log.Infof("creating project group variable") h.log.Infof("creating project group variable")
rv, resp, err = h.configstoreClient.CreateProjectGroupVariable(ctx, req.ParentRef, v) rv, resp, err = h.configstoreClient.CreateProjectGroupVariable(ctx, req.ParentRef, v)
if err != nil { if err != nil {
return nil, nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create variable")) return nil, nil, ErrFromRemote(resp, errors.Errorf("failed to create variable: %w", err))
} }
case types.ConfigTypeProject: case types.ConfigTypeProject:
var err error var err error
var resp *http.Response var resp *http.Response
cssecrets, resp, err = h.configstoreClient.GetProjectSecrets(ctx, req.ParentRef, true) cssecrets, resp, err = h.configstoreClient.GetProjectSecrets(ctx, req.ParentRef, true)
if err != nil { if err != nil {
return nil, nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get project %q secrets", req.ParentRef)) return nil, nil, ErrFromRemote(resp, errors.Errorf("failed to get project %q secrets: %w", req.ParentRef, err))
} }
h.log.Infof("creating project variable") h.log.Infof("creating project variable")
rv, resp, err = h.configstoreClient.CreateProjectVariable(ctx, req.ParentRef, v) rv, resp, err = h.configstoreClient.CreateProjectVariable(ctx, req.ParentRef, v)
if err != nil { if err != nil {
return nil, nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create variable")) return nil, nil, ErrFromRemote(resp, errors.Errorf("failed to create variable: %w", err))
} }
} }
h.log.Infof("variable %s created, ID: %s", rv.Name, rv.ID) h.log.Infof("variable %s created, ID: %s", rv.Name, rv.ID)
@ -144,7 +144,7 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR
func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType types.ConfigType, parentRef, name string) error { func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType types.ConfigType, parentRef, name string) error {
isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef) isVariableOwner, err := h.IsVariableOwner(ctx, parentType, parentRef)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to determine ownership") return errors.Errorf("failed to determine ownership: %w", err)
} }
if !isVariableOwner { if !isVariableOwner {
return util.NewErrForbidden(errors.Errorf("user not authorized")) return util.NewErrForbidden(errors.Errorf("user not authorized"))
@ -160,7 +160,7 @@ func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType types.Con
resp, err = h.configstoreClient.DeleteProjectVariable(ctx, parentRef, name) resp, err = h.configstoreClient.DeleteProjectVariable(ctx, parentRef, name)
} }
if err != nil { if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to delete variable")) return ErrFromRemote(resp, errors.Errorf("failed to delete variable: %w", err))
} }
return nil return nil
} }

View File

@ -19,10 +19,11 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/gorilla/mux"
errors "golang.org/x/xerrors"
) )
type ErrorResponse struct { type ErrorResponse struct {
@ -121,7 +122,7 @@ func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) {
vars := mux.Vars(r) vars := mux.Vars(r)
projectRef, err := url.PathUnescape(vars["projectref"]) projectRef, err := url.PathUnescape(vars["projectref"])
if err != nil { if err != nil {
return "", "", util.NewErrBadRequest(errors.Wrapf(err, "wrong projectref %q", vars["projectref"])) return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectref %q: %w", vars["projectref"], err))
} }
if projectRef != "" { if projectRef != "" {
return types.ConfigTypeProject, projectRef, nil return types.ConfigTypeProject, projectRef, nil
@ -129,7 +130,7 @@ func GetConfigTypeRef(r *http.Request) (types.ConfigType, string, error) {
projectGroupRef, err := url.PathUnescape(vars["projectgroupref"]) projectGroupRef, err := url.PathUnescape(vars["projectgroupref"])
if err != nil { if err != nil {
return "", "", util.NewErrBadRequest(errors.Wrapf(err, "wrong projectgroupref %q", vars["projectgroupref"])) return "", "", util.NewErrBadRequest(errors.Errorf("wrong projectgroupref %q: %w", vars["projectgroupref"], err))
} }
if projectGroupRef != "" { if projectGroupRef != "" {
return types.ConfigTypeProjectGroup, projectGroupRef, nil return types.ConfigTypeProjectGroup, projectGroupRef, nil

View File

@ -29,7 +29,7 @@ import (
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/pkg/errors" errors "golang.org/x/xerrors"
) )
var jsonContent = http.Header{"Content-Type": []string{"application/json"}} var jsonContent = http.Header{"Content-Type": []string{"application/json"}}

View File

@ -19,11 +19,11 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/action" "github.com/sorintlab/agola/internal/services/gateway/action"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -162,7 +162,7 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error var err error
limit, err = strconv.Atoi(limitS) limit, err = strconv.Atoi(limitS)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "cannot parse limit"))) httpError(w, util.NewErrBadRequest(errors.Errorf("cannot parse limit: %w", err)))
return return
} }
} }

View File

@ -19,11 +19,11 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"github.com/pkg/errors"
csapi "github.com/sorintlab/agola/internal/services/configstore/api" csapi "github.com/sorintlab/agola/internal/services/configstore/api"
"github.com/sorintlab/agola/internal/services/gateway/action" "github.com/sorintlab/agola/internal/services/gateway/action"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -24,8 +24,8 @@ import (
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
) )
type RemoteRepoResponse struct { type RemoteRepoResponse struct {
@ -93,13 +93,13 @@ func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
gitsource, err := h.ah.GetGitSource(ctx, rs, user.Name, la) gitsource, err := h.ah.GetGitSource(ctx, rs, user.Name, la)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "failed to create gitsource client"))) httpError(w, util.NewErrBadRequest(errors.Errorf("failed to create gitsource client: %w", err)))
return return
} }
remoteRepos, err := gitsource.ListUserRepos() remoteRepos, err := gitsource.ListUserRepos()
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "failed to get user repositories from gitsource"))) httpError(w, util.NewErrBadRequest(errors.Errorf("failed to get user repositories from gitsource: %w", err)))
return return
} }

View File

@ -19,11 +19,11 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/action" "github.com/sorintlab/agola/internal/services/gateway/action"
"github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/util"
"go.uber.org/zap" "go.uber.org/zap"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -196,7 +196,7 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
var err error var err error
limit, err = strconv.Atoi(limitS) limit, err = strconv.Atoi(limitS)
if err != nil { if err != nil {
httpError(w, util.NewErrBadRequest(errors.Wrapf(err, "cannot parse limit"))) httpError(w, util.NewErrBadRequest(errors.Errorf("cannot parse limit: %w", err)))
return return
} }
} }

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