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

Commit

Permalink
Implement first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
motchie committed Apr 23, 2017
1 parent 0b36727 commit 19937d2
Show file tree
Hide file tree
Showing 25 changed files with 1,355 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# s3w #

A CLI for Amazon S3 website configurations.

### Description

s3w is a Command Line Interface tool that control Amazon S3 website configurations.
An auxiliary tool for aws cli.

### Features

* No JSON required to use.
* AWS CLI compatible credentials and flags.
* Reduce operations for most common use.

### Usage
```
s3w is a Command Line Interface tool that control Amazon S3 website configurations.
An auxiliary tool for aws cli.
- No JSON required to use.
- AWS CLI compatible credentials and flags.
- Reduce operations for most common use.
Usage:
s3w [command]
Available Commands:
delete-website Removes the website configuration from the bucket
get-bucket-acl Gets the access control list (ACL) for the bucket.
get-bucket-policy Gets the policy of a specified bucket.
get-location Returns returns the region the bucket resides in
get-website Returns the website configuration for a bucket
help Help about any command
list-buckets List all S3 buckets
set-bucket-acl Sets the permissions on a bucket using access control list (ACL).
set-bucket-policy-for-website Replaces a policy on a bucket for Web Site.
set-redirect-all-requests Set to redirect all website requests sent to the bucket's endpoint
set-website Set the website configuration for a bucket.
version Show version and Copyright.
Flags:
-t, --toggle Help message for toggle
Use "s3w [command] --help" for more information about a command.```
## Installation
## Author
[motchie](https://github.com/motchie)
## License
[MIT](https://github.com/motchie/blob/master/LICENCE)
52 changes: 52 additions & 0 deletions cmd/delete-website.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var deleteWebsiteCmd = &cobra.Command{
Use: "delete-website",
Short: "Removes the website configuration from the bucket",
Long: `removes the website configuration from the bucket.`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(bucket) == 0 {
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
os.Exit(-1)
}
},
Run: func(cmd *cobra.Command, args []string) {
if err := s3.DeleteWebSite(bucket); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}
},
}

func init() {
RootCmd.AddCommand(deleteWebsiteCmd)
deleteWebsiteCmd.Flags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to remove the website configuration.")
}
54 changes: 54 additions & 0 deletions cmd/get-bucket-acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var getBucketACLCmd = &cobra.Command{
Use: "get-bucket-acl",
Short: "Gets the access control list (ACL) for the bucket.",
Long: `Gets the access control list (ACL) for the bucket.`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(bucket) == 0 {
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
os.Exit(-1)
}
},
Run: func(cmd *cobra.Command, args []string) {
acl, err := s3.GetBucketACL(bucket)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Println(acl)
},
}

func init() {
RootCmd.AddCommand(getBucketACLCmd)
getBucketACLCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
}
54 changes: 54 additions & 0 deletions cmd/get-bucket-policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var getBucketPolicyCmd = &cobra.Command{
Use: "get-bucket-policy",
Short: "Gets the policy of a specified bucket.",
Long: `Gets the policy of a specified bucket.`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(bucket) == 0 {
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
os.Exit(-1)
}
},
Run: func(cmd *cobra.Command, args []string) {
policy, err := s3.GetBucketPolicy(bucket)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Println(policy)
},
}

func init() {
RootCmd.AddCommand(getBucketPolicyCmd)
getBucketPolicyCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
}
58 changes: 58 additions & 0 deletions cmd/get-location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var getLocationCmd = &cobra.Command{
Use: "get-location",
Short: "Returns returns the region the bucket resides in",
Long: `returns the website configuration for a bucket:
ErrorDocument : The object key name to use when a 4XX class error occurs.
IndexDocument : A suffix that is appended to a request that is for a directory on the website endpoint(required).
`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(bucket) == 0 {
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
os.Exit(-1)
}
},
Run: func(cmd *cobra.Command, args []string) {
location, err := s3.GetLocation(bucket)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}
fmt.Println(location)
},
}

func init() {
RootCmd.AddCommand(getLocationCmd)
getLocationCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
}
56 changes: 56 additions & 0 deletions cmd/get-website.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var getWebsiteCmd = &cobra.Command{
Use: "get-website",
Short: "Returns the website configuration for a bucket",
Long: `returns the website configuration for a bucket:
ErrorDocument : The object key name to use when a 4XX class error occurs.
IndexDocument : A suffix that is appended to a request that is for a directory on the website endpoint(required).
`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(bucket) == 0 {
fmt.Fprintf(os.Stderr, "Bucketname Empty\n")
os.Exit(-1)
}
},
Run: func(cmd *cobra.Command, args []string) {
if err := s3.GetWebSite(bucket); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}
},
}

func init() {
RootCmd.AddCommand(getWebsiteCmd)
getWebsiteCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "The name of S3 bucket to get.")
}
49 changes: 49 additions & 0 deletions cmd/list-buckets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2017 Toru Motchie MOCHIDA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"

"github.com/motchie/s3w/s3"
"github.com/spf13/cobra"
)

var showCreationDate bool

var listBucketsCmd = &cobra.Command{
Use: "list-buckets",
Short: "List all S3 buckets",
Long: `List all S3 buckets and creation date.`,
Run: func(cmd *cobra.Command, args []string) {
if err := s3.ListBuckets(showCreationDate); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}

},
}

func init() {
RootCmd.AddCommand(listBucketsCmd)
listBucketsCmd.Flags().BoolVarP(&showCreationDate, "show-creation-date", "d", false, "Flag for showing creation date.")
}
Loading

0 comments on commit 19937d2

Please sign in to comment.