Пример #1
0
    def ListSubscriptions():  # pylint: disable=unused-variable
        """List all visible subscriptions based on identity.

    This is an API handler, which requires that we have an authenticated user
    making the request. We'll require that the user be a service account
    (from the main dashboard service).

    """

        try:
            list_request = json_format.Parse(request.get_data(),
                                             sheriff_config_pb2.ListRequest())
        except json_format.ParseError as error:
            return jsonify(
                {'messages': [{
                    'severity': 'ERROR',
                    'text': '%s' % (error)
                }]}), 400
        list_response = sheriff_config_pb2.ListResponse()
        configs = list(luci_config.ListAllConfigs(datastore_client))
        configs = match_policy.FilterSubscriptionsByIdentity(
            auth_client, list_request, configs)
        for config_set, revision, subscription in configs:
            subscription_metadata = list_response.subscriptions.add()
            subscription_metadata.config_set = config_set
            subscription_metadata.revision = revision
            subscription_metadata.subscription.CopyFrom(subscription)
            # We shouldn't use patterns outside the sheriff-config in any case.
            # Maybe allow being explicitily requsted for debug usage later.
            del subscription_metadata.subscription.patterns[:]
        return (json_format.MessageToJson(list_response,
                                          preserving_proto_field_name=True),
                200, {
                    'Content-Type': 'application/json'
                })
Пример #2
0
 def Warmup():  # pylint: disable=unused-variable
     """Caching configs and compiled patterns for warmup."""
     configs = luci_config.ListAllConfigs(datastore_client,
                                          _cache_timestamp=time.time() + 10)
     for _, revision, subscription in configs:
         luci_config.GetMatcher(revision, subscription)
     return jsonify({})