コード例 #1
0
    def MatchSubscriptions():  # pylint: disable=unused-variable
        """Match the subscriptions given the request.

    This is an API handler, which requires that we have an authenticated user
    making the request. We'll require that the user either be a service account
    (from the main dashboard service) or an authenticated user. We'll enforce
    that we're only serving "public" Subscriptions to non-privileged users.
    """

        match_request = json_format.Parse(request.get_data(),
                                          sheriff_config_pb2.MatchRequest())
        match_response = sheriff_config_pb2.MatchResponse()
        for config_set, revision, subscription in luci_config.FindMatchingConfigs(
                datastore_client, match_request):
            subscription_metadata = match_response.subscriptions.add()
            subscription_metadata.config_set = config_set
            subscription_metadata.revision = revision
            subscription_metadata.subscription.CopyFrom(subscription)
        if not match_response.subscriptions:
            return jsonify({}), 404
        return (json_format.MessageToJson(match_response,
                                          preserving_proto_field_name=True),
                200, {
                    'Content-Type': 'application/json'
                })
コード例 #2
0
    def MatchSubscriptions():  # pylint: disable=unused-variable
        """Match the subscriptions given the request.

    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).

    TODO(fancl): Allow access from an authenticated user. We'll enforce
    that we're only serving "public" Subscriptions to non-privileged users.
    """

        try:
            match_request = json_format.Parse(
                request.get_data(), sheriff_config_pb2.MatchRequest())
        except json_format.ParseError as error:
            return jsonify(
                {'messages': [{
                    'severity': 'ERROR',
                    'text': '%s' % (error)
                }]}), 400
        match_response = sheriff_config_pb2.MatchResponse()
        configs = list(
            luci_config.FindMatchingConfigs(datastore_client, match_request))
        configs = match_policy.FilterSubscriptionsByPolicy(
            match_request, configs)
        for config_set, revision, subscription in configs:
            subscription_metadata = match_response.subscriptions.add()
            subscription_metadata.config_set = config_set
            subscription_metadata.revision = revision
            luci_config.CopyNormalizedSubscription(
                subscription,
                subscription_metadata.subscription,
            )

            # Then we find one anomaly config that matches.
            matcher = luci_config.GetMatcher(revision, subscription)
            anomaly_config = matcher.GetAnomalyConfig(match_request.path)
            if anomaly_config:
                subscription_metadata.subscription.anomaly_configs.append(
                    anomaly_config)
        if not match_response.subscriptions:
            return jsonify({}), 404
        return (json_format.MessageToJson(match_response,
                                          preserving_proto_field_name=True),
                200, {
                    'Content-Type': 'application/json'
                })