RamRoleArnCredential.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace AlibabaCloud\Client\Credentials;
  3. use AlibabaCloud\Client\Filter\CredentialFilter;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. /**
  6. * Use the AssumeRole of the RAM account to complete the authentication.
  7. *
  8. * @package AlibabaCloud\Client\Credentials
  9. */
  10. class RamRoleArnCredential implements CredentialsInterface
  11. {
  12. /**
  13. * @var string
  14. */
  15. private $accessKeyId;
  16. /**
  17. * @var string
  18. */
  19. private $accessKeySecret;
  20. /**
  21. * @var string
  22. */
  23. private $roleArn;
  24. /**
  25. * @var string
  26. */
  27. private $roleSessionName;
  28. /**
  29. * @var string
  30. */
  31. private $policy;
  32. /**
  33. * Class constructor.
  34. *
  35. * @param string $accessKeyId
  36. * @param string $accessKeySecret
  37. * @param string $roleArn
  38. * @param string $roleSessionName
  39. * @param string|array $policy
  40. *
  41. * @throws ClientException
  42. */
  43. public function __construct($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy = '')
  44. {
  45. CredentialFilter::AccessKey($accessKeyId, $accessKeySecret);
  46. $this->accessKeyId = $accessKeyId;
  47. $this->accessKeySecret = $accessKeySecret;
  48. $this->roleArn = $roleArn;
  49. $this->roleSessionName = $roleSessionName;
  50. $this->policy = $policy;
  51. }
  52. /**
  53. * @return string
  54. */
  55. public function getAccessKeyId()
  56. {
  57. return $this->accessKeyId;
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function getAccessKeySecret()
  63. {
  64. return $this->accessKeySecret;
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function getRoleArn()
  70. {
  71. return $this->roleArn;
  72. }
  73. /**
  74. * @return string
  75. */
  76. public function getRoleSessionName()
  77. {
  78. return $this->roleSessionName;
  79. }
  80. /**
  81. * @return string
  82. */
  83. public function getPolicy()
  84. {
  85. return $this->policy;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function __toString()
  91. {
  92. return "$this->accessKeyId#$this->accessKeySecret#$this->roleArn#$this->roleSessionName";
  93. }
  94. }