Skip to content

Commit

Permalink
feat(transferacceleration): implement transferacceleration and its su…
Browse files Browse the repository at this point in the history
…bcommands
  • Loading branch information
bilalcaliskan committed Jun 11, 2023
1 parent 57d9c6b commit d7b2275
Show file tree
Hide file tree
Showing 18 changed files with 1,443 additions and 13 deletions.
8 changes: 4 additions & 4 deletions TODOLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
- [x] tags
- [x] search/text (all files, single file etc.)
- [x] bucketpolicy
- [ ] ~~storageclass~~
- [ ] ~~encryption~~
- [ ] ~~objectlock~~
- [x] transferacceleration
- [ ] mfadelete
- [ ] transferacceleration
- [ ] re-enable prompt/select logic
- [ ] fix code smells
- [ ] fix duplications
- [ ] ~~storageclass~~
- [ ] ~~encryption~~
- [ ] ~~objectlock~~
3 changes: 3 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"strings"

"github.com/bilalcaliskan/s3-manager/cmd/transferacceleration"

"github.com/bilalcaliskan/s3-manager/cmd/bucketpolicy"

"github.com/bilalcaliskan/s3-manager/cmd/tags"
Expand Down Expand Up @@ -36,6 +38,7 @@ func init() {
rootCmd.AddCommand(versioning.VersioningCmd)
rootCmd.AddCommand(tags.TagsCmd)
rootCmd.AddCommand(bucketpolicy.BucketPolicyCmd)
rootCmd.AddCommand(transferacceleration.TransferAccelerationCmd)
}

var (
Expand Down
50 changes: 50 additions & 0 deletions cmd/transferacceleration/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package options

import (
"github.com/bilalcaliskan/s3-manager/cmd/root/options"
)

type TransferAccelerationOptsKey struct{}

var (
//substringRunner prompt.PromptRunner = prompt.GetPromptRunner("Provide text to search", nil)
//extensionRunner prompt.PromptRunner = prompt.GetPromptRunner("Provide target file extensions (comma seperated)", nil)
transferAccelerationOpts = &TransferAccelerationOptions{}
)

// TransferAccelerationOptions contains frequent command line and application options.
type TransferAccelerationOptions struct {
// ActualState is state
ActualState string
// DesiredState is state
DesiredState string
*options.RootOptions
}

// GetTransferAccelerationOptions returns the pointer of FindOptions
func GetTransferAccelerationOptions() *TransferAccelerationOptions {
return transferAccelerationOpts
}

func (opts *TransferAccelerationOptions) SetZeroValues() {
opts.ActualState = "Enabled"
opts.DesiredState = "enabled"
opts.RootOptions.SetZeroValues()
}

/*func (opts *ConfigureOptions) PromptInteractiveValues() error {
res, err := substringRunner.Run()
if err != nil {
return err
}
opts.Foo = res
res, err = extensionRunner.Run()
if err != nil {
return err
}
opts.FileExtensions = res
return nil
}
*/
23 changes: 23 additions & 0 deletions cmd/transferacceleration/options/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package options

import (
"testing"

"github.com/bilalcaliskan/s3-manager/cmd/root/options"

"github.com/stretchr/testify/assert"
)

func TestGetTransferAccelerationOptions(t *testing.T) {
opts := GetTransferAccelerationOptions()
assert.NotNil(t, opts)
}

func TestTransferAccelerationOptions_SetZeroValues(t *testing.T) {
rootOpts := options.GetRootOptions()
opts := GetTransferAccelerationOptions()
opts.RootOptions = rootOpts
assert.NotNil(t, opts)

opts.SetZeroValues()
}
62 changes: 62 additions & 0 deletions cmd/transferacceleration/set/disabled/disabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package disabled

import (
options2 "github.com/bilalcaliskan/s3-manager/cmd/transferacceleration/options"
"github.com/bilalcaliskan/s3-manager/cmd/transferacceleration/utils"

"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/bilalcaliskan/s3-manager/internal/aws"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
)

func init() {
transferAccelerationOpts = options2.GetTransferAccelerationOptions()
}

var (
svc s3iface.S3API
logger zerolog.Logger
transferAccelerationOpts *options2.TransferAccelerationOptions
DisabledCmd = &cobra.Command{
Use: "disabled",
Short: "",
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
svc, transferAccelerationOpts, logger = utils.PrepareConstants(cmd, transferAccelerationOpts)

if err := utils.CheckArgs(args); err != nil {
logger.Error().
Msg(err.Error())
return err
}

transferAccelerationOpts.DesiredState = "disabled"
res, err := aws.GetTransferAcceleration(svc, transferAccelerationOpts)
if err != nil {
logger.Error().Msg(err.Error())
return err
}

if err := utils.DecideActualState(res, transferAccelerationOpts); err != nil {
logger.Error().Msg(err.Error())
return err
}

if transferAccelerationOpts.DesiredState == transferAccelerationOpts.ActualState {
logger.Warn().Msg("transferr acceleration configuration is already at desired state")
return nil
}

if _, err := aws.SetTransferAcceleration(svc, transferAccelerationOpts); err != nil {
logger.Error().Msg(err.Error())
return err
}

logger.Info().Msg("successfully set transfer acceleration as disabled")

return nil
},
}
)
Loading

0 comments on commit d7b2275

Please sign in to comment.