diff --git a/TODOLIST.md b/TODOLIST.md index ad45862..651b9bd 100644 --- a/TODOLIST.md +++ b/TODOLIST.md @@ -1,8 +1,9 @@ -- [x] versioning/show -- [x] versioning/set -- [ ] search/file +- [x] versioning +- [x] search/file +- [x] tags +- [NO] storageclass +- [NO] encryption - [ ] search/text (all files, single file etc.) -- [ ] tags -- [ ] encryption +- [ ] bucketpolicy - [ ] objectlock - [ ] re-enable prompt/select logic diff --git a/cmd/versioning/set/disabled/disabled.go b/cmd/versioning/set/disabled/disabled.go new file mode 100644 index 0000000..bd2ce86 --- /dev/null +++ b/cmd/versioning/set/disabled/disabled.go @@ -0,0 +1,72 @@ +package disabled + +import ( + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/utils" + + "github.com/aws/aws-sdk-go/service/s3/s3iface" + rootopts "github.com/bilalcaliskan/s3-manager/cmd/root/options" + "github.com/bilalcaliskan/s3-manager/cmd/versioning/options" + "github.com/bilalcaliskan/s3-manager/internal/aws" + "github.com/bilalcaliskan/s3-manager/internal/logging" + "github.com/rs/zerolog" + "github.com/spf13/cobra" +) + +func init() { + versioningOpts = options.GetVersioningOptions() +} + +var ( + svc s3iface.S3API + logger zerolog.Logger + versioningOpts *options.VersioningOptions + DisabledCmd = &cobra.Command{ + Use: "disabled", + Short: "", + SilenceUsage: true, + SilenceErrors: true, + RunE: func(cmd *cobra.Command, args []string) (err error) { + rootOpts := cmd.Context().Value(rootopts.OptsKey{}).(*rootopts.RootOptions) + svc = cmd.Context().Value(rootopts.S3SvcKey{}).(s3iface.S3API) + + versioningOpts.RootOptions = rootOpts + logger = logging.GetLogger(rootOpts) + + if err := utils.CheckArgs(args); err != nil { + logger.Error(). + Msg(err.Error()) + return err + } + + versioningOpts.DesiredState = "disabled" + versioning, err := aws.GetBucketVersioning(svc, versioningOpts.RootOptions) + if err != nil { + logger.Error().Msg(err.Error()) + return err + } + + if err := utils.DecideActualState(versioning, versioningOpts); err != nil { + logger.Error().Msg(err.Error()) + return err + } + + logger.Info().Msgf(utils.InfCurrentState, versioningOpts.ActualState) + if versioningOpts.ActualState == "disabled" { + logger.Warn(). + Str("state", versioningOpts.ActualState). + Msg(utils.WarnDesiredState) + return nil + } + + logger.Info().Msgf(utils.InfSettingVersioning, versioningOpts.DesiredState) + _, err = aws.SetBucketVersioning(svc, versioningOpts) + if err != nil { + return err + } + + logger.Info().Msgf(utils.InfSuccess, versioningOpts.DesiredState) + + return nil + }, + } +) diff --git a/cmd/versioning/set/disabled/disabled_test.go b/cmd/versioning/set/disabled/disabled_test.go new file mode 100644 index 0000000..dc27eaa --- /dev/null +++ b/cmd/versioning/set/disabled/disabled_test.go @@ -0,0 +1,259 @@ +package disabled + +import ( + "context" + "errors" + "testing" + + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/utils" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/s3/s3iface" + "github.com/bilalcaliskan/s3-manager/cmd/root/options" + internalaws "github.com/bilalcaliskan/s3-manager/internal/aws" + "github.com/stretchr/testify/assert" +) + +var ( + defaultGetBucketVersioningOutput = &s3.GetBucketVersioningOutput{ + Status: aws.String("Enabled"), + } + defaultGetBucketVersioningErr error + defaultPutBucketVersioningOutput = &s3.PutBucketVersioningOutput{} + defaultPutBucketVersioningErr error +) + +func createSvc(rootOpts *options.RootOptions) (*s3.S3, error) { + return internalaws.CreateAwsService(rootOpts) +} + +// Define a mock struct to be used in your unit tests +type mockS3Client struct { + s3iface.S3API +} + +func (m *mockS3Client) GetBucketVersioning(input *s3.GetBucketVersioningInput) (*s3.GetBucketVersioningOutput, error) { + return defaultGetBucketVersioningOutput, defaultGetBucketVersioningErr +} + +func (m *mockS3Client) PutBucketVersioning(input *s3.PutBucketVersioningInput) (*s3.PutBucketVersioningOutput, error) { + return defaultPutBucketVersioningOutput, defaultPutBucketVersioningErr +} + +func TestExecuteTooManyArguments(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + svc, err := createSvc(rootOpts) + assert.NotNil(t, svc) + assert.Nil(t, err) + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + args := []string{"enabled"} + DisabledCmd.SetArgs(args) + + err = DisabledCmd.Execute() + assert.NotNil(t, err) + assert.Equal(t, utils.ErrTooManyArguments, err.Error()) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +/*func TestExecuteWrongArguments(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + svc, err := createSvc(rootOpts) + assert.NotNil(t, svc) + assert.Nil(t, err) + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + args := []string{"eeenabled"} + DisabledCmd.SetArgs(args) + + err = DisabledCmd.Execute() + assert.NotNil(t, err) + assert.Equal(t, ErrWrongArgumentProvided, err.Error()) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +}*/ + +/* + func TestExecuteNoArgument(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + svc, err := createSvc(rootOpts) + assert.NotNil(t, svc) + assert.Nil(t, err) + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err = DisabledCmd.Execute() + assert.NotNil(t, err) + assert.Equal(t, ErrNoArgument, err.Error()) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() + } +*/ +func TestExecuteSuccessAlreadyDisabled(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Suspended") + defaultPutBucketVersioningErr = nil + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err := DisabledCmd.Execute() + assert.Nil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSuccess(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Enabled") + defaultPutBucketVersioningErr = nil + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err := DisabledCmd.Execute() + assert.Nil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteGetBucketVersioningErr(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = errors.New("dummy error") + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err := DisabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSetBucketVersioningErr(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultPutBucketVersioningErr = errors.New("new dummy error") + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err := DisabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSuccessEnabledWrongVersioning(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + DisabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Suspendeddd") + defaultPutBucketVersioningErr = nil + + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.S3SvcKey{}, svc)) + DisabledCmd.SetContext(context.WithValue(DisabledCmd.Context(), options.OptsKey{}, rootOpts)) + + DisabledCmd.SetArgs([]string{}) + err := DisabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} diff --git a/cmd/versioning/set/enabled/enabled.go b/cmd/versioning/set/enabled/enabled.go new file mode 100644 index 0000000..49192be --- /dev/null +++ b/cmd/versioning/set/enabled/enabled.go @@ -0,0 +1,72 @@ +package enabled + +import ( + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/utils" + + "github.com/aws/aws-sdk-go/service/s3/s3iface" + rootopts "github.com/bilalcaliskan/s3-manager/cmd/root/options" + "github.com/bilalcaliskan/s3-manager/cmd/versioning/options" + "github.com/bilalcaliskan/s3-manager/internal/aws" + "github.com/bilalcaliskan/s3-manager/internal/logging" + "github.com/rs/zerolog" + "github.com/spf13/cobra" +) + +func init() { + versioningOpts = options.GetVersioningOptions() +} + +var ( + svc s3iface.S3API + logger zerolog.Logger + versioningOpts *options.VersioningOptions + EnabledCmd = &cobra.Command{ + Use: "enabled", + Short: "", + SilenceUsage: true, + SilenceErrors: true, + RunE: func(cmd *cobra.Command, args []string) (err error) { + rootOpts := cmd.Context().Value(rootopts.OptsKey{}).(*rootopts.RootOptions) + svc = cmd.Context().Value(rootopts.S3SvcKey{}).(s3iface.S3API) + + versioningOpts.RootOptions = rootOpts + logger = logging.GetLogger(rootOpts) + + if err := utils.CheckArgs(args); err != nil { + logger.Error(). + Msg(err.Error()) + return err + } + + versioningOpts.DesiredState = "enabled" + versioning, err := aws.GetBucketVersioning(svc, versioningOpts.RootOptions) + if err != nil { + logger.Error().Msg(err.Error()) + return err + } + + if err := utils.DecideActualState(versioning, versioningOpts); err != nil { + logger.Error().Msg(err.Error()) + return err + } + + logger.Info().Msgf(utils.InfCurrentState, versioningOpts.ActualState) + if versioningOpts.ActualState == "enabled" { + logger.Warn(). + Str("state", versioningOpts.ActualState). + Msg(utils.WarnDesiredState) + return nil + } + + logger.Info().Msgf(utils.InfSettingVersioning, versioningOpts.DesiredState) + _, err = aws.SetBucketVersioning(svc, versioningOpts) + if err != nil { + return err + } + + logger.Info().Msgf(utils.InfSuccess, versioningOpts.DesiredState) + + return nil + }, + } +) diff --git a/cmd/versioning/set/enabled/enabled_test.go b/cmd/versioning/set/enabled/enabled_test.go new file mode 100644 index 0000000..4444005 --- /dev/null +++ b/cmd/versioning/set/enabled/enabled_test.go @@ -0,0 +1,207 @@ +package enabled + +import ( + "context" + "errors" + "testing" + + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/utils" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/s3/s3iface" + "github.com/bilalcaliskan/s3-manager/cmd/root/options" + internalaws "github.com/bilalcaliskan/s3-manager/internal/aws" + "github.com/stretchr/testify/assert" +) + +var ( + defaultGetBucketVersioningOutput = &s3.GetBucketVersioningOutput{ + Status: aws.String("Enabled"), + } + defaultGetBucketVersioningErr error + defaultPutBucketVersioningOutput = &s3.PutBucketVersioningOutput{} + defaultPutBucketVersioningErr error +) + +func createSvc(rootOpts *options.RootOptions) (*s3.S3, error) { + return internalaws.CreateAwsService(rootOpts) +} + +// Define a mock struct to be used in your unit tests +type mockS3Client struct { + s3iface.S3API +} + +func (m *mockS3Client) GetBucketVersioning(input *s3.GetBucketVersioningInput) (*s3.GetBucketVersioningOutput, error) { + return defaultGetBucketVersioningOutput, defaultGetBucketVersioningErr +} + +func (m *mockS3Client) PutBucketVersioning(input *s3.PutBucketVersioningInput) (*s3.PutBucketVersioningOutput, error) { + return defaultPutBucketVersioningOutput, defaultPutBucketVersioningErr +} + +func TestExecuteTooManyArguments(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + svc, err := createSvc(rootOpts) + assert.NotNil(t, svc) + assert.Nil(t, err) + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + args := []string{"enabled"} + EnabledCmd.SetArgs(args) + + err = EnabledCmd.Execute() + assert.NotNil(t, err) + assert.Equal(t, utils.ErrTooManyArguments, err.Error()) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSuccessEnabled(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Suspended") + defaultPutBucketVersioningErr = nil + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + EnabledCmd.SetArgs([]string{}) + err := EnabledCmd.Execute() + assert.Nil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSuccessEnabledWrongVersioning(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Suspendeddd") + defaultPutBucketVersioningErr = nil + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + EnabledCmd.SetArgs([]string{}) + err := EnabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSuccessAlreadyEnabled(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Enabled") + defaultPutBucketVersioningErr = nil + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + EnabledCmd.SetArgs([]string{}) + err := EnabledCmd.Execute() + assert.Nil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteGetBucketVersioningErr(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = errors.New("dummy error") + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + EnabledCmd.SetArgs([]string{}) + err := EnabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} + +func TestExecuteSetBucketVersioningErr(t *testing.T) { + rootOpts := options.GetRootOptions() + rootOpts.AccessKey = "thisisaccesskey" + rootOpts.SecretKey = "thisissecretkey" + rootOpts.Region = "thisisregion" + rootOpts.BucketName = "thisisbucketname" + + ctx := context.Background() + EnabledCmd.SetContext(ctx) + + mockSvc := &mockS3Client{} + svc = mockSvc + + defaultGetBucketVersioningErr = nil + defaultGetBucketVersioningOutput.Status = aws.String("Suspended") + defaultPutBucketVersioningErr = errors.New("new dummy error") + + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.S3SvcKey{}, svc)) + EnabledCmd.SetContext(context.WithValue(EnabledCmd.Context(), options.OptsKey{}, rootOpts)) + + EnabledCmd.SetArgs([]string{}) + err := EnabledCmd.Execute() + assert.NotNil(t, err) + + rootOpts.SetZeroValues() + versioningOpts.SetZeroValues() +} diff --git a/cmd/versioning/set/set.go b/cmd/versioning/set/set.go index 606f243..99077a9 100644 --- a/cmd/versioning/set/set.go +++ b/cmd/versioning/set/set.go @@ -1,89 +1,21 @@ package set import ( - "fmt" - "strings" - - "github.com/aws/aws-sdk-go/service/s3/s3iface" - rootopts "github.com/bilalcaliskan/s3-manager/cmd/root/options" - "github.com/bilalcaliskan/s3-manager/cmd/versioning/options" - "github.com/bilalcaliskan/s3-manager/internal/aws" - "github.com/bilalcaliskan/s3-manager/internal/logging" - "github.com/rs/zerolog" + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/disabled" + "github.com/bilalcaliskan/s3-manager/cmd/versioning/set/enabled" "github.com/spf13/cobra" ) -const ( - ErrTooManyArguments = "too many arguments. please provide just 'enabled' or 'disabled'" - ErrWrongArgumentProvided = "wrong argument provided. versioning state must be 'enabled' or 'disabled'" - ErrNoArgument = "no argument provided. versioning subcommand takes 'enabled' or 'disabled' argument, please provide one of them" - ErrUnknownStatus = "unknown status '%s' returned from AWS SDK" - - WarnDesiredState = "versioning is already at the desired state, skipping configuration" - - InfSuccess = "successfully configured versioning as %v" - InfCurrentState = "current versioning configuration is %s" - InfSettingVersioning = "setting versioning as %v" -) - func init() { - versioningOpts = options.GetVersioningOptions() + SetCmd.AddCommand(enabled.EnabledCmd) + SetCmd.AddCommand(disabled.DisabledCmd) } var ( - svc s3iface.S3API - logger zerolog.Logger - versioningOpts *options.VersioningOptions - SetCmd = &cobra.Command{ + SetCmd = &cobra.Command{ Use: "set", Short: "", SilenceUsage: true, SilenceErrors: true, - RunE: func(cmd *cobra.Command, args []string) (err error) { - rootOpts := cmd.Context().Value(rootopts.OptsKey{}).(*rootopts.RootOptions) - svc = cmd.Context().Value(rootopts.S3SvcKey{}).(s3iface.S3API) - - versioningOpts.RootOptions = rootOpts - logger = logging.GetLogger(rootOpts) - - if err = checkFlags(logger, args); err != nil { - return err - } - - versioningOpts.DesiredState = strings.ToLower(args[0]) - versioning, err := aws.GetBucketVersioning(svc, versioningOpts.RootOptions) - if err != nil { - return err - } - - switch *versioning.Status { - case "Enabled": - versioningOpts.ActualState = "enabled" - case "Suspended": - versioningOpts.ActualState = "disabled" - default: - err := fmt.Errorf(ErrUnknownStatus, *versioning.Status) - logger.Error().Msg(err.Error()) - return err - } - - logger.Info().Msgf(InfCurrentState, versioningOpts.ActualState) - if versioningOpts.ActualState == "enabled" && versioningOpts.DesiredState == "enabled" || versioningOpts.ActualState == "disabled" && versioningOpts.DesiredState == "disabled" { - logger.Warn(). - Str("state", versioningOpts.ActualState). - Msg(WarnDesiredState) - return nil - } - - logger.Info().Msgf(InfSettingVersioning, versioningOpts.DesiredState) - _, err = aws.SetBucketVersioning(svc, versioningOpts) - if err != nil { - return err - } - - logger.Info().Msgf(InfSuccess, versioningOpts.DesiredState) - - return nil - }, } ) diff --git a/cmd/versioning/set/set_test.go b/cmd/versioning/set/set_test.go index d3a076a..26eb414 100644 --- a/cmd/versioning/set/set_test.go +++ b/cmd/versioning/set/set_test.go @@ -1,284 +1,11 @@ package set import ( - "context" - "errors" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3" - "github.com/aws/aws-sdk-go/service/s3/s3iface" - "github.com/bilalcaliskan/s3-manager/cmd/root/options" - internalaws "github.com/bilalcaliskan/s3-manager/internal/aws" "github.com/stretchr/testify/assert" ) -var ( - defaultGetBucketVersioningOutput = &s3.GetBucketVersioningOutput{ - Status: aws.String("Enabled"), - } - defaultGetBucketVersioningErr error - defaultPutBucketVersioningOutput = &s3.PutBucketVersioningOutput{} - defaultPutBucketVersioningErr error -) - -func createSvc(rootOpts *options.RootOptions) (*s3.S3, error) { - return internalaws.CreateAwsService(rootOpts) -} - -// Define a mock struct to be used in your unit tests -type mockS3Client struct { - s3iface.S3API -} - -func (m *mockS3Client) GetBucketVersioning(input *s3.GetBucketVersioningInput) (*s3.GetBucketVersioningOutput, error) { - return defaultGetBucketVersioningOutput, defaultGetBucketVersioningErr -} - -func (m *mockS3Client) PutBucketVersioning(input *s3.PutBucketVersioningInput) (*s3.PutBucketVersioningOutput, error) { - return defaultPutBucketVersioningOutput, defaultPutBucketVersioningErr -} - -func TestExecuteTooManyArguments(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - svc, err := createSvc(rootOpts) - assert.NotNil(t, svc) - assert.Nil(t, err) - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - args := []string{"enabled", "foo"} - SetCmd.SetArgs(args) - - err = SetCmd.Execute() - assert.NotNil(t, err) - assert.Equal(t, ErrTooManyArguments, err.Error()) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteWrongArguments(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - svc, err := createSvc(rootOpts) - assert.NotNil(t, svc) - assert.Nil(t, err) - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - args := []string{"eeenabled"} - SetCmd.SetArgs(args) - - err = SetCmd.Execute() - assert.NotNil(t, err) - assert.Equal(t, ErrWrongArgumentProvided, err.Error()) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteNoArgument(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - svc, err := createSvc(rootOpts) - assert.NotNil(t, svc) - assert.Nil(t, err) - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{}) - err = SetCmd.Execute() - assert.NotNil(t, err) - assert.Equal(t, ErrNoArgument, err.Error()) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteSuccessEnabled(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = nil - defaultGetBucketVersioningOutput.Status = aws.String("Suspended") - defaultPutBucketVersioningErr = nil - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"enabled"}) - err := SetCmd.Execute() - assert.Nil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteSuccessEnabledWrongVersioning(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = nil - defaultGetBucketVersioningOutput.Status = aws.String("Suspendeddd") - defaultPutBucketVersioningErr = nil - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"enabled"}) - err := SetCmd.Execute() - assert.NotNil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteSuccessDisabled(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = nil - defaultGetBucketVersioningOutput.Status = aws.String("Enabled") - defaultPutBucketVersioningErr = nil - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"disabled"}) - err := SetCmd.Execute() - assert.Nil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteSuccessAlreadyEnabled(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = nil - defaultGetBucketVersioningOutput.Status = aws.String("Enabled") - defaultPutBucketVersioningErr = nil - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"enabled"}) - err := SetCmd.Execute() - assert.Nil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteGetBucketVersioningErr(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = errors.New("dummy error") - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"enabled"}) - err := SetCmd.Execute() - assert.NotNil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() -} - -func TestExecuteSetBucketVersioningErr(t *testing.T) { - rootOpts := options.GetRootOptions() - rootOpts.AccessKey = "thisisaccesskey" - rootOpts.SecretKey = "thisissecretkey" - rootOpts.Region = "thisisregion" - rootOpts.BucketName = "thisisbucketname" - - ctx := context.Background() - SetCmd.SetContext(ctx) - - mockSvc := &mockS3Client{} - svc = mockSvc - - defaultGetBucketVersioningErr = nil - defaultPutBucketVersioningErr = errors.New("new dummy error") - - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.S3SvcKey{}, svc)) - SetCmd.SetContext(context.WithValue(SetCmd.Context(), options.OptsKey{}, rootOpts)) - - SetCmd.SetArgs([]string{"disabled"}) - err := SetCmd.Execute() - assert.NotNil(t, err) - - rootOpts.SetZeroValues() - versioningOpts.SetZeroValues() +func TestSetCmd(t *testing.T) { + assert.NotNil(t, SetCmd) } diff --git a/cmd/versioning/set/utils.go b/cmd/versioning/set/utils.go deleted file mode 100644 index 4ff64a0..0000000 --- a/cmd/versioning/set/utils.go +++ /dev/null @@ -1,34 +0,0 @@ -package set - -import ( - "errors" - "strings" - - "github.com/rs/zerolog" -) - -func checkFlags(logger zerolog.Logger, args []string) (err error) { - if len(args) == 0 { - err = errors.New(ErrNoArgument) - logger.Error(). - Msg(err.Error()) - return err - } - - if len(args) > 1 { - err = errors.New(ErrTooManyArguments) - logger.Error(). - Msg(err.Error()) - return err - } - - ver := strings.ToLower(args[0]) - if ver != "enabled" && ver != "disabled" { - err = errors.New(ErrWrongArgumentProvided) - logger.Error(). - Msg(err.Error()) - return err - } - - return nil -} diff --git a/cmd/versioning/set/utils/utils.go b/cmd/versioning/set/utils/utils.go new file mode 100644 index 0000000..f84016a --- /dev/null +++ b/cmd/versioning/set/utils/utils.go @@ -0,0 +1,41 @@ +package utils + +import ( + "errors" + "fmt" + + "github.com/aws/aws-sdk-go/service/s3" + "github.com/bilalcaliskan/s3-manager/cmd/versioning/options" +) + +const ( + ErrTooManyArguments = "too many arguments. please provide just 'enabled' or 'disabled'" + ErrUnknownStatus = "unknown status '%s' returned from AWS SDK" + + WarnDesiredState = "versioning is already at the desired state, skipping configuration" + + InfSuccess = "successfully configured versioning as %v" + InfCurrentState = "current versioning configuration is %s" + InfSettingVersioning = "setting versioning as %v" +) + +func CheckArgs(args []string) error { + if len(args) != 0 { + return errors.New(ErrTooManyArguments) + } + + return nil +} + +func DecideActualState(versioning *s3.GetBucketVersioningOutput, opts *options.VersioningOptions) error { + switch *versioning.Status { + case "Enabled": + opts.ActualState = "enabled" + case "Suspended": + opts.ActualState = "disabled" + default: + return fmt.Errorf(ErrUnknownStatus, *versioning.Status) + } + + return nil +} diff --git a/cmd/versioning/set/utils/utils_test.go b/cmd/versioning/set/utils/utils_test.go new file mode 100644 index 0000000..b964ebf --- /dev/null +++ b/cmd/versioning/set/utils/utils_test.go @@ -0,0 +1,60 @@ +package utils + +import ( + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/s3" + "github.com/bilalcaliskan/s3-manager/cmd/root/options" + options2 "github.com/bilalcaliskan/s3-manager/cmd/versioning/options" + "github.com/stretchr/testify/assert" +) + +func TestCheckArgsSuccess(t *testing.T) { + err := CheckArgs([]string{}) + assert.Nil(t, err) +} + +func TestCheckArgsFailure(t *testing.T) { + err := CheckArgs([]string{"foo"}) + assert.NotNil(t, err) +} + +func TestDecideActualStateEnabled(t *testing.T) { + res := &s3.GetBucketVersioningOutput{ + Status: aws.String("Enabled"), + } + + rootOpts := options.GetRootOptions() + opts := options2.GetVersioningOptions() + opts.RootOptions = rootOpts + + err := DecideActualState(res, opts) + assert.Nil(t, err) +} + +func TestDecideActualStateSuspended(t *testing.T) { + res := &s3.GetBucketVersioningOutput{ + Status: aws.String("Suspended"), + } + + rootOpts := options.GetRootOptions() + opts := options2.GetVersioningOptions() + opts.RootOptions = rootOpts + + err := DecideActualState(res, opts) + assert.Nil(t, err) +} + +func TestDecideActualStateUndefined(t *testing.T) { + res := &s3.GetBucketVersioningOutput{ + Status: aws.String("Suspendedddddd"), + } + + rootOpts := options.GetRootOptions() + opts := options2.GetVersioningOptions() + opts.RootOptions = rootOpts + + err := DecideActualState(res, opts) + assert.NotNil(t, err) +} diff --git a/go.mod b/go.mod index a150d75..259a04e 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/bilalcaliskan/s3-manager go 1.20 require ( - github.com/aws/aws-sdk-go v1.44.271 + github.com/aws/aws-sdk-go v1.44.275 github.com/dimiro1/banner v1.1.0 github.com/manifoldco/promptui v0.9.0 github.com/rs/zerolog v1.29.1 github.com/spf13/cobra v1.7.0 - github.com/spf13/viper v1.15.0 - github.com/stretchr/testify v1.8.3 + github.com/spf13/viper v1.16.0 + github.com/stretchr/testify v1.8.4 ) require ( @@ -24,14 +24,14 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.18 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.0.7 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/afero v1.9.5 // indirect - github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect - golang.org/x/sys v0.7.0 // indirect + golang.org/x/sys v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 7a7097f..ab8a888 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 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/aws/aws-sdk-go v1.44.271 h1:aa+Nu2JcnFmW1TLIz/67SS7KPq1I1Adl4RmExSMjGVo= -github.com/aws/aws-sdk-go v1.44.271/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go v1.44.275 h1:VqRULgqrigvQLll4e4hXuc568EQAtZQ6jmBzLlQHzSI= +github.com/aws/aws-sdk-go v1.44.275/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= @@ -69,7 +69,7 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -148,7 +148,7 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -168,31 +168,31 @@ github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp9 github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= -github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= -github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= -github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU= -github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -202,9 +202,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -294,7 +294,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -362,8 +362,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=