Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: appengine/config_service/api.py

Issue 2981473002: config_service: Fixed bug regarding None entries in latest_revisions dict. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import logging 5 import logging
6 6
7 from google.appengine.api import memcache 7 from google.appengine.api import memcache
8 from google.appengine.ext import ndb 8 from google.appengine.ext import ndb
9 from protorpc import messages 9 from protorpc import messages
10 from protorpc import message_types 10 from protorpc import message_types
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return self.GetMappingResponseMessage( 134 return self.GetMappingResponseMessage(
135 mappings=[ 135 mappings=[
136 self.GetMappingResponseMessage.Mapping( 136 self.GetMappingResponseMessage.Mapping(
137 config_set=cs.key.id(), location=cs.location) 137 config_set=cs.key.id(), location=cs.location)
138 for cs in config_sets 138 for cs in config_sets
139 if can_read[cs.key.id()] 139 if can_read[cs.key.id()]
140 ] 140 ]
141 ) 141 )
142 142
143 ############################################################################## 143 ##############################################################################
144 # endpoint: get_config_set 144 # endpoint: get_config_sets
145 145
146 class GetConfigSetsResponseMessage(messages.Message): 146 class GetConfigSetsResponseMessage(messages.Message):
147 config_sets = messages.MessageField(ConfigSet, 1, repeated=True) 147 config_sets = messages.MessageField(ConfigSet, 1, repeated=True)
148 148
149 @auth.endpoints_method( 149 @auth.endpoints_method(
150 endpoints.ResourceContainer( 150 endpoints.ResourceContainer(
151 message_types.VoidMessage, 151 message_types.VoidMessage,
152 config_set=messages.StringField(1), 152 config_set=messages.StringField(1),
153 include_last_import_attempt=messages.BooleanField(2), 153 include_last_import_attempt=messages.BooleanField(2),
154 include_files=messages.BooleanField(3), 154 include_files=messages.BooleanField(3),
155 ), 155 ),
156 GetConfigSetsResponseMessage, 156 GetConfigSetsResponseMessage,
157 http_method='GET', 157 http_method='GET',
158 path='config-sets') 158 path='config-sets')
159 @auth.public # ACL check inside 159 @auth.public # ACL check inside
160 def get_config_sets(self, request): 160 def get_config_sets(self, request):
161 """Returns config sets.""" 161 """Returns config sets."""
162 if request.config_set and not can_read_config_set(request.config_set): 162 if request.config_set and not can_read_config_set(request.config_set):
163 raise endpoints.ForbiddenException() 163 raise endpoints.ForbiddenException()
164 164
165 # The files property must always be a list of File objects (not None). 165 # The files property must always be a list of File objects (not None).
166 files = [] 166 files = []
167 if request.include_files: 167 if request.include_files:
168 if not request.config_set: 168 if not request.config_set:
169 raise endpoints.BadRequestException( 169 raise endpoints.BadRequestException(
170 'Must specify config_set to use include_files') 170 'Must specify config_set to use include_files')
171 latest_revisions = storage.get_latest_revisions_async( 171 latest_revisions = storage.get_latest_revisions_async(
172 [request.config_set]).get_result() 172 [request.config_set]).get_result()
173 file_keys = storage.get_file_keys( 173 if latest_revisions[request.config_set]:
174 request.config_set, latest_revisions[request.config_set]) 174 file_keys = storage.get_file_keys(
175 files = [File(path=key.id()) for key in file_keys] 175 request.config_set, latest_revisions[request.config_set])
176 files = [File(path=key.id()) for key in file_keys]
176 177
177 config_sets = storage.get_config_sets_async( 178 config_sets = storage.get_config_sets_async(
178 config_set=request.config_set).get_result() 179 config_set=request.config_set).get_result()
179 180
180 if request.include_last_import_attempt: 181 if request.include_last_import_attempt:
181 attempts = ndb.get_multi([ 182 attempts = ndb.get_multi([
182 storage.last_import_attempt_key(cs.key.id()) for cs in config_sets 183 storage.last_import_attempt_key(cs.key.id()) for cs in config_sets
183 ]) 184 ])
184 else: 185 else:
185 attempts = [None] * len(config_sets) 186 attempts = [None] * len(config_sets)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 513
513 def can_read_config_sets(config_sets): 514 def can_read_config_sets(config_sets):
514 try: 515 try:
515 return acl.can_read_config_sets(config_sets) 516 return acl.can_read_config_sets(config_sets)
516 except ValueError as ex: 517 except ValueError as ex:
517 raise endpoints.BadRequestException(ex.message) 518 raise endpoints.BadRequestException(ex.message)
518 519
519 520
520 def can_read_config_set(config_set): 521 def can_read_config_set(config_set):
521 return can_read_config_sets([config_set]).get(config_set) 522 return can_read_config_sets([config_set]).get(config_set)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698