feat: Add the google.rpc.context.AuditContext and google.rpc.http message to the open source

PiperOrigin-RevId: 495222106
pull/761/head
Google APIs 2 years ago committed by Copybara-Service
parent f68e8e84be
commit f36c65081b
  1. 14
      google/rpc/code.proto
  2. 11
      google/rpc/context/attribute_context.proto
  3. 49
      google/rpc/context/audit_context.proto
  4. 146
      google/rpc/error_details.proto
  5. 64
      google/rpc/http.proto
  6. 8
      google/rpc/status.proto

@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ option objc_class_prefix = "RPC";
// `OUT_OF_RANGE` over `FAILED_PRECONDITION` if both codes apply.
// Similarly prefer `NOT_FOUND` or `ALREADY_EXISTS` over `FAILED_PRECONDITION`.
enum Code {
// Not an error; returned on success
// Not an error; returned on success.
//
// HTTP Mapping: 200 OK
OK = 0;
@ -69,7 +69,7 @@ enum Code {
// Some requested entity (e.g., file or directory) was not found.
//
// Note to server developers: if a request is denied for an entire class
// of users, such as gradual feature rollout or undocumented whitelist,
// of users, such as gradual feature rollout or undocumented allowlist,
// `NOT_FOUND` may be used. If a request is denied for some users within
// a class of users, such as user-based access control, `PERMISSION_DENIED`
// must be used.
@ -115,11 +115,11 @@ enum Code {
// Service implementors can use the following guidelines to decide
// between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:
// (a) Use `UNAVAILABLE` if the client can retry just the failing call.
// (b) Use `ABORTED` if the client should retry at a higher level
// (e.g., when a client-specified test-and-set fails, indicating the
// client should restart a read-modify-write sequence).
// (b) Use `ABORTED` if the client should retry at a higher level. For
// example, when a client-specified test-and-set fails, indicating the
// client should restart a read-modify-write sequence.
// (c) Use `FAILED_PRECONDITION` if the client should not retry until
// the system state has been explicitly fixed. E.g., if an "rmdir"
// the system state has been explicitly fixed. For example, if an "rmdir"
// fails because the directory is non-empty, `FAILED_PRECONDITION`
// should be returned since the client should not retry unless
// the files are deleted from the directory.

@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ message AttributeContext {
// The identity of this peer. Similar to `Request.auth.principal`, but
// relative to the peer instead of the request. For example, the
// idenity associated with a load balancer that forwared the request.
// identity associated with a load balancer that forwarded the request.
string principal = 7;
// The CLDR country/region code associated with the above IP address.
@ -170,7 +170,7 @@ message AttributeContext {
// lowercased, because HTTP header keys are case-insensitive.
map<string, string> headers = 3;
// The HTTP URL path.
// The HTTP URL path, excluding the query parameters.
string path = 4;
// The HTTP request `Host` header value.
@ -223,7 +223,7 @@ message AttributeContext {
// the response.
google.protobuf.Timestamp time = 4;
// The length of time it takes the backend service to fully respond to a
// The amount of time it takes the backend service to fully respond to a
// request. Measured from when the destination service starts to send the
// request to the backend until when the destination service receives the
// complete response from the backend.
@ -256,7 +256,8 @@ message AttributeContext {
// The type of the resource. The syntax is platform-specific because
// different platforms define their resources differently.
//
// For Google APIs, the type format must be "{service}/{kind}".
// For Google APIs, the type format must be "{service}/{kind}", such as
// "pubsub.googleapis.com/Topic".
string type = 3;
// The labels or tags on the resource, such as AWS resource tags and

@ -0,0 +1,49 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package google.rpc.context;
import "google/protobuf/struct.proto";
option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/rpc/context;context";
option java_multiple_files = true;
option java_outer_classname = "AuditContextProto";
option java_package = "com.google.rpc.context";
// `AuditContext` provides information that is needed for audit logging.
message AuditContext {
// Serialized audit log.
bytes audit_log = 1;
// An API request message that is scrubbed based on the method annotation.
// This field should only be filled if audit_log field is present.
// Service Control will use this to assemble a complete log for Cloud Audit
// Logs and Google internal audit logs.
google.protobuf.Struct scrubbed_request = 2;
// An API response message that is scrubbed based on the method annotation.
// This field should only be filled if audit_log field is present.
// Service Control will use this to assemble a complete log for Cloud Audit
// Logs and Google internal audit logs.
google.protobuf.Struct scrubbed_response = 3;
// Number of scrubbed response items.
int32 scrubbed_response_item_count = 4;
// Audit resource name which is scrubbed.
string target_resource = 5;
}

@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -24,6 +24,57 @@ option java_outer_classname = "ErrorDetailsProto";
option java_package = "com.google.rpc";
option objc_class_prefix = "RPC";
// Describes the cause of the error with structured details.
//
// Example of an error when contacting the "pubsub.googleapis.com" API when it
// is not enabled:
//
// { "reason": "API_DISABLED"
// "domain": "googleapis.com"
// "metadata": {
// "resource": "projects/123",
// "service": "pubsub.googleapis.com"
// }
// }
//
// This response indicates that the pubsub.googleapis.com API is not enabled.
//
// Example of an error that is returned when attempting to create a Spanner
// instance in a region that is out of stock:
//
// { "reason": "STOCKOUT"
// "domain": "spanner.googleapis.com",
// "metadata": {
// "availableRegions": "us-central1,us-east2"
// }
// }
message ErrorInfo {
// The reason of the error. This is a constant value that identifies the
// proximate cause of the error. Error reasons are unique within a particular
// domain of errors. This should be at most 63 characters and match a
// regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`, which represents
// UPPER_SNAKE_CASE.
string reason = 1;
// The logical grouping to which the "reason" belongs. The error domain
// is typically the registered service name of the tool or product that
// generates the error. Example: "pubsub.googleapis.com". If the error is
// generated by some common infrastructure, the error domain must be a
// globally unique value that identifies the infrastructure. For Google API
// infrastructure, the error domain is "googleapis.com".
string domain = 2;
// Additional structured details about this error.
//
// Keys should match /[a-zA-Z0-9-_]/ and be limited to 64 characters in
// length. When identifying the current value of an exceeded limit, the units
// should be contained in the key, not the value. For example, rather than
// {"instanceLimit": "100/request"}, should be returned as,
// {"instanceLimitPerRequest": "100"}, if the client exceeds the number of
// instances that can be created in a single (batch) request.
map<string, string> metadata = 3;
}
// Describes when the clients can retry a failed request. Clients could ignore
// the recommendation here or retry when this information is missing from error
// responses.
@ -85,56 +136,6 @@ message QuotaFailure {
repeated Violation violations = 1;
}
// Describes the cause of the error with structured details.
//
// Example of an error when contacting the "pubsub.googleapis.com" API when it
// is not enabled:
//
// { "reason": "API_DISABLED"
// "domain": "googleapis.com"
// "metadata": {
// "resource": "projects/123",
// "service": "pubsub.googleapis.com"
// }
// }
//
// This response indicates that the pubsub.googleapis.com API is not enabled.
//
// Example of an error that is returned when attempting to create a Spanner
// instance in a region that is out of stock:
//
// { "reason": "STOCKOUT"
// "domain": "spanner.googleapis.com",
// "metadata": {
// "availableRegions": "us-central1,us-east2"
// }
// }
message ErrorInfo {
// The reason of the error. This is a constant value that identifies the
// proximate cause of the error. Error reasons are unique within a particular
// domain of errors. This should be at most 63 characters and match
// /[A-Z0-9_]+/.
string reason = 1;
// The logical grouping to which the "reason" belongs. The error domain
// is typically the registered service name of the tool or product that
// generates the error. Example: "pubsub.googleapis.com". If the error is
// generated by some common infrastructure, the error domain must be a
// globally unique value that identifies the infrastructure. For Google API
// infrastructure, the error domain is "googleapis.com".
string domain = 2;
// Additional structured details about this error.
//
// Keys should match /[a-zA-Z0-9-_]/ and be limited to 64 characters in
// length. When identifying the current value of an exceeded limit, the units
// should be contained in the key, not the value. For example, rather than
// {"instanceLimit": "100/request"}, should be returned as,
// {"instanceLimitPerRequest": "100"}, if the client exceeds the number of
// instances that can be created in a single (batch) request.
map<string, string> metadata = 3;
}
// Describes what preconditions have failed.
//
// For example, if an RPC failed because it required the Terms of Service to be
@ -169,9 +170,43 @@ message PreconditionFailure {
message BadRequest {
// A message type used to describe a single bad request field.
message FieldViolation {
// A path leading to a field in the request body. The value will be a
// A path that leads to a field in the request body. The value will be a
// sequence of dot-separated identifiers that identify a protocol buffer
// field. E.g., "field_violations.field" would identify this field.
// field.
//
// Consider the following:
//
// message CreateContactRequest {
// message EmailAddress {
// enum Type {
// TYPE_UNSPECIFIED = 0;
// HOME = 1;
// WORK = 2;
// }
//
// optional string email = 1;
// repeated EmailType type = 2;
// }
//
// string full_name = 1;
// repeated EmailAddress email_addresses = 2;
// }
//
// In this example, in proto `field` could take one of the following values:
//
// * `full_name` for a violation in the `full_name` value
// * `email_addresses[1].email` for a violation in the `email` field of the
// first `email_addresses` message
// * `email_addresses[3].type[2]` for a violation in the second `type`
// value in the third `email_addresses` message.
//
// In JSON, the same values are represented as:
//
// * `fullName` for a violation in the `fullName` value
// * `emailAddresses[1].email` for a violation in the `email` field of the
// first `emailAddresses` message
// * `emailAddresses[3].type[2]` for a violation in the second `type`
// value in the third `emailAddresses` message.
string field = 1;
// A description of why the request element is bad.
@ -203,7 +238,8 @@ message ResourceInfo {
// The name of the resource being accessed. For example, a shared calendar
// name: "example.com_4fghdhgsrgh@group.calendar.google.com", if the current
// error is [google.rpc.Code.PERMISSION_DENIED][google.rpc.Code.PERMISSION_DENIED].
// error is
// [google.rpc.Code.PERMISSION_DENIED][google.rpc.Code.PERMISSION_DENIED].
string resource_name = 2;
// The owner of the resource (optional).
@ -240,7 +276,7 @@ message Help {
// which can be attached to an RPC error.
message LocalizedMessage {
// The locale used following the specification defined at
// http://www.rfc-editor.org/rfc/bcp/bcp47.txt.
// https://www.rfc-editor.org/rfc/bcp/bcp47.txt.
// Examples are: "en-US", "fr-CH", "es-MX"
string locale = 1;

@ -0,0 +1,64 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package google.rpc;
option go_package = "google.golang.org/genproto/googleapis/rpc/http;http";
option java_multiple_files = true;
option java_outer_classname = "HttpProto";
option java_package = "com.google.rpc";
option objc_class_prefix = "RPC";
// Represents an HTTP request.
message HttpRequest {
// The HTTP request method.
string method = 1;
// The HTTP request URI.
string uri = 2;
// The HTTP request headers. The ordering of the headers is significant.
// Multiple headers with the same key may present for the request.
repeated HttpHeader headers = 3;
// The HTTP request body. If the body is not expected, it should be empty.
bytes body = 4;
}
// Represents an HTTP response.
message HttpResponse {
// The HTTP status code, such as 200 or 404.
int32 status = 1;
// The HTTP reason phrase, such as "OK" or "Not Found".
string reason = 2;
// The HTTP response headers. The ordering of the headers is significant.
// Multiple headers with the same key may present for the response.
repeated HttpHeader headers = 3;
// The HTTP response body. If the body is not expected, it should be empty.
bytes body = 4;
}
// Represents an HTTP header.
message HttpHeader {
// The HTTP header key. It is case insensitive.
string key = 1;
// The HTTP header value.
string value = 2;
}

@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -33,12 +33,14 @@ option objc_class_prefix = "RPC";
// You can find out more about this error model and how to work with it in the
// [API Design Guide](https://cloud.google.com/apis/design/errors).
message Status {
// The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
// The status code, which should be an enum value of
// [google.rpc.Code][google.rpc.Code].
int32 code = 1;
// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized
// by the client.
string message = 2;
// A list of messages that carry the error details. There is a common set of

Loading…
Cancel
Save