yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/shell/bucket.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package shell 16 17 import ( 18 "yunion.io/x/cloudmux/pkg/cloudprovider" 19 "yunion.io/x/cloudmux/pkg/multicloud/google" 20 "yunion.io/x/onecloud/pkg/util/shellutils" 21 ) 22 23 func init() { 24 type BucketListOptions struct { 25 MaxResults int 26 PageToken string 27 } 28 29 shellutils.R(&BucketListOptions{}, "bucket-list", "List buckets", func(cli *google.SRegion, args *BucketListOptions) error { 30 buckets, err := cli.GetBuckets(args.MaxResults, args.PageToken) 31 if err != nil { 32 return err 33 } 34 printList(buckets, 0, 0, 0, nil) 35 return nil 36 }) 37 38 type BucketCreateOptions struct { 39 NAME string 40 StorageClass string `choices:"STANDARD|NEARLINE|COLDLINE"` 41 Acl string `choices:"private|authenticated-read|public-read|public-read-write"` 42 } 43 44 shellutils.R(&BucketCreateOptions{}, "bucket-create", "Create buckets", func(cli *google.SRegion, args *BucketCreateOptions) error { 45 bucket, err := cli.CreateBucket(args.NAME, args.StorageClass, cloudprovider.TBucketACLType(args.Acl)) 46 if err != nil { 47 return err 48 } 49 printObject(bucket) 50 return nil 51 }) 52 53 type BucketNameOptions struct { 54 NAME string 55 } 56 57 shellutils.R(&BucketNameOptions{}, "bucket-show", "Show bucket", func(cli *google.SRegion, args *BucketNameOptions) error { 58 bucket, err := cli.GetBucket(args.NAME) 59 if err != nil { 60 return err 61 } 62 printObject(bucket) 63 return nil 64 }) 65 66 shellutils.R(&BucketNameOptions{}, "bucket-delete", "Delete bucket", func(cli *google.SRegion, args *BucketNameOptions) error { 67 return cli.DeleteBucket(args.NAME) 68 }) 69 70 shellutils.R(&BucketNameOptions{}, "bucket-acl-list", "Show bucket acls", func(cli *google.SRegion, args *BucketNameOptions) error { 71 acls, err := cli.GetBucketAcl(args.NAME) 72 if err != nil { 73 return err 74 } 75 printList(acls, 0, 0, 0, nil) 76 return nil 77 }) 78 79 shellutils.R(&BucketNameOptions{}, "bucket-iam-show", "Show bucket iam", func(cli *google.SRegion, args *BucketNameOptions) error { 80 iam, err := cli.GetBucketIam(args.NAME) 81 if err != nil { 82 return err 83 } 84 printObject(iam) 85 return nil 86 }) 87 88 type BucketAclOptions struct { 89 BUCKET string 90 ACL string 91 } 92 93 shellutils.R(&BucketAclOptions{}, "bucket-acl-set", "Set bucket acl", func(cli *google.SRegion, args *BucketAclOptions) error { 94 return cli.SetBucketAcl(args.BUCKET, cloudprovider.TBucketACLType(args.ACL)) 95 }) 96 97 }