yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/shell/saml_provider.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/cloudprovider"
    19  	"yunion.io/x/cloudmux/pkg/multicloud/huawei"
    20  	"yunion.io/x/onecloud/pkg/util/samlutils"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type SAMLProviderListOptions struct {
    26  	}
    27  	shellutils.R(&SAMLProviderListOptions{}, "saml-provider-list", "List saml provider", func(cli *huawei.SRegion, args *SAMLProviderListOptions) error {
    28  		result, err := cli.GetClient().ListSAMLProviders()
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(result, 0, 0, 0, nil)
    33  		return nil
    34  	})
    35  
    36  	type SAMLProviderCreateOptions struct {
    37  		NAME     string
    38  		Metadata string
    39  	}
    40  	shellutils.R(&SAMLProviderCreateOptions{}, "saml-provider-create", "Create saml provider", func(cli *huawei.SRegion, args *SAMLProviderCreateOptions) error {
    41  		opts := cloudprovider.SAMLProviderCreateOptions{
    42  			Name: args.NAME,
    43  		}
    44  		if len(args.Metadata) > 0 {
    45  			var err error
    46  			opts.Metadata, err = samlutils.ParseMetadata([]byte(args.Metadata))
    47  			if err != nil {
    48  				return err
    49  			}
    50  		}
    51  		result, err := cli.GetClient().CreateSAMLProvider(&opts)
    52  		if err != nil {
    53  			return err
    54  		}
    55  		printObject(result)
    56  		return nil
    57  	})
    58  
    59  	type SAMLProviderIdOptions struct {
    60  		ID string
    61  	}
    62  
    63  	shellutils.R(&SAMLProviderIdOptions{}, "saml-provider-delete", "Delete saml provider", func(cli *huawei.SRegion, args *SAMLProviderIdOptions) error {
    64  		return cli.GetClient().DeleteSAMLProvider(args.ID)
    65  	})
    66  
    67  	shellutils.R(&SAMLProviderIdOptions{}, "saml-provider-protocol-list", "List saml provider protocol", func(cli *huawei.SRegion, args *SAMLProviderIdOptions) error {
    68  		result, err := cli.GetClient().GetSAMLProviderProtocols(args.ID)
    69  		if err != nil {
    70  			return err
    71  		}
    72  		printList(result, 0, 0, 0, nil)
    73  		return nil
    74  	})
    75  
    76  	type SAMLProviderProtocolDeleteOptions struct {
    77  		SAML_PROVIDER string
    78  		PROTOCOL      string
    79  	}
    80  
    81  	shellutils.R(&SAMLProviderProtocolDeleteOptions{}, "saml-provider-protocol-delete", "Delete saml provider protocol", func(cli *huawei.SRegion, args *SAMLProviderProtocolDeleteOptions) error {
    82  		return cli.GetClient().DeleteSAMLProviderProtocol(args.SAML_PROVIDER, args.PROTOCOL)
    83  	})
    84  
    85  	shellutils.R(&SAMLProviderIdOptions{}, "saml-provider-metadata-show", "Show saml provider metadata", func(cli *huawei.SRegion, args *SAMLProviderIdOptions) error {
    86  		result, err := cli.GetClient().GetSAMLProviderMetadata(args.ID)
    87  		if err != nil {
    88  			return err
    89  		}
    90  		printObject(result)
    91  		return nil
    92  	})
    93  
    94  	type SAMLProviderMetadataOptions struct {
    95  		ID       string
    96  		METADATA string
    97  	}
    98  
    99  	shellutils.R(&SAMLProviderMetadataOptions{}, "saml-provider-metadata-update", "Update saml provider metadata", func(cli *huawei.SRegion, args *SAMLProviderMetadataOptions) error {
   100  		return cli.GetClient().UpdateSAMLProviderMetadata(args.ID, args.METADATA)
   101  	})
   102  
   103  	type MappingListOptions struct {
   104  	}
   105  
   106  	shellutils.R(&MappingListOptions{}, "saml-provider-mapping-list", "List saml provider mapping", func(cli *huawei.SRegion, args *MappingListOptions) error {
   107  		mappings, err := cli.GetClient().ListSAMLProviderMappings()
   108  		if err != nil {
   109  			return err
   110  		}
   111  		printList(mappings, 0, 0, 0, nil)
   112  		return nil
   113  	})
   114  
   115  	type MappingInitOptions struct {
   116  		SAML_PROVIDER string
   117  	}
   118  
   119  	shellutils.R(&MappingInitOptions{}, "saml-provider-mapping-init", "Init saml provider mapping", func(cli *huawei.SRegion, args *MappingInitOptions) error {
   120  		return cli.GetClient().InitSAMLProviderMapping(args.SAML_PROVIDER)
   121  	})
   122  
   123  	type MappingDeleteOptions struct {
   124  		ID string
   125  	}
   126  
   127  	shellutils.R(&MappingDeleteOptions{}, "saml-provider-mapping-delete", "Delete saml provider mapping", func(cli *huawei.SRegion, args *MappingDeleteOptions) error {
   128  		return cli.GetClient().DeleteSAMLProviderMapping(args.ID)
   129  	})
   130  
   131  }