AssumeRole.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace AlibabaCloud\Credentials\Request;
  3. use AlibabaCloud\Credentials\Providers\Provider;
  4. use AlibabaCloud\Credentials\RamRoleArnCredential;
  5. use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
  6. /**
  7. * Retrieving assume role credentials.
  8. */
  9. class AssumeRole extends Request
  10. {
  11. /**
  12. * AssumeRole constructor.
  13. *
  14. * @param RamRoleArnCredential $arnCredential
  15. */
  16. public function __construct(RamRoleArnCredential $arnCredential)
  17. {
  18. parent::__construct();
  19. $this->signature = new ShaHmac1Signature();
  20. $this->credential = $arnCredential;
  21. $this->uri = $this->uri->withHost('sts.aliyuncs.com');
  22. $this->options['verify'] = false;
  23. $this->options['query']['RoleArn'] = $arnCredential->getRoleArn();
  24. $this->options['query']['RoleSessionName'] = $arnCredential->getRoleSessionName();
  25. $this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
  26. $this->options['query']['AccessKeyId'] = $this->credential->getOriginalAccessKeyId();
  27. $this->options['query']['Version'] = '2015-04-01';
  28. $this->options['query']['Action'] = 'AssumeRole';
  29. $this->options['query']['RegionId'] = 'cn-hangzhou';
  30. if ($arnCredential->getPolicy()) {
  31. $this->options['query']['Policy'] = $arnCredential->getPolicy();
  32. }
  33. }
  34. }