Scope.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace QCloud\COSSTS;
  3. class Scope{
  4. var $action;
  5. var $bucket;
  6. var $region;
  7. var $resourcePrefix;
  8. var $effect = 'allow';
  9. function __construct($action, $bucket, $region, $resourcePrefix){
  10. $this->action = $action;
  11. $this->bucket = $bucket;
  12. $this->region = $region;
  13. $this->resourcePrefix = $resourcePrefix;
  14. }
  15. function set_effect($isAllow){
  16. if($isAllow){
  17. $this->effect = 'allow';
  18. }else{
  19. $this->effect = 'deny';
  20. }
  21. }
  22. function get_action(){
  23. if($this->action == null){
  24. throw new \Exception("action == null");
  25. }
  26. return $this->action;
  27. }
  28. function get_resource(){
  29. if($this->bucket == null){
  30. throw new \Exception("bucket == null");
  31. }
  32. if($this->region == null){
  33. throw new \Exception("region == null");
  34. }
  35. if($this->resourcePrefix == null){
  36. throw new \Exception("resourcePrefix == null");
  37. }
  38. $index = strripos($this->bucket, '-');
  39. if($index < 0){
  40. throw new Exception("bucket is invalid: " . $this->bucket);
  41. }
  42. $appid = substr($this->bucket, $index + 1);
  43. if(!(strpos($this->resourcePrefix, '/') === 0)){
  44. $this->resourcePrefix = '/' . $this->resourcePrefix;
  45. }
  46. return 'qcs::cos:' . $this->region . ':uid/' . $appid . ':' . $this->bucket . $this->resourcePrefix;
  47. }
  48. function get_effect(){
  49. return $this->effect;
  50. }
  51. }
  52. ?>