yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/shell/iam_user.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/aws"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type ClouduserListOptions struct {
    24  		Offset     string
    25  		Limit      int
    26  		PathPrefix string
    27  	}
    28  	shellutils.R(&ClouduserListOptions{}, "cloud-user-list", "List cloudusers", func(cli *aws.SRegion, args *ClouduserListOptions) error {
    29  		users, err := cli.GetClient().ListUsers(args.Offset, args.Limit, args.PathPrefix)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		printList(users.Users, 0, 0, 0, nil)
    34  		return nil
    35  	})
    36  
    37  	type ClouduserCreateOptions struct {
    38  		NAME string
    39  		Path string
    40  	}
    41  
    42  	shellutils.R(&ClouduserCreateOptions{}, "cloud-user-create", "Create clouduser", func(cli *aws.SRegion, args *ClouduserCreateOptions) error {
    43  		user, err := cli.GetClient().CreateUser(args.Path, args.NAME)
    44  		if err != nil {
    45  			return err
    46  		}
    47  		printObject(user)
    48  		return nil
    49  	})
    50  
    51  	type ClouduserOptions struct {
    52  		NAME string
    53  	}
    54  
    55  	shellutils.R(&ClouduserOptions{}, "cloud-user-show", "Show clouduser details", func(cli *aws.SRegion, args *ClouduserOptions) error {
    56  		user, err := cli.GetClient().GetUser(args.NAME)
    57  		if err != nil {
    58  			return err
    59  		}
    60  		printObject(user)
    61  		return nil
    62  	})
    63  
    64  	shellutils.R(&ClouduserOptions{}, "cloud-user-loginprofile", "Show clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserOptions) error {
    65  		profile, err := cli.GetClient().GetLoginProfile(args.NAME)
    66  		if err != nil {
    67  			return err
    68  		}
    69  		printObject(profile)
    70  		return nil
    71  	})
    72  
    73  	shellutils.R(&ClouduserOptions{}, "cloud-user-loginprofile-delete", "Delete clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserOptions) error {
    74  		return cli.GetClient().DeleteLoginProfile(args.NAME)
    75  	})
    76  
    77  	shellutils.R(&ClouduserOptions{}, "cloud-user-delete", "Delete clouduser", func(cli *aws.SRegion, args *ClouduserOptions) error {
    78  		return cli.GetClient().DeleteUser(args.NAME)
    79  	})
    80  
    81  	type ClouduserLoginProfileCreateOptions struct {
    82  		NAME     string
    83  		PASSWORD string
    84  	}
    85  
    86  	shellutils.R(&ClouduserLoginProfileCreateOptions{}, "cloud-user-loginprofile-create", "Create clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserLoginProfileCreateOptions) error {
    87  		profile, err := cli.GetClient().CreateLoginProfile(args.NAME, args.PASSWORD)
    88  		if err != nil {
    89  			return err
    90  		}
    91  		printObject(profile)
    92  		return nil
    93  	})
    94  
    95  	shellutils.R(&ClouduserLoginProfileCreateOptions{}, "cloud-user-reset-password", "Reset clouduser password", func(cli *aws.SRegion, args *ClouduserLoginProfileCreateOptions) error {
    96  		return cli.GetClient().ResetUserPassword(args.NAME, args.PASSWORD)
    97  	})
    98  
    99  	type ClouduserPolicyListOptions struct {
   100  		NAME   string
   101  		Offset string
   102  		Limit  int
   103  	}
   104  
   105  	shellutils.R(&ClouduserPolicyListOptions{}, "cloud-user-policy-list", "List clouduser policies", func(cli *aws.SRegion, args *ClouduserPolicyListOptions) error {
   106  		policies, err := cli.GetClient().ListUserPolicies(args.NAME, args.Offset, args.Limit)
   107  		if err != nil {
   108  			return err
   109  		}
   110  		printObject(policies)
   111  		return nil
   112  	})
   113  
   114  	type ClouduserAttachedPolicyListOptions struct {
   115  		NAME       string
   116  		Offset     string
   117  		Limit      int
   118  		PathPrefix string
   119  	}
   120  
   121  	shellutils.R(&ClouduserAttachedPolicyListOptions{}, "cloud-user-attached-policy-list", "List clouduser attached policies", func(cli *aws.SRegion, args *ClouduserAttachedPolicyListOptions) error {
   122  		policies, err := cli.GetClient().ListAttachedUserPolicies(args.NAME, args.Offset, args.Limit, args.PathPrefix)
   123  		if err != nil {
   124  			return err
   125  		}
   126  		printList(policies.AttachedPolicies, 0, 0, 0, nil)
   127  		return nil
   128  	})
   129  
   130  	type ClouduserPolicyOptions struct {
   131  		NAME       string
   132  		POLICY_ARN string
   133  	}
   134  
   135  	shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-attach-policy", "Attach policy for clouduser", func(cli *aws.SRegion, args *ClouduserPolicyOptions) error {
   136  		return cli.GetClient().AttachUserPolicy(args.NAME, args.POLICY_ARN)
   137  	})
   138  
   139  	shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-detach-policy", "Detach policy from clouduser", func(cli *aws.SRegion, args *ClouduserPolicyOptions) error {
   140  		return cli.GetClient().DetachUserPolicy(args.NAME, args.POLICY_ARN)
   141  	})
   142  
   143  }