Credential.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  21. {
  22. private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
  23. private $refreshDate;
  24. private $expiredDate;
  25. private $accessKeyId;
  26. private $accessSecret;
  27. private $securityToken;
  28. public function __construct($accessKeyId, $accessSecret, $securityToken)
  29. {
  30. $this->accessKeyId = $accessKeyId;
  31. $this->accessSecret = $accessSecret;
  32. $this->securityToken = $securityToken;
  33. $this->refreshDate = date($this->dateTimeFormat);
  34. }
  35. public function isExpired()
  36. {
  37. if ($this->expiredDate == null) {
  38. return false;
  39. }
  40. if (strtotime($this->expiredDate)>date($this->dateTimeFormat)) {
  41. return false;
  42. }
  43. return true;
  44. }
  45. public function getRefreshDate()
  46. {
  47. return $this->refreshDate;
  48. }
  49. public function getExpiredDate()
  50. {
  51. return $this->expiredDate;
  52. }
  53. public function setExpiredDate($expiredHours)
  54. {
  55. if ($expiredHours>0) {
  56. return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
  57. }
  58. }
  59. public function getAccessKeyId()
  60. {
  61. return $this->accessKeyId;
  62. }
  63. public function setAccessKeyId($accessKeyId)
  64. {
  65. $this->accessKeyId = $accessKeyId;
  66. }
  67. public function getAccessSecret()
  68. {
  69. return $this->accessSecret;
  70. }
  71. public function setAccessSecret($accessSecret)
  72. {
  73. $this->accessSecret = $accessSecret;
  74. }
  75. public function getSecurityToken()
  76. {
  77. return $this->securityToken;
  78. }
  79. public function setSecurityToken($securityToken)
  80. {
  81. $this->securityToken = $securityToken;
  82. }
  83. }