client.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package sts
  2. //Licensed under the Apache License, Version 2.0 (the "License");
  3. //you may not use this file except in compliance with the License.
  4. //You may obtain a copy of the License at
  5. //
  6. //http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. //Unless required by applicable law or agreed to in writing, software
  9. //distributed under the License is distributed on an "AS IS" BASIS,
  10. //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. //See the License for the specific language governing permissions and
  12. //limitations under the License.
  13. //
  14. // Code generated by Alibaba Cloud SDK Code Generator.
  15. // Changes may cause incorrect behavior and will be lost if the code is regenerated.
  16. import (
  17. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  18. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth"
  19. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider"
  20. )
  21. // Client is the sdk client struct, each func corresponds to an OpenAPI
  22. type Client struct {
  23. sdk.Client
  24. }
  25. // NewClient creates a sdk client with environment variables
  26. func NewClient() (client *Client, err error) {
  27. client = &Client{}
  28. err = client.Init()
  29. return
  30. }
  31. // NewClientWithProvider creates a sdk client with providers
  32. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  33. func NewClientWithProvider(regionId string, providers ...provider.Provider) (client *Client, err error) {
  34. client = &Client{}
  35. var pc provider.Provider
  36. if len(providers) == 0 {
  37. pc = provider.DefaultChain
  38. } else {
  39. pc = provider.NewProviderChain(providers)
  40. }
  41. err = client.InitWithProviderChain(regionId, pc)
  42. return
  43. }
  44. // NewClientWithOptions creates a sdk client with regionId/sdkConfig/credential
  45. // this is the common api to create a sdk client
  46. func NewClientWithOptions(regionId string, config *sdk.Config, credential auth.Credential) (client *Client, err error) {
  47. client = &Client{}
  48. err = client.InitWithOptions(regionId, config, credential)
  49. return
  50. }
  51. // NewClientWithAccessKey is a shortcut to create sdk client with accesskey
  52. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  53. func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) {
  54. client = &Client{}
  55. err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret)
  56. return
  57. }
  58. // NewClientWithStsToken is a shortcut to create sdk client with sts token
  59. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  60. func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) {
  61. client = &Client{}
  62. err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken)
  63. return
  64. }
  65. // NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn
  66. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  67. func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) {
  68. client = &Client{}
  69. err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName)
  70. return
  71. }
  72. // NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn and policy
  73. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  74. func NewClientWithRamRoleArnAndPolicy(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (client *Client, err error) {
  75. client = &Client{}
  76. err = client.InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy)
  77. return
  78. }
  79. // NewClientWithEcsRamRole is a shortcut to create sdk client with ecs ram role
  80. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  81. func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) {
  82. client = &Client{}
  83. err = client.InitWithEcsRamRole(regionId, roleName)
  84. return
  85. }
  86. // NewClientWithRsaKeyPair is a shortcut to create sdk client with rsa key pair
  87. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  88. func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) {
  89. client = &Client{}
  90. err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration)
  91. return
  92. }