comparison env/lib/python3.9/site-packages/boto/gs/encryptionconfig.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 # Copyright 2018 Google Inc.
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
22 import types
23 from boto.gs.user import User
24 from boto.exception import InvalidEncryptionConfigError
25 from xml.sax import handler
26
27 # Relevant tags for the EncryptionConfiguration XML document.
28 DEFAULT_KMS_KEY_NAME = 'DefaultKmsKeyName'
29 ENCRYPTION_CONFIG = 'EncryptionConfiguration'
30
31 class EncryptionConfig(handler.ContentHandler):
32 """Encapsulates the EncryptionConfiguration XML document"""
33 def __init__(self):
34 # Valid items in an EncryptionConfiguration XML node.
35 self.default_kms_key_name = None
36
37 self.parse_level = 0
38
39 def validateParseLevel(self, tag, level):
40 """Verify parse level for a given tag."""
41 if self.parse_level != level:
42 raise InvalidEncryptionConfigError(
43 'Invalid tag %s at parse level %d: ' % (tag, self.parse_level))
44
45 def startElement(self, name, attrs, connection):
46 """SAX XML logic for parsing new element found."""
47 if name == ENCRYPTION_CONFIG:
48 self.validateParseLevel(name, 0)
49 self.parse_level += 1;
50 elif name == DEFAULT_KMS_KEY_NAME:
51 self.validateParseLevel(name, 1)
52 self.parse_level += 1;
53 else:
54 raise InvalidEncryptionConfigError('Unsupported tag ' + name)
55
56 def endElement(self, name, value, connection):
57 """SAX XML logic for parsing new element found."""
58 if name == ENCRYPTION_CONFIG:
59 self.validateParseLevel(name, 1)
60 self.parse_level -= 1;
61 elif name == DEFAULT_KMS_KEY_NAME:
62 self.validateParseLevel(name, 2)
63 self.parse_level -= 1;
64 self.default_kms_key_name = value.strip()
65 else:
66 raise InvalidEncryptionConfigError('Unsupported end tag ' + name)
67
68 def to_xml(self):
69 """Convert EncryptionConfig object into XML string representation."""
70 s = ['<%s>' % ENCRYPTION_CONFIG]
71 if self.default_kms_key_name:
72 s.append('<%s>%s</%s>' % (DEFAULT_KMS_KEY_NAME,
73 self.default_kms_key_name,
74 DEFAULT_KMS_KEY_NAME))
75 s.append('</%s>' % ENCRYPTION_CONFIG)
76 return ''.join(s)