yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcso/shell/clouduser.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  	huawei "yunion.io/x/cloudmux/pkg/multicloud/hcso"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type ClouduserListOptions struct {
    24  		Name string
    25  	}
    26  	shellutils.R(&ClouduserListOptions{}, "cloud-user-list", "List cloudusers", func(cli *huawei.SRegion, args *ClouduserListOptions) error {
    27  		users, err := cli.GetClient().GetCloudusers(args.Name)
    28  		if err != nil {
    29  			return err
    30  		}
    31  		printList(users, 0, 0, 0, nil)
    32  		return nil
    33  	})
    34  
    35  	type ClouduserIdOptions struct {
    36  		ID string
    37  	}
    38  
    39  	shellutils.R(&ClouduserIdOptions{}, "cloud-user-delete", "Delete clouduser", func(cli *huawei.SRegion, args *ClouduserIdOptions) error {
    40  		return cli.GetClient().DeleteClouduser(args.ID)
    41  	})
    42  
    43  	shellutils.R(&ClouduserIdOptions{}, "cloud-user-group-list", "List clouduser groups", func(cli *huawei.SRegion, args *ClouduserIdOptions) error {
    44  		groups, err := cli.GetClient().ListUserGroups(args.ID)
    45  		if err != nil {
    46  			return err
    47  		}
    48  		printList(groups, 0, 0, 0, nil)
    49  		return nil
    50  	})
    51  
    52  	type ClouduserCreateOptions struct {
    53  		NAME     string
    54  		Password string
    55  		Desc     string
    56  	}
    57  
    58  	shellutils.R(&ClouduserCreateOptions{}, "cloud-user-create", "Create clouduser", func(cli *huawei.SRegion, args *ClouduserCreateOptions) error {
    59  		user, err := cli.GetClient().CreateClouduser(args.NAME, args.Password, args.Desc)
    60  		if err != nil {
    61  			return err
    62  		}
    63  		printObject(user)
    64  		return nil
    65  	})
    66  
    67  	type RoleListOptions struct {
    68  		DomainId string
    69  		Name     string
    70  	}
    71  
    72  	shellutils.R(&RoleListOptions{}, "cloud-policy-list", "List role", func(cli *huawei.SRegion, args *RoleListOptions) error {
    73  		roles, err := cli.GetClient().GetRoles(args.DomainId, args.Name)
    74  		if err != nil {
    75  			return err
    76  		}
    77  		printList(roles, 0, 0, 0, nil)
    78  		return nil
    79  	})
    80  
    81  	type ClouduserResetPassword struct {
    82  		ID       string
    83  		PASSWORD string
    84  	}
    85  
    86  	shellutils.R(&ClouduserResetPassword{}, "cloud-user-reset-password", "Reset clouduser password", func(cli *huawei.SRegion, args *ClouduserResetPassword) error {
    87  		return cli.GetClient().ResetClouduserPassword(args.ID, args.PASSWORD)
    88  	})
    89  
    90  	type ClouduserAKSKOptions struct {
    91  		Id string
    92  	}
    93  	shellutils.R(&ClouduserAKSKOptions{}, "aksk-list", "List AKSK", func(cli *huawei.SRegion, args *ClouduserAKSKOptions) error {
    94  		res, err := cli.GetClient().GetAKSK(args.Id)
    95  		if err != nil {
    96  			return err
    97  		}
    98  		printList(res, len(res), 0, 0, []string{})
    99  		return nil
   100  	})
   101  	type ClouduserAKSKDeleteOptions struct {
   102  		AccessKey string
   103  	}
   104  	shellutils.R(&ClouduserAKSKDeleteOptions{}, "aksk-delete", "Delete AKSK", func(cli *huawei.SRegion, args *ClouduserAKSKDeleteOptions) error {
   105  		err := cli.GetClient().DeleteAKSK(args.AccessKey)
   106  		return err
   107  	})
   108  
   109  	type AKSKCreateOption struct {
   110  		UserId      string `help:"user id"`
   111  		Description string `help:"description"`
   112  	}
   113  
   114  	shellutils.R(&AKSKCreateOption{}, "aksk-create", "Create aksk", func(cli *huawei.SRegion, args *AKSKCreateOption) error {
   115  		res, err := cli.GetClient().CreateAKSK(args.UserId, args.Description)
   116  		if err != nil {
   117  			return err
   118  		}
   119  		printObject(res)
   120  		return nil
   121  	})
   122  }