Skip to content

Commit

Permalink
format: run clang-format on proto files (envoyproxy#3473)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Klein <[email protected]>
  • Loading branch information
mattklein123 authored May 23, 2018
1 parent 44da6d4 commit 033beaa
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ PointerAlignment: Left
SortIncludes: false
...

---
Language: Proto
ColumnLimit: 100
SpacesInContainerLiterals: false
AllowShortFunctionsOnASingleLine: false
...
2 changes: 1 addition & 1 deletion api/envoy/api/v2/auth/cert.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ message CertificateValidationContext {
//
// Both of those formats are acceptable.
repeated string verify_certificate_hash = 2
[(validate.rules).repeated.items.string = {min_bytes: 64, max_bytes: 95}];
[(validate.rules).repeated .items.string = {min_bytes: 64, max_bytes: 95}];

// If specified, Envoy will verify (pin) base64-encoded SHA-256 hash of
// the Subject Public Key Information (SPKI) of the presented certificate.
Expand Down
18 changes: 10 additions & 8 deletions api/envoy/api/v2/listener/listener.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ message FilterChainMatch {
google.protobuf.UInt32Value destination_port = 8;

// If non-empty, a list of server names (e.g. SNI for TLS protocol) to consider when determining
// a filter chain match. Those values will be compared against the server names of a new connection,
// when detected by one of the listener filters.
// a filter chain match. Those values will be compared against the server names of a new
// connection, when detected by one of the listener filters.
//
// The server name will be matched against all wildcard domains, i.e. ``www.example.com``
// will be first matched against ``www.example.com``, then ``*.example.com``, then ``*.com``.
Expand All @@ -128,12 +128,13 @@ message FilterChainMatch {
string transport_protocol = 9;

// If non-empty, a list of application protocols (e.g. ALPN for TLS protocol) to consider when
// determining a filter chain match. Those values will be compared against the application protocols
// of a new connection, when detected by one of the listener filters.
// determining a filter chain match. Those values will be compared against the application
// protocols of a new connection, when detected by one of the listener filters.
//
// Suggested values include:
//
// * ``http/1.1`` - set by :ref:`envoy.listener.tls_inspector <config_listener_filters_tls_inspector>`,
// * ``http/1.1`` - set by :ref:`envoy.listener.tls_inspector
// <config_listener_filters_tls_inspector>`,
// * ``h2`` - set by :ref:`envoy.listener.tls_inspector <config_listener_filters_tls_inspector>`
//
// .. attention::
Expand All @@ -148,8 +149,8 @@ message FilterChainMatch {
repeated string application_protocols = 10;

// If non-empty, a list of server names (e.g. SNI for TLS protocol) to consider when determining
// a filter chain match. Those values will be compared against the server names of a new connection,
// when detected by one of the listener filters.
// a filter chain match. Those values will be compared against the server names of a new
// connection, when detected by one of the listener filters.
//
// The server name will be matched against all wildcard domains, i.e. ``www.example.com``
// will be first matched against ``www.example.com``, then ``*.example.com``, then ``*.com``.
Expand All @@ -158,7 +159,8 @@ message FilterChainMatch {
//
// .. attention::
//
// Deprecated. Use :ref:`server_names <envoy_api_field_listener.FilterChainMatch.server_names>` instead.
// Deprecated. Use :ref:`server_names <envoy_api_field_listener.FilterChainMatch.server_names>`
// instead.
repeated string sni_domains = 1 [deprecated = true];
}

Expand Down
18 changes: 10 additions & 8 deletions api/envoy/api/v2/route/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -570,23 +570,25 @@ message RouteAction {
google.protobuf.BoolValue use_websocket = 16;

message WebSocketProxyConfig {
// See :ref:`stat_prefix <envoy_api_field_config.filter.network.tcp_proxy.v2.TcpProxy.stat_prefix>`.
// If the parameter is not specified, the default value of "websocket" is used.
// See :ref:`stat_prefix
// <envoy_api_field_config.filter.network.tcp_proxy.v2.TcpProxy.stat_prefix>`. If the parameter
// is not specified, the default value of "websocket" is used.
//
// WebSocket connections support the :ref:`downstream statistics
// <config_network_filters_tcp_proxy_stats>` for TCP proxy, except for the following, which are reported
// in the :ref:`HTTP Connection Manager statistics <config_http_conn_man_stats>`:
// <config_network_filters_tcp_proxy_stats>` for TCP proxy, except for the following, which are
// reported in the :ref:`HTTP Connection Manager statistics <config_http_conn_man_stats>`:
// - downstream_cx_tx_bytes_total
// - downstream_cx_tx_bytes_buffered
// - downstream_cx_rx_bytes_total
// - downstream_cx_rx_bytes_buffered
string stat_prefix = 1;

// See :ref:`idle_timeout <envoy_api_field_config.filter.network.tcp_proxy.v2.TcpProxy.idle_timeout>`.
// This timeout is only in effect after the WebSocket upgrade request is received by Envoy. It does
// not cover the initial part of the HTTP request.
// See :ref:`idle_timeout
// <envoy_api_field_config.filter.network.tcp_proxy.v2.TcpProxy.idle_timeout>`. This timeout is
// only in effect after the WebSocket upgrade request is received by Envoy. It does not cover
// the initial part of the HTTP request.
google.protobuf.Duration idle_timeout = 2
[(validate.rules).duration.gt = {}, (gogoproto.stdduration) = true];
[(validate.rules).duration.gt = {}, (gogoproto.stdduration) = true];

// See :ref:`max_connect_attempts
// <envoy_api_field_config.filter.network.tcp_proxy.v2.TcpProxy.max_connect_attempts>`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ message GrpcJsonTranscoder {
// A list of strings that
// supplies the fully qualified service names (i.e. "package_name.service_name") that
// the transcoder will translate. If the service name doesn't exist in ``proto_descriptor``,
// Envoy will fail at startup. The ``proto_descriptor`` may contain more services than
// Envoy will fail at startup. The ``proto_descriptor`` may contain more services than
// the service names specified here, but they won't be translated.
repeated string services = 2 [(validate.rules).repeated .min_items = 1];

Expand Down
28 changes: 15 additions & 13 deletions api/envoy/config/rbac/v2alpha/rbac.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import "envoy/type/string_match.proto";
package envoy.config.rbac.v2alpha;
option go_package = "v2alpha";

// Role Based Access Control (RBAC) provides service-level and method-level access control for a service.
// The RBAC engine authorizes a request by evaluating the request context (expressed in the form of
// :ref: `AttributeContext <envoy_api_msg_service.auth.v2alpha.AttributeContext>`) against the RBAC policies.
// Role Based Access Control (RBAC) provides service-level and method-level access control for a
// service. The RBAC engine authorizes a request by evaluating the request context (expressed in the
// form of :ref: `AttributeContext <envoy_api_msg_service.auth.v2alpha.AttributeContext>`) against
// the RBAC policies.
//
// RBAC policies are additive. The policies are examined in order. A request is allowed once a matching policy
// is found (suppose the `action` is ALLOW).
// RBAC policies are additive. The policies are examined in order. A request is allowed once a
// matching policy is found (suppose the `action` is ALLOW).
//
// Here is an example of RBAC configuration. It has two policies:
// * Service account "cluster.local/ns/default/sa/admin" has full access (empty permission entry means full access)
// to the service.
// * Any user (empty principal entry means any user) can read ("GET") the service at paths with prefix "/products" or
// suffix "/reviews" when request header "version" set to either "v1" or "v2".
// * Service account "cluster.local/ns/default/sa/admin" has full access (empty permission entry
// means full access) to the service.
// * Any user (empty principal entry means any user) can read ("GET") the service at paths with
// prefix "/products" or suffix "/reviews" when request header "version" set to either "v1" or
// "v2".
//
// action: ALLOW
// policies:
Expand Down Expand Up @@ -59,11 +61,11 @@ message RBAC {

// Policy specifies a role and the principals that are assigned/denied the role.
message Policy {
// Required. The set of permissions that define a role.
repeated Permission permissions = 1 [(validate.rules).repeated .min_items = 1];
// Required. The set of permissions that define a role.
repeated Permission permissions = 1 [(validate.rules).repeated .min_items = 1];

// Required. List of principals that are assigned/denied the role based on “action”.
repeated Principal principals = 2 [(validate.rules).repeated .min_items = 1];
// Required. List of principals that are assigned/denied the role based on “action”.
repeated Principal principals = 2 [(validate.rules).repeated .min_items = 1];
}

// Specifies how to match an entry in a map.
Expand Down
3 changes: 1 addition & 2 deletions api/envoy/type/string_match.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ message StringMatch {
// The regex grammar is defined `here
// <http://en.cppreference.com/w/cpp/regex/ecmascript>`_.
string regex = 4;
}
}
}

11 changes: 6 additions & 5 deletions source/common/ratelimit/ratelimit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package pb.lyft.ratelimit;

service RateLimitService {
// Determine whether rate limiting should take place.
rpc ShouldRateLimit (RateLimitRequest) returns (RateLimitResponse) {}
rpc ShouldRateLimit(RateLimitRequest) returns (RateLimitResponse) {
}
}

// Main message for a rate limit request. The rate limit service is designed to be fully generic
Expand Down Expand Up @@ -60,10 +61,10 @@ message RateLimitDescriptor {
message RateLimit {
enum Unit {
UNKNOWN = 0;
SECOND = 1;
MINUTE = 2;
HOUR = 3;
DAY = 4;
SECOND = 1;
MINUTE = 2;
HOUR = 3;
DAY = 4;
}

uint32 requests_per_unit = 1;
Expand Down
5 changes: 1 addition & 4 deletions test/proto/bookstore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ service Bookstore {
}
rpc BookstoreOptions(GetShelfRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
custom {
kind: "OPTIONS"
path: "/shelves/{shelf}"
}
custom {kind: "OPTIONS" path: "/shelves/{shelf}"}
};
}
// Returns a specific author.
Expand Down
3 changes: 2 additions & 1 deletion test/proto/helloworld.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHello(HelloRequest) returns (HelloReply) {
}
}

// The request message containing the user's name.
Expand Down
35 changes: 21 additions & 14 deletions tools/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
EXCLUDED_PREFIXES = ("./generated/", "./thirdparty/", "./build", "./.git/",
"./bazel-", "./bazel/external", "./.cache")
SUFFIXES = (".cc", ".h", "BUILD", ".md", ".rst", ".proto")
DOCS_SUFFIX = (".md", ".rst", ".proto")
DOCS_SUFFIX = (".md", ".rst")
PROTO_SUFFIX = (".proto")

# Files in these paths can make reference to protobuf stuff directly
GOOGLE_PROTOBUF_WHITELIST = ('ci/prebuilt', 'source/common/protobuf', 'api/test')
Expand Down Expand Up @@ -167,11 +168,13 @@ def checkFilePath(file_path):

if file_path.endswith(DOCS_SUFFIX):
return error_messages
error_messages += checkNamespace(file_path)
error_messages += checkProtobufExternalDeps(file_path)

command = ("%s %s | diff %s -" % (HEADER_ORDER_PATH, file_path, file_path))
error_messages += executeCommand(command, "header_order.py check failed", file_path)
if not file_path.endswith(PROTO_SUFFIX):
error_messages += checkNamespace(file_path)
error_messages += checkProtobufExternalDeps(file_path)

command = ("%s %s | diff %s -" % (HEADER_ORDER_PATH, file_path, file_path))
error_messages += executeCommand(command, "header_order.py check failed", file_path)

command = ("%s %s | diff %s -" % (CLANG_FORMAT_PATH, file_path, file_path))
error_messages += executeCommand(command, "clang-format check failed", file_path)
Expand Down Expand Up @@ -223,19 +226,23 @@ def fixFilePath(file_path):
return ["buildifier rewrite failed for file: %s" % file_path]
return []
fixFileContents(file_path)

if file_path.endswith(DOCS_SUFFIX):
return []

error_messages = checkNamespace(file_path)
if error_messages == []:
error_messages = checkProtobufExternalDepsBuild(file_path)
if error_messages == []:
error_messages = checkProtobufExternalDeps(file_path)
if error_messages:
return error_messages + ["This cannot be automatically corrected. Please fix by hand."]

error_messages = []
error_messages += fixHeaderOrder(file_path)
if not file_path.endswith(PROTO_SUFFIX):
error_messages = checkNamespace(file_path)
if error_messages == []:
error_messages = checkProtobufExternalDepsBuild(file_path)
if error_messages == []:
error_messages = checkProtobufExternalDeps(file_path)
if error_messages:
return error_messages + ["This cannot be automatically corrected. Please fix by hand."]

error_messages = []
error_messages += fixHeaderOrder(file_path)

error_messages += clangFormat(file_path)
return error_messages

Expand Down

0 comments on commit 033beaa

Please sign in to comment.