client.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  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. package sdk
  15. import (
  16. "context"
  17. "crypto/tls"
  18. "fmt"
  19. "net"
  20. "net/http"
  21. "net/url"
  22. "os"
  23. "runtime"
  24. "strconv"
  25. "strings"
  26. "sync"
  27. "time"
  28. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider"
  29. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth"
  30. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  31. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints"
  32. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
  33. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
  34. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
  35. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
  36. )
  37. var debug utils.Debug
  38. func init() {
  39. debug = utils.Init("sdk")
  40. }
  41. // Version this value will be replaced while build: -ldflags="-X sdk.version=x.x.x"
  42. var Version = "0.0.1"
  43. var defaultConnectTimeout = 5 * time.Second
  44. var defaultReadTimeout = 10 * time.Second
  45. var DefaultUserAgent = fmt.Sprintf("AlibabaCloud (%s; %s) Golang/%s Core/%s", runtime.GOOS, runtime.GOARCH, strings.Trim(runtime.Version(), "go"), Version)
  46. var hookDo = func(fn func(req *http.Request) (*http.Response, error)) func(req *http.Request) (*http.Response, error) {
  47. return fn
  48. }
  49. // Client the type Client
  50. type Client struct {
  51. isInsecure bool
  52. regionId string
  53. config *Config
  54. userAgent map[string]string
  55. signer auth.Signer
  56. httpClient *http.Client
  57. asyncTaskQueue chan func()
  58. readTimeout time.Duration
  59. connectTimeout time.Duration
  60. debug bool
  61. isRunning bool
  62. // void "panic(write to close channel)" cause of addAsync() after Shutdown()
  63. asyncChanLock *sync.RWMutex
  64. }
  65. func (client *Client) Init() (err error) {
  66. panic("not support yet")
  67. }
  68. func (client *Client) SetHTTPSInsecure(isInsecure bool) {
  69. client.isInsecure = isInsecure
  70. }
  71. func (client *Client) GetHTTPSInsecure() bool {
  72. return client.isInsecure
  73. }
  74. // InitWithProviderChain will get credential from the providerChain,
  75. // the RsaKeyPairCredential Only applicable to regionID `ap-northeast-1`,
  76. // if your providerChain may return a credential type with RsaKeyPairCredential,
  77. // please ensure your regionID is `ap-northeast-1`.
  78. func (client *Client) InitWithProviderChain(regionId string, provider provider.Provider) (err error) {
  79. config := client.InitClientConfig()
  80. credential, err := provider.Resolve()
  81. if err != nil {
  82. return
  83. }
  84. return client.InitWithOptions(regionId, config, credential)
  85. }
  86. func (client *Client) InitWithOptions(regionId string, config *Config, credential auth.Credential) (err error) {
  87. client.isRunning = true
  88. client.asyncChanLock = new(sync.RWMutex)
  89. client.regionId = regionId
  90. client.config = config
  91. client.httpClient = &http.Client{}
  92. if config.HttpTransport != nil {
  93. client.httpClient.Transport = config.HttpTransport
  94. }
  95. if config.Timeout > 0 {
  96. client.httpClient.Timeout = config.Timeout
  97. }
  98. if config.EnableAsync {
  99. client.EnableAsync(config.GoRoutinePoolSize, config.MaxTaskQueueSize)
  100. }
  101. client.signer, err = auth.NewSignerWithCredential(credential, client.ProcessCommonRequestWithSigner)
  102. return
  103. }
  104. func (client *Client) SetReadTimeout(readTimeout time.Duration) {
  105. client.readTimeout = readTimeout
  106. }
  107. func (client *Client) SetConnectTimeout(connectTimeout time.Duration) {
  108. client.connectTimeout = connectTimeout
  109. }
  110. func (client *Client) GetReadTimeout() time.Duration {
  111. return client.readTimeout
  112. }
  113. func (client *Client) GetConnectTimeout() time.Duration {
  114. return client.connectTimeout
  115. }
  116. func getHttpProxy(scheme string) *url.URL {
  117. var proxy *url.URL
  118. if scheme == "https" {
  119. if rawurl := os.Getenv("HTTPS_PROXY"); rawurl != "" {
  120. proxy, _ = url.Parse(rawurl)
  121. }
  122. if rawurl := os.Getenv("https_proxy"); rawurl != "" && proxy == nil {
  123. proxy, _ = url.Parse(rawurl)
  124. }
  125. } else {
  126. if rawurl := os.Getenv("HTTP_PROXY"); rawurl != "" {
  127. proxy, _ = url.Parse(rawurl)
  128. }
  129. if rawurl := os.Getenv("http_proxy"); rawurl != "" && proxy == nil {
  130. proxy, _ = url.Parse(rawurl)
  131. }
  132. }
  133. return proxy
  134. }
  135. // EnableAsync enable the async task queue
  136. func (client *Client) EnableAsync(routinePoolSize, maxTaskQueueSize int) {
  137. client.asyncTaskQueue = make(chan func(), maxTaskQueueSize)
  138. for i := 0; i < routinePoolSize; i++ {
  139. go func() {
  140. for client.isRunning {
  141. select {
  142. case task, notClosed := <-client.asyncTaskQueue:
  143. if notClosed {
  144. task()
  145. }
  146. }
  147. }
  148. }()
  149. }
  150. }
  151. func (client *Client) InitWithAccessKey(regionId, accessKeyId, accessKeySecret string) (err error) {
  152. config := client.InitClientConfig()
  153. credential := &credentials.BaseCredential{
  154. AccessKeyId: accessKeyId,
  155. AccessKeySecret: accessKeySecret,
  156. }
  157. return client.InitWithOptions(regionId, config, credential)
  158. }
  159. func (client *Client) InitWithStsToken(regionId, accessKeyId, accessKeySecret, securityToken string) (err error) {
  160. config := client.InitClientConfig()
  161. credential := &credentials.StsTokenCredential{
  162. AccessKeyId: accessKeyId,
  163. AccessKeySecret: accessKeySecret,
  164. AccessKeyStsToken: securityToken,
  165. }
  166. return client.InitWithOptions(regionId, config, credential)
  167. }
  168. func (client *Client) InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (err error) {
  169. config := client.InitClientConfig()
  170. credential := &credentials.RamRoleArnCredential{
  171. AccessKeyId: accessKeyId,
  172. AccessKeySecret: accessKeySecret,
  173. RoleArn: roleArn,
  174. RoleSessionName: roleSessionName,
  175. }
  176. return client.InitWithOptions(regionId, config, credential)
  177. }
  178. func (client *Client) InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (err error) {
  179. config := client.InitClientConfig()
  180. credential := &credentials.RamRoleArnCredential{
  181. AccessKeyId: accessKeyId,
  182. AccessKeySecret: accessKeySecret,
  183. RoleArn: roleArn,
  184. RoleSessionName: roleSessionName,
  185. Policy: policy,
  186. }
  187. return client.InitWithOptions(regionId, config, credential)
  188. }
  189. func (client *Client) InitWithRsaKeyPair(regionId, publicKeyId, privateKey string, sessionExpiration int) (err error) {
  190. config := client.InitClientConfig()
  191. credential := &credentials.RsaKeyPairCredential{
  192. PrivateKey: privateKey,
  193. PublicKeyId: publicKeyId,
  194. SessionExpiration: sessionExpiration,
  195. }
  196. return client.InitWithOptions(regionId, config, credential)
  197. }
  198. func (client *Client) InitWithEcsRamRole(regionId, roleName string) (err error) {
  199. config := client.InitClientConfig()
  200. credential := &credentials.EcsRamRoleCredential{
  201. RoleName: roleName,
  202. }
  203. return client.InitWithOptions(regionId, config, credential)
  204. }
  205. func (client *Client) InitClientConfig() (config *Config) {
  206. if client.config != nil {
  207. return client.config
  208. } else {
  209. return NewConfig()
  210. }
  211. }
  212. func (client *Client) DoAction(request requests.AcsRequest, response responses.AcsResponse) (err error) {
  213. return client.DoActionWithSigner(request, response, nil)
  214. }
  215. func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer auth.Signer) (httpRequest *http.Request, err error) {
  216. // add clientVersion
  217. request.GetHeaders()["x-sdk-core-version"] = Version
  218. regionId := client.regionId
  219. if len(request.GetRegionId()) > 0 {
  220. regionId = request.GetRegionId()
  221. }
  222. // resolve endpoint
  223. resolveParam := &endpoints.ResolveParam{
  224. Domain: request.GetDomain(),
  225. Product: request.GetProduct(),
  226. RegionId: regionId,
  227. LocationProduct: request.GetLocationServiceCode(),
  228. LocationEndpointType: request.GetLocationEndpointType(),
  229. CommonApi: client.ProcessCommonRequest,
  230. }
  231. endpoint, err := endpoints.Resolve(resolveParam)
  232. if err != nil {
  233. return
  234. }
  235. request.SetDomain(endpoint)
  236. if request.GetScheme() == "" {
  237. request.SetScheme(client.config.Scheme)
  238. }
  239. // init request params
  240. err = requests.InitParams(request)
  241. if err != nil {
  242. return
  243. }
  244. // signature
  245. var finalSigner auth.Signer
  246. if signer != nil {
  247. finalSigner = signer
  248. } else {
  249. finalSigner = client.signer
  250. }
  251. httpRequest, err = buildHttpRequest(request, finalSigner, regionId)
  252. if err == nil {
  253. userAgent := DefaultUserAgent + getSendUserAgent(client.config.UserAgent, client.userAgent, request.GetUserAgent())
  254. httpRequest.Header.Set("User-Agent", userAgent)
  255. }
  256. return
  257. }
  258. func getSendUserAgent(configUserAgent string, clientUserAgent, requestUserAgent map[string]string) string {
  259. realUserAgent := ""
  260. for key1, value1 := range clientUserAgent {
  261. for key2, _ := range requestUserAgent {
  262. if key1 == key2 {
  263. key1 = ""
  264. }
  265. }
  266. if key1 != "" {
  267. realUserAgent += fmt.Sprintf(" %s/%s", key1, value1)
  268. }
  269. }
  270. for key, value := range requestUserAgent {
  271. realUserAgent += fmt.Sprintf(" %s/%s", key, value)
  272. }
  273. if configUserAgent != "" {
  274. return realUserAgent + fmt.Sprintf(" Extra/%s", configUserAgent)
  275. }
  276. return realUserAgent
  277. }
  278. func (client *Client) AppendUserAgent(key, value string) {
  279. newkey := true
  280. if client.userAgent == nil {
  281. client.userAgent = make(map[string]string)
  282. }
  283. if strings.ToLower(key) != "core" && strings.ToLower(key) != "go" {
  284. for tag, _ := range client.userAgent {
  285. if tag == key {
  286. client.userAgent[tag] = value
  287. newkey = false
  288. }
  289. }
  290. if newkey {
  291. client.userAgent[key] = value
  292. }
  293. }
  294. }
  295. func (client *Client) BuildRequestWithSigner(request requests.AcsRequest, signer auth.Signer) (err error) {
  296. _, err = client.buildRequestWithSigner(request, signer)
  297. return
  298. }
  299. func (client *Client) getTimeout(request requests.AcsRequest) (time.Duration, time.Duration) {
  300. readTimeout := defaultReadTimeout
  301. connectTimeout := defaultConnectTimeout
  302. reqReadTimeout := request.GetReadTimeout()
  303. reqConnectTimeout := request.GetConnectTimeout()
  304. if reqReadTimeout != 0*time.Millisecond {
  305. readTimeout = reqReadTimeout
  306. } else if client.readTimeout != 0*time.Millisecond {
  307. readTimeout = client.readTimeout
  308. }
  309. if reqConnectTimeout != 0*time.Millisecond {
  310. connectTimeout = reqConnectTimeout
  311. } else if client.connectTimeout != 0*time.Millisecond {
  312. connectTimeout = client.connectTimeout
  313. }
  314. return readTimeout, connectTimeout
  315. }
  316. func Timeout(connectTimeout, readTimeout time.Duration) func(cxt context.Context, net, addr string) (c net.Conn, err error) {
  317. return func(ctx context.Context, network, address string) (net.Conn, error) {
  318. conn, err := (&net.Dialer{
  319. Timeout: connectTimeout,
  320. KeepAlive: 0 * time.Second,
  321. DualStack: true,
  322. }).DialContext(ctx, network, address)
  323. if err == nil {
  324. conn.SetDeadline(time.Now().Add(readTimeout))
  325. }
  326. return conn, err
  327. }
  328. }
  329. func (client *Client) setTimeout(request requests.AcsRequest) {
  330. readTimeout, connectTimeout := client.getTimeout(request)
  331. if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil {
  332. trans.DialContext = Timeout(connectTimeout, readTimeout)
  333. client.httpClient.Transport = trans
  334. } else {
  335. client.httpClient.Transport = &http.Transport{
  336. DialContext: Timeout(connectTimeout, readTimeout),
  337. }
  338. }
  339. }
  340. func (client *Client) getHTTPSInsecure(request requests.AcsRequest) (insecure bool) {
  341. if request.GetHTTPSInsecure() != nil {
  342. insecure = *request.GetHTTPSInsecure()
  343. } else {
  344. insecure = client.GetHTTPSInsecure()
  345. }
  346. return insecure
  347. }
  348. func (client *Client) DoActionWithSigner(request requests.AcsRequest, response responses.AcsResponse, signer auth.Signer) (err error) {
  349. httpRequest, err := client.buildRequestWithSigner(request, signer)
  350. if err != nil {
  351. return
  352. }
  353. client.setTimeout(request)
  354. proxy := getHttpProxy(httpRequest.URL.Scheme)
  355. // Set whether to ignore certificate validation.
  356. // Default InsecureSkipVerify is false.
  357. if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil {
  358. trans.TLSClientConfig = &tls.Config{
  359. InsecureSkipVerify: client.getHTTPSInsecure(request),
  360. }
  361. if proxy != nil {
  362. trans.Proxy = http.ProxyURL(proxy)
  363. }
  364. client.httpClient.Transport = trans
  365. }
  366. var httpResponse *http.Response
  367. for retryTimes := 0; retryTimes <= client.config.MaxRetryTime; retryTimes++ {
  368. debug("> %s %s %s", httpRequest.Method, httpRequest.URL.RequestURI(), httpRequest.Proto)
  369. debug("> Host: %s", httpRequest.Host)
  370. for key, value := range httpRequest.Header {
  371. debug("> %s: %v", key, strings.Join(value, ""))
  372. }
  373. debug(">")
  374. httpResponse, err = hookDo(client.httpClient.Do)(httpRequest)
  375. if err == nil {
  376. debug("< %s %s", httpResponse.Proto, httpResponse.Status)
  377. for key, value := range httpResponse.Header {
  378. debug("< %s: %v", key, strings.Join(value, ""))
  379. }
  380. }
  381. debug("<")
  382. // receive error
  383. if err != nil {
  384. if !client.config.AutoRetry {
  385. return
  386. } else if retryTimes >= client.config.MaxRetryTime {
  387. // timeout but reached the max retry times, return
  388. var timeoutErrorMsg string
  389. if strings.Contains(err.Error(), "read tcp") {
  390. timeoutErrorMsg = fmt.Sprintf(errors.TimeoutErrorMessage, strconv.Itoa(retryTimes+1), strconv.Itoa(retryTimes+1)) + " Read timeout. Please set a valid ReadTimeout."
  391. } else {
  392. timeoutErrorMsg = fmt.Sprintf(errors.TimeoutErrorMessage, strconv.Itoa(retryTimes+1), strconv.Itoa(retryTimes+1)) + " Connect timeout. Please set a valid ConnectTimeout."
  393. }
  394. err = errors.NewClientError(errors.TimeoutErrorCode, timeoutErrorMsg, err)
  395. return
  396. }
  397. }
  398. // if status code >= 500 or timeout, will trigger retry
  399. if client.config.AutoRetry && (err != nil || isServerError(httpResponse)) {
  400. client.setTimeout(request)
  401. // rewrite signatureNonce and signature
  402. httpRequest, err = client.buildRequestWithSigner(request, signer)
  403. // buildHttpRequest(request, finalSigner, regionId)
  404. if err != nil {
  405. return
  406. }
  407. continue
  408. }
  409. break
  410. }
  411. err = responses.Unmarshal(response, httpResponse, request.GetAcceptFormat())
  412. // wrap server errors
  413. if serverErr, ok := err.(*errors.ServerError); ok {
  414. var wrapInfo = map[string]string{}
  415. wrapInfo["StringToSign"] = request.GetStringToSign()
  416. err = errors.WrapServerError(serverErr, wrapInfo)
  417. }
  418. return
  419. }
  420. func buildHttpRequest(request requests.AcsRequest, singer auth.Signer, regionId string) (httpRequest *http.Request, err error) {
  421. err = auth.Sign(request, singer, regionId)
  422. if err != nil {
  423. return
  424. }
  425. requestMethod := request.GetMethod()
  426. requestUrl := request.BuildUrl()
  427. body := request.GetBodyReader()
  428. httpRequest, err = http.NewRequest(requestMethod, requestUrl, body)
  429. if err != nil {
  430. return
  431. }
  432. for key, value := range request.GetHeaders() {
  433. httpRequest.Header[key] = []string{value}
  434. }
  435. // host is a special case
  436. if host, containsHost := request.GetHeaders()["Host"]; containsHost {
  437. httpRequest.Host = host
  438. }
  439. return
  440. }
  441. func isServerError(httpResponse *http.Response) bool {
  442. return httpResponse.StatusCode >= http.StatusInternalServerError
  443. }
  444. /**
  445. only block when any one of the following occurs:
  446. 1. the asyncTaskQueue is full, increase the queue size to avoid this
  447. 2. Shutdown() in progressing, the client is being closed
  448. **/
  449. func (client *Client) AddAsyncTask(task func()) (err error) {
  450. if client.asyncTaskQueue != nil {
  451. client.asyncChanLock.RLock()
  452. defer client.asyncChanLock.RUnlock()
  453. if client.isRunning {
  454. client.asyncTaskQueue <- task
  455. }
  456. } else {
  457. err = errors.NewClientError(errors.AsyncFunctionNotEnabledCode, errors.AsyncFunctionNotEnabledMessage, nil)
  458. }
  459. return
  460. }
  461. func (client *Client) GetConfig() *Config {
  462. return client.config
  463. }
  464. func NewClient() (client *Client, err error) {
  465. client = &Client{}
  466. err = client.Init()
  467. return
  468. }
  469. func NewClientWithProvider(regionId string, providers ...provider.Provider) (client *Client, err error) {
  470. client = &Client{}
  471. var pc provider.Provider
  472. if len(providers) == 0 {
  473. pc = provider.DefaultChain
  474. } else {
  475. pc = provider.NewProviderChain(providers)
  476. }
  477. err = client.InitWithProviderChain(regionId, pc)
  478. return
  479. }
  480. func NewClientWithOptions(regionId string, config *Config, credential auth.Credential) (client *Client, err error) {
  481. client = &Client{}
  482. err = client.InitWithOptions(regionId, config, credential)
  483. return
  484. }
  485. func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) {
  486. client = &Client{}
  487. err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret)
  488. return
  489. }
  490. func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) {
  491. client = &Client{}
  492. err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken)
  493. return
  494. }
  495. func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) {
  496. client = &Client{}
  497. err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName)
  498. return
  499. }
  500. func NewClientWithRamRoleArnAndPolicy(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (client *Client, err error) {
  501. client = &Client{}
  502. err = client.InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy)
  503. return
  504. }
  505. func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) {
  506. client = &Client{}
  507. err = client.InitWithEcsRamRole(regionId, roleName)
  508. return
  509. }
  510. func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) {
  511. client = &Client{}
  512. err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration)
  513. return
  514. }
  515. func (client *Client) ProcessCommonRequest(request *requests.CommonRequest) (response *responses.CommonResponse, err error) {
  516. request.TransToAcsRequest()
  517. response = responses.NewCommonResponse()
  518. err = client.DoAction(request, response)
  519. return
  520. }
  521. func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonRequest, signerInterface interface{}) (response *responses.CommonResponse, err error) {
  522. if signer, isSigner := signerInterface.(auth.Signer); isSigner {
  523. request.TransToAcsRequest()
  524. response = responses.NewCommonResponse()
  525. err = client.DoActionWithSigner(request, response, signer)
  526. return
  527. }
  528. panic("should not be here")
  529. }
  530. func (client *Client) Shutdown() {
  531. // lock the addAsync()
  532. client.asyncChanLock.Lock()
  533. defer client.asyncChanLock.Unlock()
  534. if client.asyncTaskQueue != nil {
  535. close(client.asyncTaskQueue)
  536. }
  537. client.isRunning = false
  538. }
  539. // Deprecated: Use NewClientWithRamRoleArn in this package instead.
  540. func NewClientWithStsRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) {
  541. return NewClientWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName)
  542. }
  543. // Deprecated: Use NewClientWithEcsRamRole in this package instead.
  544. func NewClientWithStsRoleNameOnEcs(regionId string, roleName string) (client *Client, err error) {
  545. return NewClientWithEcsRamRole(regionId, roleName)
  546. }