yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/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  	"yunion.io/x/cloudmux/pkg/multicloud/azure"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type ClouduserListOptions struct {
    24  	}
    25  	shellutils.R(&ClouduserListOptions{}, "cloud-user-list", "List cloudusers", func(cli *azure.SRegion, args *ClouduserListOptions) error {
    26  		users, err := cli.GetClient().GetCloudusers()
    27  		if err != nil {
    28  			return err
    29  		}
    30  		printList(users, 0, 0, 0, nil)
    31  		return nil
    32  	})
    33  
    34  	type ClouduserIdOptions struct {
    35  		ID string
    36  	}
    37  
    38  	shellutils.R(&ClouduserIdOptions{}, "cloud-user-delete", "Delete clouduser", func(cli *azure.SRegion, args *ClouduserIdOptions) error {
    39  		return cli.GetClient().DeleteClouduser(args.ID)
    40  	})
    41  
    42  	shellutils.R(&ClouduserIdOptions{}, "cloud-user-group-list", "List clouduser groups", func(cli *azure.SRegion, args *ClouduserIdOptions) error {
    43  		groups, err := cli.GetClient().GetUserGroups(args.ID)
    44  		if err != nil {
    45  			return err
    46  		}
    47  		printList(groups, 0, 0, 0, nil)
    48  		return nil
    49  	})
    50  
    51  	type ClouduserCreateOptions struct {
    52  		NAME     string
    53  		Password string
    54  	}
    55  
    56  	shellutils.R(&ClouduserCreateOptions{}, "cloud-user-create", "Create clouduser", func(cli *azure.SRegion, args *ClouduserCreateOptions) error {
    57  		user, err := cli.GetClient().CreateClouduser(args.NAME, args.Password)
    58  		if err != nil {
    59  			return err
    60  		}
    61  		printObject(user)
    62  		return nil
    63  	})
    64  
    65  	type ClouduserResetPasswordOptions struct {
    66  		NAME     string
    67  		PASSWORD string
    68  	}
    69  
    70  	shellutils.R(&ClouduserResetPasswordOptions{}, "cloud-user-reset-password", "Reset clouduser password", func(cli *azure.SRegion, args *ClouduserResetPasswordOptions) error {
    71  		return cli.GetClient().ResetClouduserPassword(args.NAME, args.PASSWORD)
    72  	})
    73  
    74  	type DomainListOptions struct {
    75  	}
    76  
    77  	shellutils.R(&DomainListOptions{}, "domain-list", "List domains", func(cli *azure.SRegion, args *DomainListOptions) error {
    78  		domains, err := cli.GetClient().GetDomains()
    79  		if err != nil {
    80  			return err
    81  		}
    82  		printList(domains, 0, 0, 0, nil)
    83  		return nil
    84  	})
    85  
    86  	type GroupUserList struct {
    87  	}
    88  
    89  	shellutils.R(&GroupUserList{}, "graph-user-list", "List graph users", func(cli *azure.SRegion, args *GroupUserList) error {
    90  		users, err := cli.GetClient().ListGraphUsers()
    91  		if err != nil {
    92  			return err
    93  		}
    94  		printObject(users)
    95  		return nil
    96  	})
    97  
    98  }