Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit 19937d2

Browse files
committed
Implement first draft
1 parent 0b36727 commit 19937d2

25 files changed

+1355
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# s3w #
2+
3+
A CLI for Amazon S3 website configurations.
4+
5+
### Description
6+
7+
s3w is a Command Line Interface tool that control Amazon S3 website configurations.
8+
An auxiliary tool for aws cli.
9+
10+
### Features
11+
12+
* No JSON required to use.
13+
* AWS CLI compatible credentials and flags.
14+
* Reduce operations for most common use.
15+
16+
### Usage
17+
```
18+
s3w is a Command Line Interface tool that control Amazon S3 website configurations.
19+
An auxiliary tool for aws cli.
20+
21+
- No JSON required to use.
22+
- AWS CLI compatible credentials and flags.
23+
- Reduce operations for most common use.
24+
25+
Usage:
26+
s3w [command]
27+
28+
Available Commands:
29+
delete-website Removes the website configuration from the bucket
30+
get-bucket-acl Gets the access control list (ACL) for the bucket.
31+
get-bucket-policy Gets the policy of a specified bucket.
32+
get-location Returns returns the region the bucket resides in
33+
get-website Returns the website configuration for a bucket
34+
help Help about any command
35+
list-buckets List all S3 buckets
36+
set-bucket-acl Sets the permissions on a bucket using access control list (ACL).
37+
set-bucket-policy-for-website Replaces a policy on a bucket for Web Site.
38+
set-redirect-all-requests Set to redirect all website requests sent to the bucket's endpoint
39+
set-website Set the website configuration for a bucket.
40+
version Show version and Copyright.
41+
42+
Flags:
43+
-t, --toggle Help message for toggle
44+
45+
Use "s3w [command] --help" for more information about a command.```
46+
## Installation
47+
48+
## Author
49+
50+
[motchie](https://github.com/motchie)
51+
52+
## License
53+
54+
[MIT](https://github.com/motchie/blob/master/LICENCE)

cmd/delete-website.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var deleteWebsiteCmd = &cobra.Command{
32+
Use: "delete-website",
33+
Short: "Removes the website configuration from the bucket",
34+
Long: `removes the website configuration from the bucket.`,
35+
PreRun: func(cmd *cobra.Command, args []string) {
36+
if len(bucket) == 0 {
37+
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
38+
os.Exit(-1)
39+
}
40+
},
41+
Run: func(cmd *cobra.Command, args []string) {
42+
if err := s3.DeleteWebSite(bucket); err != nil {
43+
fmt.Fprintf(os.Stderr, "%v\n", err)
44+
os.Exit(-1)
45+
}
46+
},
47+
}
48+
49+
func init() {
50+
RootCmd.AddCommand(deleteWebsiteCmd)
51+
deleteWebsiteCmd.Flags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to remove the website configuration.")
52+
}

cmd/get-bucket-acl.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var getBucketACLCmd = &cobra.Command{
32+
Use: "get-bucket-acl",
33+
Short: "Gets the access control list (ACL) for the bucket.",
34+
Long: `Gets the access control list (ACL) for the bucket.`,
35+
PreRun: func(cmd *cobra.Command, args []string) {
36+
if len(bucket) == 0 {
37+
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
38+
os.Exit(-1)
39+
}
40+
},
41+
Run: func(cmd *cobra.Command, args []string) {
42+
acl, err := s3.GetBucketACL(bucket)
43+
if err != nil {
44+
fmt.Fprintf(os.Stderr, "%v\n", err)
45+
os.Exit(1)
46+
}
47+
fmt.Println(acl)
48+
},
49+
}
50+
51+
func init() {
52+
RootCmd.AddCommand(getBucketACLCmd)
53+
getBucketACLCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
54+
}

cmd/get-bucket-policy.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var getBucketPolicyCmd = &cobra.Command{
32+
Use: "get-bucket-policy",
33+
Short: "Gets the policy of a specified bucket.",
34+
Long: `Gets the policy of a specified bucket.`,
35+
PreRun: func(cmd *cobra.Command, args []string) {
36+
if len(bucket) == 0 {
37+
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
38+
os.Exit(-1)
39+
}
40+
},
41+
Run: func(cmd *cobra.Command, args []string) {
42+
policy, err := s3.GetBucketPolicy(bucket)
43+
if err != nil {
44+
fmt.Fprintf(os.Stderr, "%v\n", err)
45+
os.Exit(1)
46+
}
47+
fmt.Println(policy)
48+
},
49+
}
50+
51+
func init() {
52+
RootCmd.AddCommand(getBucketPolicyCmd)
53+
getBucketPolicyCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
54+
}

cmd/get-location.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var getLocationCmd = &cobra.Command{
32+
Use: "get-location",
33+
Short: "Returns returns the region the bucket resides in",
34+
Long: `returns the website configuration for a bucket:
35+
36+
ErrorDocument : The object key name to use when a 4XX class error occurs.
37+
IndexDocument : A suffix that is appended to a request that is for a directory on the website endpoint(required).
38+
`,
39+
PreRun: func(cmd *cobra.Command, args []string) {
40+
if len(bucket) == 0 {
41+
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
42+
os.Exit(-1)
43+
}
44+
},
45+
Run: func(cmd *cobra.Command, args []string) {
46+
location, err := s3.GetLocation(bucket)
47+
if err != nil {
48+
fmt.Fprintf(os.Stderr, "%v\n", err)
49+
os.Exit(-1)
50+
}
51+
fmt.Println(location)
52+
},
53+
}
54+
55+
func init() {
56+
RootCmd.AddCommand(getLocationCmd)
57+
getLocationCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
58+
}

cmd/get-website.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var getWebsiteCmd = &cobra.Command{
32+
Use: "get-website",
33+
Short: "Returns the website configuration for a bucket",
34+
Long: `returns the website configuration for a bucket:
35+
36+
ErrorDocument : The object key name to use when a 4XX class error occurs.
37+
IndexDocument : A suffix that is appended to a request that is for a directory on the website endpoint(required).
38+
`,
39+
PreRun: func(cmd *cobra.Command, args []string) {
40+
if len(bucket) == 0 {
41+
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
42+
os.Exit(-1)
43+
}
44+
},
45+
Run: func(cmd *cobra.Command, args []string) {
46+
if err := s3.GetWebSite(bucket); err != nil {
47+
fmt.Fprintf(os.Stderr, "%v\n", err)
48+
os.Exit(-1)
49+
}
50+
},
51+
}
52+
53+
func init() {
54+
RootCmd.AddCommand(getWebsiteCmd)
55+
getWebsiteCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
56+
}

cmd/list-buckets.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2017 Toru Motchie MOCHIDA
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"fmt"
25+
"os"
26+
27+
"github.com/motchie/s3w/s3"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
var showCreationDate bool
32+
33+
var listBucketsCmd = &cobra.Command{
34+
Use: "list-buckets",
35+
Short: "List all S3 buckets",
36+
Long: `List all S3 buckets and creation date.`,
37+
Run: func(cmd *cobra.Command, args []string) {
38+
if err := s3.ListBuckets(showCreationDate); err != nil {
39+
fmt.Fprintf(os.Stderr, "%v\n", err)
40+
os.Exit(-1)
41+
}
42+
43+
},
44+
}
45+
46+
func init() {
47+
RootCmd.AddCommand(listBucketsCmd)
48+
listBucketsCmd.Flags().BoolVarP(&showCreationDate, "show-creation-date", "d", false, "Flag for showing creation date.")
49+
}

0 commit comments

Comments
 (0)