yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/objectstore/shell/minio.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  	"fmt"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  	"yunion.io/x/cloudmux/pkg/multicloud/objectstore"
    22  	"yunion.io/x/onecloud/pkg/util/shellutils"
    23  )
    24  
    25  func init() {
    26  	type MinioBucketOption struct {
    27  		BUCKET string `help:"name of bucket"`
    28  	}
    29  	shellutils.R(&MinioBucketOption{}, "bucket-head", "HEAD bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    30  		cli.IBucketExist(args.BUCKET)
    31  		return nil
    32  	})
    33  
    34  	shellutils.R(&MinioBucketOption{}, "bucket-acl", "Get ACL of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    35  		acl, err := cli.GetIBucketAcl(args.BUCKET)
    36  		if err != nil {
    37  			return err
    38  		}
    39  		fmt.Println("ACL:", acl)
    40  		return nil
    41  	})
    42  
    43  	type MinioBucketCannedAclConfigOption struct {
    44  		BUCKET string `help:"name of bucket"`
    45  		ACL    string `help:"canned ACL" choices:"private|public-read|public-read-write|auth-read"`
    46  	}
    47  	shellutils.R(&MinioBucketCannedAclConfigOption{}, "bucket-canned-acl-config", "Set canned ACL of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketCannedAclConfigOption) error {
    48  		err := cli.SetIBucketAcl(args.BUCKET, cloudprovider.TBucketACLType(args.ACL))
    49  		if err != nil {
    50  			return err
    51  		}
    52  		return nil
    53  	})
    54  
    55  	shellutils.R(&MinioBucketOption{}, "bucket-policy", "Get Policy of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    56  		policy, err := cli.GetIBucketPolicy(args.BUCKET)
    57  		if err != nil {
    58  			return err
    59  		}
    60  		fmt.Println("Policy:", policy)
    61  		return nil
    62  	})
    63  
    64  	shellutils.R(&MinioBucketOption{}, "bucket-lifecycle", "Get lifecycle of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    65  		lifecycle, err := cli.GetIBucketLiftcycle(args.BUCKET)
    66  		if err != nil {
    67  			return err
    68  		}
    69  		fmt.Println("Lifecycle:", lifecycle)
    70  		return nil
    71  	})
    72  
    73  	shellutils.R(&MinioBucketOption{}, "bucket-info", "Get info of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    74  		info, err := cli.GetIBucketInfo(args.BUCKET)
    75  		if err != nil {
    76  			return err
    77  		}
    78  		fmt.Println("Info:", info)
    79  		return nil
    80  	})
    81  
    82  	shellutils.R(&MinioBucketOption{}, "bucket-location", "Get location of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    83  		info, err := cli.GetIBucketLocation(args.BUCKET)
    84  		if err != nil {
    85  			return err
    86  		}
    87  		fmt.Println("Info:", info)
    88  		return nil
    89  	})
    90  
    91  	shellutils.R(&MinioBucketOption{}, "bucket-website", "Get website info of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
    92  		info, err := cli.GetIBucketWebsite(args.BUCKET)
    93  		if err != nil {
    94  			return err
    95  		}
    96  		fmt.Println("Info:", info)
    97  		return nil
    98  	})
    99  
   100  	shellutils.R(&MinioBucketOption{}, "bucket-logging", "Get logging configuration of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
   101  		info, err := cli.GetIBucketLogging(args.BUCKET)
   102  		if err != nil {
   103  			return err
   104  		}
   105  		fmt.Println("Logging:", info)
   106  		return nil
   107  	})
   108  
   109  	type MinioSetLoggingOption struct {
   110  		BUCKET string `help:"id or name of bucket"`
   111  		Target string `help:"target bucket"`
   112  		Prefix string `help:"target prefix"`
   113  		Email  string `help:"email"`
   114  	}
   115  	shellutils.R(&MinioSetLoggingOption{}, "bucket-logging-config", "Set logging configuration of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioSetLoggingOption) error {
   116  		err := cli.SetIBucketLogging(args.BUCKET, args.Target, args.Prefix, args.Email)
   117  		if err != nil {
   118  			return err
   119  		}
   120  		return nil
   121  	})
   122  
   123  	shellutils.R(&MinioBucketOption{}, "bucket-referer", "Get info of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
   124  		info, err := cli.GetIBucketReferer(args.BUCKET)
   125  		if err != nil {
   126  			return err
   127  		}
   128  		fmt.Println("Info:", info)
   129  		return nil
   130  	})
   131  
   132  	shellutils.R(&MinioBucketOption{}, "bucket-cors", "Get info of bucket", func(cli *objectstore.SObjectStoreClient, args *MinioBucketOption) error {
   133  		info, err := cli.GetIBucketCors(args.BUCKET)
   134  		if err != nil {
   135  			return err
   136  		}
   137  		fmt.Println("Info:", info)
   138  		return nil
   139  	})
   140  }