-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
- Loading branch information
Showing
7 changed files
with
181 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Package cp implements "aws s3 cp" commands. | ||
package cp | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
pkg_aws "github.com/aws/aws-k8s-tester/pkg/aws" | ||
pkg_s3 "github.com/aws/aws-k8s-tester/pkg/aws/s3" | ||
"github.com/aws/aws-k8s-tester/pkg/logutil" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var ( | ||
logLevel string | ||
partition string | ||
region string | ||
s3Bucket string | ||
s3Key string | ||
localPath string | ||
) | ||
|
||
func init() { | ||
cobra.EnablePrefixMatching = true | ||
} | ||
|
||
// NewCommand implements "s3-utils cp" command. | ||
func NewCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "cp", | ||
Short: "AWS s3 cp commands", | ||
Run: cpFunc, | ||
} | ||
cmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error, dpanic, panic, fatal)") | ||
cmd.PersistentFlags().StringVar(&partition, "partition", "aws", "AWS partition") | ||
cmd.PersistentFlags().StringVar(®ion, "region", "us-west-2", "AWS region") | ||
cmd.PersistentFlags().StringVar(&s3Bucket, "s3-bucket", "", "s3 bucket") | ||
cmd.PersistentFlags().StringVar(&s3Key, "s3-key", "", "s3 key") | ||
cmd.PersistentFlags().StringVar(&localPath, "local-path", "", "local download path") | ||
return cmd | ||
} | ||
|
||
func cpFunc(cmd *cobra.Command, args []string) { | ||
lcfg := logutil.GetDefaultZapLoggerConfig() | ||
lcfg.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(logLevel)) | ||
lg, err := lcfg.Build() | ||
if err != nil { | ||
panic(err) | ||
} | ||
ss, stsOutput, _, err := pkg_aws.New(&pkg_aws.Config{ | ||
Logger: lg, | ||
DebugAPICalls: logLevel == "debug", | ||
Partition: partition, | ||
Region: region, | ||
}) | ||
if stsOutput == nil || err != nil { | ||
lg.Warn("failed to create AWS session and get sts caller identity", zap.Error(err)) | ||
} else { | ||
roleARN := aws.StringValue(stsOutput.Arn) | ||
fmt.Fprintf(os.Stderr, "\nAccount: %q\n", aws.StringValue(stsOutput.Account)) | ||
fmt.Fprintf(os.Stderr, "Role Arn: %q\n", roleARN) | ||
fmt.Fprintf(os.Stderr, "UserId: %q\n\n", aws.StringValue(stsOutput.UserId)) | ||
} | ||
|
||
if err = pkg_s3.Download(lg, s3.New(ss), s3Bucket, s3Key, localPath, pkg_s3.WithOverwrite(true)); err != nil { | ||
lg.Fatal("failed to download S3 file", | ||
zap.String("s3-bucket", s3Bucket), | ||
zap.String("s3-key", s3Key), | ||
zap.Error(err), | ||
) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "SUCCESSFULLY DOWNLOADED %q %q to %q\n", s3Bucket, s3Key, localPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// s3-utils is a set of AWS utilities commands. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/aws/aws-k8s-tester/cmd/s3-utils/cp" | ||
"github.com/aws/aws-k8s-tester/cmd/s3-utils/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "s3-utils", | ||
Short: "AWS utils CLI", | ||
} | ||
|
||
func init() { | ||
cobra.EnablePrefixMatching = true | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand( | ||
cp.NewCommand(), | ||
version.NewCommand(), | ||
) | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "s3-utils failed %v\n", err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// sts-utils is a set of AWS utilities commands. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
get_caller_identity "github.com/aws/aws-k8s-tester/cmd/sts-utils/get-caller-identity" | ||
"github.com/aws/aws-k8s-tester/cmd/sts-utils/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "sts-utils", | ||
Short: "AWS utils CLI", | ||
SuggestFor: []string{"stsutils"}, | ||
} | ||
|
||
func init() { | ||
cobra.EnablePrefixMatching = true | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand( | ||
get_caller_identity.NewCommand(), | ||
version.NewCommand(), | ||
) | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "sts-utils failed %v\n", err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Package version implements version command. | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-k8s-tester/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
cobra.EnablePrefixMatching = true | ||
} | ||
|
||
// NewCommand implements "cw-utils version" command. | ||
func NewCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints out cw-utils version", | ||
Run: versionFunc, | ||
} | ||
} | ||
|
||
func versionFunc(cmd *cobra.Command, args []string) { | ||
fmt.Println(version.Version()) | ||
} |