Skip to content

Commit bd0c551

Browse files
committed
update
1 parent dfba8e1 commit bd0c551

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

cmd/s3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Cobra is a CLI library for Go that empowers applications.
3333
This application is a tool to generate the needed files
3434
to quickly create a Cobra application.`,
3535
Run: func(cmd *cobra.Command, args []string) {
36-
fmt.Println(myaws.OpenS3(args[0]))
36+
fmt.Println(myaws.OpenS3(args))
3737
},
3838
}
3939

pkg/myaws/myaws.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,32 @@ func ListeneRule(arnstr string) string {
3535
return url
3636
}
3737

38-
func OpenS3(s3path string) string {
38+
func OpenS3(s3args []string) string {
39+
u, _ := url.Parse("https://s3.console.aws.amazon.com/s3/")
40+
q := u.Query()
41+
u.Path = "s3/"
42+
43+
s3path := s3args[0]
3944
r := regexp.MustCompile(`/`)
4045
str := r.Split(s3path, 2)
4146
log.WithFields(
4247
log.Fields{
43-
"s3 args": str,
48+
"s3args": s3args,
49+
"str": str,
4450
}).Debug()
45-
u, _ := url.Parse("https://s3.console.aws.amazon.com/s3/")
46-
q := u.Query()
47-
u.Path = "s3/"
4851
if len(str) > 1 {
52+
// objects
4953
q.Set("prefix", str[1])
5054
u.Path += "object/" + str[0]
5155
} else {
52-
q.Set("tab", "objects")
56+
// buckets
5357
u.Path += "buckets/" + str[0]
58+
q.Set("tab", "objects")
5459
}
5560

61+
if len(s3args) > 1 {
62+
q.Set("tab", s3args[1])
63+
}
5664
u.RawQuery = q.Encode()
5765
return u.String()
5866
}

pkg/myaws/myaws_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ func TestListeneRule(t *testing.T) {
1818

1919
func TestOpenS3(t *testing.T) {
2020
a := []struct {
21-
input string
21+
input []string
2222
want string
2323
}{
2424
{
25-
input: "cf-templates-xxxxxxxxxxx-ap-northeast-1",
25+
input: []string{"cf-templates-xxxxxxxxxxx-ap-northeast-1"},
2626
want: "https://s3.console.aws.amazon.com/s3/buckets/cf-templates-xxxxxxxxxxx-ap-northeast-1?tab=objects",
2727
},
2828
{
29-
input: "cf-templates-xxxxxxxxx-ap-northeast-1/20130701Ac-cf2.txt",
29+
input: []string{"cf-templates-xxxxxxxxx-ap-northeast-1/20130701Ac-cf2.txt"},
3030
want: "https://s3.console.aws.amazon.com/s3/object/cf-templates-xxxxxxxxx-ap-northeast-1?prefix=20130701Ac-cf2.txt",
3131
},
32+
{
33+
input: []string{"cf-templates-xxxxxxxxx-ap-northeast-1", "permissions"},
34+
want: "https://s3.console.aws.amazon.com/s3/buckets/cf-templates-xxxxxxxxx-ap-northeast-1?tab=permissions",
35+
},
3236
}
3337

3438
for _, v := range a {

0 commit comments

Comments
 (0)