|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "coscli/util" |
| 5 | + "fmt" |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
| 8 | + |
| 9 | +var bucketAclCmd = &cobra.Command{ |
| 10 | + Use: "bucket-acl", |
| 11 | + Short: "Modify bucket acl", |
| 12 | + Long: `Modify bucket acl |
| 13 | +
|
| 14 | +Format: |
| 15 | + ./coscli bucket-acl --method [method] cos://<bucket-name> |
| 16 | +
|
| 17 | +Example: |
| 18 | + ./coscli bucket-acl --method put cos://examplebucket --grant-read="id=\"100000000003\",id=\"100000000002\"" |
| 19 | + ./coscli bucket-acl --method get cos://examplebucket`, |
| 20 | + Args: cobra.ExactArgs(1), |
| 21 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 22 | + var aclSettings util.ACLSettings |
| 23 | + method, _ := cmd.Flags().GetString("method") |
| 24 | + aclSettings.ACL, _ = cmd.Flags().GetString("acl") |
| 25 | + aclSettings.GrantRead, _ = cmd.Flags().GetString("grant-read") |
| 26 | + aclSettings.GrantWrite, _ = cmd.Flags().GetString("grant-write") |
| 27 | + aclSettings.GrantReadACP, _ = cmd.Flags().GetString("grant-read-acp") |
| 28 | + aclSettings.GrantWriteACP, _ = cmd.Flags().GetString("grant-write-acp") |
| 29 | + aclSettings.GrantFullControl, _ = cmd.Flags().GetString("grant-full-control") |
| 30 | + |
| 31 | + var err error |
| 32 | + cosPath := args[0] |
| 33 | + if !util.IsCosPath(cosPath) { |
| 34 | + return fmt.Errorf("cospath needs to contain cos://") |
| 35 | + } |
| 36 | + |
| 37 | + bucketName, _ := util.ParsePath(cosPath) |
| 38 | + c, err := util.NewClient(&config, ¶m, bucketName) |
| 39 | + if err != nil { |
| 40 | + return err |
| 41 | + } |
| 42 | + |
| 43 | + if method == "put" { |
| 44 | + err = util.PutBucketAcl(c, aclSettings) |
| 45 | + } else if method == "get" { |
| 46 | + err = util.GetBucketAcl(c) |
| 47 | + } else { |
| 48 | + err = fmt.Errorf("method '%s' is not supported, valid methods are 'put' and 'get'", method) |
| 49 | + } |
| 50 | + |
| 51 | + return err |
| 52 | + }, |
| 53 | +} |
| 54 | + |
| 55 | +func init() { |
| 56 | + rootCmd.AddCommand(bucketAclCmd) |
| 57 | + bucketAclCmd.Flags().String("method", "", "put/get") |
| 58 | + bucketAclCmd.Flags().String("acl", "", "Defines the Access Control List (ACL) property of an bucket. The default value is default.") |
| 59 | + bucketAclCmd.Flags().String("grant-read", "", "Grants the grantee permission to read the bucket. The format is id=\"[OwnerUin]\", for example, id=\"100000000001\". Multiple grantees can be specified using commas (,), for example, id=\"100000000001\",id=\"100000000002\".") |
| 60 | + bucketAclCmd.Flags().String("grant-write", "", "Grants the grantee permission to write the bucket. The format is id=\"[OwnerUin]\", for example, id=\"100000000001\". Multiple grantees can be specified using commas (,), for example, id='100000000001',id=\"100000000002\".") |
| 61 | + bucketAclCmd.Flags().String("grant-read-acp", "", "Grants the grantee permission to read the bucket's Access Control List (ACL). The format is id=\"[OwnerUin]\", for example, id=\"100000000001\". Multiple grantees can be specified using commas (,), for example, id=\"100000000001\",id=\"100000000002\".") |
| 62 | + bucketAclCmd.Flags().String("grant-write-acp", "", "Grants the grantee permission to write the bucket's Access Control List (ACL). The format is id=\"[OwnerUin]\", for example, id=\"100000000001\". Multiple grantees can be specified using commas (,), for example, id=\"100000000001\",id=\"100000000002\".") |
| 63 | + bucketAclCmd.Flags().String("grant-full-control", "", "Grants the grantee full permissions to operate on the bucket. The format is id=\"[OwnerUin]\", for example, id=\"100000000001\". Multiple grantees can be specified using commas (,), for example, id=\"100000000001\",id=\"100000000002\".") |
| 64 | +} |
0 commit comments