client.go 4.0 KB

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