Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/cloudsearch2/optionstatus.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/ | |
2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. | |
3 # All Rights Reserved | |
4 # | |
5 # Permission is hereby granted, free of charge, to any person obtaining a | |
6 # copy of this software and associated documentation files (the | |
7 # "Software"), to deal in the Software without restriction, including | |
8 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
9 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
10 # persons to whom the Software is furnished to do so, subject to the fol- | |
11 # lowing conditions: | |
12 # | |
13 # The above copyright notice and this permission notice shall be included | |
14 # in all copies or substantial portions of the Software. | |
15 # | |
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
22 # IN THE SOFTWARE. | |
23 # | |
24 | |
25 from boto.compat import json | |
26 | |
27 | |
28 class OptionStatus(dict): | |
29 """ | |
30 Presents a combination of status field (defined below) which are | |
31 accessed as attributes and option values which are stored in the | |
32 native Python dictionary. In this class, the option values are | |
33 merged from a JSON object that is stored as the Option part of | |
34 the object. | |
35 | |
36 :ivar domain_name: The name of the domain this option is associated with. | |
37 :ivar create_date: A timestamp for when this option was created. | |
38 :ivar state: The state of processing a change to an option. | |
39 Possible values: | |
40 | |
41 * RequiresIndexDocuments: the option's latest value will not | |
42 be visible in searches until IndexDocuments has been called | |
43 and indexing is complete. | |
44 * Processing: the option's latest value is not yet visible in | |
45 all searches but is in the process of being activated. | |
46 * Active: the option's latest value is completely visible. | |
47 | |
48 :ivar update_date: A timestamp for when this option was updated. | |
49 :ivar update_version: A unique integer that indicates when this | |
50 option was last updated. | |
51 """ | |
52 | |
53 def __init__(self, domain, data=None, refresh_fn=None, refresh_key=None, | |
54 save_fn=None): | |
55 self.domain = domain | |
56 self.refresh_fn = refresh_fn | |
57 self.refresh_key = refresh_key | |
58 self.save_fn = save_fn | |
59 self.refresh(data) | |
60 | |
61 def _update_status(self, status): | |
62 self.creation_date = status['CreationDate'] | |
63 self.status = status['State'] | |
64 self.update_date = status['UpdateDate'] | |
65 self.update_version = int(status['UpdateVersion']) | |
66 | |
67 def _update_options(self, options): | |
68 if options: | |
69 self.update(options) | |
70 | |
71 def refresh(self, data=None): | |
72 """ | |
73 Refresh the local state of the object. You can either pass | |
74 new state data in as the parameter ``data`` or, if that parameter | |
75 is omitted, the state data will be retrieved from CloudSearch. | |
76 """ | |
77 if not data: | |
78 if self.refresh_fn: | |
79 data = self.refresh_fn(self.domain.name) | |
80 | |
81 if data and self.refresh_key: | |
82 # Attempt to pull out the right nested bag of data | |
83 for key in self.refresh_key: | |
84 data = data[key] | |
85 if data: | |
86 self._update_status(data['Status']) | |
87 self._update_options(data['Options']) | |
88 | |
89 def to_json(self): | |
90 """ | |
91 Return the JSON representation of the options as a string. | |
92 """ | |
93 return json.dumps(self) | |
94 | |
95 def save(self): | |
96 """ | |
97 Write the current state of the local object back to the | |
98 CloudSearch service. | |
99 """ | |
100 if self.save_fn: | |
101 data = self.save_fn(self.domain.name, self.to_json()) | |
102 self.refresh(data) | |
103 | |
104 | |
105 class IndexFieldStatus(OptionStatus): | |
106 def save(self): | |
107 pass | |
108 | |
109 | |
110 class AvailabilityOptionsStatus(OptionStatus): | |
111 def save(self): | |
112 pass | |
113 | |
114 | |
115 class ScalingParametersStatus(IndexFieldStatus): | |
116 pass | |
117 | |
118 | |
119 class ExpressionStatus(IndexFieldStatus): | |
120 pass | |
121 | |
122 | |
123 class ServicePoliciesStatus(OptionStatus): | |
124 | |
125 def new_statement(self, arn, ip): | |
126 """ | |
127 Returns a new policy statement that will allow | |
128 access to the service described by ``arn`` by the | |
129 ip specified in ``ip``. | |
130 | |
131 :type arn: string | |
132 :param arn: The Amazon Resource Notation identifier for the | |
133 service you wish to provide access to. This would be | |
134 either the search service or the document service. | |
135 | |
136 :type ip: string | |
137 :param ip: An IP address or CIDR block you wish to grant access | |
138 to. | |
139 """ | |
140 return { | |
141 "Effect": "Allow", | |
142 "Action": "*", # Docs say use GET, but denies unless * | |
143 "Resource": arn, | |
144 "Condition": { | |
145 "IpAddress": { | |
146 "aws:SourceIp": [ip] | |
147 } | |
148 } | |
149 } | |
150 | |
151 def _allow_ip(self, arn, ip): | |
152 if 'Statement' not in self: | |
153 s = self.new_statement(arn, ip) | |
154 self['Statement'] = [s] | |
155 self.save() | |
156 else: | |
157 add_statement = True | |
158 for statement in self['Statement']: | |
159 if statement['Resource'] == arn: | |
160 for condition_name in statement['Condition']: | |
161 if condition_name == 'IpAddress': | |
162 add_statement = False | |
163 condition = statement['Condition'][condition_name] | |
164 if ip not in condition['aws:SourceIp']: | |
165 condition['aws:SourceIp'].append(ip) | |
166 | |
167 if add_statement: | |
168 s = self.new_statement(arn, ip) | |
169 self['Statement'].append(s) | |
170 self.save() | |
171 | |
172 def allow_search_ip(self, ip): | |
173 """ | |
174 Add the provided ip address or CIDR block to the list of | |
175 allowable address for the search service. | |
176 | |
177 :type ip: string | |
178 :param ip: An IP address or CIDR block you wish to grant access | |
179 to. | |
180 """ | |
181 arn = self.domain.service_arn | |
182 self._allow_ip(arn, ip) | |
183 | |
184 def allow_doc_ip(self, ip): | |
185 """ | |
186 Add the provided ip address or CIDR block to the list of | |
187 allowable address for the document service. | |
188 | |
189 :type ip: string | |
190 :param ip: An IP address or CIDR block you wish to grant access | |
191 to. | |
192 """ | |
193 arn = self.domain.service_arn | |
194 self._allow_ip(arn, ip) | |
195 | |
196 def _disallow_ip(self, arn, ip): | |
197 if 'Statement' not in self: | |
198 return | |
199 need_update = False | |
200 for statement in self['Statement']: | |
201 if statement['Resource'] == arn: | |
202 for condition_name in statement['Condition']: | |
203 if condition_name == 'IpAddress': | |
204 condition = statement['Condition'][condition_name] | |
205 if ip in condition['aws:SourceIp']: | |
206 condition['aws:SourceIp'].remove(ip) | |
207 need_update = True | |
208 if need_update: | |
209 self.save() | |
210 | |
211 def disallow_search_ip(self, ip): | |
212 """ | |
213 Remove the provided ip address or CIDR block from the list of | |
214 allowable address for the search service. | |
215 | |
216 :type ip: string | |
217 :param ip: An IP address or CIDR block you wish to grant access | |
218 to. | |
219 """ | |
220 arn = self.domain.service_arn | |
221 self._disallow_ip(arn, ip) | |
222 | |
223 def disallow_doc_ip(self, ip): | |
224 """ | |
225 Remove the provided ip address or CIDR block from the list of | |
226 allowable address for the document service. | |
227 | |
228 :type ip: string | |
229 :param ip: An IP address or CIDR block you wish to grant access | |
230 to. | |
231 """ | |
232 arn = self.domain.service_arn | |
233 self._disallow_ip(arn, ip) |