PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/cloudfront/identity.py

#
Python | 122 lines | 99 code | 3 blank | 20 comment | 0 complexity | 487c868089f9408991ccdaeabf966e88 MD5 | raw file
  1. # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a
  4. # copy of this software and associated documentation files (the
  5. # "Software"), to deal in the Software without restriction, including
  6. # without limitation the rights to use, copy, modify, merge, publish, dis-
  7. # tribute, sublicense, and/or sell copies of the Software, and to permit
  8. # persons to whom the Software is furnished to do so, subject to the fol-
  9. # lowing conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included
  12. # in all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  16. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  17. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. # IN THE SOFTWARE.
  21. import uuid
  22. class OriginAccessIdentity:
  23. def __init__(self, connection=None, config=None, id='',
  24. s3_user_id='', comment=''):
  25. self.connection = connection
  26. self.config = config
  27. self.id = id
  28. self.s3_user_id = s3_user_id
  29. self.comment = comment
  30. self.etag = None
  31. def startElement(self, name, attrs, connection):
  32. if name == 'CloudFrontOriginAccessIdentityConfig':
  33. self.config = OriginAccessIdentityConfig()
  34. return self.config
  35. else:
  36. return None
  37. def endElement(self, name, value, connection):
  38. if name == 'Id':
  39. self.id = value
  40. elif name == 'S3CanonicalUserId':
  41. self.s3_user_id = value
  42. elif name == 'Comment':
  43. self.comment = value
  44. else:
  45. setattr(self, name, value)
  46. def update(self, comment=None):
  47. new_config = OriginAccessIdentityConfig(self.connection,
  48. self.config.caller_reference,
  49. self.config.comment)
  50. if comment != None:
  51. new_config.comment = comment
  52. self.etag = self.connection.set_origin_identity_config(self.id, self.etag, new_config)
  53. self.config = new_config
  54. def delete(self):
  55. return self.connection.delete_origin_access_identity(self.id, self.etag)
  56. def uri(self):
  57. return 'origin-access-identity/cloudfront/%s' % self.id
  58. class OriginAccessIdentityConfig:
  59. def __init__(self, connection=None, caller_reference='', comment=''):
  60. self.connection = connection
  61. if caller_reference:
  62. self.caller_reference = caller_reference
  63. else:
  64. self.caller_reference = str(uuid.uuid4())
  65. self.comment = comment
  66. def to_xml(self):
  67. s = '<?xml version="1.0" encoding="UTF-8"?>\n'
  68. s += '<CloudFrontOriginAccessIdentityConfig xmlns="http://cloudfront.amazonaws.com/doc/2009-09-09/">\n'
  69. s += ' <CallerReference>%s</CallerReference>\n' % self.caller_reference
  70. if self.comment:
  71. s += ' <Comment>%s</Comment>\n' % self.comment
  72. s += '</CloudFrontOriginAccessIdentityConfig>\n'
  73. return s
  74. def startElement(self, name, attrs, connection):
  75. return None
  76. def endElement(self, name, value, connection):
  77. if name == 'Comment':
  78. self.comment = value
  79. elif name == 'CallerReference':
  80. self.caller_reference = value
  81. else:
  82. setattr(self, name, value)
  83. class OriginAccessIdentitySummary:
  84. def __init__(self, connection=None, id='',
  85. s3_user_id='', comment=''):
  86. self.connection = connection
  87. self.id = id
  88. self.s3_user_id = s3_user_id
  89. self.comment = comment
  90. self.etag = None
  91. def startElement(self, name, attrs, connection):
  92. return None
  93. def endElement(self, name, value, connection):
  94. if name == 'Id':
  95. self.id = value
  96. elif name == 'S3CanonicalUserId':
  97. self.s3_user_id = value
  98. elif name == 'Comment':
  99. self.comment = value
  100. else:
  101. setattr(self, name, value)
  102. def get_origin_access_identity(self):
  103. return self.connection.get_origin_access_identity_info(self.id)