yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/shell/cloudpolicy.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 CloudpolicyListOptions struct {
    24  		Name       string
    25  		PolicyType string `choices:"CustomRole|BuiltInRole"`
    26  	}
    27  	shellutils.R(&CloudpolicyListOptions{}, "cloud-policy-list", "List cloudpolicies", func(cli *azure.SRegion, args *CloudpolicyListOptions) error {
    28  		roles, err := cli.GetClient().GetRoles(args.Name, args.PolicyType)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(roles, 0, 0, 0, nil)
    33  		return nil
    34  	})
    35  
    36  	type CloudpolicyAssignOption struct {
    37  		OBJECT         string
    38  		ROLE           string
    39  		SubscriptionId string
    40  	}
    41  
    42  	shellutils.R(&CloudpolicyAssignOption{}, "cloud-policy-assign-object", "Assign cloudpolicy for object", func(cli *azure.SRegion, args *CloudpolicyAssignOption) error {
    43  		return cli.GetClient().AssignPolicy(args.OBJECT, args.ROLE, args.SubscriptionId)
    44  	})
    45  
    46  	type AssignmentListOption struct {
    47  		ObjectId string
    48  	}
    49  
    50  	shellutils.R(&AssignmentListOption{}, "assignment-list", "List role assignments", func(cli *azure.SRegion, args *AssignmentListOption) error {
    51  		assignments, err := cli.GetClient().GetAssignments(args.ObjectId)
    52  		if err != nil {
    53  			return err
    54  		}
    55  		printList(assignments, 0, 0, 0, nil)
    56  		return nil
    57  	})
    58  
    59  	type AssignmentIdOption struct {
    60  		ID string
    61  	}
    62  
    63  	shellutils.R(&AssignmentIdOption{}, "assignment-delete", "Delete role assignment", func(cli *azure.SRegion, args *AssignmentIdOption) error {
    64  		return cli.GetClient().GDelete(args.ID)
    65  	})
    66  
    67  	type ObjectPolicyListOptions struct {
    68  		OBJECT string
    69  	}
    70  
    71  	shellutils.R(&ObjectPolicyListOptions{}, "object-policy-list", "List object policies", func(cli *azure.SRegion, args *ObjectPolicyListOptions) error {
    72  		policies, err := cli.GetClient().GetCloudpolicies(args.OBJECT)
    73  		if err != nil {
    74  			return err
    75  		}
    76  		printList(policies, 0, 0, 0, nil)
    77  		return nil
    78  	})
    79  
    80  }