yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/shell/organizations.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/multicloud/aws"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type AccountListOptions struct {
    26  	}
    27  	shellutils.R(&AccountListOptions{}, "account-list", "List accounts", func(cli *aws.SRegion, args *AccountListOptions) error {
    28  		accounts, err := cli.ListAccounts()
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(accounts, 0, 0, 0, []string{})
    33  		return nil
    34  	})
    35  
    36  	type OrganizationPoliciesListOptions struct {
    37  		FILTER string `json:"filter" choices:"SERVICE_CONTROL_POLICY|TAG_POLICY|BACKUP_POLICY|AISERVICES_OPT_OUT_POLICY"`
    38  	}
    39  	shellutils.R(&OrganizationPoliciesListOptions{}, "org-policy-list", "List policies of organizations", func(cli *aws.SRegion, args *OrganizationPoliciesListOptions) error {
    40  		policies, err := cli.ListPolicies(args.FILTER)
    41  		if err != nil {
    42  			return err
    43  		}
    44  		printList(policies, 0, 0, 0, []string{})
    45  		return nil
    46  	})
    47  
    48  	type OrganizationPolicyShowOptions struct {
    49  		ID string `json:"id"`
    50  	}
    51  	shellutils.R(&OrganizationPolicyShowOptions{}, "org-policy-show", "Show details of an organizations policy", func(cli *aws.SRegion, args *OrganizationPolicyShowOptions) error {
    52  		content, err := cli.DescribeOrgPolicy(args.ID)
    53  		if err != nil {
    54  			return err
    55  		}
    56  		fmt.Println(content.PrettyString())
    57  		return nil
    58  	})
    59  
    60  	type OrganizationPoliciesListForTargetOptions struct {
    61  		OrganizationPoliciesListOptions
    62  		TARGET string `json:"target"`
    63  	}
    64  	shellutils.R(&OrganizationPoliciesListForTargetOptions{}, "org-target-policy-list", "List policies for target of organizations", func(cli *aws.SRegion, args *OrganizationPoliciesListForTargetOptions) error {
    65  		policies, err := cli.ListPoliciesForTarget(args.FILTER, args.TARGET)
    66  		if err != nil {
    67  			return err
    68  		}
    69  		printList(policies, 0, 0, 0, []string{})
    70  		return nil
    71  	})
    72  
    73  	type OrganizationParentsListOptions struct {
    74  		ID string `json:"id"`
    75  	}
    76  	shellutils.R(&OrganizationParentsListOptions{}, "org-parent-list", "List parent nodes of a child node", func(cli *aws.SRegion, args *OrganizationParentsListOptions) error {
    77  		err := cli.ListParents(args.ID)
    78  		if err != nil {
    79  			return err
    80  		}
    81  		return nil
    82  	})
    83  
    84  	type OrganizationalUnitShowOptions struct {
    85  		ID string `help:"Id of organizational unit"`
    86  	}
    87  	shellutils.R(&OrganizationalUnitShowOptions{}, "org-ou-show", "Show details of organizational unit", func(cli *aws.SRegion, args *OrganizationalUnitShowOptions) error {
    88  		err := cli.DescribeOrganizationalUnit(args.ID)
    89  		if err != nil {
    90  			return err
    91  		}
    92  		return nil
    93  	})
    94  }