1package ecs
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// Code generated by Alibaba Cloud SDK Code Generator.
16// Changes may cause incorrect behavior and will be lost if the code is regenerated.
17
18import (
19	"reflect"
20
21	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
22	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth"
23	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider"
24)
25
26// Client is the sdk client struct, each func corresponds to an OpenAPI
27type Client struct {
28	sdk.Client
29}
30
31// SetClientProperty Set Property by Reflect
32func SetClientProperty(client *Client, propertyName string, propertyValue interface{}) {
33	v := reflect.ValueOf(client).Elem()
34	if v.FieldByName(propertyName).IsValid() && v.FieldByName(propertyName).CanSet() {
35		v.FieldByName(propertyName).Set(reflect.ValueOf(propertyValue))
36	}
37}
38
39// SetEndpointDataToClient Set EndpointMap and ENdpointType
40func SetEndpointDataToClient(client *Client) {
41	SetClientProperty(client, "EndpointMap", GetEndpointMap())
42	SetClientProperty(client, "EndpointType", GetEndpointType())
43}
44
45// NewClient creates a sdk client with environment variables
46func NewClient() (client *Client, err error) {
47	client = &Client{}
48	err = client.Init()
49	SetEndpointDataToClient(client)
50	return
51}
52
53// NewClientWithProvider creates a sdk client with providers
54// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
55func NewClientWithProvider(regionId string, providers ...provider.Provider) (client *Client, err error) {
56	client = &Client{}
57	var pc provider.Provider
58	if len(providers) == 0 {
59		pc = provider.DefaultChain
60	} else {
61		pc = provider.NewProviderChain(providers)
62	}
63	err = client.InitWithProviderChain(regionId, pc)
64	SetEndpointDataToClient(client)
65	return
66}
67
68// NewClientWithOptions creates a sdk client with regionId/sdkConfig/credential
69// this is the common api to create a sdk client
70func NewClientWithOptions(regionId string, config *sdk.Config, credential auth.Credential) (client *Client, err error) {
71	client = &Client{}
72	err = client.InitWithOptions(regionId, config, credential)
73	SetEndpointDataToClient(client)
74	return
75}
76
77// NewClientWithAccessKey is a shortcut to create sdk client with accesskey
78// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
79func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) {
80	client = &Client{}
81	err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret)
82	SetEndpointDataToClient(client)
83	return
84}
85
86// NewClientWithStsToken is a shortcut to create sdk client with sts token
87// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
88func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) {
89	client = &Client{}
90	err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken)
91	SetEndpointDataToClient(client)
92	return
93}
94
95// NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn
96// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
97func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) {
98	client = &Client{}
99	err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName)
100	SetEndpointDataToClient(client)
101	return
102}
103
104// NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn and policy
105// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
106func NewClientWithRamRoleArnAndPolicy(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (client *Client, err error) {
107	client = &Client{}
108	err = client.InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy)
109	SetEndpointDataToClient(client)
110	return
111}
112
113// NewClientWithEcsRamRole is a shortcut to create sdk client with ecs ram role
114// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
115func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) {
116	client = &Client{}
117	err = client.InitWithEcsRamRole(regionId, roleName)
118	SetEndpointDataToClient(client)
119	return
120}
121
122// NewClientWithRsaKeyPair is a shortcut to create sdk client with rsa key pair
123// usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
124func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) {
125	client = &Client{}
126	err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration)
127	SetEndpointDataToClient(client)
128	return
129}
130