AssumeRole.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace AlibabaCloud\Client\Credentials\Requests;
  3. use AlibabaCloud\Client\Request\RpcRequest;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Credentials\Providers\Provider;
  6. use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
  7. /**
  8. * Retrieving assume role credentials.
  9. *
  10. * @package AlibabaCloud\Client\Credentials\Requests
  11. */
  12. class AssumeRole extends RpcRequest
  13. {
  14. /**
  15. * AssumeRole constructor.
  16. *
  17. * @param RamRoleArnCredential $arnCredential
  18. *
  19. * @throws ClientException
  20. */
  21. public function __construct(RamRoleArnCredential $arnCredential)
  22. {
  23. parent::__construct();
  24. $this->product('Sts');
  25. $this->version('2015-04-01');
  26. $this->action('AssumeRole');
  27. $this->host('sts.aliyuncs.com');
  28. $this->scheme('https');
  29. $this->regionId('cn-hangzhou');
  30. $this->options['verify'] = false;
  31. $this->options['query']['RoleArn'] = $arnCredential->getRoleArn();
  32. $this->options['query']['RoleSessionName'] = $arnCredential->getRoleSessionName();
  33. $this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
  34. if ($arnCredential->getPolicy()) {
  35. if (is_array($arnCredential->getPolicy())) {
  36. $this->options['query']['Policy'] = json_encode($arnCredential->getPolicy());
  37. }
  38. if (is_string($arnCredential->getPolicy())) {
  39. $this->options['query']['Policy'] = $arnCredential->getPolicy();
  40. }
  41. }
  42. }
  43. }