Credential.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. class Credential extends AbstractCredential
  21. {
  22. /**
  23. * @var string
  24. */
  25. private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
  26. /**
  27. * @var false|string
  28. */
  29. private $refreshDate;
  30. /**
  31. * @var string
  32. */
  33. private $expiredDate;
  34. /**
  35. * @var string
  36. */
  37. private $accessKeyId;
  38. /**
  39. * @var string
  40. */
  41. private $accessSecret;
  42. /**
  43. * @var string
  44. */
  45. private $securityToken;
  46. /**
  47. * Credential constructor.
  48. *
  49. * @param $accessKeyId
  50. * @param $accessSecret
  51. * @param $securityToken
  52. */
  53. public function __construct($accessKeyId, $accessSecret, $securityToken)
  54. {
  55. $this->accessKeyId = $accessKeyId;
  56. $this->accessSecret = $accessSecret;
  57. $this->securityToken = $securityToken;
  58. $this->refreshDate = date($this->dateTimeFormat);
  59. }
  60. /**
  61. * @return bool
  62. */
  63. public function isExpired()
  64. {
  65. if ($this->expiredDate == null) {
  66. return false;
  67. }
  68. if (strtotime($this->expiredDate) > strtotime(date($this->dateTimeFormat))) {
  69. return false;
  70. }
  71. return true;
  72. }
  73. /**
  74. * @return false|string
  75. */
  76. public function getRefreshDate()
  77. {
  78. return $this->refreshDate;
  79. }
  80. /**
  81. * @return string
  82. */
  83. public function getExpiredDate()
  84. {
  85. return $this->expiredDate;
  86. }
  87. /**
  88. * @param $expiredHours
  89. *
  90. * @return false|string
  91. */
  92. public function setExpiredDate($expiredHours)
  93. {
  94. if ($expiredHours > 0) {
  95. return $this->expiredDate = date($this->dateTimeFormat, strtotime('+' . $expiredHours . ' hour'));
  96. }
  97. }
  98. /**
  99. * @return string
  100. */
  101. public function getAccessKeyId()
  102. {
  103. return $this->accessKeyId;
  104. }
  105. /**
  106. * @param $accessKeyId
  107. */
  108. public function setAccessKeyId($accessKeyId)
  109. {
  110. $this->accessKeyId = $accessKeyId;
  111. }
  112. /**
  113. * @return string
  114. */
  115. public function getAccessSecret()
  116. {
  117. return $this->accessSecret;
  118. }
  119. /**
  120. * @param $accessSecret
  121. */
  122. public function setAccessSecret($accessSecret)
  123. {
  124. $this->accessSecret = $accessSecret;
  125. }
  126. /**
  127. * @return string
  128. */
  129. public function getSecurityToken()
  130. {
  131. return $this->securityToken;
  132. }
  133. /**
  134. * @param $securityToken
  135. */
  136. public function setSecurityToken($securityToken)
  137. {
  138. $this->securityToken = $securityToken;
  139. }
  140. }