def get_firebase_messaging_access_token(): """ Get a access token for the application with the Firebase messaging scope Return: access_token(string): Bearer token used to authenticate requests """ access_token, _ = app_identity.get_access_token('https://www.googleapis.com/auth/firebase.messaging') return access_token
def UpdateSwarmingTaskIdForFailedSteps( master_name, builder_name, build_number, failed_steps, http_client): """Checks failed step_names in swarming log for the build. Searches each failed step_name to identify swarming/non-swarming tests and keeps track of task ids for each failed swarming steps. """ data = { 'items':[] } step_name_prefix = 'stepname:' base_url = TEMPLATE_URL.format( master=master_name, buildername=builder_name, buildnumber=build_number) cursor = None while True: if not cursor: url = base_url else: url = base_url + '?cursor=%s' % urllib.quote(cursor) auth_token, _ = app_identity.get_access_token( 'https://www.googleapis.com/auth/userinfo.email') status_code, new_data = http_client.Get( url, headers={'Authorization': 'Bearer <' + auth_token + '>'}) if status_code != 200: return False new_data_json = json.loads(new_data) data['items'].extend(new_data_json['items']) if new_data_json.get('cursor'): cursor = new_data_json['cursor'] else: break task_ids = defaultdict(list) for item in data['items']: if item['failure'] and not item['internal_failure']: # Only retrieves test results from tasks which have failures and # the failure should not be internal infrastructure failure. for tag in item['tags']: # pragma: no cover if tag.startswith(step_name_prefix): swarming_step_name = tag[len(step_name_prefix):] break if swarming_step_name in failed_steps: task_ids[swarming_step_name].append(item['id']) for step_name in task_ids: failed_steps[step_name]['swarming_task_ids'] = task_ids[step_name] return True
def post(self): backup_bucket = self.request.get('bucket', None) path = self.request.get('object', None) if not backup_bucket or not path: logging.warning("Bad arguments, bucket: {}, path: {}".format(backup_bucket, path)) self.abort(400) logging.info("Updating storage class for {}/{}".format(backup_bucket, path)) # This uses the default service account for this application access_token, _ = app_identity.get_access_token( 'https://www.googleapis.com/auth/devstorage.read_write') metadata = self.get_object_metadata(backup_bucket, path, access_token) storage_class = metadata.get('storageClass') if storage_class == 'COLDLINE': logging.info("File is already set to COLDLINE") return self.set_file_storage_class(backup_bucket, path, 'coldline', access_token)
def post(self): backup_bucket = self.request.get('bucket', None) path = self.request.get('object', None) if not backup_bucket or not path: logging.warning("Bad arguments, bucket: {}, path: {}".format(backup_bucket, path)) self.abort(400) logging.info("Updating storage class for {}/{}".format(backup_bucket, path)) # This uses the default service account for this application access_token, _ = app_identity.get_access_token( 'https://www.googleapis.com/auth/devstorage.read_write') metadata = self.get_object_metadata(backup_bucket, path, access_token) storage_class = metadata.get('storageClass') if storage_class == 'COLDLINE': logging.info("File is already set to COLDLINE") return self.set_file_storage_class(backup_bucket, path, 'coldline', access_token)
def get_oauth_token(self, scope): # This uses the default service account for this application access_token, _ = app_identity.get_access_token(scope) return access_token
def GetAuthToken(scope=_EMAIL_SCOPE): """Gets auth token for requests to hosts that need authorizations.""" auth_token, _ = app_identity.get_access_token(scope) return auth_token
def _get_access_token(): # This uses the default service account for this application access_token, _ = app_identity.get_access_token('https://www.googleapis.com/auth/firebase.messaging') return access_token
def get_oauth_token(self, scope): # This uses the default service account for this application access_token, _ = app_identity.get_access_token(scope) return access_token
def GetAuthToken(): # pragma: no cover """Gets auth token for requests to swarming server and isolated server.""" auth_token, _ = app_identity.get_access_token( 'https://www.googleapis.com/auth/userinfo.email') return auth_token