*: use zerolog for logging

Replace zap with zerolog.

zerolog has a cleaner interface and can be easily configured with custom
error chain printing using a new error handling library that will be
implemented in another PR.
This commit is contained in:
Simone Gotti 2022-02-21 18:07:58 +01:00
parent fa7813392c
commit d1b4ab4296
130 changed files with 1788 additions and 1781 deletions

View File

@ -17,22 +17,29 @@ package cmd
import (
"net/url"
"os"
"time"
"agola.io/agola/cmd"
slog "agola.io/agola/internal/log"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
errors "golang.org/x/xerrors"
)
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
var logger = slog.New(level)
var log = logger.Sugar()
var token string
func init() {
cw := zerolog.ConsoleWriter{
Out: os.Stderr,
TimeFormat: time.RFC3339Nano,
}
zerolog.TimeFieldFormat = time.RFC3339Nano
log.Logger = log.With().Stack().Caller().Logger().Level(zerolog.InfoLevel).Output(cw)
}
var cmdAgola = &cobra.Command{
Use: "agola",
Short: "agola",
@ -40,16 +47,16 @@ var cmdAgola = &cobra.Command{
// just defined to make --version work
PersistentPreRun: func(c *cobra.Command, args []string) {
if err := parseGatewayURL(); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
if agolaOpts.debug {
level.SetLevel(zapcore.DebugLevel)
log.Logger = log.Level(zerolog.DebugLevel)
}
},
Run: func(c *cobra.Command, args []string) {
if err := c.Help(); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
},
}

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -22,7 +23,7 @@ var cmdCompletionBash = &cobra.Command{
Use: "bash",
Run: func(cmd *cobra.Command, args []string) {
if err := completionShell(cmd, args, "bash"); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "generates bash completion scripts",

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -22,7 +23,7 @@ var cmdCompletionZsh = &cobra.Command{
Use: "zsh",
Run: func(cmd *cobra.Command, args []string) {
if err := completionShell(cmd, args, "zsh"); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "generates zsh completion scripts",

View File

@ -30,6 +30,7 @@ import (
"github.com/ghodss/yaml"
"github.com/gofrs/uuid"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -38,7 +39,7 @@ var cmdDirectRunStart = &cobra.Command{
Use: "start",
Run: func(cmd *cobra.Command, args []string) {
if err := directRunStart(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "executes a run from a local git repository",
@ -169,7 +170,7 @@ func directRunStart(cmd *cobra.Command, args []string) error {
}
}
gs := gitsave.NewGitSave(logger, &gitsave.GitSaveConfig{
gs := gitsave.NewGitSave(log.Logger, &gitsave.GitSaveConfig{
AddUntracked: directRunStartOpts.untracked,
AddIgnored: directRunStartOpts.ignored,
})
@ -182,7 +183,7 @@ func directRunStart(cmd *cobra.Command, args []string) error {
return err
}
log.Infof("pushing branch")
log.Info().Msgf("pushing branch")
repoPath := fmt.Sprintf("%s/%s", user.ID, repoUUID)
repoURL := fmt.Sprintf("%s/repos/%s/%s.git", gatewayURL, user.ID, repoUUID)
@ -201,7 +202,7 @@ func directRunStart(cmd *cobra.Command, args []string) error {
}
}
log.Infof("starting direct run")
log.Info().Msgf("starting direct run")
req := &gwapitypes.UserCreateRunRequest{
RepoUUID: repoUUID,
RepoPath: repoPath,

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdLogDelete = &cobra.Command{
Short: "delete a setup/step log",
Run: func(cmd *cobra.Command, args []string) {
if err := logDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -54,7 +55,7 @@ func init() {
flags.BoolVar(&logDeleteOpts.setup, "setup", false, "Setup step")
if err := cmdLogDelete.MarkFlagRequired("runid"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdLog.AddCommand(cmdLogDelete)
@ -106,7 +107,7 @@ func logDelete(cmd *cobra.Command, args []string) error {
}
taskid = task.ID
}
log.Infof("deleting log")
log.Info().Msgf("deleting log")
if _, err := gwclient.DeleteLogs(context.TODO(), logDeleteOpts.runid, taskid, logDeleteOpts.setup, logDeleteOpts.step); err != nil {
return errors.Errorf("failed to delete log: %v", err)
}

View File

@ -22,6 +22,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -31,7 +32,7 @@ var cmdLogGet = &cobra.Command{
Short: "get a setup/step log",
Run: func(cmd *cobra.Command, args []string) {
if err := logGet(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -60,7 +61,7 @@ func init() {
flags.StringVar(&logGetOpts.output, "output", "", "Write output to file")
if err := cmdLogGet.MarkFlagRequired("runid"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdLog.AddCommand(cmdLogGet)
@ -116,7 +117,7 @@ func logGet(cmd *cobra.Command, args []string) error {
taskid = task.ID
}
log.Infof("getting log")
log.Info().Msgf("getting log")
resp, err := gwclient.GetLogs(context.TODO(), logGetOpts.runid, taskid, logGetOpts.setup, logGetOpts.step, logGetOpts.follow)
if err != nil {
return errors.Errorf("failed to get log: %v", err)

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdOrgCreate = &cobra.Command{
Short: "create an organization",
Run: func(cmd *cobra.Command, args []string) {
if err := orgCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -48,7 +49,7 @@ func init() {
flags.StringVar(&orgCreateOpts.visibility, "visibility", "public", `organization visibility (public or private)`)
if err := cmdOrgCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdOrg.AddCommand(cmdOrgCreate)
@ -67,12 +68,12 @@ func orgCreate(cmd *cobra.Command, args []string) error {
Visibility: gwapitypes.Visibility(orgCreateOpts.visibility),
}
log.Infof("creating org")
log.Info().Msgf("creating org")
org, _, err := gwclient.CreateOrg(context.TODO(), req)
if err != nil {
return errors.Errorf("failed to create org: %w", err)
}
log.Infof("org %q created, ID: %q", org.Name, org.ID)
log.Info().Msgf("org %q created, ID: %q", org.Name, org.ID)
return nil
}

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdOrgDelete = &cobra.Command{
Short: "delete an organization",
Run: func(cmd *cobra.Command, args []string) {
if err := orgDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -45,7 +46,7 @@ func init() {
flags.StringVarP(&orgDeleteOpts.name, "name", "n", "", "organization name")
if err := cmdOrgDelete.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdOrg.AddCommand(cmdOrgDelete)
@ -54,7 +55,7 @@ func init() {
func orgDelete(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting organization %q", orgDeleteOpts.name)
log.Info().Msgf("deleting organization %q", orgDeleteOpts.name)
if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil {
return errors.Errorf("failed to delete organization: %w", err)
}

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdOrgMemberAdd = &cobra.Command{
Short: "adds or updates an organization member",
Run: func(cmd *cobra.Command, args []string) {
if err := orgMemberAdd(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -50,10 +51,10 @@ func init() {
flags.StringVarP(&orgMemberAddOpts.role, "role", "r", "member", "member role (owner or member)")
if err := cmdOrgMemberAdd.MarkFlagRequired("orgname"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdOrgMemberAdd.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdOrgMember.AddCommand(cmdOrgMemberAdd)
@ -62,7 +63,7 @@ func init() {
func orgMemberAdd(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role)
log.Info().Msgf("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, gwapitypes.MemberRole(orgMemberAddOpts.role))
if err != nil {
return errors.Errorf("failed to add/update organization member: %w", err)

View File

@ -21,6 +21,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -30,7 +31,7 @@ var cmdOrgMemberList = &cobra.Command{
Short: "lists organization members",
Run: func(cmd *cobra.Command, args []string) {
if err := orgMemberList(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,7 +48,7 @@ func init() {
flags.StringVarP(&orgMemberListOpts.orgname, "orgname", "n", "", "organization name")
if err := cmdOrgMemberList.MarkFlagRequired("orgname"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdOrgMember.AddCommand(cmdOrgMemberList)

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdOrgMemberRemove = &cobra.Command{
Short: "removes an organization member",
Run: func(cmd *cobra.Command, args []string) {
if err := orgMemberRemove(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,10 +48,10 @@ func init() {
flags.StringVar(&orgMemberRemoveOpts.username, "username", "", "user name")
if err := cmdOrgMemberRemove.MarkFlagRequired("orgname"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdOrgMemberRemove.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdOrgMember.AddCommand(cmdOrgMemberRemove)
@ -59,7 +60,7 @@ func init() {
func orgMemberRemove(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname)
log.Info().Msgf("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname)
_, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username)
if err != nil {
return errors.Errorf("failed to remove organization member: %w", err)

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdProjectCreate = &cobra.Command{
Short: "create a project",
Run: func(cmd *cobra.Command, args []string) {
if err := projectCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -58,16 +59,16 @@ func init() {
flags.BoolVar(&projectCreateOpts.passVarsToForkedPR, "pass-vars-to-forked-pr", false, `pass variables to run even if triggered by PR from forked repo`)
if err := cmdProjectCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectCreate.MarkFlagRequired("parent"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectCreate.MarkFlagRequired("repo-path"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectCreate.MarkFlagRequired("remote-source"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProject.AddCommand(cmdProjectCreate)
@ -101,13 +102,13 @@ func projectCreate(cmd *cobra.Command, args []string) error {
PassVarsToForkedPR: projectCreateOpts.passVarsToForkedPR,
}
log.Infof("creating project")
log.Info().Msgf("creating project")
project, _, err := gwclient.CreateProject(context.TODO(), req)
if err != nil {
return errors.Errorf("failed to create project: %w", err)
}
log.Infof("project %s created, ID: %s", project.Name, project.ID)
log.Info().Msgf("project %s created, ID: %s", project.Name, project.ID)
return nil
}

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdProjectDelete = &cobra.Command{
Short: "delete a project",
Run: func(cmd *cobra.Command, args []string) {
if err := projectDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -45,7 +46,7 @@ func init() {
flags.StringVar(&projectDeleteOpts.ref, "ref", "", "project path or id")
if err := cmdProjectDelete.MarkFlagRequired("ref"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProject.AddCommand(cmdProjectDelete)
@ -54,7 +55,7 @@ func init() {
func projectDelete(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting project")
log.Info().Msgf("deleting project")
if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.ref); err != nil {
return errors.Errorf("failed to delete project: %w", err)

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdProjectGroupCreate = &cobra.Command{
Short: "create a project group",
Run: func(cmd *cobra.Command, args []string) {
if err := projectGroupCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -50,10 +51,10 @@ func init() {
flags.StringVar(&projectGroupCreateOpts.visibility, "visibility", "public", `project group visibility (public or private)`)
if err := cmdProjectGroupCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupCreate.MarkFlagRequired("parent"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroup.AddCommand(cmdProjectGroupCreate)
@ -73,13 +74,13 @@ func projectGroupCreate(cmd *cobra.Command, args []string) error {
Visibility: gwapitypes.Visibility(projectGroupCreateOpts.visibility),
}
log.Infof("creating project group")
log.Info().Msgf("creating project group")
projectGroup, _, err := gwclient.CreateProjectGroup(context.TODO(), req)
if err != nil {
return errors.Errorf("failed to create project group: %w", err)
}
log.Infof("project group %s created, ID: %s", projectGroup.Name, projectGroup.ID)
log.Info().Msgf("project group %s created, ID: %s", projectGroup.Name, projectGroup.ID)
return nil
}

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdProjectGroupDelete = &cobra.Command{
Short: "delete a project group",
Run: func(cmd *cobra.Command, args []string) {
if err := projectGroupDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -45,7 +46,7 @@ func init() {
flags.StringVarP(&projectGroupDeleteOpts.ref, "ref", "", "", "current project group path or id")
if err := cmdProjectGroupDelete.MarkFlagRequired("ref"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroup.AddCommand(cmdProjectGroupDelete)
@ -54,7 +55,7 @@ func init() {
func projectGroupDelete(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting project group")
log.Info().Msgf("deleting project group")
if _, err := gwclient.DeleteProjectGroup(context.TODO(), projectGroupDeleteOpts.ref); err != nil {
return errors.Errorf("failed to delete project group: %w", err)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -30,7 +31,7 @@ data02: secretvalue02
`,
Run: func(cmd *cobra.Command, args []string) {
if err := secretCreate(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -43,13 +44,13 @@ func init() {
flags.StringVarP(&secretCreateOpts.file, "file", "f", "", `yaml file containing the secret data (use "-" to read from stdin)`)
if err := cmdProjectGroupSecretCreate.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupSecretCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupSecretCreate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupSecret.AddCommand(cmdProjectGroupSecretCreate)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -23,7 +24,7 @@ var cmdProjectGroupSecretDelete = &cobra.Command{
Short: "delete a secret",
Run: func(cmd *cobra.Command, args []string) {
if err := secretDelete(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -35,10 +36,10 @@ func init() {
flags.StringVarP(&secretDeleteOpts.name, "name", "n", "", "secret name")
if err := cmdProjectGroupSecretDelete.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupSecretDelete.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupSecret.AddCommand(cmdProjectGroupSecretDelete)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -23,7 +24,7 @@ var cmdProjectGroupSecretList = &cobra.Command{
Short: "list project group secrets",
Run: func(cmd *cobra.Command, args []string) {
if err := secretList(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -34,7 +35,7 @@ func init() {
flags.StringVar(&secretListOpts.parentRef, "projectgroup", "", "project group id or full path")
if err := cmdProjectGroupSecretList.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupSecret.AddCommand(cmdProjectGroupSecretList)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -30,7 +31,7 @@ data02: secretvalue02
`,
Run: func(cmd *cobra.Command, args []string) {
if err := secretUpdate(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -44,13 +45,13 @@ func init() {
flags.StringVarP(&secretUpdateOpts.file, "file", "f", "", `yaml file containing the secret data (use "-" to read from stdin)`)
if err := cmdProjectGroupSecretUpdate.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupSecretUpdate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupSecretUpdate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupSecret.AddCommand(cmdProjectGroupSecretUpdate)

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdProjectGroupUpdate = &cobra.Command{
Short: "update a project group",
Run: func(cmd *cobra.Command, args []string) {
if err := projectGroupUpdate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -53,7 +54,7 @@ func init() {
flags.StringVar(&projectGroupUpdateOpts.visibility, "visibility", "public", `project group visibility (public or private)`)
if err := cmdProjectGroupUpdate.MarkFlagRequired("ref"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroup.AddCommand(cmdProjectGroupUpdate)
@ -78,12 +79,12 @@ func projectGroupUpdate(cmd *cobra.Command, args []string) error {
req.Name = &projectGroupUpdateOpts.visibility
}
log.Infof("updating project group")
log.Info().Msgf("updating project group")
projectGroup, _, err := gwclient.UpdateProjectGroup(context.TODO(), projectGroupUpdateOpts.ref, req)
if err != nil {
return errors.Errorf("failed to update project group: %w", err)
}
log.Infof("project group %s update, ID: %s", projectGroup.Name, projectGroup.ID)
log.Info().Msgf("project group %s update, ID: %s", projectGroup.Name, projectGroup.ID)
return nil
}

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -45,7 +46,7 @@ The above yaml document defines a variable that can have two different values de
`,
Run: func(cmd *cobra.Command, args []string) {
if err := variableCreate(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -58,13 +59,13 @@ func init() {
flags.StringVarP(&variableCreateOpts.file, "file", "f", "", `yaml file containing the variable definition (use "-" to read from stdin)`)
if err := cmdProjectGroupVariableCreate.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupVariableCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupVariableCreate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupVariable.AddCommand(cmdProjectGroupVariableCreate)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -23,7 +24,7 @@ var cmdProjectGroupVariableDelete = &cobra.Command{
Short: "delete a variable",
Run: func(cmd *cobra.Command, args []string) {
if err := variableDelete(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -35,10 +36,10 @@ func init() {
flags.StringVarP(&variableDeleteOpts.name, "name", "n", "", "variable name")
if err := cmdProjectGroupVariableDelete.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupVariableDelete.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupVariable.AddCommand(cmdProjectGroupVariableDelete)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -23,7 +24,7 @@ var cmdProjectGroupVariableList = &cobra.Command{
Short: "list project group variables",
Run: func(cmd *cobra.Command, args []string) {
if err := variableList(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -34,7 +35,7 @@ func init() {
flags.StringVar(&variableListOpts.parentRef, "projectgroup", "", "project group id or full path")
if err := cmdProjectGroupVariableList.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupVariable.AddCommand(cmdProjectGroupVariableList)

View File

@ -15,6 +15,7 @@
package cmd
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -23,7 +24,7 @@ var cmdProjectGroupVariableUpdate = &cobra.Command{
Short: "update a project group variable",
Run: func(cmd *cobra.Command, args []string) {
if err := variableUpdate(cmd, "projectgroup", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -37,13 +38,13 @@ func init() {
flags.StringVarP(&variableUpdateOpts.file, "file", "f", "", `yaml file containing the variable definition (use "-" to read from stdin)`)
if err := cmdProjectGroupVariableUpdate.MarkFlagRequired("projectgroup"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupVariableUpdate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectGroupVariableUpdate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectGroupVariable.AddCommand(cmdProjectGroupVariableUpdate)

View File

@ -21,6 +21,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -28,7 +29,7 @@ var cmdProjectList = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
if err := projectList(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "list",
@ -46,7 +47,7 @@ func init() {
flags.StringVar(&projectListOpts.parentPath, "parent", "", `project group path (i.e "org/org01" for root project group in org01, "user/user01/group01/subgroub01") or project group id`)
if err := cmdProjectList.MarkFlagRequired("parent"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProject.AddCommand(cmdProjectList)

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdProjectReconfig = &cobra.Command{
Short: "reconfigures a project remote (reinstalls ssh deploy key and webhooks)",
Run: func(cmd *cobra.Command, args []string) {
if err := projectReconfig(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -45,7 +46,7 @@ func init() {
flags.StringVarP(&projectReconfigOpts.name, "name", "n", "", "project name")
if err := cmdProjectReconfig.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProject.AddCommand(cmdProjectReconfig)
@ -54,11 +55,11 @@ func init() {
func projectReconfig(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("reconfiguring remote project")
log.Info().Msgf("reconfiguring remote project")
if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil {
return errors.Errorf("failed to reconfigure remote project: %w", err)
}
log.Infof("project reconfigured")
log.Info().Msgf("project reconfigured")
return nil
}

View File

@ -23,6 +23,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -39,7 +40,7 @@ data02: secretvalue02
`,
Run: func(cmd *cobra.Command, args []string) {
if err := secretCreate(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -60,13 +61,13 @@ func init() {
flags.StringVarP(&secretCreateOpts.file, "file", "f", "", `yaml file containing the secret data (use "-" to read from stdin)`)
if err := cmdProjectSecretCreate.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectSecretCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectSecretCreate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectSecret.AddCommand(cmdProjectSecretCreate)
@ -92,7 +93,7 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
var secretData map[string]string
if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err)
log.Fatal().Msgf("failed to unmarshal secret: %v", err)
}
req := &gwapitypes.CreateSecretRequest{
Name: secretCreateOpts.name,
@ -102,19 +103,19 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("creating project secret")
log.Info().Msgf("creating project secret")
secret, _, err := gwclient.CreateProjectSecret(context.TODO(), secretCreateOpts.parentRef, req)
if err != nil {
return errors.Errorf("failed to create project secret: %w", err)
}
log.Infof("project secret %q created, ID: %q", secret.Name, secret.ID)
log.Info().Msgf("project secret %q created, ID: %q", secret.Name, secret.ID)
case "projectgroup":
log.Infof("creating project group secret")
log.Info().Msgf("creating project group secret")
secret, _, err := gwclient.CreateProjectGroupSecret(context.TODO(), secretCreateOpts.parentRef, req)
if err != nil {
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.Info().Msgf("project group secret %q created, ID: %q", secret.Name, secret.ID)
}
return nil

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdProjectSecretDelete = &cobra.Command{
Short: "delete a secret",
Run: func(cmd *cobra.Command, args []string) {
if err := secretDelete(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,10 +48,10 @@ func init() {
flags.StringVarP(&secretDeleteOpts.name, "name", "n", "", "secret name")
if err := cmdProjectSecretDelete.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectSecretDelete.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectSecret.AddCommand(cmdProjectSecretDelete)
@ -61,19 +62,19 @@ func secretDelete(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("deleting project secret")
log.Info().Msgf("deleting project secret")
_, err := gwclient.DeleteProjectSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name)
if err != nil {
return errors.Errorf("failed to delete project secret: %w", err)
}
log.Infof("project secret deleted")
log.Info().Msgf("project secret deleted")
case "projectgroup":
log.Infof("deleting project group secret")
log.Info().Msgf("deleting project group secret")
_, err := gwclient.DeleteProjectGroupSecret(context.TODO(), secretDeleteOpts.parentRef, secretDeleteOpts.name)
if err != nil {
return errors.Errorf("failed to delete project group secret: %w", err)
}
log.Infof("project group secret deleted")
log.Info().Msgf("project group secret deleted")
}
return nil

View File

@ -22,6 +22,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -31,7 +32,7 @@ var cmdProjectSecretList = &cobra.Command{
Short: "list project secrets",
Run: func(cmd *cobra.Command, args []string) {
if err := secretList(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -48,7 +49,7 @@ func init() {
flags.StringVar(&secretListOpts.parentRef, "project", "", "project id or full path")
if err := cmdProjectSecretList.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectSecret.AddCommand(cmdProjectSecretList)

View File

@ -23,6 +23,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -39,7 +40,7 @@ data02: secretvalue02
`,
Run: func(cmd *cobra.Command, args []string) {
if err := secretUpdate(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -62,13 +63,13 @@ func init() {
flags.StringVarP(&secretUpdateOpts.file, "file", "f", "", `yaml file containing the secret data (use "-" to read from stdin)`)
if err := cmdProjectSecretUpdate.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectSecretUpdate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectSecretUpdate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectSecret.AddCommand(cmdProjectSecretUpdate)
@ -94,7 +95,7 @@ func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
var secretData map[string]string
if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err)
log.Fatal().Msgf("failed to unmarshal secret: %v", err)
}
req := &gwapitypes.UpdateSecretRequest{
Name: secretUpdateOpts.name,
@ -109,19 +110,19 @@ func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("creating project secret")
log.Info().Msgf("creating project secret")
secret, _, err := gwclient.UpdateProjectSecret(context.TODO(), secretUpdateOpts.parentRef, secretUpdateOpts.name, req)
if err != nil {
return errors.Errorf("failed to update project secret: %w", err)
}
log.Infof("project secret %q updated, ID: %q", secret.Name, secret.ID)
log.Info().Msgf("project secret %q updated, ID: %q", secret.Name, secret.ID)
case "projectgroup":
log.Infof("creating project group secret")
log.Info().Msgf("creating project group secret")
secret, _, err := gwclient.UpdateProjectGroupSecret(context.TODO(), secretUpdateOpts.parentRef, secretUpdateOpts.name, req)
if err != nil {
return errors.Errorf("failed to update project group secret: %w", err)
}
log.Infof("project group secret %q updated, ID: %q", secret.Name, secret.ID)
log.Info().Msgf("project group secret %q updated, ID: %q", secret.Name, secret.ID)
}
return nil

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdProjectUpdate = &cobra.Command{
Short: "update a project",
Run: func(cmd *cobra.Command, args []string) {
if err := projectUpdate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -55,7 +56,7 @@ func init() {
flags.BoolVar(&projectUpdateOpts.passVarsToForkedPR, "pass-vars-to-forked-pr", false, `pass variables to run even if triggered by PR from forked repo`)
if err := cmdProjectUpdate.MarkFlagRequired("ref"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProject.AddCommand(cmdProjectUpdate)
@ -84,12 +85,12 @@ func projectUpdate(cmd *cobra.Command, args []string) error {
req.PassVarsToForkedPR = &projectUpdateOpts.passVarsToForkedPR
}
log.Infof("updating project")
log.Info().Msgf("updating project")
project, _, err := gwclient.UpdateProject(context.TODO(), projectUpdateOpts.ref, req)
if err != nil {
return errors.Errorf("failed to update project: %w", err)
}
log.Infof("project %s update, ID: %s", project.Name, project.ID)
log.Info().Msgf("project %s update, ID: %s", project.Name, project.ID)
return nil
}

View File

@ -24,6 +24,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -55,7 +56,7 @@ The above yaml document defines a variable that can have two different values de
`,
Run: func(cmd *cobra.Command, args []string) {
if err := variableCreate(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -76,13 +77,13 @@ func init() {
flags.StringVarP(&variableCreateOpts.file, "file", "f", "", `yaml file containing the variable definition (use "-" to read from stdin)`)
if err := cmdProjectVariableCreate.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectVariableCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectVariableCreate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectVariable.AddCommand(cmdProjectVariableCreate)
@ -115,7 +116,7 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
var values []VariableValue
if err := yaml.Unmarshal(data, &values); err != nil {
log.Fatalf("failed to unmarshal values: %v", err)
log.Fatal().Msgf("failed to unmarshal values: %v", err)
}
rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values {
@ -132,19 +133,19 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("creating project variable")
log.Info().Msgf("creating project variable")
variable, _, err := gwclient.CreateProjectVariable(context.TODO(), variableCreateOpts.parentRef, req)
if err != nil {
return errors.Errorf("failed to create project variable: %w", err)
}
log.Infof("project variable %q created, ID: %q", variable.Name, variable.ID)
log.Info().Msgf("project variable %q created, ID: %q", variable.Name, variable.ID)
case "projectgroup":
log.Infof("creating project group variable")
log.Info().Msgf("creating project group variable")
variable, _, err := gwclient.CreateProjectGroupVariable(context.TODO(), variableCreateOpts.parentRef, req)
if err != nil {
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.Info().Msgf("project group variable %q created, ID: %q", variable.Name, variable.ID)
}
return nil

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdProjectVariableDelete = &cobra.Command{
Short: "delete a variable",
Run: func(cmd *cobra.Command, args []string) {
if err := variableDelete(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,10 +48,10 @@ func init() {
flags.StringVarP(&variableDeleteOpts.name, "name", "n", "", "variable name")
if err := cmdProjectVariableDelete.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectVariableDelete.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectVariable.AddCommand(cmdProjectVariableDelete)
@ -61,19 +62,19 @@ func variableDelete(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("deleting project variable")
log.Info().Msgf("deleting project variable")
_, err := gwclient.DeleteProjectVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name)
if err != nil {
return errors.Errorf("failed to delete project variable: %w", err)
}
log.Infof("project variable deleted")
log.Info().Msgf("project variable deleted")
case "projectgroup":
log.Infof("deleting project group variable")
log.Info().Msgf("deleting project group variable")
_, err := gwclient.DeleteProjectGroupVariable(context.TODO(), variableDeleteOpts.parentRef, variableDeleteOpts.name)
if err != nil {
return errors.Errorf("failed to delete project group variable: %w", err)
}
log.Infof("project group variable deleted")
log.Info().Msgf("project group variable deleted")
}
return nil

View File

@ -22,6 +22,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -31,7 +32,7 @@ var cmdProjectVariableList = &cobra.Command{
Short: "list project variables",
Run: func(cmd *cobra.Command, args []string) {
if err := variableList(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -48,7 +49,7 @@ func init() {
flags.StringVar(&variableListOpts.parentRef, "project", "", "project id or full path")
if err := cmdProjectVariableList.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectVariable.AddCommand(cmdProjectVariableList)

View File

@ -23,6 +23,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/ghodss/yaml"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -32,7 +33,7 @@ var cmdProjectVariableUpdate = &cobra.Command{
Short: "update a project variable",
Run: func(cmd *cobra.Command, args []string) {
if err := variableUpdate(cmd, "project", args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -55,13 +56,13 @@ func init() {
flags.StringVarP(&variableUpdateOpts.file, "file", "f", "", `yaml file containing the variable definition (use "-" to read from stdin)`)
if err := cmdProjectVariableUpdate.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectVariableUpdate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdProjectVariableUpdate.MarkFlagRequired("file"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdProjectVariable.AddCommand(cmdProjectVariableUpdate)
@ -87,7 +88,7 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
var values []VariableValue
if err := yaml.Unmarshal(data, &values); err != nil {
log.Fatalf("failed to unmarshall values: %v", err)
log.Fatal().Msgf("failed to unmarshall values: %v", err)
}
rvalues := []gwapitypes.VariableValueRequest{}
for _, value := range values {
@ -109,19 +110,19 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
switch ownertype {
case "project":
log.Infof("updating project variable")
log.Info().Msgf("updating project variable")
variable, _, err := gwclient.UpdateProjectVariable(context.TODO(), variableUpdateOpts.parentRef, variableUpdateOpts.name, req)
if err != nil {
return errors.Errorf("failed to update project variable: %w", err)
}
log.Infof("project variable %q updated, ID: %q", variable.Name, variable.ID)
log.Info().Msgf("project variable %q updated, ID: %q", variable.Name, variable.ID)
case "projectgroup":
log.Infof("updating project group variable")
log.Info().Msgf("updating project group variable")
variable, _, err := gwclient.UpdateProjectGroupVariable(context.TODO(), variableUpdateOpts.parentRef, variableUpdateOpts.name, req)
if err != nil {
return errors.Errorf("failed to update project group variable: %w", err)
}
log.Infof("project group variable %q updated, ID: %q", variable.Name, variable.ID)
log.Info().Msgf("project group variable %q updated, ID: %q", variable.Name, variable.ID)
}
return nil

View File

@ -22,6 +22,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"agola.io/agola/util"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -31,7 +32,7 @@ var cmdRemoteSourceCreate = &cobra.Command{
Short: "create a remotesource",
Run: func(cmd *cobra.Command, args []string) {
if err := remoteSourceCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -68,13 +69,13 @@ func init() {
flags.BoolVar(&remoteSourceCreateOpts.loginEnabled, "login-enabled", true, "enabled/disable user login with this remote source")
if err := cmdRemoteSourceCreate.MarkFlagRequired("name"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdRemoteSourceCreate.MarkFlagRequired("type"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdRemoteSourceCreate.MarkFlagRequired("auth-type"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdRemoteSource.AddCommand(cmdRemoteSourceCreate)
@ -113,12 +114,12 @@ func remoteSourceCreate(cmd *cobra.Command, args []string) error {
LoginEnabled: util.BoolP(remoteSourceCreateOpts.loginEnabled),
}
log.Infof("creating remotesource")
log.Info().Msgf("creating remotesource")
remoteSource, _, err := gwclient.CreateRemoteSource(context.TODO(), req)
if err != nil {
return errors.Errorf("failed to create remotesource: %w", err)
}
log.Infof("remotesource %s created, ID: %s", remoteSource.Name, remoteSource.ID)
log.Info().Msgf("remotesource %s created, ID: %s", remoteSource.Name, remoteSource.ID)
return nil
}

View File

@ -21,6 +21,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -28,7 +29,7 @@ var cmdRemoteSourceList = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
if err := remoteSourceList(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "list",

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdRemoteSourceUpdate = &cobra.Command{
Short: "update a remotesource",
Run: func(cmd *cobra.Command, args []string) {
if err := remoteSourceUpdate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -65,7 +66,7 @@ func init() {
flags.BoolVar(&remoteSourceUpdateOpts.loginEnabled, "login-enabled", false, "enabled/disable user login with this remote source")
if err := cmdRemoteSourceUpdate.MarkFlagRequired("ref"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdRemoteSource.AddCommand(cmdRemoteSourceUpdate)
@ -105,12 +106,12 @@ func remoteSourceUpdate(cmd *cobra.Command, args []string) error {
req.LoginEnabled = &remoteSourceUpdateOpts.loginEnabled
}
log.Infof("updating remotesource")
log.Info().Msgf("updating remotesource")
remoteSource, _, err := gwclient.UpdateRemoteSource(context.TODO(), remoteSourceUpdateOpts.ref, req)
if err != nil {
return errors.Errorf("failed to update remotesource: %w", err)
}
log.Infof("remotesource %s updated, ID: %s", remoteSource.Name, remoteSource.ID)
log.Info().Msgf("remotesource %s updated, ID: %s", remoteSource.Name, remoteSource.ID)
return nil
}

View File

@ -21,6 +21,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -28,7 +29,7 @@ var cmdRunCreate = &cobra.Command{
Use: "create",
Run: func(cmd *cobra.Command, args []string) {
if err := runCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "create",
@ -54,7 +55,7 @@ func init() {
flags.StringVar(&runCreateOpts.commitSHA, "commit-sha", "", "git commit sha")
if err := cmdRunCreate.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdRun.AddCommand(cmdRunCreate)

View File

@ -24,6 +24,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
errors "golang.org/x/xerrors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -31,7 +32,7 @@ var cmdRunList = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
if err := runList(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "list",
@ -67,7 +68,7 @@ func init() {
flags.StringVar(&runListOpts.start, "start", "", "starting run id (excluded) to fetch")
if err := cmdRunList.MarkFlagRequired("project"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdRun.AddCommand(cmdRunList)

View File

@ -30,6 +30,7 @@ import (
"agola.io/agola/internal/services/scheduler"
"agola.io/agola/internal/util"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"go.etcd.io/etcd/embed"
errors "golang.org/x/xerrors"
@ -57,7 +58,7 @@ var cmdServe = &cobra.Command{
Version: cmd.Version,
Run: func(cmd *cobra.Command, args []string) {
if err := serve(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -80,7 +81,7 @@ func init() {
flags.StringVar(&serveOpts.embeddedEtcdDataDir, "embedded-etcd-data-dir", "/tmp/agola/etcd", "embedded etcd data dir, only for testing purpose")
if err := cmdServe.MarkFlagRequired("components"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdAgola.AddCommand(cmdServe)
@ -92,7 +93,7 @@ func embeddedEtcd(ctx context.Context) error {
cfg.Logger = "zap"
cfg.LogOutputs = []string{"stderr"}
log.Infof("starting embedded etcd server")
log.Info().Msgf("starting embedded etcd server")
e, err := embed.StartEtcd(cfg)
if err != nil {
return err
@ -100,10 +101,10 @@ func embeddedEtcd(ctx context.Context) error {
go func() {
<-e.Server.ReadyNotify()
log.Infof("embedded etcd server is ready")
log.Info().Msgf("embedded etcd server is ready")
<-ctx.Done()
log.Infof("stopping embedded etcd server")
log.Info().Msgf("stopping embedded etcd server")
e.Close()
}()
@ -142,7 +143,7 @@ func serve(cmd *cobra.Command, args []string) error {
var rs *rsscheduler.Runservice
if isComponentEnabled("runservice") {
rs, err = rsscheduler.NewRunservice(ctx, nil, &c.Runservice)
rs, err = rsscheduler.NewRunservice(ctx, log.Logger, &c.Runservice)
if err != nil {
return errors.Errorf("failed to start run service scheduler: %w", err)
}
@ -150,7 +151,7 @@ func serve(cmd *cobra.Command, args []string) error {
var ex *rsexecutor.Executor
if isComponentEnabled("executor") {
ex, err = executor.NewExecutor(ctx, nil, &c.Executor)
ex, err = executor.NewExecutor(ctx, log.Logger, &c.Executor)
if err != nil {
return errors.Errorf("failed to start run service executor: %w", err)
}
@ -158,7 +159,7 @@ func serve(cmd *cobra.Command, args []string) error {
var cs *configstore.Configstore
if isComponentEnabled("configstore") {
cs, err = configstore.NewConfigstore(ctx, nil, &c.Configstore)
cs, err = configstore.NewConfigstore(ctx, log.Logger, &c.Configstore)
if err != nil {
return errors.Errorf("failed to start config store: %w", err)
}
@ -166,7 +167,7 @@ func serve(cmd *cobra.Command, args []string) error {
var sched *scheduler.Scheduler
if isComponentEnabled("scheduler") {
sched, err = scheduler.NewScheduler(ctx, nil, &c.Scheduler)
sched, err = scheduler.NewScheduler(ctx, log.Logger, &c.Scheduler)
if err != nil {
return errors.Errorf("failed to start scheduler: %w", err)
}
@ -174,7 +175,7 @@ func serve(cmd *cobra.Command, args []string) error {
var ns *notification.NotificationService
if isComponentEnabled("notification") {
ns, err = notification.NewNotificationService(ctx, nil, c)
ns, err = notification.NewNotificationService(ctx, log.Logger, c)
if err != nil {
return errors.Errorf("failed to start notification service: %w", err)
}
@ -182,7 +183,7 @@ func serve(cmd *cobra.Command, args []string) error {
var gw *gateway.Gateway
if isComponentEnabled("gateway") {
gw, err = gateway.NewGateway(ctx, nil, c)
gw, err = gateway.NewGateway(ctx, log.Logger, c)
if err != nil {
return errors.Errorf("failed to start gateway: %w", err)
}
@ -190,7 +191,7 @@ func serve(cmd *cobra.Command, args []string) error {
var gs *gitserver.Gitserver
if isComponentEnabled("gitserver") {
gs, err = gitserver.NewGitserver(ctx, nil, &c.Gitserver)
gs, err = gitserver.NewGitserver(ctx, log.Logger, &c.Gitserver)
if err != nil {
return errors.Errorf("failed to start git server: %w", err)
}

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdUserCreate = &cobra.Command{
Short: "create a user",
Run: func(cmd *cobra.Command, args []string) {
if err := userCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -46,7 +47,7 @@ func init() {
flags.StringVarP(&userCreateOpts.username, "username", "n", "", "user name")
if err := cmdUserCreate.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUser.AddCommand(cmdUserCreate)
@ -59,12 +60,12 @@ func userCreate(cmd *cobra.Command, args []string) error {
UserName: userCreateOpts.username,
}
log.Infof("creating user")
log.Info().Msgf("creating user")
user, _, err := gwclient.CreateUser(context.TODO(), req)
if err != nil {
return errors.Errorf("failed to create user: %w", err)
}
log.Infof("user %q created, ID: %q", user.UserName, user.ID)
log.Info().Msgf("user %q created, ID: %q", user.UserName, user.ID)
return nil
}

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdUserDelete = &cobra.Command{
Short: "delete a user",
Run: func(cmd *cobra.Command, args []string) {
if err := userDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -45,7 +46,7 @@ func init() {
flags.StringVarP(&userDeleteOpts.username, "username", "n", "", "user name")
if err := cmdUserDelete.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUser.AddCommand(cmdUserDelete)
@ -54,7 +55,7 @@ func init() {
func userDelete(cmd *cobra.Command, args []string) error {
gwclient := gwclient.NewClient(gatewayURL, token)
log.Infof("deleting user %q", userDeleteOpts.username)
log.Info().Msgf("deleting user %q", userDeleteOpts.username)
if _, err := gwclient.DeleteUser(context.TODO(), userDeleteOpts.username); err != nil {
return errors.Errorf("failed to delete user: %w", err)
}

View File

@ -20,6 +20,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -29,7 +30,7 @@ var cmdUserLACreate = &cobra.Command{
Short: "create a user linkedaccount",
Run: func(cmd *cobra.Command, args []string) {
if err := userLACreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -52,10 +53,10 @@ func init() {
flags.StringVar(&userLACreateOpts.remoteSourceLoginPassword, "remote-password", "", "remote source password")
if err := cmdUserLACreate.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdUserLACreate.MarkFlagRequired("remote-source"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUserLA.AddCommand(cmdUserLACreate)
@ -70,15 +71,15 @@ func userLACreate(cmd *cobra.Command, args []string) error {
RemoteSourceLoginPassword: userLACreateOpts.remoteSourceLoginPassword,
}
log.Infof("creating linked account for user %q", userLACreateOpts.username)
log.Info().Msgf("creating linked account for user %q", userLACreateOpts.username)
resp, _, err := gwclient.CreateUserLA(context.TODO(), userLACreateOpts.username, req)
if err != nil {
return errors.Errorf("failed to create linked account: %w", err)
}
if resp.Oauth2Redirect != "" {
log.Infof("visit %s to continue", resp.Oauth2Redirect)
log.Info().Msgf("visit %s to continue", resp.Oauth2Redirect)
} else {
log.Infof("linked account for user %q created, ID: %s", userLACreateOpts.username, resp.LinkedAccount.ID)
log.Info().Msgf("linked account for user %q created, ID: %s", userLACreateOpts.username, resp.LinkedAccount.ID)
}
return nil

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdUserLADelete = &cobra.Command{
Short: "delete a user linkedaccount",
Run: func(cmd *cobra.Command, args []string) {
if err := userLADelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,10 +48,10 @@ func init() {
flags.StringVar(&userLADeleteOpts.laID, "laid", "", "linked account id")
if err := cmdUserLADelete.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdUserLADelete.MarkFlagRequired("laid"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUserLA.AddCommand(cmdUserLADelete)
@ -62,13 +63,13 @@ func userLADelete(cmd *cobra.Command, args []string) error {
userName := userLADeleteOpts.userName
laID := userLADeleteOpts.laID
log.Infof("deleting linked account %q for user %q", laID, userName)
log.Info().Msgf("deleting linked account %q for user %q", laID, userName)
_, err := gwclient.DeleteUserLA(context.TODO(), userName, laID)
if err != nil {
return errors.Errorf("failed to delete linked account: %w", err)
}
log.Infof("linked account %q for user %q deleted", laID, userName)
log.Info().Msgf("linked account %q for user %q deleted", laID, userName)
return nil
}

View File

@ -21,6 +21,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -28,7 +29,7 @@ var cmdUserList = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
if err := userList(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
Short: "list",

View File

@ -21,6 +21,7 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -30,7 +31,7 @@ var cmdUserTokenCreate = &cobra.Command{
Short: "create a user token",
Run: func(cmd *cobra.Command, args []string) {
if err := userTokenCreate(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -49,10 +50,10 @@ func init() {
flags.StringVarP(&userTokenCreateOpts.tokenName, "tokenname", "t", "", "token name")
if err := cmdUserTokenCreate.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdUserTokenCreate.MarkFlagRequired("tokenname"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUserToken.AddCommand(cmdUserTokenCreate)
@ -65,12 +66,12 @@ func userTokenCreate(cmd *cobra.Command, args []string) error {
TokenName: userTokenCreateOpts.tokenName,
}
log.Infof("creating token for user %q", userTokenCreateOpts.username)
log.Info().Msgf("creating token for user %q", userTokenCreateOpts.username)
resp, _, err := gwclient.CreateUserToken(context.TODO(), userTokenCreateOpts.username, req)
if err != nil {
return errors.Errorf("failed to create token: %w", err)
}
log.Infof("token for user %q created: %s", userTokenCreateOpts.username, resp.Token)
log.Info().Msgf("token for user %q created: %s", userTokenCreateOpts.username, resp.Token)
fmt.Println(resp.Token)
return nil

View File

@ -19,6 +19,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
)
@ -28,7 +29,7 @@ var cmdUserTokenDelete = &cobra.Command{
Short: "delete a user token",
Run: func(cmd *cobra.Command, args []string) {
if err := userTokenDelete(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}
@ -47,10 +48,10 @@ func init() {
flags.StringVarP(&userTokenDeleteOpts.tokenName, "tokenname", "t", "", "token name")
if err := cmdUserTokenDelete.MarkFlagRequired("username"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
if err := cmdUserTokenDelete.MarkFlagRequired("tokenname"); err != nil {
log.Fatal(err)
log.Fatal().Err(err).Send()
}
cmdUserToken.AddCommand(cmdUserTokenDelete)
@ -62,13 +63,13 @@ func userTokenDelete(cmd *cobra.Command, args []string) error {
userName := userTokenDeleteOpts.userName
tokenName := userTokenDeleteOpts.tokenName
log.Infof("deleting token %q for user %q", tokenName, userName)
log.Info().Msgf("deleting token %q for user %q", tokenName, userName)
_, err := gwclient.DeleteUserToken(context.TODO(), userName, tokenName)
if err != nil {
return errors.Errorf("failed to delete user token: %w", err)
}
log.Infof("token %q for user %q deleted", tokenName, userName)
log.Info().Msgf("token %q for user %q deleted", tokenName, userName)
return nil
}

View File

@ -20,6 +20,7 @@ import (
gwclient "agola.io/agola/services/gateway/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@ -28,7 +29,7 @@ var cmdVersion = &cobra.Command{
Short: "version",
Run: func(cmd *cobra.Command, args []string) {
if err := printVersions(cmd, args); err != nil {
log.Fatalf("err: %v", err)
log.Fatal().Err(err).Send()
}
},
}

6
go.mod
View File

@ -26,16 +26,16 @@ require (
github.com/mitchellh/copystructure v1.0.0
github.com/mitchellh/go-homedir v1.1.0
github.com/opencontainers/runc v0.1.1 // indirect
github.com/rs/zerolog v1.26.1
github.com/sanity-io/litter v1.2.0
github.com/sgotti/gexpect v0.0.0-20210315095146-1ec64e69809b
github.com/spf13/cobra v0.0.5
github.com/xanzy/go-gitlab v0.26.0
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
go.starlark.net v0.0.0-20200203144150-6677ee5c7211
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
gopkg.in/src-d/go-billy.v4 v4.3.2
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.2.8

55
go.sum
View File

@ -23,7 +23,6 @@ github.com/Azure/go-autorest/autorest/to v0.3.0/go.mod h1:MgwOyqaIuKdG4TL/2ywSsI
github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQvokg3NZAlQTalVMtOIAs1aGK7G6u8=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534/go.mod h1:iroGtC8B3tQiqtds1l+mgk/BBOrxbqjH+eUfFQYRc14=
@ -86,6 +85,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea h1:n2Ltr3SrfQlf/9nOna1DoGKxLx3qTSI8Ttl6Xrqp6mw=
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
@ -154,6 +154,7 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -341,8 +342,9 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -363,6 +365,9 @@ github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
@ -429,6 +434,7 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0=
@ -437,17 +443,12 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.starlark.net v0.0.0-20200203144150-6677ee5c7211 h1:Qoe+9POtDT51UBQ8XEnS9QKeHDQzEl2QRh3eok9R4aw=
go.starlark.net v0.0.0-20200203144150-6677ee5c7211/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@ -461,8 +462,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e h1:1SzTfNOXwIS2oWiMF+6qu0OUDKb0dauo6MoDUQyu+yU=
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190312203227-4b39c73a6495/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -472,12 +473,11 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -498,8 +498,10 @@ golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -510,8 +512,9 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -538,13 +541,20 @@ golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210314195730-07df6a141424 h1:+39ahH47SWi1PhMRAHfIrm8f69HRZ5K2koXH6dmO8TQ=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210314195730-07df6a141424/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
@ -567,15 +577,15 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200115165105-de0b1760071a h1:bEJ3JL2YUH3tt9KX9dsy0WUF3WOrhjtNjK93o0svepY=
golang.org/x/tools v0.0.0-20200115165105-de0b1760071a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ=
@ -636,7 +646,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI=
k8s.io/api v0.17.3 h1:XAm3PZp3wnEdzekNkcmj/9Y1zdmQYJ1I4GKSBBZ8aG0=

View File

@ -24,7 +24,8 @@ import (
"agola.io/agola/internal/etcd"
"agola.io/agola/internal/objectstorage"
"agola.io/agola/internal/services/config"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -109,9 +110,9 @@ func NewObjectStorage(c *config.ObjectStorage) (*objectstorage.ObjStorage, error
return objectstorage.NewObjStorage(ost, "/"), nil
}
func NewEtcd(c *config.Etcd, logger *zap.Logger, prefix string) (*etcd.Store, error) {
func NewEtcd(c *config.Etcd, log zerolog.Logger, prefix string) (*etcd.Store, error) {
e, err := etcd.New(etcd.Config{
Logger: logger,
Log: log,
Endpoints: c.Endpoints,
Prefix: prefix,
CertFile: c.TLSCertFile,

View File

@ -176,18 +176,18 @@ func (d *DataManager) watcherLoop(ctx context.Context) {
initialized := d.changes.initialized
if !initialized {
if err := d.initializeChanges(ctx); err != nil {
d.log.Errorf("watcher err: %+v", err)
d.log.Err(err).Msgf("watcher err")
}
} else {
if err := d.watcher(ctx); err != nil {
d.log.Errorf("watcher err: %+v", err)
d.log.Err(err).Msgf("watcher err")
}
}
sleepCh := time.NewTimer(1 * time.Second).C
select {
case <-ctx.Done():
d.log.Infof("watcher exiting")
d.log.Info().Msgf("watcher exiting")
return
case <-sleepCh:
}
@ -262,7 +262,7 @@ func (d *DataManager) watcher(ctx context.Context) error {
if wresp.Canceled {
err := wresp.Err()
if errors.Is(err, etcdclientv3rpc.ErrCompacted) {
d.log.Errorf("required events already compacted, reinitializing watcher changes")
d.log.Err(err).Msgf("required events already compacted, reinitializing watcher changes")
d.changes.Lock()
d.changes.initialized = false
d.changes.Unlock()

View File

@ -564,13 +564,13 @@ func (d *DataManager) GetFirstDataStatusSequences(n int) ([]*sequence.Sequence,
if m := DataStatusFileRegexp.FindStringSubmatch(path.Base(object.Path)); m != nil {
seq, err := sequence.Parse(m[1])
if err != nil {
d.log.Warnf("cannot parse sequence for data status file %q", object.Path)
d.log.Warn().Msgf("cannot parse sequence for data status file %q", object.Path)
continue
}
dataStatusSequences = append(dataStatusSequences, seq)
c++
} else {
d.log.Warnf("bad file %q found in storage data dir", object.Path)
d.log.Warn().Msgf("bad file %q found in storage data dir", object.Path)
}
if c >= n {
break
@ -601,13 +601,13 @@ func (d *DataManager) GetLastDataStatusSequences(n int) ([]*sequence.Sequence, e
if m := DataStatusFileRegexp.FindStringSubmatch(path.Base(object.Path)); m != nil {
seq, err := sequence.Parse(m[1])
if err != nil {
d.log.Warnf("cannot parse sequence for data status file %q", object.Path)
d.log.Warn().Msgf("cannot parse sequence for data status file %q", object.Path)
continue
}
re.Value = seq
re = re.Next()
} else {
d.log.Warnf("bad file %q found in storage data dir", object.Path)
d.log.Warn().Msgf("bad file %q found in storage data dir", object.Path)
}
}
@ -869,7 +869,7 @@ func (d *DataManager) cleanOldCheckpoints(ctx context.Context, dataStatusSequenc
if m := DataStatusFileRegexp.FindStringSubmatch(path.Base(object.Path)); m != nil {
seq, err := sequence.Parse(m[1])
if err == nil && seq.String() > lastDataStatusSequence.String() {
d.log.Infof("skipping file %q since its sequence is greater than %q", object.Path, lastDataStatusSequence)
d.log.Info().Msgf("skipping file %q since its sequence is greater than %q", object.Path, lastDataStatusSequence)
skip = true
}
}
@ -878,7 +878,7 @@ func (d *DataManager) cleanOldCheckpoints(ctx context.Context, dataStatusSequenc
}
if _, ok := dataStatusPathsMap[object.Path]; !ok {
d.log.Infof("removing %q", object.Path)
d.log.Info().Msgf("removing %q", object.Path)
if err := d.ost.DeleteObject(object.Path); err != nil {
if !objectstorage.IsNotExist(err) {
return fromOSTError(err)
@ -937,7 +937,7 @@ func (d *DataManager) cleanOldCheckpoints(ctx context.Context, dataStatusSequenc
if m := DataFileRegexp.FindStringSubmatch(pb); m != nil {
seq, err := sequence.Parse(m[1])
if err == nil && seq.String() > lastDataStatusSequence.String() {
d.log.Infof("skipping file %q since its sequence is greater than %q", p, lastDataStatusSequence)
d.log.Info().Msgf("skipping file %q since its sequence is greater than %q", p, lastDataStatusSequence)
skip = true
}
}
@ -946,7 +946,7 @@ func (d *DataManager) cleanOldCheckpoints(ctx context.Context, dataStatusSequenc
}
if _, ok := files[pne]; !ok {
d.log.Infof("removing %q", object.Path)
d.log.Info().Msgf("removing %q", object.Path)
if err := d.ost.DeleteObject(object.Path); err != nil {
if !objectstorage.IsNotExist(err) {
return fromOSTError(err)

View File

@ -25,7 +25,7 @@ import (
"agola.io/agola/internal/objectstorage"
"agola.io/agola/internal/sequence"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -130,7 +130,7 @@ type DataManagerConfig struct {
type DataManager struct {
basePath string
log *zap.SugaredLogger
log zerolog.Logger
e *etcd.Store
ost *objectstorage.ObjStorage
changes *WalChanges
@ -143,7 +143,7 @@ type DataManager struct {
maintenanceMode bool
}
func NewDataManager(ctx context.Context, logger *zap.Logger, conf *DataManagerConfig) (*DataManager, error) {
func NewDataManager(ctx context.Context, log zerolog.Logger, conf *DataManagerConfig) (*DataManager, error) {
if conf.EtcdWalsKeepNum == 0 {
conf.EtcdWalsKeepNum = DefaultEtcdWalsKeepNum
}
@ -168,7 +168,7 @@ func NewDataManager(ctx context.Context, logger *zap.Logger, conf *DataManagerCo
d := &DataManager{
basePath: conf.BasePath,
log: logger.Sugar(),
log: log,
e: conf.E,
ost: conf.OST,
changes: NewWalChanges(conf.DataTypes),
@ -266,7 +266,7 @@ func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
if err == nil {
break
}
d.log.Errorf("failed to initialize etcd: %+v", err)
d.log.Err(err).Msgf("failed to initialize etcd")
sleepCh := time.NewTimer(1 * time.Second).C
select {
@ -288,12 +288,12 @@ func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
go d.etcdPingerLoop(ctx)
} else {
d.log.Infof("datamanager starting in maintenance mode")
d.log.Info().Msgf("datamanager starting in maintenance mode")
readyCh <- struct{}{}
}
<-ctx.Done()
d.log.Infof("datamanager exiting")
d.log.Info().Msgf("datamanager exiting")
return nil
}

View File

@ -33,13 +33,12 @@ import (
"agola.io/agola/internal/testutil"
"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
func setupEtcd(t *testing.T, logger *zap.Logger, dir string) *testutil.TestEmbeddedEtcd {
tetcd, err := testutil.NewTestEmbeddedEtcd(t, logger, dir)
func setupEtcd(t *testing.T, log zerolog.Logger, dir string) *testutil.TestEmbeddedEtcd {
tetcd, err := testutil.NewTestEmbeddedEtcd(t, log, dir)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -65,13 +64,13 @@ func TestEtcdReset(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
ctx, cancel := context.WithCancel(context.Background())
@ -92,7 +91,7 @@ func TestEtcdReset(t *testing.T) {
EtcdWalsKeepNum: 10,
DataTypes: []string{"datatype01"},
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -131,7 +130,7 @@ func TestEtcdReset(t *testing.T) {
t.Logf("resetting etcd")
os.RemoveAll(etcdDir)
t.Logf("starting etcd")
tetcd = setupEtcd(t, logger, etcdDir)
tetcd = setupEtcd(t, log, etcdDir)
if err := tetcd.Start(); err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -146,7 +145,7 @@ func TestEtcdReset(t *testing.T) {
EtcdWalsKeepNum: 10,
DataTypes: []string{"datatype01"},
}
dm, err = NewDataManager(ctx, logger, dmConfig)
dm, err = NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -174,13 +173,13 @@ func TestEtcdResetWalsGap(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
ctx, cancel := context.WithCancel(context.Background())
@ -201,7 +200,7 @@ func TestEtcdResetWalsGap(t *testing.T) {
EtcdWalsKeepNum: 10,
DataTypes: []string{"datatype01"},
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -240,7 +239,7 @@ func TestEtcdResetWalsGap(t *testing.T) {
t.Logf("resetting etcd")
os.RemoveAll(etcdDir)
t.Logf("starting etcd")
tetcd = setupEtcd(t, logger, etcdDir)
tetcd = setupEtcd(t, log, etcdDir)
if err := tetcd.Start(); err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -279,7 +278,7 @@ func TestEtcdResetWalsGap(t *testing.T) {
EtcdWalsKeepNum: 10,
DataTypes: []string{"datatype01"},
}
dm, err = NewDataManager(ctx, logger, dmConfig)
dm, err = NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -302,13 +301,13 @@ func TestConcurrentUpdate(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -329,7 +328,7 @@ func TestConcurrentUpdate(t *testing.T) {
EtcdWalsKeepNum: 10,
DataTypes: []string{"datatype01"},
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -395,13 +394,13 @@ func TestEtcdWalCleaner(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -424,7 +423,7 @@ func TestEtcdWalCleaner(t *testing.T) {
DataTypes: []string{"datatype01"},
MinCheckpointWalsNum: 1,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -471,13 +470,13 @@ func TestReadObject(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -498,7 +497,7 @@ func TestReadObject(t *testing.T) {
EtcdWalsKeepNum: 1,
DataTypes: []string{"datatype01"},
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -766,13 +765,13 @@ func testCheckpoint(t *testing.T, basePath string) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -798,7 +797,7 @@ func testCheckpoint(t *testing.T, basePath string) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -984,13 +983,13 @@ func TestRead(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -1016,7 +1015,7 @@ func TestRead(t *testing.T) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1100,13 +1099,13 @@ func testClean(t *testing.T, basePath string) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -1132,7 +1131,7 @@ func testClean(t *testing.T, basePath string) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1220,13 +1219,13 @@ func testCleanConcurrentCheckpoint(t *testing.T, basePath string) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -1252,7 +1251,7 @@ func testCleanConcurrentCheckpoint(t *testing.T, basePath string) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1351,13 +1350,13 @@ func testStorageWalCleaner(t *testing.T, basePath string) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
ctx := context.Background()
@ -1383,7 +1382,7 @@ func testStorageWalCleaner(t *testing.T, basePath string) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1493,13 +1492,13 @@ func TestExportImport(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
ctx, cancel := context.WithCancel(context.Background())
@ -1524,7 +1523,7 @@ func TestExportImport(t *testing.T) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err := NewDataManager(ctx, logger, dmConfig)
dm, err := NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1603,7 +1602,7 @@ func TestExportImport(t *testing.T) {
t.Logf("resetting etcd")
os.RemoveAll(etcdDir)
t.Logf("starting etcd")
tetcd = setupEtcd(t, logger, etcdDir)
tetcd = setupEtcd(t, log, etcdDir)
if err := tetcd.Start(); err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1634,7 +1633,7 @@ func TestExportImport(t *testing.T) {
MaxDataFileSize: 10 * 1024,
MaintenanceMode: true,
}
dm, err = NewDataManager(ctx, logger, dmConfig)
dm, err = NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -1671,7 +1670,7 @@ func TestExportImport(t *testing.T) {
// use a small maxDataFileSize
MaxDataFileSize: 10 * 1024,
}
dm, err = NewDataManager(ctx, logger, dmConfig)
dm, err = NewDataManager(ctx, log, dmConfig)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

View File

@ -118,7 +118,7 @@ func (d *DataManager) ReadObject(dataType, id string, cgNames []string) (io.Read
for _, action := range actions {
if action.ActionType == ActionTypePut {
if action.DataType == dataType && action.ID == id {
d.log.Debugf("reading datatype %q, id %q from wal: %q", dataType, id)
d.log.Debug().Msgf("reading datatype %q, id %q from wal: %q", dataType, id, walseq)
return ioutil.NopCloser(bytes.NewReader(action.Data)), cgt, nil
}
}
@ -455,7 +455,7 @@ func (d *DataManager) WriteWalAdditionalOps(ctx context.Context, actions []*Acti
if err := d.ost.WriteObject(walDataFilePath, bytes.NewReader(buf.Bytes()), int64(buf.Len()), true); err != nil {
return nil, fromOSTError(err)
}
d.log.Debugf("wrote wal file: %s", walDataFilePath)
d.log.Debug().Msgf("wrote wal file: %s", walDataFilePath)
walData := &WalData{
WalSequence: walSequence.String(),
@ -534,7 +534,7 @@ func (d *DataManager) WriteWalAdditionalOps(ctx context.Context, actions []*Acti
// try to commit storage right now
if err := d.sync(ctx); err != nil {
d.log.Errorf("wal sync error: %+v", err)
d.log.Err(err).Msgf("wal sync error")
}
return ncgt, nil
@ -542,9 +542,9 @@ func (d *DataManager) WriteWalAdditionalOps(ctx context.Context, actions []*Acti
func (d *DataManager) syncLoop(ctx context.Context) {
for {
d.log.Debugf("syncer")
d.log.Debug().Msgf("syncer")
if err := d.sync(ctx); err != nil {
d.log.Errorf("syncer error: %+v", err)
d.log.Err(err).Msgf("syncer error")
}
sleepCh := time.NewTimer(DefaultSyncInterval).C
@ -587,7 +587,7 @@ func (d *DataManager) sync(ctx context.Context) error {
switch walData.WalStatus {
case WalStatusCommitted:
walFilePath := d.storageWalStatusFile(walData.WalSequence)
d.log.Debugf("syncing committed wal %q to storage", walData.WalSequence)
d.log.Debug().Msgf("syncing committed wal %q to storage", walData.WalSequence)
header := &WalHeader{
WalDataFileID: walData.WalDataFileID,
PreviousWalSequence: walData.PreviousWalSequence,
@ -602,7 +602,7 @@ func (d *DataManager) sync(ctx context.Context) error {
return fromOSTError(err)
}
d.log.Debugf("updating wal to state %q", WalStatusCommittedStorage)
d.log.Debug().Msgf("updating wal to state %q", WalStatusCommittedStorage)
walData.WalStatus = WalStatusCommittedStorage
walDataj, err := json.Marshal(walData)
if err != nil {
@ -631,9 +631,9 @@ func (d *DataManager) sync(ctx context.Context) error {
func (d *DataManager) checkpointLoop(ctx context.Context) {
for {
d.log.Debugf("checkpointer")
d.log.Debug().Msgf("checkpointer")
if err := d.checkpoint(ctx, false); err != nil {
d.log.Errorf("checkpoint error: %v", err)
d.log.Err(err).Msgf("checkpoint error")
}
sleepCh := time.NewTimer(d.checkpointInterval).C
@ -675,7 +675,7 @@ func (d *DataManager) checkpoint(ctx context.Context, force bool) error {
walData.Revision = kv.ModRevision
if walData.WalStatus == WalStatusCommitted {
d.log.Warnf("wal %s not yet committed storage", walData.WalSequence)
d.log.Warn().Msgf("wal %s not yet committed storage", walData.WalSequence)
break
}
if walData.WalStatus == WalStatusCheckpointed {
@ -696,7 +696,7 @@ func (d *DataManager) checkpoint(ctx context.Context, force bool) error {
}
for _, walData := range walsData {
d.log.Debugf("updating wal to state %q", WalStatusCheckpointed)
d.log.Debug().Msgf("updating wal to state %q", WalStatusCheckpointed)
walData.WalStatus = WalStatusCheckpointed
walDataj, err := json.Marshal(walData)
if err != nil {
@ -713,9 +713,9 @@ func (d *DataManager) checkpoint(ctx context.Context, force bool) error {
func (d *DataManager) checkpointCleanLoop(ctx context.Context) {
for {
d.log.Debugf("checkpointCleanLoop")
d.log.Debug().Msgf("checkpointCleanLoop")
if err := d.checkpointClean(ctx); err != nil {
d.log.Errorf("checkpointClean error: %v", err)
d.log.Err(err).Msgf("checkpointClean error")
}
sleepCh := time.NewTimer(d.checkpointCleanInterval).C
@ -753,9 +753,9 @@ func (d *DataManager) checkpointClean(ctx context.Context) error {
func (d *DataManager) etcdWalCleanerLoop(ctx context.Context) {
for {
d.log.Debugf("etcdwalcleaner")
d.log.Debug().Msgf("etcdwalcleaner")
if err := d.etcdWalCleaner(ctx); err != nil {
d.log.Errorf("etcdwalcleaner error: %v", err)
d.log.Err(err).Msgf("etcdwalcleaner error")
}
sleepCh := time.NewTimer(DefaultEtcdWalCleanInterval).C
@ -812,7 +812,7 @@ func (d *DataManager) etcdWalCleaner(ctx context.Context) error {
// sure that no objects with old data will be returned? Is it enough to read
// it back or the result could just be luckily correct but another client may
// arrive to a differnt S3 server that is not yet in sync?
d.log.Infof("removing wal %q from etcd", walData.WalSequence)
d.log.Info().Msgf("removing wal %q from etcd", walData.WalSequence)
if _, err := d.e.AtomicDelete(ctx, string(kv.Key), kv.ModRevision); err != nil {
return err
}
@ -828,9 +828,9 @@ func (d *DataManager) etcdWalCleaner(ctx context.Context) error {
func (d *DataManager) storageWalCleanerLoop(ctx context.Context) {
for {
d.log.Debugf("storagewalcleaner")
d.log.Debug().Msgf("storagewalcleaner")
if err := d.storageWalCleaner(ctx); err != nil {
d.log.Errorf("storagewalcleaner error: %v", err)
d.log.Err(err).Msgf("storagewalcleaner error")
}
sleepCh := time.NewTimer(DefaultStorageWalCleanInterval).C
@ -907,7 +907,7 @@ func (d *DataManager) storageWalCleaner(ctx context.Context) error {
// first remove wal data file
walStatusFilePath := d.storageWalDataFile(header.WalDataFileID)
d.log.Infof("removing %q", walStatusFilePath)
d.log.Info().Msgf("removing %q", walStatusFilePath)
if err := d.ost.DeleteObject(walStatusFilePath); err != nil {
if !objectstorage.IsNotExist(err) {
return fromOSTError(err)
@ -915,7 +915,7 @@ func (d *DataManager) storageWalCleaner(ctx context.Context) error {
}
// then remove wal status files
d.log.Infof("removing %q", object.Path)
d.log.Info().Msgf("removing %q", object.Path)
if err := d.ost.DeleteObject(object.Path); err != nil {
if !objectstorage.IsNotExist(err) {
return fromOSTError(err)
@ -926,7 +926,7 @@ func (d *DataManager) storageWalCleaner(ctx context.Context) error {
// handle old checkpointed status file
// TODO(sgotti) remove this in future versions since .checkpointed files are not created anymore
if ext == ".checkpointed" {
d.log.Infof("removing %q", object.Path)
d.log.Info().Msgf("removing %q", object.Path)
if err := d.ost.DeleteObject(object.Path); err != nil {
if !objectstorage.IsNotExist(err) {
return fromOSTError(err)
@ -941,7 +941,7 @@ func (d *DataManager) storageWalCleaner(ctx context.Context) error {
func (d *DataManager) compactChangeGroupsLoop(ctx context.Context) {
for {
if err := d.compactChangeGroups(ctx); err != nil {
d.log.Errorf("err: %+v", err)
d.log.Err(err).Send()
}
sleepCh := time.NewTimer(DefaultCompactChangeGroupsInterval).C
@ -1009,7 +1009,7 @@ func (d *DataManager) compactChangeGroups(ctx context.Context) error {
return etcd.FromEtcdError(err)
}
if !tresp.Succeeded {
d.log.Errorf("failed to update change group min revision key due to concurrent update")
d.log.Err(err).Msgf("failed to update change group min revision key due to concurrent update")
}
}
}
@ -1026,7 +1026,7 @@ func (d *DataManager) compactChangeGroups(ctx context.Context) error {
func (d *DataManager) etcdPingerLoop(ctx context.Context) {
for {
if err := d.etcdPinger(ctx); err != nil {
d.log.Errorf("err: %+v", err)
d.log.Err(err).Send()
}
sleepCh := time.NewTimer(DefaultEtcdPingerInterval).C
@ -1119,7 +1119,7 @@ func (d *DataManager) InitEtcd(ctx context.Context, dataStatus *DataStatus) erro
}
if mustInit {
d.log.Infof("no data found in etcd, initializing")
d.log.Info().Msgf("no data found in etcd, initializing")
// delete all wals from etcd
if err := d.deleteEtcd(ctx); err != nil {
@ -1170,7 +1170,7 @@ func (d *DataManager) InitEtcd(ctx context.Context, dataStatus *DataStatus) erro
if dataStatus == nil {
return errors.Errorf("no datastatus in etcd but some wals are present, this shouldn't happen")
}
d.log.Debugf("wal: %s", wal)
d.log.Debug().Msgf("wal: %s", wal)
if wal.Err != nil {
return wal.Err
}
@ -1202,10 +1202,10 @@ func (d *DataManager) InitEtcd(ctx context.Context, dataStatus *DataStatus) erro
if err := d.ost.WriteObject(walDataFilePath, bytes.NewReader([]byte{}), 0, true); err != nil {
return fromOSTError(err)
}
d.log.Debugf("wrote wal file: %s", walDataFilePath)
d.log.Debug().Msgf("wrote wal file: %s", walDataFilePath)
walFilePath := d.storageWalStatusFile(walSequence.String())
d.log.Infof("syncing committed wal %q to storage", walSequence.String())
d.log.Info().Msgf("syncing committed wal %q to storage", walSequence.String())
header := &WalHeader{
WalDataFileID: walDataFileID,
PreviousWalSequence: lastCommittedStorageWalSequence,

View File

@ -24,11 +24,11 @@ import (
"agola.io/agola/internal/util"
"github.com/rs/zerolog"
"go.etcd.io/etcd/clientv3"
etcdclientv3 "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/namespace"
"go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
@ -50,7 +50,7 @@ type WriteOptions struct {
}
type Config struct {
Logger *zap.Logger
Log zerolog.Logger
Endpoints string
Prefix string
CertFile string
@ -69,7 +69,7 @@ func FromEtcdError(err error) error {
}
type Store struct {
log *zap.SugaredLogger
log zerolog.Logger
c *etcdclientv3.Client
}
@ -127,7 +127,7 @@ func New(cfg Config) (*Store, error) {
c.Lease = namespace.NewLease(c.Lease, prefix)
s := &Store{
log: cfg.Logger.Sugar(),
log: cfg.Log,
c: c,
}
@ -379,9 +379,9 @@ func (s *Store) compact(ctx context.Context, version, rev int64) (int64, int64,
return curVersion, curRev, nil
}
if _, err = s.c.Compact(ctx, rev); err != nil {
s.log.Warnf("compact error: %v", err)
s.log.Warn().Msgf("compact error: %v", err)
return curVersion, curRev, err
}
s.log.Infof("compacted revision: %d", rev)
s.log.Info().Msgf("compacted revision: %d", rev)
return curVersion, curRev, nil
}

View File

@ -26,7 +26,7 @@ import (
"agola.io/agola/internal/util"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -138,16 +138,16 @@ type RepoAbsPathFunc func(reposDir, path string) (absPath string, exists bool, e
type RepoPostCreateFunc func(repoPath, repoAbsPath string) error
type GitSmartHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
reposDir string
createRepo bool
repoAbsPathFunc RepoAbsPathFunc
repoPostCreateFunc RepoPostCreateFunc
}
func NewGitSmartHandler(logger *zap.Logger, reposDir string, createRepo bool, repoAbsPathFunc RepoAbsPathFunc, repoPostCreateFunc RepoPostCreateFunc) *GitSmartHandler {
func NewGitSmartHandler(log zerolog.Logger, reposDir string, createRepo bool, repoAbsPathFunc RepoAbsPathFunc, repoPostCreateFunc RepoPostCreateFunc) *GitSmartHandler {
return &GitSmartHandler{
log: logger.Sugar(),
log: log,
reposDir: reposDir,
createRepo: createRepo,
repoAbsPathFunc: repoAbsPathFunc,
@ -188,7 +188,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case RequestTypeInfoRefs:
if h.createRepo && !exists {
if output, err := git.Output(ctx, nil, "init", "--bare", repoAbsPath); err != nil {
h.log.Errorf("git error %v, output: %s", err, output)
h.log.Err(err).Msgf("git error, output: %s", output)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@ -208,7 +208,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
res, err := InfoRefsResponse(ctx, repoAbsPath, serviceName)
if err != nil {
// we cannot return any http error since the http header has already been written
h.log.Errorf("git command error: %v", err)
h.log.Err(err).Msgf("git command error")
return
}
@ -220,27 +220,27 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err := gitService(ctx, w, body, repoAbsPath, "upload-pack"); err != nil {
// we cannot return any http error since the http header has already been written
h.log.Errorf("git command error: %v", err)
h.log.Err(err).Msgf("git command error")
}
case RequestTypeReceivePack:
w.Header().Set("Content-Type", "application/x-git-receive-pack-result")
if err := gitService(ctx, w, body, repoAbsPath, "receive-pack"); err != nil {
// we cannot return any http error since the http header has already been written
h.log.Errorf("git command error: %v", err)
h.log.Err(err).Msgf("git command error")
}
}
}
type FetchFileHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
reposDir string
repoAbsPathFunc RepoAbsPathFunc
}
func NewFetchFileHandler(logger *zap.Logger, reposDir string, repoAbsPathFunc RepoAbsPathFunc) *FetchFileHandler {
func NewFetchFileHandler(log zerolog.Logger, reposDir string, repoAbsPathFunc RepoAbsPathFunc) *FetchFileHandler {
return &FetchFileHandler{
log: logger.Sugar(),
log: log,
reposDir: reposDir,
repoAbsPathFunc: repoAbsPathFunc,
}
@ -266,7 +266,7 @@ func (h *FetchFileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := gitFetchFile(ctx, w, r.Body, repoAbsPath, fetchData.Ref, fetchData.Path); err != nil {
h.log.Errorf("git command error: %v", err)
h.log.Err(err).Msgf("git command error")
// since we already answered with a 200 we cannot return another error code
// So abort the connection and the client will detect the missing ending chunk

View File

@ -23,7 +23,7 @@ import (
"agola.io/agola/internal/util"
"github.com/gofrs/uuid"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -150,18 +150,18 @@ type GitSaveConfig struct {
}
type GitSave struct {
log *zap.SugaredLogger
log zerolog.Logger
conf *GitSaveConfig
refsPrefix string
}
func NewGitSave(logger *zap.Logger, conf *GitSaveConfig) *GitSave {
func NewGitSave(log zerolog.Logger, conf *GitSaveConfig) *GitSave {
refsPrefix := conf.RefsPrefix
if refsPrefix == "" {
refsPrefix = defaultRefsPrefix
}
return &GitSave{
log: logger.Sugar(),
log: log,
conf: conf,
refsPrefix: refsPrefix,
}
@ -201,7 +201,7 @@ func (s *GitSave) Save(message, branchName string) (string, error) {
if err := copyFile(indexPath, tmpIndexPath); err != nil {
return "", err
}
s.log.Infof("created temporary index: %s", tmpIndexPath)
s.log.Info().Msgf("created temporary index: %s", tmpIndexPath)
// read the current branch tree information into the index
git := &util.Git{Env: []string{"GIT_INDEX_FILE=" + tmpIndexPath}}
_, err = git.Output(context.Background(), nil, "read-tree", curBranch)
@ -209,43 +209,43 @@ func (s *GitSave) Save(message, branchName string) (string, error) {
return "", err
}
} else {
s.log.Infof("index %s does not exist", indexPath)
s.log.Info().Msgf("index %s does not exist", indexPath)
}
s.log.Infof("updating files already in the index")
s.log.Info().Msgf("updating files already in the index")
if err := gitUpdateFiles(tmpIndexPath); err != nil {
return "", err
}
if s.conf.AddUntracked {
s.log.Infof("adding untracked files")
s.log.Info().Msgf("adding untracked files")
if err := gitAddUntrackedFiles(tmpIndexPath); err != nil {
return "", err
}
}
if s.conf.AddIgnored {
s.log.Infof("adding ignored files")
s.log.Info().Msgf("adding ignored files")
if err := gitAddIgnoredFiles(tmpIndexPath); err != nil {
return "", err
}
}
s.log.Infof("writing tree file")
s.log.Info().Msgf("writing tree file")
treeSHA, err := gitWriteTree(tmpIndexPath)
if err != nil {
return "", err
}
s.log.Infof("tree: %s", treeSHA)
s.log.Info().Msgf("tree: %s", treeSHA)
s.log.Infof("committing tree")
s.log.Info().Msgf("committing tree")
commitSHA, err := gitCommitTree(message, treeSHA)
if err != nil {
return "", err
}
s.log.Infof("commit: %s", commitSHA)
s.log.Info().Msgf("commit: %s", commitSHA)
s.log.Infof("updating ref")
s.log.Info().Msgf("updating ref")
if err = gitUpdateRef("git-save", filepath.Join(s.refsPrefix, branchName), commitSHA); err != nil {
return "", err
}

View File

@ -1,43 +0,0 @@
// Copyright 2019 Sorint.lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// See the License for the specific language governing permissions and
// limitations under the License.
package log
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func New(level zap.AtomicLevel) *zap.Logger {
config := zap.Config{
Level: level,
Development: true,
DisableStacktrace: true,
Encoding: "console",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
logger, err := config.Build()
if err != nil {
panic(fmt.Errorf("failed to initialize logger: %w", err))
}
return logger
}

View File

@ -22,21 +22,21 @@ import (
"agola.io/agola/internal/util"
"agola.io/agola/services/configstore/types"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
type ActionHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
dm *datamanager.DataManager
e *etcd.Store
maintenanceMode bool
}
func NewActionHandler(logger *zap.Logger, readDB *readdb.ReadDB, dm *datamanager.DataManager, e *etcd.Store) *ActionHandler {
func NewActionHandler(log zerolog.Logger, readDB *readdb.ReadDB, dm *datamanager.DataManager, e *etcd.Store) *ActionHandler {
return &ActionHandler{
log: logger.Sugar(),
log: log,
readDB: readDB,
dm: dm,
e: e,

View File

@ -21,17 +21,17 @@ import (
"agola.io/agola/internal/services/configstore/action"
"agola.io/agola/internal/util"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type MaintenanceModeHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
e *etcd.Store
}
func NewMaintenanceModeHandler(logger *zap.Logger, ah *action.ActionHandler, e *etcd.Store) *MaintenanceModeHandler {
return &MaintenanceModeHandler{log: logger.Sugar(), ah: ah, e: e}
func NewMaintenanceModeHandler(log zerolog.Logger, ah *action.ActionHandler, e *etcd.Store) *MaintenanceModeHandler {
return &MaintenanceModeHandler{log: log, ah: ah, e: e}
}
func (h *MaintenanceModeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -47,24 +47,24 @@ func (h *MaintenanceModeHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
err := h.ah.MaintenanceMode(ctx, enable)
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ExportHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewExportHandler(logger *zap.Logger, ah *action.ActionHandler) *ExportHandler {
return &ExportHandler{log: logger.Sugar(), ah: ah}
func NewExportHandler(log zerolog.Logger, ah *action.ActionHandler) *ExportHandler {
return &ExportHandler{log: log, ah: ah}
}
func (h *ExportHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -72,7 +72,7 @@ func (h *ExportHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.ah.Export(ctx, w)
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
// since we already answered with a 200 we cannot return another error code
// So abort the connection and the client will detect the missing ending chunk
// and consider this an error
@ -83,12 +83,12 @@ func (h *ExportHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
type ImportHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewImportHandler(logger *zap.Logger, ah *action.ActionHandler) *ImportHandler {
return &ImportHandler{log: logger.Sugar(), ah: ah}
func NewImportHandler(log zerolog.Logger, ah *action.ActionHandler) *ImportHandler {
return &ImportHandler{log: log, ah: ah}
}
func (h *ImportHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -96,13 +96,13 @@ func (h *ImportHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.ah.Import(ctx, r.Body)
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -27,17 +27,17 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
type OrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewOrgHandler(logger *zap.Logger, readDB *readdb.ReadDB) *OrgHandler {
return &OrgHandler{log: logger.Sugar(), readDB: readDB}
func NewOrgHandler(log zerolog.Logger, readDB *readdb.ReadDB) *OrgHandler {
return &OrgHandler{log: log, readDB: readDB}
}
func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -52,7 +52,7 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -63,17 +63,17 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := util.HTTPResponse(w, http.StatusOK, org); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateOrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateOrgHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateOrgHandler {
return &CreateOrgHandler{log: logger.Sugar(), ah: ah}
func NewCreateOrgHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateOrgHandler {
return &CreateOrgHandler{log: log, ah: ah}
}
func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -88,22 +88,22 @@ func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
org, err := h.ah.CreateOrg(ctx, &req)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, org); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteOrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteOrgHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteOrgHandler {
return &DeleteOrgHandler{log: logger.Sugar(), ah: ah}
func NewDeleteOrgHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteOrgHandler {
return &DeleteOrgHandler{log: log, ah: ah}
}
func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -114,11 +114,11 @@ func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.ah.DeleteOrg(ctx, orgRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -128,12 +128,12 @@ const (
)
type OrgsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewOrgsHandler(logger *zap.Logger, readDB *readdb.ReadDB) *OrgsHandler {
return &OrgsHandler{log: logger.Sugar(), readDB: readDB}
func NewOrgsHandler(log zerolog.Logger, readDB *readdb.ReadDB) *OrgsHandler {
return &OrgsHandler{log: log, readDB: readDB}
}
func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -171,23 +171,23 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, orgs); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type AddOrgMemberHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewAddOrgMemberHandler(logger *zap.Logger, ah *action.ActionHandler) *AddOrgMemberHandler {
return &AddOrgMemberHandler{log: logger.Sugar(), ah: ah}
func NewAddOrgMemberHandler(log zerolog.Logger, ah *action.ActionHandler) *AddOrgMemberHandler {
return &AddOrgMemberHandler{log: log, ah: ah}
}
func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -206,22 +206,22 @@ func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
org, err := h.ah.AddOrgMember(ctx, orgRef, userRef, req.Role)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, org); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type RemoveOrgMemberHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewRemoveOrgMemberHandler(logger *zap.Logger, ah *action.ActionHandler) *RemoveOrgMemberHandler {
return &RemoveOrgMemberHandler{log: logger.Sugar(), ah: ah}
func NewRemoveOrgMemberHandler(log zerolog.Logger, ah *action.ActionHandler) *RemoveOrgMemberHandler {
return &RemoveOrgMemberHandler{log: log, ah: ah}
}
func (h *RemoveOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -233,12 +233,12 @@ func (h *RemoveOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
err := h.ah.RemoveOrgMember(ctx, orgRef, userRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -250,12 +250,12 @@ func orgMemberResponse(orgUser *action.OrgMemberResponse) *csapitypes.OrgMemberR
}
type OrgMembersHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewOrgMembersHandler(logger *zap.Logger, ah *action.ActionHandler) *OrgMembersHandler {
return &OrgMembersHandler{log: logger.Sugar(), ah: ah}
func NewOrgMembersHandler(log zerolog.Logger, ah *action.ActionHandler) *OrgMembersHandler {
return &OrgMembersHandler{log: log, ah: ah}
}
func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -265,7 +265,7 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
orgUsers, err := h.ah.GetOrgMembers(ctx, orgRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -275,6 +275,6 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -29,7 +29,7 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
func projectResponse(ctx context.Context, readDB *readdb.ReadDB, project *types.Project) (*csapitypes.Project, error) {
@ -112,13 +112,13 @@ func getGlobalVisibility(readDB *readdb.ReadDB, tx *db.Tx, curVisibility types.V
}
type ProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewProjectHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectHandler {
return &ProjectHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewProjectHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectHandler {
return &ProjectHandler{log: log, ah: ah, readDB: readDB}
}
func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -132,29 +132,29 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
project, err := h.ah.GetProject(ctx, projectRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProject, err := projectResponse(ctx, h.readDB, project)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, resProject); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewCreateProjectHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *CreateProjectHandler {
return &CreateProjectHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewCreateProjectHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *CreateProjectHandler {
return &CreateProjectHandler{log: log, ah: ah, readDB: readDB}
}
func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -169,29 +169,29 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
project, err := h.ah.CreateProject(ctx, &req)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProject, err := projectResponse(ctx, h.readDB, project)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, resProject); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewUpdateProjectHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *UpdateProjectHandler {
return &UpdateProjectHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewUpdateProjectHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *UpdateProjectHandler {
return &UpdateProjectHandler{log: log, ah: ah, readDB: readDB}
}
func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -217,28 +217,28 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
project, err = h.ah.UpdateProject(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProject, err := projectResponse(ctx, h.readDB, project)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, resProject); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteProjectHandler {
return &DeleteProjectHandler{log: logger.Sugar(), ah: ah}
func NewDeleteProjectHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteProjectHandler {
return &DeleteProjectHandler{log: log, ah: ah}
}
func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -253,10 +253,10 @@ func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
err = h.ah.DeleteProject(ctx, projectRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -29,7 +29,7 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
func projectGroupResponse(ctx context.Context, readDB *readdb.ReadDB, projectGroup *types.ProjectGroup) (*csapitypes.ProjectGroup, error) {
@ -80,13 +80,13 @@ func projectGroupsResponse(ctx context.Context, readDB *readdb.ReadDB, projectGr
}
type ProjectGroupHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupHandler {
return &ProjectGroupHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewProjectGroupHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupHandler {
return &ProjectGroupHandler{log: log, ah: ah, readDB: readDB}
}
func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -101,29 +101,29 @@ func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
projectGroup, err := h.ah.GetProjectGroup(ctx, projectGroupRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProjectGroup, err := projectGroupResponse(ctx, h.readDB, projectGroup)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, resProjectGroup); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ProjectGroupProjectsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewProjectGroupProjectsHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupProjectsHandler {
return &ProjectGroupProjectsHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewProjectGroupProjectsHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupProjectsHandler {
return &ProjectGroupProjectsHandler{log: log, ah: ah, readDB: readDB}
}
func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -138,29 +138,29 @@ func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.R
projects, err := h.ah.GetProjectGroupProjects(ctx, projectGroupRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProjects, err := projectsResponse(ctx, h.readDB, projects)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, resProjects); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ProjectGroupSubgroupsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewProjectGroupSubgroupsHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupSubgroupsHandler {
return &ProjectGroupSubgroupsHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewProjectGroupSubgroupsHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *ProjectGroupSubgroupsHandler {
return &ProjectGroupSubgroupsHandler{log: log, ah: ah, readDB: readDB}
}
func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -174,29 +174,29 @@ func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.
projectGroups, err := h.ah.GetProjectGroupSubgroups(ctx, projectGroupRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProjectGroups, err := projectGroupsResponse(ctx, h.readDB, projectGroups)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, resProjectGroups); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateProjectGroupHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewCreateProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *CreateProjectGroupHandler {
return &CreateProjectGroupHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewCreateProjectGroupHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *CreateProjectGroupHandler {
return &CreateProjectGroupHandler{log: log, ah: ah, readDB: readDB}
}
func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -211,29 +211,29 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
projectGroup, err := h.ah.CreateProjectGroup(ctx, &req)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProjectGroup, err := projectGroupResponse(ctx, h.readDB, projectGroup)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, resProjectGroup); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateProjectGroupHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewUpdateProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *UpdateProjectGroupHandler {
return &UpdateProjectGroupHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewUpdateProjectGroupHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *UpdateProjectGroupHandler {
return &UpdateProjectGroupHandler{log: log, ah: ah, readDB: readDB}
}
func (h *UpdateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -259,28 +259,28 @@ func (h *UpdateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
}
projectGroup, err = h.ah.UpdateProjectGroup(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
resProjectGroup, err := projectGroupResponse(ctx, h.readDB, projectGroup)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, resProjectGroup); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteProjectGroupHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteProjectGroupHandler {
return &DeleteProjectGroupHandler{log: logger.Sugar(), ah: ah}
func NewDeleteProjectGroupHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteProjectGroupHandler {
return &DeleteProjectGroupHandler{log: log, ah: ah}
}
func (h *DeleteProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -295,9 +295,9 @@ func (h *DeleteProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
err = h.ah.DeleteProjectGroup(ctx, projectGroupRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -26,17 +26,17 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
type RemoteSourceHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewRemoteSourceHandler(logger *zap.Logger, readDB *readdb.ReadDB) *RemoteSourceHandler {
return &RemoteSourceHandler{log: logger.Sugar(), readDB: readDB}
func NewRemoteSourceHandler(log zerolog.Logger, readDB *readdb.ReadDB) *RemoteSourceHandler {
return &RemoteSourceHandler{log: log, readDB: readDB}
}
func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -51,7 +51,7 @@ func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -62,17 +62,17 @@ func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
if err := util.HTTPResponse(w, http.StatusOK, remoteSource); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateRemoteSourceHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateRemoteSourceHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateRemoteSourceHandler {
return &CreateRemoteSourceHandler{log: logger.Sugar(), ah: ah}
func NewCreateRemoteSourceHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateRemoteSourceHandler {
return &CreateRemoteSourceHandler{log: log, ah: ah}
}
func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -87,22 +87,22 @@ func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
remoteSource, err := h.ah.CreateRemoteSource(ctx, &req)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, remoteSource); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateRemoteSourceHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateRemoteSourceHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateRemoteSourceHandler {
return &UpdateRemoteSourceHandler{log: logger.Sugar(), ah: ah}
func NewUpdateRemoteSourceHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateRemoteSourceHandler {
return &UpdateRemoteSourceHandler{log: log, ah: ah}
}
func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -124,22 +124,22 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
}
remoteSource, err := h.ah.UpdateRemoteSource(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, remoteSource); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteRemoteSourceHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteRemoteSourceHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteRemoteSourceHandler {
return &DeleteRemoteSourceHandler{log: logger.Sugar(), ah: ah}
func NewDeleteRemoteSourceHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteRemoteSourceHandler {
return &DeleteRemoteSourceHandler{log: log, ah: ah}
}
func (h *DeleteRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -150,10 +150,10 @@ func (h *DeleteRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
err := h.ah.DeleteRemoteSource(ctx, rsRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -163,12 +163,12 @@ const (
)
type RemoteSourcesHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewRemoteSourcesHandler(logger *zap.Logger, readDB *readdb.ReadDB) *RemoteSourcesHandler {
return &RemoteSourcesHandler{log: logger.Sugar(), readDB: readDB}
func NewRemoteSourcesHandler(log zerolog.Logger, readDB *readdb.ReadDB) *RemoteSourcesHandler {
return &RemoteSourcesHandler{log: log, readDB: readDB}
}
func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -201,12 +201,12 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
remoteSources, err := h.readDB.GetRemoteSources(ctx, start, limit, asc)
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, remoteSources); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -26,17 +26,17 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type SecretHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewSecretHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *SecretHandler {
return &SecretHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewSecretHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *SecretHandler {
return &SecretHandler{log: log, ah: ah, readDB: readDB}
}
func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -46,23 +46,23 @@ func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
secret, err := h.ah.GetSecret(ctx, secretID)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, secret); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type SecretsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewSecretsHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *SecretsHandler {
return &SecretsHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewSecretsHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *SecretsHandler {
return &SecretsHandler{log: log, ah: ah, readDB: readDB}
}
func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -72,13 +72,13 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
secrets, err := h.ah.GetSecrets(ctx, parentType, parentRef, tree)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -99,30 +99,30 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, resSecrets); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateSecretHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateSecretHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateSecretHandler {
return &CreateSecretHandler{log: logger.Sugar(), ah: ah}
func NewCreateSecretHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateSecretHandler {
return &CreateSecretHandler{log: log, ah: ah}
}
func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -138,22 +138,22 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
secret, err = h.ah.CreateSecret(ctx, secret)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, secret); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateSecretHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateSecretHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateSecretHandler {
return &UpdateSecretHandler{log: logger.Sugar(), ah: ah}
func NewUpdateSecretHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateSecretHandler {
return &UpdateSecretHandler{log: log, ah: ah}
}
func (h *UpdateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -163,7 +163,7 @@ func (h *UpdateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -183,22 +183,22 @@ func (h *UpdateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
secret, err = h.ah.UpdateSecret(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, secret); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteSecretHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteSecretHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteSecretHandler {
return &DeleteSecretHandler{log: logger.Sugar(), ah: ah}
func NewDeleteSecretHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteSecretHandler {
return &DeleteSecretHandler{log: log, ah: ah}
}
func (h *DeleteSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -208,15 +208,15 @@ func (h *DeleteSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
err = h.ah.DeleteSecret(ctx, parentType, parentRef, secretName)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -27,17 +27,17 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
type UserHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewUserHandler(logger *zap.Logger, readDB *readdb.ReadDB) *UserHandler {
return &UserHandler{log: logger.Sugar(), readDB: readDB}
func NewUserHandler(log zerolog.Logger, readDB *readdb.ReadDB) *UserHandler {
return &UserHandler{log: log, readDB: readDB}
}
func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -52,7 +52,7 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -63,17 +63,17 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := util.HTTPResponse(w, http.StatusOK, user); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateUserHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateUserHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateUserHandler {
return &CreateUserHandler{log: logger.Sugar(), ah: ah}
func NewCreateUserHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateUserHandler {
return &CreateUserHandler{log: log, ah: ah}
}
func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -103,22 +103,22 @@ func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
user, err := h.ah.CreateUser(ctx, creq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, user); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateUserHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateUserHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateUserHandler {
return &UpdateUserHandler{log: logger.Sugar(), ah: ah}
func NewUpdateUserHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateUserHandler {
return &UpdateUserHandler{log: log, ah: ah}
}
func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -141,22 +141,22 @@ func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
user, err := h.ah.UpdateUser(ctx, creq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, user); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteUserHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteUserHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteUserHandler {
return &DeleteUserHandler{log: logger.Sugar(), ah: ah}
func NewDeleteUserHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteUserHandler {
return &DeleteUserHandler{log: log, ah: ah}
}
func (h *DeleteUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -167,10 +167,10 @@ func (h *DeleteUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.ah.DeleteUser(ctx, userRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -180,12 +180,12 @@ const (
)
type UsersHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
readDB *readdb.ReadDB
}
func NewUsersHandler(logger *zap.Logger, readDB *readdb.ReadDB) *UsersHandler {
return &UsersHandler{log: logger.Sugar(), readDB: readDB}
func NewUsersHandler(log zerolog.Logger, readDB *readdb.ReadDB) *UsersHandler {
return &UsersHandler{log: log, readDB: readDB}
}
func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -230,7 +230,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -248,7 +248,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -267,7 +267,7 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
@ -284,24 +284,24 @@ func (h *UsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
}
if err := util.HTTPResponse(w, http.StatusOK, users); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateUserLAHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateUserLAHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateUserLAHandler {
return &CreateUserLAHandler{log: logger.Sugar(), ah: ah}
func NewCreateUserLAHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateUserLAHandler {
return &CreateUserLAHandler{log: log, ah: ah}
}
func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -328,22 +328,22 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
user, err := h.ah.CreateUserLA(ctx, creq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, user); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteUserLAHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteUserLAHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteUserLAHandler {
return &DeleteUserLAHandler{log: logger.Sugar(), ah: ah}
func NewDeleteUserLAHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteUserLAHandler {
return &DeleteUserLAHandler{log: log, ah: ah}
}
func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -354,20 +354,20 @@ func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
err := h.ah.DeleteUserLA(ctx, userRef, laID)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateUserLAHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateUserLAHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateUserLAHandler {
return &UpdateUserLAHandler{log: logger.Sugar(), ah: ah}
func NewUpdateUserLAHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateUserLAHandler {
return &UpdateUserLAHandler{log: log, ah: ah}
}
func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -395,22 +395,22 @@ func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
user, err := h.ah.UpdateUserLA(ctx, creq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, user); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateUserTokenHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateUserTokenHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateUserTokenHandler {
return &CreateUserTokenHandler{log: logger.Sugar(), ah: ah}
func NewCreateUserTokenHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateUserTokenHandler {
return &CreateUserTokenHandler{log: log, ah: ah}
}
func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -427,7 +427,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
token, err := h.ah.CreateUserToken(ctx, userRef, req.TokenName)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -435,17 +435,17 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
Token: token,
}
if err := util.HTTPResponse(w, http.StatusCreated, resp); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteUserTokenHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteUserTokenHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteUserTokenHandler {
return &DeleteUserTokenHandler{log: logger.Sugar(), ah: ah}
func NewDeleteUserTokenHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteUserTokenHandler {
return &DeleteUserTokenHandler{log: log, ah: ah}
}
func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -456,11 +456,11 @@ func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
err := h.ah.DeleteUserToken(ctx, userRef, tokenName)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -472,12 +472,12 @@ func userOrgsResponse(userOrg *action.UserOrgsResponse) *csapitypes.UserOrgsResp
}
type UserOrgsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUserOrgsHandler(logger *zap.Logger, ah *action.ActionHandler) *UserOrgsHandler {
return &UserOrgsHandler{log: logger.Sugar(), ah: ah}
func NewUserOrgsHandler(log zerolog.Logger, ah *action.ActionHandler) *UserOrgsHandler {
return &UserOrgsHandler{log: log, ah: ah}
}
func (h *UserOrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -487,7 +487,7 @@ func (h *UserOrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
userOrgs, err := h.ah.GetUserOrgs(ctx, userRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -497,6 +497,6 @@ func (h *UserOrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -26,17 +26,17 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type VariablesHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
readDB *readdb.ReadDB
}
func NewVariablesHandler(logger *zap.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *VariablesHandler {
return &VariablesHandler{log: logger.Sugar(), ah: ah, readDB: readDB}
func NewVariablesHandler(log zerolog.Logger, ah *action.ActionHandler, readDB *readdb.ReadDB) *VariablesHandler {
return &VariablesHandler{log: log, ah: ah, readDB: readDB}
}
func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -46,13 +46,13 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
variables, err := h.ah.GetVariables(ctx, parentType, parentRef, tree)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -72,30 +72,30 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, err)
return
}
if err := util.HTTPResponse(w, http.StatusOK, resVariables); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type CreateVariableHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateVariableHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateVariableHandler {
return &CreateVariableHandler{log: logger.Sugar(), ah: ah}
func NewCreateVariableHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateVariableHandler {
return &CreateVariableHandler{log: log, ah: ah}
}
func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -111,22 +111,22 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
variable, err = h.ah.CreateVariable(ctx, variable)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, variable); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateVariableHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateVariableHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateVariableHandler {
return &UpdateVariableHandler{log: logger.Sugar(), ah: ah}
func NewUpdateVariableHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateVariableHandler {
return &UpdateVariableHandler{log: log, ah: ah}
}
func (h *UpdateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -136,7 +136,7 @@ func (h *UpdateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -156,22 +156,22 @@ func (h *UpdateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
}
variable, err = h.ah.UpdateVariable(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusOK, variable); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteVariableHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteVariableHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteVariableHandler {
return &DeleteVariableHandler{log: logger.Sugar(), ah: ah}
func NewDeleteVariableHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteVariableHandler {
return &DeleteVariableHandler{log: log, ah: ah}
}
func (h *DeleteVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -181,15 +181,15 @@ func (h *DeleteVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
parentType, parentRef, err := GetConfigTypeRef(r)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
err = h.ah.DeleteVariable(ctx, parentType, parentRef, variableName)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -25,7 +25,6 @@ import (
scommon "agola.io/agola/internal/common"
"agola.io/agola/internal/datamanager"
"agola.io/agola/internal/etcd"
slog "agola.io/agola/internal/log"
"agola.io/agola/internal/objectstorage"
"agola.io/agola/internal/services/config"
action "agola.io/agola/internal/services/configstore/action"
@ -36,24 +35,20 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/gorilla/mux"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
etcdclientv3 "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/mvcc/mvccpb"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
errors "golang.org/x/xerrors"
)
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
var logger = slog.New(level)
var log = logger.Sugar()
func (s *Configstore) maintenanceModeWatcherLoop(ctx context.Context, runCtxCancel context.CancelFunc, maintenanceModeEnabled bool) {
for {
log.Debugf("maintenanceModeWatcherLoop")
log.Debug().Msgf("maintenanceModeWatcherLoop")
// at first watch restart from previous processed revision
if err := s.maintenanceModeWatcher(ctx, runCtxCancel, maintenanceModeEnabled); err != nil {
log.Errorf("err: %+v", err)
log.Err(err).Send()
}
sleepCh := time.NewTimer(1 * time.Second).C
@ -66,14 +61,14 @@ func (s *Configstore) maintenanceModeWatcherLoop(ctx context.Context, runCtxCanc
}
func (s *Configstore) maintenanceModeWatcher(ctx context.Context, runCtxCancel context.CancelFunc, maintenanceModeEnabled bool) error {
log.Infof("watcher: maintenance mode enabled: %t", maintenanceModeEnabled)
log.Info().Msgf("watcher: maintenance mode enabled: %t", maintenanceModeEnabled)
resp, err := s.e.Get(ctx, common.EtcdMaintenanceKey, 0)
if err != nil && !errors.Is(err, etcd.ErrKeyNotFound) {
return err
}
if len(resp.Kvs) > 0 {
log.Infof("maintenance mode key is present")
log.Info().Msgf("maintenance mode key is present")
if !maintenanceModeEnabled {
runCtxCancel()
}
@ -94,13 +89,13 @@ func (s *Configstore) maintenanceModeWatcher(ctx context.Context, runCtxCancel c
for _, ev := range wresp.Events {
switch ev.Type {
case mvccpb.PUT:
log.Infof("maintenance mode key set")
log.Info().Msgf("maintenance mode key set")
if !maintenanceModeEnabled {
runCtxCancel()
}
case mvccpb.DELETE:
log.Infof("maintenance mode key removed")
log.Info().Msgf("maintenance mode key removed")
if maintenanceModeEnabled {
runCtxCancel()
}
@ -112,6 +107,7 @@ func (s *Configstore) maintenanceModeWatcher(ctx context.Context, runCtxCancel c
}
type Configstore struct {
log zerolog.Logger
c *config.Configstore
e *etcd.Store
dm *datamanager.DataManager
@ -121,25 +117,22 @@ type Configstore struct {
maintenanceMode bool
}
func NewConfigstore(ctx context.Context, l *zap.Logger, c *config.Configstore) (*Configstore, error) {
if l != nil {
logger = l
}
func NewConfigstore(ctx context.Context, log zerolog.Logger, c *config.Configstore) (*Configstore, error) {
if c.Debug {
level.SetLevel(zapcore.DebugLevel)
log = log.Level(zerolog.DebugLevel)
}
log = logger.Sugar()
ost, err := scommon.NewObjectStorage(&c.ObjectStorage)
if err != nil {
return nil, err
}
e, err := scommon.NewEtcd(&c.Etcd, logger, "configstore")
e, err := scommon.NewEtcd(&c.Etcd, log, "configstore")
if err != nil {
return nil, err
}
cs := &Configstore{
log: log,
c: c,
e: e,
ost: ost,
@ -160,11 +153,11 @@ func NewConfigstore(ctx context.Context, l *zap.Logger, c *config.Configstore) (
string(types.ConfigTypeVariable),
},
}
dm, err := datamanager.NewDataManager(ctx, logger, dmConf)
dm, err := datamanager.NewDataManager(ctx, log, dmConf)
if err != nil {
return nil, err
}
readDB, err := readdb.NewReadDB(ctx, logger, filepath.Join(c.DataDir, "readdb"), e, ost, dm)
readDB, err := readdb.NewReadDB(ctx, log, filepath.Join(c.DataDir, "readdb"), e, ost, dm)
if err != nil {
return nil, err
}
@ -172,67 +165,67 @@ func NewConfigstore(ctx context.Context, l *zap.Logger, c *config.Configstore) (
cs.dm = dm
cs.readDB = readDB
ah := action.NewActionHandler(logger, readDB, dm, e)
ah := action.NewActionHandler(log, readDB, dm, e)
cs.ah = ah
return cs, nil
}
func (s *Configstore) setupDefaultRouter() http.Handler {
maintenanceModeHandler := api.NewMaintenanceModeHandler(logger, s.ah, s.e)
exportHandler := api.NewExportHandler(logger, s.ah)
maintenanceModeHandler := api.NewMaintenanceModeHandler(s.log, s.ah, s.e)
exportHandler := api.NewExportHandler(s.log, s.ah)
projectGroupHandler := api.NewProjectGroupHandler(logger, s.ah, s.readDB)
projectGroupSubgroupsHandler := api.NewProjectGroupSubgroupsHandler(logger, s.ah, s.readDB)
projectGroupProjectsHandler := api.NewProjectGroupProjectsHandler(logger, s.ah, s.readDB)
createProjectGroupHandler := api.NewCreateProjectGroupHandler(logger, s.ah, s.readDB)
updateProjectGroupHandler := api.NewUpdateProjectGroupHandler(logger, s.ah, s.readDB)
deleteProjectGroupHandler := api.NewDeleteProjectGroupHandler(logger, s.ah)
projectGroupHandler := api.NewProjectGroupHandler(s.log, s.ah, s.readDB)
projectGroupSubgroupsHandler := api.NewProjectGroupSubgroupsHandler(s.log, s.ah, s.readDB)
projectGroupProjectsHandler := api.NewProjectGroupProjectsHandler(s.log, s.ah, s.readDB)
createProjectGroupHandler := api.NewCreateProjectGroupHandler(s.log, s.ah, s.readDB)
updateProjectGroupHandler := api.NewUpdateProjectGroupHandler(s.log, s.ah, s.readDB)
deleteProjectGroupHandler := api.NewDeleteProjectGroupHandler(s.log, s.ah)
projectHandler := api.NewProjectHandler(logger, s.ah, s.readDB)
createProjectHandler := api.NewCreateProjectHandler(logger, s.ah, s.readDB)
updateProjectHandler := api.NewUpdateProjectHandler(logger, s.ah, s.readDB)
deleteProjectHandler := api.NewDeleteProjectHandler(logger, s.ah)
projectHandler := api.NewProjectHandler(s.log, s.ah, s.readDB)
createProjectHandler := api.NewCreateProjectHandler(s.log, s.ah, s.readDB)
updateProjectHandler := api.NewUpdateProjectHandler(s.log, s.ah, s.readDB)
deleteProjectHandler := api.NewDeleteProjectHandler(s.log, s.ah)
secretsHandler := api.NewSecretsHandler(logger, s.ah, s.readDB)
createSecretHandler := api.NewCreateSecretHandler(logger, s.ah)
updateSecretHandler := api.NewUpdateSecretHandler(logger, s.ah)
deleteSecretHandler := api.NewDeleteSecretHandler(logger, s.ah)
secretsHandler := api.NewSecretsHandler(s.log, s.ah, s.readDB)
createSecretHandler := api.NewCreateSecretHandler(s.log, s.ah)
updateSecretHandler := api.NewUpdateSecretHandler(s.log, s.ah)
deleteSecretHandler := api.NewDeleteSecretHandler(s.log, s.ah)
variablesHandler := api.NewVariablesHandler(logger, s.ah, s.readDB)
createVariableHandler := api.NewCreateVariableHandler(logger, s.ah)
updateVariableHandler := api.NewUpdateVariableHandler(logger, s.ah)
deleteVariableHandler := api.NewDeleteVariableHandler(logger, s.ah)
variablesHandler := api.NewVariablesHandler(s.log, s.ah, s.readDB)
createVariableHandler := api.NewCreateVariableHandler(s.log, s.ah)
updateVariableHandler := api.NewUpdateVariableHandler(s.log, s.ah)
deleteVariableHandler := api.NewDeleteVariableHandler(s.log, s.ah)
userHandler := api.NewUserHandler(logger, s.readDB)
usersHandler := api.NewUsersHandler(logger, s.readDB)
createUserHandler := api.NewCreateUserHandler(logger, s.ah)
updateUserHandler := api.NewUpdateUserHandler(logger, s.ah)
deleteUserHandler := api.NewDeleteUserHandler(logger, s.ah)
userHandler := api.NewUserHandler(s.log, s.readDB)
usersHandler := api.NewUsersHandler(s.log, s.readDB)
createUserHandler := api.NewCreateUserHandler(s.log, s.ah)
updateUserHandler := api.NewUpdateUserHandler(s.log, s.ah)
deleteUserHandler := api.NewDeleteUserHandler(s.log, s.ah)
createUserLAHandler := api.NewCreateUserLAHandler(logger, s.ah)
deleteUserLAHandler := api.NewDeleteUserLAHandler(logger, s.ah)
updateUserLAHandler := api.NewUpdateUserLAHandler(logger, s.ah)
createUserLAHandler := api.NewCreateUserLAHandler(s.log, s.ah)
deleteUserLAHandler := api.NewDeleteUserLAHandler(s.log, s.ah)
updateUserLAHandler := api.NewUpdateUserLAHandler(s.log, s.ah)
createUserTokenHandler := api.NewCreateUserTokenHandler(logger, s.ah)
deleteUserTokenHandler := api.NewDeleteUserTokenHandler(logger, s.ah)
createUserTokenHandler := api.NewCreateUserTokenHandler(s.log, s.ah)
deleteUserTokenHandler := api.NewDeleteUserTokenHandler(s.log, s.ah)
userOrgsHandler := api.NewUserOrgsHandler(logger, s.ah)
userOrgsHandler := api.NewUserOrgsHandler(s.log, s.ah)
orgHandler := api.NewOrgHandler(logger, s.readDB)
orgsHandler := api.NewOrgsHandler(logger, s.readDB)
createOrgHandler := api.NewCreateOrgHandler(logger, s.ah)
deleteOrgHandler := api.NewDeleteOrgHandler(logger, s.ah)
orgHandler := api.NewOrgHandler(s.log, s.readDB)
orgsHandler := api.NewOrgsHandler(s.log, s.readDB)
createOrgHandler := api.NewCreateOrgHandler(s.log, s.ah)
deleteOrgHandler := api.NewDeleteOrgHandler(s.log, s.ah)
orgMembersHandler := api.NewOrgMembersHandler(logger, s.ah)
addOrgMemberHandler := api.NewAddOrgMemberHandler(logger, s.ah)
removeOrgMemberHandler := api.NewRemoveOrgMemberHandler(logger, s.ah)
orgMembersHandler := api.NewOrgMembersHandler(s.log, s.ah)
addOrgMemberHandler := api.NewAddOrgMemberHandler(s.log, s.ah)
removeOrgMemberHandler := api.NewRemoveOrgMemberHandler(s.log, s.ah)
remoteSourceHandler := api.NewRemoteSourceHandler(logger, s.readDB)
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, s.readDB)
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, s.ah)
updateRemoteSourceHandler := api.NewUpdateRemoteSourceHandler(logger, s.ah)
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(logger, s.ah)
remoteSourceHandler := api.NewRemoteSourceHandler(s.log, s.readDB)
remoteSourcesHandler := api.NewRemoteSourcesHandler(s.log, s.readDB)
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(s.log, s.ah)
updateRemoteSourceHandler := api.NewUpdateRemoteSourceHandler(s.log, s.ah)
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(s.log, s.ah)
router := mux.NewRouter()
apirouter := router.PathPrefix("/api/v1alpha").Subrouter().UseEncodedPath()
@ -306,9 +299,9 @@ func (s *Configstore) setupDefaultRouter() http.Handler {
}
func (s *Configstore) setupMaintenanceRouter() http.Handler {
maintenanceModeHandler := api.NewMaintenanceModeHandler(logger, s.ah, s.e)
exportHandler := api.NewExportHandler(logger, s.ah)
importHandler := api.NewImportHandler(logger, s.ah)
maintenanceModeHandler := api.NewMaintenanceModeHandler(s.log, s.ah, s.e)
exportHandler := api.NewExportHandler(s.log, s.ah)
importHandler := api.NewImportHandler(s.log, s.ah)
router := mux.NewRouter()
apirouter := router.PathPrefix("/api/v1alpha").Subrouter().UseEncodedPath()
@ -327,13 +320,13 @@ func (s *Configstore) setupMaintenanceRouter() http.Handler {
func (s *Configstore) Run(ctx context.Context) error {
for {
if err := s.run(ctx); err != nil {
log.Errorf("run error: %+v", err)
log.Err(err).Msgf("run error")
}
sleepCh := time.NewTimer(1 * time.Second).C
select {
case <-ctx.Done():
log.Infof("configstore exiting")
s.log.Info().Msgf("configstore exiting")
return nil
case <-sleepCh:
}
@ -346,7 +339,7 @@ func (s *Configstore) run(ctx context.Context) error {
var err error
tlsConfig, err = util.NewTLSConfig(s.c.Web.TLSCertFile, s.c.Web.TLSKeyFile, "", false)
if err != nil {
log.Errorf("err: %+v")
s.log.Err(err).Send()
return err
}
}
@ -358,7 +351,7 @@ func (s *Configstore) run(ctx context.Context) error {
maintenanceMode := false
if len(resp.Kvs) > 0 {
log.Infof("maintenance mode key is present")
log.Info().Msgf("maintenance mode key is present")
maintenanceMode = true
}
@ -408,15 +401,15 @@ func (s *Configstore) run(ctx context.Context) error {
select {
case <-ctx.Done():
log.Infof("configstore run exiting")
log.Info().Msgf("configstore run exiting")
case err := <-lerrCh:
if err != nil {
log.Errorf("http server listen error: %+v", err)
log.Err(err).Msgf("http server listen error")
return err
}
case err := <-errCh:
if err != nil {
log.Errorf("error: %+v", err)
s.log.Err(err).Send()
return err
}
}

View File

@ -35,12 +35,11 @@ import (
"agola.io/agola/services/configstore/types"
"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"github.com/rs/zerolog"
)
func setupEtcd(t *testing.T, logger *zap.Logger, dir string) *testutil.TestEmbeddedEtcd {
tetcd, err := testutil.NewTestEmbeddedEtcd(t, logger, dir)
func setupEtcd(t *testing.T, log zerolog.Logger, dir string) *testutil.TestEmbeddedEtcd {
tetcd, err := testutil.NewTestEmbeddedEtcd(t, log, dir)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -59,12 +58,12 @@ func shutdownEtcd(tetcd *testutil.TestEmbeddedEtcd) {
}
}
func setupConfigstore(ctx context.Context, t *testing.T, logger *zap.Logger, dir string) (*Configstore, *testutil.TestEmbeddedEtcd) {
func setupConfigstore(ctx context.Context, t *testing.T, log zerolog.Logger, dir string) (*Configstore, *testutil.TestEmbeddedEtcd) {
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
listenAddress, port, err := testutil.GetFreePort(true, false)
if err != nil {
@ -94,7 +93,7 @@ func setupConfigstore(ctx context.Context, t *testing.T, logger *zap.Logger, dir
csConfig.DataDir = csDir
csConfig.Web.ListenAddress = net.JoinHostPort(listenAddress, port)
cs, err := NewConfigstore(ctx, logger, &csConfig)
cs, err := NewConfigstore(ctx, log, &csConfig)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -129,13 +128,13 @@ func TestResync(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
listenAddress1, port1, err := testutil.GetFreePort(true, false)
@ -188,11 +187,11 @@ func TestResync(t *testing.T) {
cs2Config.DataDir = csDir2
cs2Config.Web.ListenAddress = net.JoinHostPort(listenAddress2, port2)
cs1, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs1")), &cs1Config)
cs1, err := NewConfigstore(ctx, log.With().Str("name", "cs1").Logger(), &cs1Config)
if err != nil {
t.Fatalf("err: %v", err)
}
cs2, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs2")), &cs2Config)
cs2, err := NewConfigstore(ctx, log.With().Str("name", "cs2").Logger(), &cs2Config)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -217,7 +216,7 @@ func TestResync(t *testing.T) {
time.Sleep(5 * time.Second)
// stop cs2
log.Infof("stopping cs2")
log.Info().Msgf("stopping cs2")
cancel2()
// Do some more changes
@ -237,11 +236,11 @@ func TestResync(t *testing.T) {
// start cs2
// it should resync from wals since the etcd revision as been compacted
cs2, err = NewConfigstore(ctx, logger.With(zap.String("name", "cs2")), &cs2Config)
cs2, err = NewConfigstore(ctx, log.With().Str("name", "cs2").Logger(), &cs2Config)
if err != nil {
t.Fatalf("err: %v", err)
}
log.Infof("starting cs2")
log.Info().Msgf("starting cs2")
ctx2 = context.Background()
go func() { _ = cs2.Run(ctx2) }()
@ -274,11 +273,11 @@ func TestResync(t *testing.T) {
cs3Config.DataDir = csDir3
cs3Config.Web.ListenAddress = net.JoinHostPort(listenAddress3, port3)
cs3, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs3")), &cs3Config)
cs3, err := NewConfigstore(ctx, log.With().Str("name", "cs3").Logger(), &cs3Config)
if err != nil {
t.Fatalf("err: %v", err)
}
log.Infof("starting cs3")
log.Info().Msgf("starting cs3")
ctx3 := context.Background()
go func() { _ = cs3.Run(ctx3) }()
@ -305,13 +304,13 @@ func TestExportImport(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
etcdDir, err := ioutil.TempDir(dir, "etcd")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
tetcd := setupEtcd(t, logger, etcdDir)
tetcd := setupEtcd(t, log, etcdDir)
defer shutdownEtcd(tetcd)
listenAddress1, port1, err := testutil.GetFreePort(true, false)
@ -368,15 +367,15 @@ func TestExportImport(t *testing.T) {
cs3Config.DataDir = csDir3
cs3Config.Web.ListenAddress = net.JoinHostPort(listenAddress3, port3)
cs1, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs1")), &cs1Config)
cs1, err := NewConfigstore(ctx, log.With().Str("name", "cs1").Logger(), &cs1Config)
if err != nil {
t.Fatalf("err: %v", err)
}
cs2, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs2")), &cs2Config)
cs2, err := NewConfigstore(ctx, log.With().Str("name", "cs2").Logger(), &cs2Config)
if err != nil {
t.Fatalf("err: %v", err)
}
cs3, err := NewConfigstore(ctx, logger.With(zap.String("name", "cs3")), &cs3Config)
cs3, err := NewConfigstore(ctx, log.With().Str("name", "cs3").Logger(), &cs3Config)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -404,10 +403,10 @@ func TestExportImport(t *testing.T) {
time.Sleep(5 * time.Second)
// stop cs2
log.Infof("stopping cs2")
log.Info().Msgf("stopping cs2")
cancel2()
// stop cs3
log.Infof("stopping cs3")
log.Info().Msgf("stopping cs3")
cancel3()
// Do some more changes
@ -465,11 +464,11 @@ func TestExportImport(t *testing.T) {
// start cs2
// it should do a full resync since we have imported new data and there's now wal in etcd
cs2, err = NewConfigstore(ctx, logger.With(zap.String("name", "cs2")), &cs2Config)
cs2, err = NewConfigstore(ctx, log.With().Str("name", "cs2").Logger(), &cs2Config)
if err != nil {
t.Fatalf("err: %v", err)
}
log.Infof("starting cs2")
log.Info().Msgf("starting cs2")
ctx2 = context.Background()
go func() { _ = cs2.Run(ctx2) }()
@ -509,11 +508,11 @@ func TestExportImport(t *testing.T) {
// start cs3
// it should do a full resync since we have imported new data and there're some wals with a different epoch
cs3, err = NewConfigstore(ctx, logger.With(zap.String("name", "cs3")), &cs3Config)
cs3, err = NewConfigstore(ctx, log.With().Str("name", "cs3").Logger(), &cs3Config)
if err != nil {
t.Fatalf("err: %v", err)
}
log.Infof("starting cs3")
log.Info().Msgf("starting cs3")
ctx3 = context.Background()
go func() { _ = cs3.Run(ctx3) }()
@ -555,9 +554,9 @@ func TestUser(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -623,9 +622,9 @@ func TestProjectGroupsAndProjectsCreate(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -771,9 +770,9 @@ func TestProjectUpdate(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -848,9 +847,9 @@ func TestProjectGroupUpdate(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -999,9 +998,9 @@ func TestProjectGroupDelete(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -1056,9 +1055,9 @@ func TestProjectGroupDeleteDontSeeOldChildObjects(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -1192,9 +1191,9 @@ func TestOrgMembers(t *testing.T) {
defer os.RemoveAll(dir)
ctx := context.Background()
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")
@ -1282,7 +1281,7 @@ func TestRemoteSource(t *testing.T) {
}
defer os.RemoveAll(dir)
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
tests := []struct {
name string
@ -1432,7 +1431,7 @@ func TestRemoteSource(t *testing.T) {
}
ctx := context.Background()
cs, tetcd := setupConfigstore(ctx, t, logger, dir)
cs, tetcd := setupConfigstore(ctx, t, log, dir)
defer shutdownEtcd(tetcd)
t.Logf("starting cs")

View File

@ -40,7 +40,7 @@ func (r *ReadDB) insertOrg(tx *db.Tx, data []byte) error {
if err := json.Unmarshal(data, &org); err != nil {
return errors.Errorf("failed to unmarshal org: %w", err)
}
r.log.Debugf("inserting org: %s", util.Dump(org))
r.log.Debug().Msgf("inserting org: %s", util.Dump(org))
// poor man insert or update...
if err := r.deleteOrg(tx, org.ID); err != nil {
return err
@ -81,7 +81,7 @@ func (r *ReadDB) GetOrg(tx *db.Tx, orgRef string) (*types.Organization, error) {
func (r *ReadDB) GetOrgByID(tx *db.Tx, orgID string) (*types.Organization, error) {
q, args, err := orgSelect.Where(sq.Eq{"id": orgID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -101,7 +101,7 @@ func (r *ReadDB) GetOrgByID(tx *db.Tx, orgID string) (*types.Organization, error
func (r *ReadDB) GetOrgByName(tx *db.Tx, name string) (*types.Organization, error) {
q, args, err := orgSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -147,7 +147,7 @@ func (r *ReadDB) GetOrgs(tx *db.Tx, startOrgName string, limit int, asc bool) ([
s := getOrgsFilteredQuery(startOrgName, limit, asc)
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -209,7 +209,7 @@ func (r *ReadDB) insertOrgMember(tx *db.Tx, data []byte) error {
if err := json.Unmarshal(data, &orgmember); err != nil {
return errors.Errorf("failed to unmarshal orgmember: %w", err)
}
r.log.Debugf("inserting orgmember: %s", util.Dump(orgmember))
r.log.Debug().Msgf("inserting orgmember: %s", util.Dump(orgmember))
// poor man insert or update...
if err := r.deleteOrgMember(tx, orgmember.ID); err != nil {
return err
@ -234,7 +234,7 @@ func (r *ReadDB) deleteOrgMember(tx *db.Tx, orgmemberID string) error {
func (r *ReadDB) GetOrgMemberByOrgUserID(tx *db.Tx, orgID, userID string) (*types.OrganizationMember, error) {
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.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -307,7 +307,7 @@ func (r *ReadDB) GetOrgUsers(tx *db.Tx, orgID string) ([]*OrgUser, error) {
s = s.Join("user on user.id = orgmember.userid")
s = s.OrderBy("user.name")
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -358,7 +358,7 @@ func (r *ReadDB) GetUserOrgs(tx *db.Tx, userID string) ([]*UserOrg, error) {
s = s.Join("org on org.id = orgmember.orgid")
s = s.OrderBy("org.name")
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -109,7 +109,7 @@ func (r *ReadDB) GetProject(tx *db.Tx, projectRef string) (*types.Project, error
func (r *ReadDB) GetProjectByID(tx *db.Tx, projectID string) (*types.Project, error) {
q, args, err := projectSelect.Where(sq.Eq{"id": projectID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -129,7 +129,7 @@ func (r *ReadDB) GetProjectByID(tx *db.Tx, projectID string) (*types.Project, er
func (r *ReadDB) GetProjectByName(tx *db.Tx, parentID, name string) (*types.Project, error) {
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.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -173,7 +173,7 @@ func (r *ReadDB) GetProjectGroupProjects(tx *db.Tx, parentID string) ([]*types.P
var projects []*types.Project
q, args, err := projectSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -231,7 +231,7 @@ func (r *ReadDB) GetAllProjects(tx *db.Tx) ([]*types.Project, error) {
var projects []*types.Project
q, args, err := projectSelect.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -166,7 +166,7 @@ func (r *ReadDB) GetProjectGroup(tx *db.Tx, projectGroupRef string) (*types.Proj
func (r *ReadDB) GetProjectGroupByID(tx *db.Tx, projectGroupID string) (*types.ProjectGroup, error) {
q, args, err := projectgroupSelect.Where(sq.Eq{"id": projectGroupID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -186,7 +186,7 @@ func (r *ReadDB) GetProjectGroupByID(tx *db.Tx, projectGroupID string) (*types.P
func (r *ReadDB) GetProjectGroupByName(tx *db.Tx, parentID, name string) (*types.ProjectGroup, error) {
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.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -254,7 +254,7 @@ func (r *ReadDB) GetProjectGroupSubgroups(tx *db.Tx, parentID string) ([]*types.
var projectGroups []*types.ProjectGroup
q, args, err := projectgroupSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -33,7 +33,7 @@ import (
"agola.io/agola/services/configstore/types"
sq "github.com/Masterminds/squirrel"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -52,7 +52,7 @@ var (
)
type ReadDB struct {
log *zap.SugaredLogger
log zerolog.Logger
dataDir string
e *etcd.Store
rdb *db.DB
@ -63,13 +63,13 @@ type ReadDB struct {
initLock sync.Mutex
}
func NewReadDB(ctx context.Context, logger *zap.Logger, dataDir string, e *etcd.Store, ost *objectstorage.ObjStorage, dm *datamanager.DataManager) (*ReadDB, error) {
func NewReadDB(ctx context.Context, log zerolog.Logger, dataDir string, e *etcd.Store, ost *objectstorage.ObjStorage, dm *datamanager.DataManager) (*ReadDB, error) {
if err := os.MkdirAll(dataDir, 0770); err != nil {
return nil, err
}
readDB := &ReadDB{
log: logger.Sugar(),
log: log,
dataDir: dataDir,
e: e,
ost: ost,
@ -264,14 +264,14 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
doFullSync := false
if curWalSeq == "" {
doFullSync = true
r.log.Warn("no startWalSeq in db, doing a full sync")
r.log.Warn().Msgf("no startWalSeq in db, doing a full sync")
} else {
ok, err := r.dm.HasOSTWal(curWalSeq)
if err != nil {
return err
}
if !ok {
r.log.Warnf("no wal with seq %q in objectstorage, doing a full sync", curWalSeq)
r.log.Warn().Msgf("no wal with seq %q in objectstorage, doing a full sync", curWalSeq)
doFullSync = true
}
@ -291,13 +291,13 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
return err
}
if curWalEpoch != lastCommittedStorageWalSequence.Epoch {
r.log.Warnf("current rdb wal sequence epoch %d different than new wal sequence epoch %d, doing a full sync", curWalEpoch, lastCommittedStorageWalSequence.Epoch)
r.log.Warn().Msgf("current rdb wal sequence epoch %d different than new wal sequence epoch %d, doing a full sync", curWalEpoch, lastCommittedStorageWalSequence.Epoch)
doFullSync = true
}
}
if doFullSync {
r.log.Infof("doing a full sync from dump")
r.log.Info().Msgf("doing a full sync from dump")
if err := r.ResetDB(ctx); err != nil {
return err
}
@ -309,7 +309,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
}
}
r.log.Debugf("startWalSeq: %s", curWalSeq)
r.log.Debug().Msgf("startWalSeq: %s", curWalSeq)
// Sync from wals
// sync from objectstorage until the current known lastCommittedStorageWal in
@ -329,8 +329,8 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
if err != nil {
return errors.Errorf("failed to get first available wal data: %w", err)
}
r.log.Debugf("firstAvailableWalData: %s", util.Dump(firstAvailableWalData))
r.log.Debugf("revision: %d", revision)
r.log.Debug().Msgf("firstAvailableWalData: %s", util.Dump(firstAvailableWalData))
r.log.Debug().Msgf("revision: %d", revision)
if firstAvailableWalData == nil {
return errors.Errorf("no wal data in etcd")
}
@ -338,7 +338,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
return errors.Errorf("current applied wal seq %q is smaller than the first available wal in etcd %q", curWalSeq, firstAvailableWalData.WalSequence)
}
r.log.Infof("syncing from wals")
r.log.Info().Msgf("syncing from wals")
err = r.rdb.Do(ctx, func(tx *db.Tx) error {
if err := r.insertRevision(tx, revision); err != nil {
return err
@ -362,7 +362,7 @@ func (r *ReadDB) SyncRDB(ctx context.Context) error {
return err
}
r.log.Debugf("applying wal to db")
r.log.Debug().Msgf("applying wal to db")
if err := r.applyWal(tx, walElement.WalData.WalDataFileID); err != nil {
return err
}
@ -412,7 +412,7 @@ func (r *ReadDB) Run(ctx context.Context) error {
if err == nil {
break
}
r.log.Errorf("initialize err: %+v", err)
r.log.Err(err).Msgf("initialize err")
sleepCh := time.NewTimer(1 * time.Second).C
select {
@ -435,7 +435,7 @@ func (r *ReadDB) Run(ctx context.Context) error {
r.SetInitialized(true)
break
}
r.log.Errorf("initialize err: %+v", err)
r.log.Err(err).Msgf("initialize err")
sleepCh := time.NewTimer(1 * time.Second).C
select {
@ -452,9 +452,9 @@ func (r *ReadDB) Run(ctx context.Context) error {
wg.Add(1)
go func() {
r.log.Infof("starting handleEvents")
r.log.Info().Msgf("starting handleEvents")
if err := r.handleEvents(hctx); err != nil {
r.log.Errorf("handleEvents err: %+v", err)
r.log.Err(err).Msgf("handleEvents err")
}
wg.Done()
doneCh <- struct{}{}
@ -462,7 +462,7 @@ func (r *ReadDB) Run(ctx context.Context) error {
select {
case <-ctx.Done():
r.log.Infof("readdb exiting")
r.log.Info().Msgf("readdb exiting")
cancel()
return nil
case <-doneCh:
@ -502,14 +502,14 @@ func (r *ReadDB) handleEvents(ctx context.Context) error {
wctx, cancel := context.WithCancel(ctx)
defer cancel()
r.log.Debugf("revision: %d", revision)
r.log.Debug().Msgf("revision: %d", revision)
wch := r.dm.Watch(wctx, revision+1)
for we := range wch {
r.log.Debugf("we: %s", util.Dump(we))
r.log.Debug().Msgf("we: %s", util.Dump(we))
if we.Err != nil {
err := we.Err
if errors.Is(err, datamanager.ErrCompacted) {
r.log.Warnf("required events already compacted, reinitializing readdb")
r.log.Warn().Msgf("required events already compacted, reinitializing readdb")
r.Initialized = false
return nil
}
@ -529,7 +529,7 @@ func (r *ReadDB) handleEvents(ctx context.Context) error {
if err != nil {
return err
}
r.log.Debugf("curWalSeq: %q", curWalSeq)
r.log.Debug().Msgf("curWalSeq: %q", curWalSeq)
if curWalSeq != "" && we.WalData != nil {
curWalSequence, err := sequence.Parse(curWalSeq)
if err != nil {
@ -541,7 +541,7 @@ func (r *ReadDB) handleEvents(ctx context.Context) error {
if err != nil {
return err
}
r.log.Debugf("we.WalData.WalSequence: %q", we.WalData.WalSequence)
r.log.Debug().Msgf("we.WalData.WalSequence: %q", we.WalData.WalSequence)
weWalEpoch := weWalSequence.Epoch
if curWalEpoch != weWalEpoch {
r.Initialized = false
@ -562,13 +562,13 @@ func (r *ReadDB) handleEvents(ctx context.Context) error {
return err
}
}
r.log.Infof("wch closed")
r.log.Info().Msgf("wch closed")
return nil
}
func (r *ReadDB) handleEvent(tx *db.Tx, we *datamanager.WatchElement) error {
//r.log.Debugf("event: %s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value)
//r.log.Debug().Msgf("event: %s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value)
//key := string(ev.Kv.Key)
if err := r.handleWalEvent(tx, we); err != nil {
@ -594,7 +594,7 @@ func (r *ReadDB) handleWalEvent(tx *db.Tx, we *datamanager.WatchElement) error {
return err
}
r.log.Debugf("applying wal to db")
r.log.Debug().Msgf("applying wal to db")
return r.applyWal(tx, we.WalData.WalDataFileID)
}
return nil
@ -669,42 +669,42 @@ func (r *ReadDB) applyAction(tx *db.Tx, action *datamanager.Action) error {
case datamanager.ActionTypeDelete:
switch types.ConfigType(action.DataType) {
case types.ConfigTypeUser:
r.log.Debugf("deleting user with id: %s", action.ID)
r.log.Debug().Msgf("deleting user with id: %s", action.ID)
if err := r.deleteUser(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeOrg:
r.log.Debugf("deleting org with id: %s", action.ID)
r.log.Debug().Msgf("deleting org with id: %s", action.ID)
if err := r.deleteOrg(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeOrgMember:
r.log.Debugf("deleting orgmember with id: %s", action.ID)
r.log.Debug().Msgf("deleting orgmember with id: %s", action.ID)
if err := r.deleteOrgMember(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeProjectGroup:
r.log.Debugf("deleting project group with id: %s", action.ID)
r.log.Debug().Msgf("deleting project group with id: %s", action.ID)
if err := r.deleteProjectGroup(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeProject:
r.log.Debugf("deleting project with id: %s", action.ID)
r.log.Debug().Msgf("deleting project with id: %s", action.ID)
if err := r.deleteProject(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeRemoteSource:
r.log.Debugf("deleting remote source with id: %s", action.ID)
r.log.Debug().Msgf("deleting remote source with id: %s", action.ID)
if err := r.deleteRemoteSource(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeSecret:
r.log.Debugf("deleting secret with id: %s", action.ID)
r.log.Debug().Msgf("deleting secret with id: %s", action.ID)
if err := r.deleteSecret(tx, action.ID); err != nil {
return err
}
case types.ConfigTypeVariable:
r.log.Debugf("deleting variable with id: %s", action.ID)
r.log.Debug().Msgf("deleting variable with id: %s", action.ID)
if err := r.deleteVariable(tx, action.ID); err != nil {
return err
}
@ -749,7 +749,7 @@ func (r *ReadDB) getRevision(tx *db.Tx) (int64, error) {
var revision int64
q, args, err := revisionSelect.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return 0, errors.Errorf("failed to build query: %w", err)
}
@ -762,7 +762,7 @@ func (r *ReadDB) getRevision(tx *db.Tx) (int64, error) {
}
func (r *ReadDB) insertCommittedWalSequence(tx *db.Tx, seq string) error {
r.log.Debugf("insert seq: %s", seq)
r.log.Debug().Msgf("insert seq: %s", seq)
// poor man insert or update that works because transaction isolation level is serializable
if _, err := tx.Exec("delete from committedwalsequence"); err != nil {
return errors.Errorf("failed to delete committedwalsequence: %w", err)
@ -781,7 +781,7 @@ func (r *ReadDB) GetCommittedWalSequence(tx *db.Tx) (string, error) {
var seq string
q, args, err := committedwalsequenceSelect.OrderBy("seq").Limit(1).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return "", errors.Errorf("failed to build query: %w", err)
}
@ -794,7 +794,7 @@ func (r *ReadDB) GetCommittedWalSequence(tx *db.Tx) (string, error) {
}
func (r *ReadDB) insertChangeGroupRevision(tx *db.Tx, changegroup string, revision int64) error {
r.log.Debugf("insertChangeGroupRevision: %s %d", changegroup, revision)
r.log.Debug().Msgf("insertChangeGroupRevision: %s %d", changegroup, revision)
// 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 {
@ -816,7 +816,7 @@ func (r *ReadDB) insertChangeGroupRevision(tx *db.Tx, changegroup string, revisi
func (r *ReadDB) GetChangeGroupsUpdateTokens(tx *db.Tx, groups []string) (*datamanager.ChangeGroupsUpdateToken, error) {
s := changegrouprevisionSelect.Where(sq.Eq{"id": groups})
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -79,7 +79,7 @@ func (r *ReadDB) GetRemoteSource(tx *db.Tx, rsRef string) (*types.RemoteSource,
func (r *ReadDB) GetRemoteSourceByID(tx *db.Tx, remoteSourceID string) (*types.RemoteSource, error) {
q, args, err := remotesourceSelect.Where(sq.Eq{"id": remoteSourceID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -99,7 +99,7 @@ func (r *ReadDB) GetRemoteSourceByID(tx *db.Tx, remoteSourceID string) (*types.R
func (r *ReadDB) GetRemoteSourceByName(tx *db.Tx, name string) (*types.RemoteSource, error) {
q, args, err := remotesourceSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -145,7 +145,7 @@ func (r *ReadDB) GetRemoteSources(ctx context.Context, startRemoteSourceName str
s := getRemoteSourcesFilteredQuery(startRemoteSourceName, limit, asc)
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -61,7 +61,7 @@ func (r *ReadDB) deleteSecret(tx *db.Tx, id string) error {
func (r *ReadDB) GetSecretByID(tx *db.Tx, secretID string) (*types.Secret, error) {
q, args, err := secretSelect.Where(sq.Eq{"id": secretID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -81,7 +81,7 @@ func (r *ReadDB) GetSecretByID(tx *db.Tx, secretID string) (*types.Secret, error
func (r *ReadDB) GetSecretByName(tx *db.Tx, parentID, name string) (*types.Secret, error) {
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.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -101,7 +101,7 @@ func (r *ReadDB) GetSecretByName(tx *db.Tx, parentID, name string) (*types.Secre
func (r *ReadDB) GetSecrets(tx *db.Tx, parentID string) ([]*types.Secret, error) {
q, args, err := secretSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -46,7 +46,7 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
if err := json.Unmarshal(data, &user); err != nil {
return errors.Errorf("failed to unmarshal user: %w", err)
}
r.log.Debugf("inserting user: %s", util.Dump(user))
r.log.Debug().Msgf("inserting user: %s", util.Dump(user))
// poor man insert or update...
if err := r.deleteUser(tx, user.ID); err != nil {
return err
@ -74,7 +74,7 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
}
// insert user_token
for _, tokenValue := range user.Tokens {
r.log.Debugf("inserting user token: %s", tokenValue)
r.log.Debug().Msgf("inserting user token: %s", tokenValue)
if err := r.deleteUserToken(tx, tokenValue); err != nil {
return err
}
@ -157,7 +157,7 @@ func (r *ReadDB) GetUser(tx *db.Tx, userRef string) (*types.User, error) {
func (r *ReadDB) GetUserByID(tx *db.Tx, userID string) (*types.User, error) {
q, args, err := userSelect.Where(sq.Eq{"id": userID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -177,7 +177,7 @@ func (r *ReadDB) GetUserByID(tx *db.Tx, userID string) (*types.User, error) {
func (r *ReadDB) GetUserByName(tx *db.Tx, name string) (*types.User, error) {
q, args, err := userSelect.Where(sq.Eq{"name": name}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -200,7 +200,7 @@ func (r *ReadDB) GetUserByTokenValue(tx *db.Tx, tokenValue string) (*types.User,
s = s.Join("user_token on user_token.userid = user.id")
s = s.Where(sq.Eq{"user_token.tokenvalue": tokenValue})
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -223,7 +223,7 @@ func (r *ReadDB) GetUserByLinkedAccount(tx *db.Tx, linkedAccountID string) (*typ
s = s.Join("linkedaccount_user as lau on lau.userid = user.id")
s = s.Where(sq.Eq{"lau.id": linkedAccountID})
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -246,7 +246,7 @@ func (r *ReadDB) GetUserByLinkedAccountRemoteUserIDandSource(tx *db.Tx, remoteUs
s = s.Join("linkedaccount_user as lau on lau.userid = user.id")
s = s.Where(sq.Eq{"lau.remoteuserid": remoteUserID, "lau.remotesourceid": remoteSourceID})
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -292,7 +292,7 @@ func (r *ReadDB) GetUsers(tx *db.Tx, startUserName string, limit int, asc bool)
s := getUsersFilteredQuery(startUserName, limit, asc)
q, args, err := s.ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -61,7 +61,7 @@ func (r *ReadDB) deleteVariable(tx *db.Tx, id string) error {
func (r *ReadDB) GetVariableByID(tx *db.Tx, variableID string) (*types.Variable, error) {
q, args, err := variableSelect.Where(sq.Eq{"id": variableID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -81,7 +81,7 @@ func (r *ReadDB) GetVariableByID(tx *db.Tx, variableID string) (*types.Variable,
func (r *ReadDB) GetVariableByName(tx *db.Tx, parentID, name string) (*types.Variable, error) {
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.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}
@ -101,7 +101,7 @@ func (r *ReadDB) GetVariableByName(tx *db.Tx, parentID, name string) (*types.Var
func (r *ReadDB) GetVariables(tx *db.Tx, parentID string) ([]*types.Variable, error) {
q, args, err := variableSelect.Where(sq.Eq{"parentid": parentID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
r.log.Debug().Msgf("q: %s, args: %s", q, util.Dump(args))
if err != nil {
return nil, errors.Errorf("failed to build query: %w", err)
}

View File

@ -24,7 +24,7 @@ import (
"time"
"agola.io/agola/services/runservice/types"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
)
@ -49,13 +49,13 @@ func (h *taskSubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
}
type logsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
e *Executor
}
func NewLogsHandler(logger *zap.Logger, e *Executor) *logsHandler {
func NewLogsHandler(log zerolog.Logger, e *Executor) *logsHandler {
return &logsHandler{
log: logger.Sugar(),
log: log,
e: e,
}
}
@ -97,7 +97,7 @@ func (h *logsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if err := h.readTaskLogs(taskID, setup, step, w, follow); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -40,11 +40,11 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/stdcopy"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type DockerDriver struct {
log *zap.SugaredLogger
log zerolog.Logger
client *client.Client
toolboxPath string
initImage string
@ -53,14 +53,14 @@ type DockerDriver struct {
arch types.Arch
}
func NewDockerDriver(logger *zap.Logger, executorID, toolboxPath, initImage string, initDockerConfig *registry.DockerConfig) (*DockerDriver, error) {
func NewDockerDriver(log zerolog.Logger, executorID, toolboxPath, initImage string, initDockerConfig *registry.DockerConfig) (*DockerDriver, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.26"))
if err != nil {
return nil, err
}
return &DockerDriver{
log: logger.Sugar(),
log: log,
client: cli,
toolboxPath: toolboxPath,
initImage: initImage,

View File

@ -27,8 +27,6 @@ import (
"github.com/docker/docker/api/types"
"github.com/gofrs/uuid"
"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)
func TestDockerPod(t *testing.T) {
@ -40,11 +38,11 @@ func TestDockerPod(t *testing.T) {
t.Fatalf("env var AGOLA_TOOLBOX_PATH is undefined")
}
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
initImage := "busybox:stable"
d, err := NewDockerDriver(logger, "executorid01", toolboxPath, initImage, nil)
d, err := NewDockerDriver(log, "executorid01", toolboxPath, initImage, nil)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

View File

@ -32,7 +32,7 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/gofrs/uuid"
"go.uber.org/zap"
"github.com/rs/zerolog"
errors "golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@ -71,7 +71,7 @@ const (
)
type K8sDriver struct {
log *zap.SugaredLogger
log zerolog.Logger
restconfig *restclient.Config
client *kubernetes.Clientset
toolboxPath string
@ -98,7 +98,7 @@ type K8sPod struct {
initVolumeDir string
}
func NewK8sDriver(logger *zap.Logger, executorID, toolboxPath, initImage string, initDockerConfig *registry.DockerConfig) (*K8sDriver, error) {
func NewK8sDriver(log zerolog.Logger, executorID, toolboxPath, initImage string, initDockerConfig *registry.DockerConfig) (*K8sDriver, error) {
kubeClientConfig := NewKubeClientConfig("", "", "")
kubecfg, err := kubeClientConfig.ClientConfig()
if err != nil {
@ -115,7 +115,7 @@ func NewK8sDriver(logger *zap.Logger, executorID, toolboxPath, initImage string,
}
d := &K8sDriver{
log: logger.Sugar(),
log: log,
restconfig: kubecfg,
client: kubecli,
toolboxPath: toolboxPath,
@ -133,7 +133,7 @@ func NewK8sDriver(logger *zap.Logger, executorID, toolboxPath, initImage string,
sv, err := parseGitVersion(serverVersion.GitVersion)
// if server version parsing fails just warn but ignore it
if err != nil {
d.log.Warnf("failed to parse k8s server version: %w", err)
d.log.Warn().Err(err).Msgf("failed to parse k8s server version")
}
if sv != nil {
// for k8s version < v1.14.x use old arch label
@ -194,7 +194,7 @@ func NewK8sDriver(logger *zap.Logger, executorID, toolboxPath, initImage string,
go func() {
for {
if err := d.updateLease(ctx); err != nil {
d.log.Errorf("failed to update executor lease: %+v", err)
d.log.Err(err).Msgf("failed to update executor lease")
}
select {
@ -210,7 +210,7 @@ func NewK8sDriver(logger *zap.Logger, executorID, toolboxPath, initImage string,
go func() {
for {
if err := d.cleanStaleExecutorsLease(ctx); err != nil {
d.log.Errorf("failed to clean stale executors lease: %+v", err)
d.log.Err(err).Msgf("failed to clean stale executors lease")
}
select {

View File

@ -26,8 +26,6 @@ import (
"agola.io/agola/internal/testutil"
"github.com/gofrs/uuid"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)
func TestK8sPod(t *testing.T) {
@ -39,11 +37,11 @@ func TestK8sPod(t *testing.T) {
t.Fatalf("env var AGOLA_TOOLBOX_PATH is undefined")
}
logger := zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))
log := testutil.NewLogger(t)
initImage := "busybox:stable"
d, err := NewK8sDriver(logger, "executorid01", toolboxPath, initImage, nil)
d, err := NewK8sDriver(log, "executorid01", toolboxPath, initImage, nil)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

View File

@ -181,7 +181,7 @@ func (d *K8sDriver) cleanStaleExecutorsLease(ctx context.Context) error {
}
for _, lease := range leases {
if lease.Spec.HolderIdentity == nil {
d.log.Warnf("missing holder identity for lease %q", lease.Name)
d.log.Warn().Msgf("missing holder identity for lease %q", lease.Name)
continue
}
// skip our lease
@ -189,13 +189,13 @@ func (d *K8sDriver) cleanStaleExecutorsLease(ctx context.Context) error {
continue
}
if lease.Spec.RenewTime == nil {
d.log.Warnf("missing renew time for lease %q", lease.Name)
d.log.Warn().Msgf("missing renew time for lease %q", lease.Name)
continue
}
if lease.Spec.RenewTime.Add(staleExecutorLeaseInterval).Before(time.Now()) {
d.log.Infof("deleting stale lease %q", lease.Name)
d.log.Info().Msgf("deleting stale lease %q", lease.Name)
if err := leaseClient.Delete(lease.Name, nil); err != nil {
d.log.Errorf("failed to delete stale lease %q, err: %v", lease.Name, err)
d.log.Err(err).Msgf("failed to delete stale lease %q", lease.Name)
}
}
}
@ -210,7 +210,7 @@ func (d *K8sDriver) cleanStaleExecutorsLease(ctx context.Context) error {
var ld *LeaseData
if cm.Annotations == nil {
// this shouldn't happen
d.log.Warnf("missing configmap lease annotations for configmap %q", cm.Name)
d.log.Warn().Msgf("missing configmap lease annotations for configmap %q", cm.Name)
continue
}
if recordBytes, found := cm.Annotations[cmLeaseKey]; found {
@ -223,9 +223,9 @@ func (d *K8sDriver) cleanStaleExecutorsLease(ctx context.Context) error {
continue
}
if ld.RenewTime.Add(staleExecutorLeaseInterval).Before(time.Now()) {
d.log.Infof("deleting stale configmap lease %q", cm.Name)
d.log.Info().Msgf("deleting stale configmap lease %q", cm.Name)
if err := cmClient.Delete(cm.Name, nil); err != nil {
d.log.Errorf("failed to delete stale configmap lease %q, err: %v", cm.Name, err)
d.log.Err(err).Msgf("failed to delete stale configmap lease %q", cm.Name)
}
}
}

View File

@ -31,7 +31,6 @@ import (
"time"
"agola.io/agola/internal/common"
slog "agola.io/agola/internal/log"
"agola.io/agola/internal/services/config"
"agola.io/agola/internal/services/executor/driver"
"agola.io/agola/internal/services/executor/registry"
@ -42,15 +41,11 @@ import (
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
sockaddr "github.com/hashicorp/go-sockaddr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
errors "golang.org/x/xerrors"
)
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
var logger = slog.New(level)
var log = logger.Sugar()
const (
defaultShell = "/bin/sh -e"
@ -433,7 +428,7 @@ func (e *Executor) doRestoreWorkspaceStep(ctx context.Context, s *types.RestoreW
defer logf.Close()
for _, op := range t.Spec.WorkspaceOperations {
log.Debugf("unarchiving workspace for taskID: %s, step: %d", level, op.TaskID, op.Step)
e.log.Debug().Msgf("unarchiving workspace for taskID: %s, step: %d", op.TaskID, op.Step)
resp, err := e.runserviceClient.GetArchive(ctx, op.TaskID, op.Step)
if err != nil {
// TODO(sgotti) retry before giving up
@ -713,13 +708,13 @@ func (e *Executor) sendExecutorStatus(ctx context.Context) error {
SiblingsExecutors: siblingsExecutors,
}
log.Debugf("send executor status: %s", util.Dump(executor))
e.log.Debug().Msgf("send executor status: %s", util.Dump(executor))
_, err = e.runserviceClient.SendExecutorStatus(ctx, executor)
return err
}
func (e *Executor) sendExecutorTaskStatus(ctx context.Context, et *types.ExecutorTask) error {
log.Debugf("send executor task: %s. status: %s", et.ID, et.Status.Phase)
e.log.Debug().Msgf("send executor task: %s. status: %s", et.ID, et.Status.Phase)
_, err := e.runserviceClient.SendExecutorTaskStatus(ctx, e.id, et)
return err
}
@ -740,7 +735,7 @@ func (e *Executor) executeTask(rt *runningTask) {
<-ctx.Done()
if rt.pod != nil {
if err := rt.pod.Stop(context.Background()); err != nil {
log.Errorf("error stopping the pod: %+v", err)
log.Err(err).Msgf("error stopping the pod: %+v", err)
}
}
}()
@ -758,17 +753,17 @@ func (e *Executor) executeTask(rt *runningTask) {
et.Status.SetupStep.Phase = types.ExecutorTaskPhaseRunning
et.Status.SetupStep.StartTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
if err := e.setupTask(ctx, rt); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
et.Status.Phase = types.ExecutorTaskPhaseFailed
et.Status.EndTime = util.TimeP(time.Now())
et.Status.SetupStep.Phase = types.ExecutorTaskPhaseFailed
et.Status.SetupStep.EndTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
rt.Unlock()
return
@ -777,7 +772,7 @@ func (e *Executor) executeTask(rt *runningTask) {
et.Status.SetupStep.Phase = types.ExecutorTaskPhaseSuccess
et.Status.SetupStep.EndTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
rt.Unlock()
@ -786,7 +781,7 @@ func (e *Executor) executeTask(rt *runningTask) {
rt.Lock()
if err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
if rt.et.Spec.Stop {
et.Status.Phase = types.ExecutorTaskPhaseStopped
} else {
@ -799,7 +794,7 @@ func (e *Executor) executeTask(rt *runningTask) {
et.Status.EndTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
rt.Unlock()
}
@ -836,7 +831,7 @@ func (e *Executor) setupTask(ctx context.Context, rt *runningTask) error {
return errors.Errorf("executor doesn't allow executing privileged containers")
}
log.Debugf("starting pod")
e.log.Debug().Msgf("starting pod")
dockerConfig, err := registry.GenDockerConfig(et.Spec.DockerRegistriesAuth, []string{et.Spec.Containers[0].Image})
if err != nil {
@ -911,7 +906,7 @@ func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod dr
rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseRunning
rt.et.Status.Steps[i].StartTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, rt.et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
rt.Unlock()
@ -921,29 +916,29 @@ func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod dr
switch s := step.(type) {
case *types.RunStep:
log.Debugf("run step: %s", util.Dump(s))
e.log.Debug().Msgf("run step: %s", util.Dump(s))
stepName = s.Name
exitCode, err = e.doRunStep(ctx, s, rt.et, pod, e.stepLogPath(rt.et.ID, i))
case *types.SaveToWorkspaceStep:
log.Debugf("save to workspace step: %s", util.Dump(s))
e.log.Debug().Msgf("save to workspace step: %s", util.Dump(s))
stepName = s.Name
archivePath := e.archivePath(rt.et.ID, i)
exitCode, err = e.doSaveToWorkspaceStep(ctx, s, rt.et, pod, e.stepLogPath(rt.et.ID, i), archivePath)
case *types.RestoreWorkspaceStep:
log.Debugf("restore workspace step: %s", util.Dump(s))
e.log.Debug().Msgf("restore workspace step: %s", util.Dump(s))
stepName = s.Name
exitCode, err = e.doRestoreWorkspaceStep(ctx, s, rt.et, pod, e.stepLogPath(rt.et.ID, i))
case *types.SaveCacheStep:
log.Debugf("save cache step: %s", util.Dump(s))
e.log.Debug().Msgf("save cache step: %s", util.Dump(s))
stepName = s.Name
archivePath := e.archivePath(rt.et.ID, i)
exitCode, err = e.doSaveCacheStep(ctx, s, rt.et, pod, e.stepLogPath(rt.et.ID, i), archivePath)
case *types.RestoreCacheStep:
log.Debugf("restore cache step: %s", util.Dump(s))
e.log.Debug().Msgf("restore cache step: %s", util.Dump(s))
stepName = s.Name
exitCode, err = e.doRestoreCacheStep(ctx, s, rt.et, pod, e.stepLogPath(rt.et.ID, i))
@ -978,7 +973,7 @@ func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod dr
}
if err := e.sendExecutorTaskStatus(ctx, rt.et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
rt.Unlock()
@ -992,10 +987,10 @@ func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod dr
func (e *Executor) podsCleanerLoop(ctx context.Context) {
for {
log.Debugf("podsCleaner")
e.log.Debug().Msgf("podsCleaner")
if err := e.podsCleaner(ctx); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
sleepCh := time.NewTimer(1 * time.Second).C
@ -1024,7 +1019,7 @@ func (e *Executor) podsCleaner(ctx context.Context) error {
// clean our owned pods
if pod.ExecutorID() == e.id {
if _, ok := e.runningTasks.get(taskID); !ok {
log.Infof("removing pod %s for not running task: %s", pod.ID(), taskID)
e.log.Info().Msgf("removing pod %s for not running task: %s", pod.ID(), taskID)
_ = pod.Remove(ctx)
}
}
@ -1038,7 +1033,7 @@ func (e *Executor) podsCleaner(ctx context.Context) error {
}
}
if !owned {
log.Infof("removing pod %s since it's not owned by any active executor", pod.ID())
e.log.Info().Msgf("removing pod %s since it's not owned by any active executor", pod.ID())
_ = pod.Remove(ctx)
}
}
@ -1048,10 +1043,10 @@ func (e *Executor) podsCleaner(ctx context.Context) error {
func (e *Executor) executorStatusSenderLoop(ctx context.Context) {
for {
log.Debugf("executorStatusSenderLoop")
e.log.Debug().Msgf("executorStatusSenderLoop")
if err := e.sendExecutorStatus(ctx); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
sleepCh := time.NewTimer(2 * time.Second).C
@ -1065,7 +1060,7 @@ func (e *Executor) executorStatusSenderLoop(ctx context.Context) {
func (e *Executor) executorTasksStatusSenderLoop(ctx context.Context) {
for {
log.Debugf("executorTasksStatusSenderLoop")
e.log.Debug().Msgf("executorTasksStatusSenderLoop")
for _, rtID := range e.runningTasks.ids() {
rt, ok := e.runningTasks.get(rtID)
@ -1075,7 +1070,7 @@ func (e *Executor) executorTasksStatusSenderLoop(ctx context.Context) {
rt.Lock()
if err := e.sendExecutorTaskStatus(ctx, rt.et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
rt.Unlock()
continue
}
@ -1101,10 +1096,10 @@ func (e *Executor) executorTasksStatusSenderLoop(ctx context.Context) {
func (e *Executor) tasksUpdaterLoop(ctx context.Context) {
for {
log.Debugf("tasksUpdater")
e.log.Debug().Msgf("tasksUpdater")
if err := e.tasksUpdater(ctx); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
sleepCh := time.NewTimer(2 * time.Second).C
@ -1122,10 +1117,10 @@ func (e *Executor) tasksUpdaterLoop(ctx context.Context) {
func (e *Executor) tasksUpdater(ctx context.Context) error {
ets, _, err := e.runserviceClient.GetExecutorTasks(ctx, e.id)
if err != nil {
log.Warnf("err: %v", err)
e.log.Warn().Err(err).Send()
return err
}
log.Debugf("ets: %v", util.Dump(ets))
e.log.Debug().Msgf("ets: %v", util.Dump(ets))
for _, et := range ets {
e.taskUpdater(ctx, et)
}
@ -1150,7 +1145,7 @@ func (e *Executor) tasksUpdater(ctx context.Context) error {
}
func (e *Executor) taskUpdater(ctx context.Context, et *types.ExecutorTask) {
log.Debugf("et: %v", util.Dump(et))
e.log.Debug().Msgf("et: %v", util.Dump(et))
if et.Spec.ExecutorID != e.id {
return
}
@ -1178,13 +1173,13 @@ func (e *Executor) taskUpdater(ctx context.Context, et *types.ExecutorTask) {
et.Status.Phase = types.ExecutorTaskPhaseCancelled
go func() {
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
}()
}
if et.Status.Phase == types.ExecutorTaskPhaseRunning {
log.Infof("marking executor task %s as failed since there's no running task", et.ID)
e.log.Info().Msgf("marking executor task %s as failed since there's no running task", et.ID)
et.Status.Phase = types.ExecutorTaskPhaseFailed
et.Status.EndTime = util.TimeP(time.Now())
// mark in progress step as failed too
@ -1196,7 +1191,7 @@ func (e *Executor) taskUpdater(ctx context.Context, et *types.ExecutorTask) {
}
go func() {
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
}()
}
@ -1216,7 +1211,7 @@ func (e *Executor) taskUpdater(ctx context.Context, et *types.ExecutorTask) {
}
if !e.runningTasks.addIfNotExists(et.ID, rt) {
log.Warnf("task %s already running, this shouldn't happen", et.ID)
e.log.Warn().Msgf("task %s already running, this shouldn't happen", et.ID)
return
}
@ -1226,10 +1221,10 @@ func (e *Executor) taskUpdater(ctx context.Context, et *types.ExecutorTask) {
func (e *Executor) tasksDataCleanerLoop(ctx context.Context) {
for {
log.Debugf("tasksDataCleaner")
e.log.Debug().Msgf("tasksDataCleaner")
if err := e.tasksDataCleaner(ctx); err != nil {
log.Errorf("err: %+v", err)
e.log.Err(err).Send()
}
sleepCh := time.NewTimer(2 * time.Second).C
@ -1264,7 +1259,7 @@ func (e *Executor) tasksDataCleaner(ctx context.Context) error {
}
if resp.StatusCode == http.StatusNotFound {
taskDir := e.taskPath(etID)
log.Infof("removing task dir %q", taskDir)
e.log.Info().Msgf("removing task dir %q", taskDir)
// remove task dir
if err := os.RemoveAll(taskDir); err != nil {
return err
@ -1351,6 +1346,7 @@ func (e *Executor) saveExecutorID(id string) error {
}
type Executor struct {
log zerolog.Logger
c *config.Executor
runserviceClient *rsclient.Client
id string
@ -1361,14 +1357,10 @@ type Executor struct {
dynamic bool
}
func NewExecutor(ctx context.Context, l *zap.Logger, c *config.Executor) (*Executor, error) {
if l != nil {
logger = l
}
func NewExecutor(ctx context.Context, log zerolog.Logger, c *config.Executor) (*Executor, error) {
if c.Debug {
level.SetLevel(zapcore.DebugLevel)
log = log.Level(zerolog.DebugLevel)
}
log = logger.Sugar()
var err error
c.ToolboxPath, err = filepath.Abs(c.ToolboxPath)
@ -1377,6 +1369,7 @@ func NewExecutor(ctx context.Context, l *zap.Logger, c *config.Executor) (*Execu
}
e := &Executor{
log: log,
c: c,
runserviceClient: rsclient.NewClient(c.RunserviceURL),
runningTasks: &runningTasks{
@ -1446,12 +1439,12 @@ func NewExecutor(ctx context.Context, l *zap.Logger, c *config.Executor) (*Execu
var d driver.Driver
switch c.Driver.Type {
case config.DriverTypeDocker:
d, err = driver.NewDockerDriver(logger, e.id, e.c.ToolboxPath, e.c.InitImage.Image, initDockerConfig)
d, err = driver.NewDockerDriver(log, e.id, e.c.ToolboxPath, e.c.InitImage.Image, initDockerConfig)
if err != nil {
return nil, errors.Errorf("failed to create docker driver: %w", err)
}
case config.DriverTypeK8s:
d, err = driver.NewK8sDriver(logger, e.id, c.ToolboxPath, e.c.InitImage.Image, initDockerConfig)
d, err = driver.NewK8sDriver(log, e.id, c.ToolboxPath, e.c.InitImage.Image, initDockerConfig)
if err != nil {
return nil, errors.Errorf("failed to create kubernetes driver: %w", err)
}
@ -1471,7 +1464,7 @@ func (e *Executor) Run(ctx context.Context) error {
ch := make(chan *types.ExecutorTask)
schedulerHandler := NewTaskSubmissionHandler(ch)
logsHandler := NewLogsHandler(logger, e)
logsHandler := NewLogsHandler(e.log, e)
archivesHandler := NewArchivesHandler(e)
router := mux.NewRouter()
@ -1504,11 +1497,11 @@ func (e *Executor) Run(ctx context.Context) error {
select {
case <-ctx.Done():
log.Infof("runservice executor exiting")
log.Info().Msgf("runservice executor exiting")
httpServer.Close()
case err := <-lerrCh:
if err != nil {
log.Errorf("http server listen error: %v", err)
log.Err(err).Msgf("http server listen error")
return err
}
}

View File

@ -19,11 +19,11 @@ import (
csclient "agola.io/agola/services/configstore/client"
rsclient "agola.io/agola/services/runservice/client"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type ActionHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
sd *common.TokenSigningData
configstoreClient *csclient.Client
runserviceClient *rsclient.Client
@ -32,9 +32,9 @@ type ActionHandler struct {
webExposedURL string
}
func NewActionHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csclient.Client, runserviceClient *rsclient.Client, agolaID, apiExposedURL, webExposedURL string) *ActionHandler {
func NewActionHandler(log zerolog.Logger, sd *common.TokenSigningData, configstoreClient *csclient.Client, runserviceClient *rsclient.Client, agolaID, apiExposedURL, webExposedURL string) *ActionHandler {
return &ActionHandler{
log: logger.Sugar(),
log: log,
sd: sd,
configstoreClient: configstoreClient,
runserviceClient: runserviceClient,

View File

@ -107,12 +107,12 @@ func (h *ActionHandler) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*
org.CreatorUserID = req.CreatorUserID
}
h.log.Infof("creating organization")
h.log.Info().Msgf("creating organization")
org, _, err := h.configstoreClient.CreateOrg(ctx, org)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create organization: %w", err))
}
h.log.Infof("organization %s created, ID: %s", org.Name, org.ID)
h.log.Info().Msgf("organization %s created, ID: %s", org.Name, org.ID)
return org, nil
}

View File

@ -130,7 +130,7 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
return nil, errors.Errorf("failed to get repository info from gitsource: %w", err)
}
h.log.Infof("generating ssh key pairs")
h.log.Info().Msgf("generating ssh key pairs")
privateKey, _, err := util.GenSSHKeyPair(4096)
if err != nil {
return nil, errors.Errorf("failed to generate ssh key pair: %w", err)
@ -153,25 +153,25 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
PassVarsToForkedPR: req.PassVarsToForkedPR,
}
h.log.Infof("creating project")
h.log.Info().Msgf("creating project")
rp, _, err := h.configstoreClient.CreateProject(ctx, p)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create project: %w", err))
}
h.log.Infof("project %s created, ID: %s", rp.Name, rp.ID)
h.log.Info().Msgf("project %s created, ID: %s", rp.Name, rp.ID)
if serr := h.setupGitSourceRepo(ctx, rs, user, la, rp); serr != nil {
var err error
h.log.Errorf("failed to setup git source repo, trying to cleanup: %+v", err)
h.log.Err(err).Msgf("failed to setup git source repo, trying to cleanup")
// try to cleanup gitsource configs and remove project
// we'll log but ignore errors
h.log.Infof("deleting project with ID: %q", rp.ID)
h.log.Info().Msgf("deleting project with ID: %q", rp.ID)
if _, err := h.configstoreClient.DeleteProject(ctx, rp.ID); err != nil {
h.log.Errorf("failed to delete project: %+v", err)
h.log.Err(err).Msgf("failed to delete project ")
}
h.log.Infof("cleanup git source repo")
h.log.Info().Msgf("cleanup git source repo")
if err := h.cleanupGitSourceRepo(ctx, rs, user, la, rp); err != nil {
h.log.Errorf("failed to cleanup git source repo: %+v", err)
h.log.Err(err).Msgf("failed to cleanup git source repo")
}
return nil, errors.Errorf("failed to setup git source repo: %w", serr)
}
@ -214,12 +214,12 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, re
p.PassVarsToForkedPR = *req.PassVarsToForkedPR
}
h.log.Infof("updating project")
h.log.Info().Msgf("updating project")
rp, _, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update project: %w", err))
}
h.log.Infof("project %s updated, ID: %s", p.Name, p.ID)
h.log.Info().Msgf("project %s updated, ID: %s", p.Name, p.ID)
return rp, nil
}
@ -273,12 +273,12 @@ func (h *ActionHandler) ProjectUpdateRepoLinkedAccount(ctx context.Context, proj
p.LinkedAccountID = la.ID
h.log.Infof("updating project")
h.log.Info().Msgf("updating project")
rp, _, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update project: %w", err))
}
h.log.Infof("project %s updated, ID: %s", p.Name, p.ID)
h.log.Info().Msgf("project %s updated, ID: %s", p.Name, p.ID)
return rp, nil
}
@ -303,15 +303,15 @@ func (h *ActionHandler) setupGitSourceRepo(ctx context.Context, rs *cstypes.Remo
// can have multiple projects referencing the same remote repository and this
// will trigger multiple different runs
deployKeyName := fmt.Sprintf("agola deploy key - %s", project.ID)
h.log.Infof("creating/updating deploy key: %s", deployKeyName)
h.log.Info().Msgf("creating/updating deploy key: %s", deployKeyName)
if err := gitsource.UpdateDeployKey(project.RepositoryPath, deployKeyName, string(pubKey), true); err != nil {
return errors.Errorf("failed to create deploy key: %w", err)
}
h.log.Infof("deleting existing webhooks")
h.log.Info().Msgf("deleting existing webhooks")
if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL); err != nil {
return errors.Errorf("failed to delete repository webhook: %w", err)
}
h.log.Infof("creating webhook to url: %s", webhookURL)
h.log.Info().Msgf("creating webhook to url: %s", webhookURL)
if err := gitsource.CreateRepoWebhook(project.RepositoryPath, webhookURL, project.WebhookSecret); err != nil {
return errors.Errorf("failed to create repository webhook: %w", err)
}
@ -334,11 +334,11 @@ func (h *ActionHandler) cleanupGitSourceRepo(ctx context.Context, rs *cstypes.Re
// can have multiple projects referencing the same remote repository and this
// will trigger multiple different runs
deployKeyName := fmt.Sprintf("agola deploy key - %s", project.ID)
h.log.Infof("deleting deploy key: %s", deployKeyName)
h.log.Info().Msgf("deleting deploy key: %s", deployKeyName)
if err := gitsource.DeleteDeployKey(project.RepositoryPath, deployKeyName); err != nil {
return errors.Errorf("failed to create deploy key: %w", err)
}
h.log.Infof("deleting existing webhooks")
h.log.Info().Msgf("deleting existing webhooks")
if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL); err != nil {
return errors.Errorf("failed to delete repository webhook: %w", err)
}
@ -404,10 +404,10 @@ func (h *ActionHandler) DeleteProject(ctx context.Context, projectRef string) er
user, rs, la, err := h.getRemoteRepoAccessData(ctx, p.LinkedAccountID)
if err != nil {
canDoRepCleanup = false
h.log.Errorf("failed to get remote repo access data: %+v", err)
h.log.Err(err).Msgf("failed to get remote repo access data: %+v", err)
}
h.log.Infof("deleting project with ID: %q", p.ID)
h.log.Info().Msgf("deleting project with ID: %q", p.ID)
if _, err = h.configstoreClient.DeleteProject(ctx, projectRef); err != nil {
return util.NewAPIError(util.KindFromRemoteError(err), err)
}
@ -415,9 +415,9 @@ func (h *ActionHandler) DeleteProject(ctx context.Context, projectRef string) er
// try to cleanup gitsource configs
// we'll log but ignore errors
if canDoRepCleanup {
h.log.Infof("cleanup git source repo")
h.log.Info().Msgf("cleanup git source repo")
if err := h.cleanupGitSourceRepo(ctx, rs, user, la, p); err != nil {
h.log.Errorf("failed to cleanup git source repo: %+v", err)
h.log.Err(err).Msgf("failed to cleanup git source repo: %+v", err)
}
}

View File

@ -94,12 +94,12 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje
Visibility: req.Visibility,
}
h.log.Infof("creating projectGroup")
h.log.Info().Msgf("creating projectGroup")
rp, _, err := h.configstoreClient.CreateProjectGroup(ctx, p)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create projectGroup: %w", err))
}
h.log.Infof("projectGroup %s created, ID: %s", rp.Name, rp.ID)
h.log.Info().Msgf("projectGroup %s created, ID: %s", rp.Name, rp.ID)
return rp, nil
}
@ -135,12 +135,12 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef
pg.Visibility = *req.Visibility
}
h.log.Infof("updating project group")
h.log.Info().Msgf("updating project group")
rp, _, err := h.configstoreClient.UpdateProjectGroup(ctx, pg.ID, pg.ProjectGroup)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update project group: %w", err))
}
h.log.Infof("project group %q updated, ID: %s", pg.Name, pg.ID)
h.log.Info().Msgf("project group %q updated, ID: %s", pg.Name, pg.ID)
return rp, nil
}

View File

@ -110,12 +110,12 @@ func (h *ActionHandler) CreateRemoteSource(ctx context.Context, req *CreateRemot
LoginEnabled: req.LoginEnabled,
}
h.log.Infof("creating remotesource")
h.log.Info().Msgf("creating remotesource")
rs, _, err := h.configstoreClient.CreateRemoteSource(ctx, rs)
if err != nil {
return nil, errors.Errorf("failed to create remotesource: %w", err)
}
h.log.Infof("remotesource %s created, ID: %s", rs.Name, rs.ID)
h.log.Info().Msgf("remotesource %s created, ID: %s", rs.Name, rs.ID)
return rs, nil
}
@ -172,12 +172,12 @@ func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemot
rs.LoginEnabled = req.LoginEnabled
}
h.log.Infof("updating remotesource")
h.log.Info().Msgf("updating remotesource")
rs, _, err = h.configstoreClient.UpdateRemoteSource(ctx, req.RemoteSourceRef, rs)
if err != nil {
return nil, errors.Errorf("failed to update remotesource: %w", err)
}
h.log.Infof("remotesource %s updated", rs.Name)
h.log.Info().Msgf("remotesource %s updated", rs.Name)
return rs, nil
}

View File

@ -483,7 +483,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
if err != nil {
return util.NewAPIError(util.ErrInternal, errors.Errorf("failed to fetch config file: %w", err))
}
h.log.Debug("data: %s", data)
h.log.Debug().Msgf("data: %s", data)
var configFormat config.ConfigFormat
switch path.Ext(filename) {
@ -509,7 +509,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
config, err := config.ParseConfig([]byte(data), configFormat, configContext)
if err != nil {
h.log.Errorf("failed to parse config: %+v", err)
h.log.Err(err).Msgf("failed to parse config")
// create a run (per config file) with a generic error since we cannot parse
// it and know how many runs are defined
@ -524,7 +524,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
}
if _, _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
h.log.Errorf("failed to create run: %+v", err)
h.log.Err(err).Msgf("failed to create run")
return util.NewAPIError(util.KindFromRemoteError(err), err)
}
return nil
@ -532,12 +532,12 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
for _, run := range config.Runs {
if SkipRunMessage.MatchString(req.Message) {
h.log.Debugf("skipping run since special commit message")
h.log.Debug().Msgf("skipping run since special commit message")
continue
}
if match := types.MatchWhen(run.When.ToWhen(), req.RefType, req.Branch, req.Tag, req.Ref); !match {
h.log.Debugf("skipping run since when condition doesn't match")
h.log.Debug().Msgf("skipping run since when condition doesn't match")
continue
}
@ -554,7 +554,7 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
}
if _, _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
h.log.Errorf("failed to create run: %+v", err)
h.log.Err(err).Msgf("failed to create run")
return util.NewAPIError(util.KindFromRemoteError(err), err)
}
}
@ -572,7 +572,7 @@ func (h *ActionHandler) fetchConfigFiles(ctx context.Context, gitSource gitsourc
if err == nil {
return true, nil
}
h.log.Errorf("get file err: %v", err)
h.log.Err(err).Msgf("get file err")
}
return false, nil
})

View File

@ -92,16 +92,16 @@ func (h *ActionHandler) CreateSecret(ctx context.Context, req *CreateSecretReque
var rs *csapitypes.Secret
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("creating project group secret")
h.log.Info().Msgf("creating project group secret")
rs, _, err = h.configstoreClient.CreateProjectGroupSecret(ctx, req.ParentRef, s)
case cstypes.ConfigTypeProject:
h.log.Infof("creating project secret")
h.log.Info().Msgf("creating project secret")
rs, _, err = h.configstoreClient.CreateProjectSecret(ctx, req.ParentRef, s)
}
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create secret: %w", err))
}
h.log.Infof("secret %s created, ID: %s", rs.Name, rs.ID)
h.log.Info().Msgf("secret %s created, ID: %s", rs.Name, rs.ID)
return rs, nil
}
@ -146,16 +146,16 @@ func (h *ActionHandler) UpdateSecret(ctx context.Context, req *UpdateSecretReque
var rs *csapitypes.Secret
switch req.ParentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("updating project group secret")
h.log.Info().Msgf("updating project group secret")
rs, _, err = h.configstoreClient.UpdateProjectGroupSecret(ctx, req.ParentRef, req.SecretName, s)
case cstypes.ConfigTypeProject:
h.log.Infof("updating project secret")
h.log.Info().Msgf("updating project secret")
rs, _, err = h.configstoreClient.UpdateProjectSecret(ctx, req.ParentRef, req.SecretName, s)
}
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update secret: %w", err))
}
h.log.Infof("secret %s updated, ID: %s", rs.Name, rs.ID)
h.log.Info().Msgf("secret %s updated, ID: %s", rs.Name, rs.ID)
return rs, nil
}
@ -171,10 +171,10 @@ func (h *ActionHandler) DeleteSecret(ctx context.Context, parentType cstypes.Con
switch parentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("deleting project group secret")
h.log.Info().Msgf("deleting project group secret")
_, err = h.configstoreClient.DeleteProjectGroupSecret(ctx, parentRef, name)
case cstypes.ConfigTypeProject:
h.log.Infof("deleting project secret")
h.log.Info().Msgf("deleting project secret")
_, err = h.configstoreClient.DeleteProjectSecret(ctx, parentRef, name)
}
if err != nil {

View File

@ -108,12 +108,12 @@ func (h *ActionHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
UserName: req.UserName,
}
h.log.Infof("creating user")
h.log.Info().Msgf("creating user")
u, _, err := h.configstoreClient.CreateUser(ctx, creq)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create user: %w", err))
}
h.log.Infof("user %s created, ID: %s", u.Name, u.ID)
h.log.Info().Msgf("user %s created, ID: %s", u.Name, u.ID)
return u, nil
}
@ -141,7 +141,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
return "", util.NewAPIError(util.ErrBadRequest, errors.Errorf("user %q already have a token with name %q", userRef, req.TokenName))
}
h.log.Infof("creating user token")
h.log.Info().Msgf("creating user token")
creq := &csapitypes.CreateUserTokenRequest{
TokenName: req.TokenName,
}
@ -149,7 +149,7 @@ func (h *ActionHandler) CreateUserToken(ctx context.Context, req *CreateUserToke
if err != nil {
return "", util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create user token: %w", err))
}
h.log.Infof("token %q for user %q created", req.TokenName, userRef)
h.log.Info().Msgf("token %q for user %q created", req.TokenName, userRef)
return res.Token, nil
}
@ -212,12 +212,12 @@ func (h *ActionHandler) CreateUserLA(ctx context.Context, req *CreateUserLAReque
Oauth2AccessTokenExpiresAt: req.Oauth2AccessTokenExpiresAt,
}
h.log.Infof("creating linked account")
h.log.Info().Msgf("creating linked account")
la, _, err = h.configstoreClient.CreateUserLA(ctx, userRef, creq)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create linked account: %w", err))
}
h.log.Infof("linked account %q for user %q created", la.ID, userRef)
h.log.Info().Msgf("linked account %q for user %q created", la.ID, userRef)
return la, nil
}
@ -247,12 +247,12 @@ func (h *ActionHandler) UpdateUserLA(ctx context.Context, userRef string, la *cs
Oauth2AccessTokenExpiresAt: la.Oauth2AccessTokenExpiresAt,
}
h.log.Infof("updating user %q linked account", userRef)
h.log.Info().Msgf("updating user %q linked account", userRef)
la, _, err = h.configstoreClient.UpdateUserLA(ctx, userRef, la.ID, creq)
if err != nil {
return util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update user: %w", err))
}
h.log.Infof("linked account %q for user %q updated", la.ID, userRef)
h.log.Info().Msgf("linked account %q for user %q updated", la.ID, userRef)
return nil
}
@ -351,12 +351,12 @@ func (h *ActionHandler) RegisterUser(ctx context.Context, req *RegisterUserReque
},
}
h.log.Infof("creating user account")
h.log.Info().Msgf("creating user account")
u, _, err := h.configstoreClient.CreateUser(ctx, creq)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create linked account: %w", err))
}
h.log.Infof("user %q created", req.UserName)
h.log.Info().Msgf("user %q created", req.UserName)
return u, nil
}
@ -434,12 +434,12 @@ func (h *ActionHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*
Oauth2AccessTokenExpiresAt: la.Oauth2AccessTokenExpiresAt,
}
h.log.Infof("updating user %q linked account", user.Name)
h.log.Info().Msgf("updating user %q linked account", user.Name)
la, _, err = h.configstoreClient.UpdateUserLA(ctx, user.Name, la.ID, creq)
if err != nil {
return nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to update user: %w", err))
}
h.log.Infof("linked account %q for user %q updated", la.ID, user.Name)
h.log.Info().Msgf("linked account %q for user %q updated", la.ID, user.Name)
}
// generate jwt token

View File

@ -113,7 +113,7 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to get project group %q secrets: %w", req.ParentRef, err))
}
h.log.Infof("creating project group variable")
h.log.Info().Msgf("creating project group variable")
rv, _, err = h.configstoreClient.CreateProjectGroupVariable(ctx, req.ParentRef, v)
if err != nil {
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create variable: %w", err))
@ -125,13 +125,13 @@ func (h *ActionHandler) CreateVariable(ctx context.Context, req *CreateVariableR
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to get project %q secrets: %w", req.ParentRef, err))
}
h.log.Infof("creating project variable")
h.log.Info().Msgf("creating project variable")
rv, _, err = h.configstoreClient.CreateProjectVariable(ctx, req.ParentRef, v)
if err != nil {
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create variable: %w", err))
}
}
h.log.Infof("variable %s created, ID: %s", rv.Name, rv.ID)
h.log.Info().Msgf("variable %s created, ID: %s", rv.Name, rv.ID)
return rv, cssecrets, nil
}
@ -184,7 +184,7 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to get project group %q secrets: %w", req.ParentRef, err))
}
h.log.Infof("creating project group variable")
h.log.Info().Msgf("creating project group variable")
rv, _, err = h.configstoreClient.UpdateProjectGroupVariable(ctx, req.ParentRef, req.VariableName, v)
if err != nil {
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create variable: %w", err))
@ -196,13 +196,13 @@ func (h *ActionHandler) UpdateVariable(ctx context.Context, req *UpdateVariableR
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to get project %q secrets: %w", req.ParentRef, err))
}
h.log.Infof("creating project variable")
h.log.Info().Msgf("creating project variable")
rv, _, err = h.configstoreClient.UpdateProjectVariable(ctx, req.ParentRef, req.VariableName, v)
if err != nil {
return nil, nil, util.NewAPIError(util.KindFromRemoteError(err), errors.Errorf("failed to create variable: %w", err))
}
}
h.log.Infof("variable %s created, ID: %s", rv.Name, rv.ID)
h.log.Info().Msgf("variable %s created, ID: %s", rv.Name, rv.ID)
return rv, cssecrets, nil
}
@ -218,10 +218,10 @@ func (h *ActionHandler) DeleteVariable(ctx context.Context, parentType cstypes.C
switch parentType {
case cstypes.ConfigTypeProjectGroup:
h.log.Infof("deleting project group variable")
h.log.Info().Msgf("deleting project group variable")
_, err = h.configstoreClient.DeleteProjectGroupVariable(ctx, parentRef, name)
case cstypes.ConfigTypeProject:
h.log.Infof("deleting project variable")
h.log.Info().Msgf("deleting project variable")
_, err = h.configstoreClient.DeleteProjectVariable(ctx, parentRef, name)
}
if err != nil {

View File

@ -22,16 +22,16 @@ import (
"agola.io/agola/internal/util"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type BadgeHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewBadgeHandler(logger *zap.Logger, ah *action.ActionHandler) *BadgeHandler {
return &BadgeHandler{log: logger.Sugar(), ah: ah}
func NewBadgeHandler(log zerolog.Logger, ah *action.ActionHandler) *BadgeHandler {
return &BadgeHandler{log: log, ah: ah}
}
func (h *BadgeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -48,7 +48,7 @@ func (h *BadgeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
badge, err := h.ah.GetBadge(ctx, projectRef, branch)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -57,6 +57,6 @@ func (h *BadgeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache")
if _, err := w.Write([]byte(badge)); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -21,16 +21,16 @@ import (
"agola.io/agola/internal/util"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type OAuth2CallbackHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewOAuth2CallbackHandler(logger *zap.Logger, ah *action.ActionHandler) *OAuth2CallbackHandler {
return &OAuth2CallbackHandler{log: logger.Sugar(), ah: ah}
func NewOAuth2CallbackHandler(log zerolog.Logger, ah *action.ActionHandler) *OAuth2CallbackHandler {
return &OAuth2CallbackHandler{log: log, ah: ah}
}
func (h *OAuth2CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -41,7 +41,7 @@ func (h *OAuth2CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
cresp, err := h.ah.HandleOauth2Callback(ctx, code, state)
if err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
util.HTTPError(w, util.NewAPIError(util.ErrBadRequest, err))
return
}
@ -87,6 +87,6 @@ func (h *OAuth2CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
Response: response,
}
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -24,19 +24,19 @@ import (
"agola.io/agola/internal/util"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
"github.com/gorilla/mux"
"github.com/rs/zerolog"
)
type CreateOrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateOrgHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateOrgHandler {
return &CreateOrgHandler{log: logger.Sugar(), ah: ah}
func NewCreateOrgHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateOrgHandler {
return &CreateOrgHandler{log: log, ah: ah}
}
func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -59,23 +59,23 @@ func (h *CreateOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
org, err := h.ah.CreateOrg(ctx, creq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createOrgResponse(org)
if err := util.HTTPResponse(w, http.StatusCreated, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteOrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteOrgHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteOrgHandler {
return &DeleteOrgHandler{log: logger.Sugar(), ah: ah}
func NewDeleteOrgHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteOrgHandler {
return &DeleteOrgHandler{log: log, ah: ah}
}
func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -85,22 +85,22 @@ func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.ah.DeleteOrg(ctx, orgRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type OrgHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewOrgHandler(logger *zap.Logger, ah *action.ActionHandler) *OrgHandler {
return &OrgHandler{log: logger.Sugar(), ah: ah}
func NewOrgHandler(log zerolog.Logger, ah *action.ActionHandler) *OrgHandler {
return &OrgHandler{log: log, ah: ah}
}
func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -110,13 +110,13 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
org, err := h.ah.GetOrg(ctx, orgRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createOrgResponse(org)
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -130,12 +130,12 @@ func createOrgResponse(o *cstypes.Organization) *gwapitypes.OrgResponse {
}
type OrgsHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewOrgsHandler(logger *zap.Logger, ah *action.ActionHandler) *OrgsHandler {
return &OrgsHandler{log: logger.Sugar(), ah: ah}
func NewOrgsHandler(log zerolog.Logger, ah *action.ActionHandler) *OrgsHandler {
return &OrgsHandler{log: log, ah: ah}
}
func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -173,7 +173,7 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
csorgs, err := h.ah.GetOrgs(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -182,7 +182,7 @@ func (h *OrgsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
orgs[i] = createOrgResponse(p)
}
if err := util.HTTPResponse(w, http.StatusOK, orgs); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -194,12 +194,12 @@ func createOrgMemberResponse(user *cstypes.User, role cstypes.MemberRole) *gwapi
}
type OrgMembersHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewOrgMembersHandler(logger *zap.Logger, ah *action.ActionHandler) *OrgMembersHandler {
return &OrgMembersHandler{log: logger.Sugar(), ah: ah}
func NewOrgMembersHandler(log zerolog.Logger, ah *action.ActionHandler) *OrgMembersHandler {
return &OrgMembersHandler{log: log, ah: ah}
}
func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -210,7 +210,7 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ares, err := h.ah.GetOrgMembers(ctx, orgRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
@ -222,7 +222,7 @@ func (h *OrgMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
res.Members[i] = createOrgMemberResponse(m.User, m.Role)
}
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -237,12 +237,12 @@ func createAddOrgMemberResponse(org *cstypes.Organization, user *cstypes.User, r
}
type AddOrgMemberHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewAddOrgMemberHandler(logger *zap.Logger, ah *action.ActionHandler) *AddOrgMemberHandler {
return &AddOrgMemberHandler{log: logger.Sugar(), ah: ah}
func NewAddOrgMemberHandler(log zerolog.Logger, ah *action.ActionHandler) *AddOrgMemberHandler {
return &AddOrgMemberHandler{log: log, ah: ah}
}
func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -261,23 +261,23 @@ func (h *AddOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ares, err := h.ah.AddOrgMember(ctx, orgRef, userRef, cstypes.MemberRole(req.Role))
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createAddOrgMemberResponse(ares.Org, ares.User, ares.OrganizationMember.MemberRole)
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type RemoveOrgMemberHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewRemoveOrgMemberHandler(logger *zap.Logger, ah *action.ActionHandler) *RemoveOrgMemberHandler {
return &RemoveOrgMemberHandler{log: logger.Sugar(), ah: ah}
func NewRemoveOrgMemberHandler(log zerolog.Logger, ah *action.ActionHandler) *RemoveOrgMemberHandler {
return &RemoveOrgMemberHandler{log: log, ah: ah}
}
func (h *RemoveOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -289,11 +289,11 @@ func (h *RemoveOrgMemberHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
err := h.ah.RemoveOrgMember(ctx, orgRef, userRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

View File

@ -26,16 +26,16 @@ import (
gwapitypes "agola.io/agola/services/gateway/api/types"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/rs/zerolog"
)
type CreateProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewCreateProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *CreateProjectHandler {
return &CreateProjectHandler{log: logger.Sugar(), ah: ah}
func NewCreateProjectHandler(log zerolog.Logger, ah *action.ActionHandler) *CreateProjectHandler {
return &CreateProjectHandler{log: log, ah: ah}
}
func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -60,23 +60,23 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
project, err := h.ah.CreateProject(ctx, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createProjectResponse(project)
if err := util.HTTPResponse(w, http.StatusCreated, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type UpdateProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewUpdateProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *UpdateProjectHandler {
return &UpdateProjectHandler{log: logger.Sugar(), ah: ah}
func NewUpdateProjectHandler(log zerolog.Logger, ah *action.ActionHandler) *UpdateProjectHandler {
return &UpdateProjectHandler{log: log, ah: ah}
}
func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -109,23 +109,23 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
project, err := h.ah.UpdateProject(ctx, projectRef, areq)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createProjectResponse(project)
if err := util.HTTPResponse(w, http.StatusCreated, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ProjectReconfigHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewProjectReconfigHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectReconfigHandler {
return &ProjectReconfigHandler{log: logger.Sugar(), ah: ah}
func NewProjectReconfigHandler(log zerolog.Logger, ah *action.ActionHandler) *ProjectReconfigHandler {
return &ProjectReconfigHandler{log: log, ah: ah}
}
func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -142,17 +142,17 @@ func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ProjectUpdateRepoLinkedAccountHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewProjectUpdateRepoLinkedAccountHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectUpdateRepoLinkedAccountHandler {
return &ProjectUpdateRepoLinkedAccountHandler{log: logger.Sugar(), ah: ah}
func NewProjectUpdateRepoLinkedAccountHandler(log zerolog.Logger, ah *action.ActionHandler) *ProjectUpdateRepoLinkedAccountHandler {
return &ProjectUpdateRepoLinkedAccountHandler{log: log, ah: ah}
}
func (h *ProjectUpdateRepoLinkedAccountHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -166,23 +166,23 @@ func (h *ProjectUpdateRepoLinkedAccountHandler) ServeHTTP(w http.ResponseWriter,
project, err := h.ah.ProjectUpdateRepoLinkedAccount(ctx, projectRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createProjectResponse(project)
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type DeleteProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewDeleteProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteProjectHandler {
return &DeleteProjectHandler{log: logger.Sugar(), ah: ah}
func NewDeleteProjectHandler(log zerolog.Logger, ah *action.ActionHandler) *DeleteProjectHandler {
return &DeleteProjectHandler{log: log, ah: ah}
}
func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -196,22 +196,22 @@ func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
err = h.ah.DeleteProject(ctx, projectRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
type ProjectHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectHandler {
return &ProjectHandler{log: logger.Sugar(), ah: ah}
func NewProjectHandler(log zerolog.Logger, ah *action.ActionHandler) *ProjectHandler {
return &ProjectHandler{log: log, ah: ah}
}
func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -225,13 +225,13 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
project, err := h.ah.GetProject(ctx, projectRef)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
res := createProjectResponse(project)
if err := util.HTTPResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}
@ -250,12 +250,12 @@ func createProjectResponse(r *csapitypes.Project) *gwapitypes.ProjectResponse {
}
type ProjectCreateRunHandler struct {
log *zap.SugaredLogger
log zerolog.Logger
ah *action.ActionHandler
}
func NewProjectCreateRunHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectCreateRunHandler {
return &ProjectCreateRunHandler{log: logger.Sugar(), ah: ah}
func NewProjectCreateRunHandler(log zerolog.Logger, ah *action.ActionHandler) *ProjectCreateRunHandler {
return &ProjectCreateRunHandler{log: log, ah: ah}
}
func (h *ProjectCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -276,11 +276,11 @@ func (h *ProjectCreateRunHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
err = h.ah.ProjectCreateRun(ctx, projectRef, req.Branch, req.Tag, req.Ref, req.CommitSHA)
if util.HTTPError(w, err) {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
return
}
if err := util.HTTPResponse(w, http.StatusCreated, nil); err != nil {
h.log.Errorf("err: %+v", err)
h.log.Err(err).Send()
}
}

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