Skip to content

Commit

Permalink
Run buf format
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Aug 1, 2024
1 parent c2ceaf7 commit 86e238e
Show file tree
Hide file tree
Showing 56 changed files with 134 additions and 134 deletions.
6 changes: 3 additions & 3 deletions examples/cel_assert_value_is_in_a_list.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ message IsDivisibleRequest {
int32 dividend = 1;
// divisor is the divisor in the division.
int32 divisor = 2 [(buf.validate.field).cel = {
id: "divisor_must_be_a_small_prime",
message: "the divisor must be one of 2, 3 and 5",
id: "divisor_must_be_a_small_prime"
message: "the divisor must be one of 2, 3 and 5"
// `in` evaluates list membership. The expression evaluates to
// true when the value is in the list.
// Validates that divisor must be one of 2, 3 and 5.
expression: "this in [2, 3, 5]",
expression: "this in [2, 3, 5]"
// Similarly, you can assert that it's not in a list with `!(this in [2, 3, 5])`.
}];
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_bytes_concatenation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import "buf/validate/validate.proto";

message CompactDocument {
option (buf.validate.message).cel = {
id: "header_footer_size_limit",
message: "header and footer should be less than 500 bytes in total",
id: "header_footer_size_limit"
message: "header and footer should be less than 500 bytes in total"
// the `+` operator concatenates two `bytes` together and `size` returns
// the length of a `bytes`.
// This validates that the combined size of header and footer should be < 500.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_bytes_contains.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import "buf/validate/validate.proto";
message Application {
// binary is the application's binary
bytes binary = 1 [(buf.validate.field).cel = {
id: "without_malicious_code",
message: "binary should not contain malicious code",
id: "without_malicious_code"
message: "binary should not contain malicious code"
// `contains` returns if the receiver `bytes` contains the argument `bytes`.
// This validates that the application binary should not contain bytes for
// `'malicious code'`.
Expand Down
2 changes: 1 addition & 1 deletion examples/cel_bytes_starts_with_ends_with.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "buf/validate/validate.proto";

message ScriptFile {
bytes content = 1 [(buf.validate.field).cel = {
id: "script_start_with_shabang_end_with_line_feed",
id: "script_start_with_shabang_end_with_line_feed"
expression:
// this is a ternary expression in the form of a ? b : c, if the the
// script file doesn't start with '#!', the expression evaluates to the
Expand Down
10 changes: 5 additions & 5 deletions examples/cel_conditional_operator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import "buf/validate/validate.proto";

message Triangle {
option (buf.validate.message).cel = {
id: "triangle.distinct_points",
id: "triangle.distinct_points"
// This is a nested ternary expression. If the expression evaluates to a non-empty
// string, validation will fail with that string as the error message.
// The expression below is a nested ternary expression.
expression:
"this.point_a == this.point_b ? 'point A and point B cannot be the same'"
": this.point_b == this.point_c ? 'point B and point C cannot be the same'"
": this.point_a == this.point_c ? 'point A and point C cannot be the same'"
": ''",
": ''"
};
option (buf.validate.message).cel = {
id: "triangle.non_linear_points",
message: "three points must not be on the same line",
id: "triangle.non_linear_points"
message: "three points must not be on the same line"
expression:
"(this.point_a.y - this.point_b.y) * (this.point_a.x - this.point_c.x)"
"!= (this.point_a.y - this.point_c.y) * (this.point_a.x - this.point_b.x)";
"!= (this.point_a.y - this.point_c.y) * (this.point_a.x - this.point_b.x)"
};
Point point_a = 1;
Point point_b = 2;
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_duration_arithmetic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import "google/protobuf/duration.proto";

message IndirectFlight {
option (buf.validate.message).cel = {
id: "total_length_limit",
message: "the entire trip should be less than 48 hours",
id: "total_length_limit"
message: "the entire trip should be less than 48 hours"
expression:
// This validates that the total duration of an indirect flight should be
// less than 48 hours.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_duration_from_string.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ service TimerService {

message StartTimerRequest {
google.protobuf.Duration duration = 1 [(buf.validate.field).cel = {
id: "maximum_duration",
message: "timer duration must be shorter than a day",
id: "maximum_duration"
message: "timer duration must be shorter than a day"
// You can create a duration from a string literal in the form of `1m30s`,
// where each number is has a unit suffix. The suffix supported are "h", "m",
// "s", "ms", "us" and "ns".
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_enum_comparison.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ service FileService {
message UploadFileRequest {
bytes content = 1;
CompressionScheme compression_scheme = 2 [(buf.validate.field).cel = {
id: "compression_specified",
message: "compression scheme must be specified",
id: "compression_specified"
message: "compression scheme must be specified"
// Validate that compression_scheme is specified.
// Note that `this`, as a enum, can be directly compared with an int.
// In this case, 0 is the variant COMPRESSION_SCHEME_UNSPECIFIED from the
Expand Down
6 changes: 3 additions & 3 deletions examples/cel_field_access.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ message PlaceWholeSaleOrderRequest {
uint64 item_id = 1;
// quantity is the quantity of the item to purchase.
uint32 quantity = 2 [(buf.validate.field).cel = {
id: "minimum_whole_sale_quantity",
message: "order quantity must be 100 or greater",
id: "minimum_whole_sale_quantity"
message: "order quantity must be 100 or greater"
// `this` refers to this field and the expression evaluates to a boolean result.
// If the result is false, validation will fail with the above error message.
expression: "this >= 100",
expression: "this >= 100"
}];
}

Expand Down
22 changes: 11 additions & 11 deletions examples/cel_field_map.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ message IPAddressMapping {
keys: {
cel: [
{
id: "ip_prefix",
message: "key must be IPv4 prefix",
expression: "this.isIpPrefix(4, true)",
id: "ip_prefix"
message: "key must be IPv4 prefix"
expression: "this.isIpPrefix(4, true)"
}
],
},
]
}
values: {
cel: [
{
id: "ip_address",
message: "value must be IPv4 address",
expression: "this.isIpPrefix(4, true)",
id: "ip_address"
message: "value must be IPv4 address"
expression: "this.isIpPrefix(4, true)"
}
],
},
]
}
}];
};
}
6 changes: 3 additions & 3 deletions examples/cel_field_mask.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ message UpdateSongRequest {
Song song = 1;
// field_mask masks the fields to update.
google.protobuf.FieldMask field_mask = 2 [(buf.validate.field).cel = {
id: "valid_field_mask",
message: "a field mask path must be one of name, duration and artist.name",
id: "valid_field_mask"
message: "a field mask path must be one of name, duration and artist.name"
// `some_list.all()` validates that a predicate is true for all elements
// from that list.
// In this case, `this.paths` is the field paths from.
expression: "this.paths.all(path, path in ['name', 'duration', 'artist.name'])",
expression: "this.paths.all(path, path in ['name', 'duration', 'artist.name'])"
}];
}

Expand Down
2 changes: 1 addition & 1 deletion examples/cel_field_presence.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ service AddressService {
message UpdateAddressInfoRequest {
// If a secondary residence is set, the primary one must also be set.
option (buf.validate.message).cel = {
id: "secondary_residence_depends_on_primary",
id: "secondary_residence_depends_on_primary"
// `has(this.field)` evaluates to true if a field is present.
expression:
"has(this.new_secondary_residence) && !has(this.new_primary_residence)"
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_field_presence_nested.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ service ContactService {

message CreateContactRequest {
option (buf.validate.message).cel = {
id: "create_contact_with_first_name",
message: "the contact must have first name",
id: "create_contact_with_first_name"
message: "the contact must have first name"
// This expression validates that all of `this.contact`, `this.contact.full_name`
// and `this.contact.full_name.first_name` are set.
expression: "has(this.contact.full_name.first_name)"
Expand Down
12 changes: 6 additions & 6 deletions examples/cel_field_repeated.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import "buf/validate/validate.proto";

message IPAllowlist {
repeated string allow_cidr = 1 [(buf.validate.field).repeated = {
min_items: 1,
min_items: 1
items: {
cel: [
{
id: "ip_prefix",
message: "value must be IPv4 prefix",
expression: "this.isIpPrefix(4, true)",
id: "ip_prefix"
message: "value must be IPv4 prefix"
expression: "this.isIpPrefix(4, true)"
}
],
},
]
}
}];
}
4 changes: 2 additions & 2 deletions examples/cel_field_selection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ service ApartmentService {

message SearchApartmentRequest {
option (buf.validate.message).cel = {
id: "secondary_address_after_primary_address",
message: "the minimum number of bedrooms cannot be higher than the maximum number",
id: "secondary_address_after_primary_address"
message: "the minimum number of bedrooms cannot be higher than the maximum number"
// In a message-level constraint, `this` refers to the message itself, the `SearchApartmentRequest`.
// You can access a field with `this.field_name`.
// The following expression is broken down into three string literals.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_infinity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ service BalanceService {

message SetBalanceRequest {
double new_balance = 1 [(buf.validate.field).cel = {
id: "finite_balance",
message: "balance should be finite",
id: "finite_balance"
message: "balance should be finite"
// `isInf()` works on float and double, and returns true if the value is
// infinity.
// This validates that the new balance is finite.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_list_concatenation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ message BeverageMenu {
string daily_special = 3;

option (buf.validate.message).cel = {
id: "daily_special_either_hot_or_cold",
message: "the daily special must be in either the hot menu or the cold menu",
id: "daily_special_either_hot_or_cold"
message: "the daily special must be in either the hot menu or the cold menu"
// The `+` is loaded for lists (repeated fields) and it concatenates two lists.
// In this case `this.hot_beverages` + `this.cold_beverages` evaluates to a list
// containing beverages from both lists.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_map_all.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ message ShoppingCart {
// product_id_to_quantity maps from a product id to its quantity in the shopping cart
map<uint64, uint32> product_id_to_quantity = 1;
option (buf.validate.message).cel = {
id: "quantity_positive",
message: "each product in the shopping cart must have positive quantity",
id: "quantity_positive"
message: "each product in the shopping cart must have positive quantity"
// `all` checks whether a predicate holds true for all keys in a map. In this
// case, each key of the map binds to a `pid` and the predicate is evaluated.
// `this[pid]` looks up this product id in the map and evaluates to its amount.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_map_exists.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ message CustomerReviews {
// This validates that there is at least one review from customer_id_to_review
// such that its rating is the same as highest_rating.
option (buf.validate.message).cel = {
id: "highest_rating_exists",
message: "highest_rating must be the highest from reviews",
id: "highest_rating_exists"
message: "highest_rating must be the highest from reviews"
expression:
// `some_map.exists` validates that a predicate (condition) is true for some
// key in this map. To validate that a predicate is true for some _value_ in
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_map_exists_one.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ message TeamRoles {
// name_to_role maps from a team member's name to role.
map<string, TeamRole> name_to_role = 1;
option (buf.validate.message).cel = {
id: "exactly_one_captain",
message: "there must be exactly one captain",
id: "exactly_one_captain"
message: "there must be exactly one captain"
// `exists_one` validates that exactly one key in the map satisfies the predicate.
// In this case, it validates that exactly one player in the team has the
// captain role.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_map_size.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ message PenInventory {
// color_to_count maps from a color id to the amount of pens of the color.
map<uint32, uint32> color_to_count = 1;
option (buf.validate.message).cel = {
id: "at_most_30_colors",
message: "there must not be more than 30 colors",
id: "at_most_30_colors"
message: "there must not be more than 30 colors"
// `size(some_map)` returns the number of keys in this map.
// In this case, it validates that the map has at most 30 keys.
expression: "size(this.color_to_count) <= 30"
Expand Down
6 changes: 3 additions & 3 deletions examples/cel_number_arithmetic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import "buf/validate/validate.proto";

message FiveDigitPrimeLookalike {
int32 value = 1 [(buf.validate.field).cel = {
id: "prime_lookalike",
message: "value must have 5 digits and look like a prime",
id: "prime_lookalike"
message: "value must have 5 digits and look like a prime"
// Arithmetic operators include `+`, `-`, `*`, `/`, `%`.
expression:
"this % 2 != 0"
"&& this % 3 != 0"
"&& this % 5 != 0"
"&& (this - 10000) * (this - 99999) <= 0"
"&& -this != 77777",
"&& -this != 77777"
}];
}
4 changes: 2 additions & 2 deletions examples/cel_repeated_field_all.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ message CreateGroupChatRequest {
// Note: to treat a repeated field as a list in cel, access it from the message
// option as opposed to the field option.
option (buf.validate.message).cel = {
id: "group_chat_member_must_be_verified",
message: "all group chat members must be verified users",
id: "group_chat_member_must_be_verified"
message: "all group chat members must be verified users"
// `m.is_verified` must be true for all `m` in `this.member`
expression: "this.member.all(m, m.is_verified)"
};
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_repeated_field_exists_one.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import "buf/validate/validate.proto";
message TeamRoster {
// one and only one players on the team is the captain.
option (buf.validate.message).cel = {
id: "captain_exists",
message: "captain must be among the list of players",
id: "captain_exists"
message: "captain must be among the list of players"
// `exists_one` checks that one and only one item in the list satisfies
// the predicate, which is `p.name == this.captain_name` in this case.
expression: "this.players.exists_one(p, p.name == this.captain_name)"
Expand Down
8 changes: 4 additions & 4 deletions examples/cel_repeated_field_filter_and_count.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import "buf/validate/validate.proto";
// FiveTruthsThreeLies is a new game based on the classic Two Truths One Lie.
message FiveTruthsThreeLies {
option (buf.validate.message).cel = {
id: "exactly_three_lies",
message: "there must be exactly three lies",
id: "exactly_three_lies"
message: "there must be exactly three lies"
// `this.statement.filter` evaluates to a new list, whose elements are those
// from the original one that satisfies the predicate. In this case, the filter
// evaluates to the list of statements that are true.
Expand All @@ -29,8 +29,8 @@ message FiveTruthsThreeLies {
expression: "size(this.statement.filter(s, !s.is_truth)) == 3"
};
option (buf.validate.message).cel = {
id: "exactly_five_truths",
message: "there must be exactly five truths",
id: "exactly_five_truths"
message: "there must be exactly five truths"
// Similarly, validate that exactly five truths
expression: "size(this.statement.filter(s, s.is_truth)) == 5"
};
Expand Down
2 changes: 1 addition & 1 deletion examples/cel_string_concatenation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ service NewsLetterService {

message JoinNewsLetterRequest {
string email = 1 [(buf.validate.field).cel = {
id: "join_news_letter_request_valid_email",
id: "join_news_letter_request_valid_email"
expression:
"this.isEmail() ? ''"
// The `+` operator is overloaded for strings and concatenates two strings.
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_string_contains.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ service ArticleService {

message PublishArticleRequest {
option (buf.validate.message).cel = {
id: "article_contain_keyword",
message: "article must contain all the keywords it is tagged with",
id: "article_contain_keyword"
message: "article must contain all the keywords it is tagged with"
// For each keyword `kw`, validate that it appears in the article.
// `contains` checks whether a string contains another string.
expression: "this.keyword.all(kw, this.article_content.contains(kw))"
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_string_is_email.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ service MailingListService {

message AddEmailToMailingListRequest {
string email = 1 [(buf.validate.field).cel = {
id: "valid_email",
message: "email must be a valid email",
id: "valid_email"
message: "email must be a valid email"
expression: "this.isEmail()"
}];
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cel_string_is_hostname.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import "buf/validate/validate.proto";
message DeviceInfo {
// hostname is the device's hostname on the network.
string hostname = 1 [(buf.validate.field).cel = {
id: "device_info_valid_hostname",
message: "hostname must be valid",
id: "device_info_valid_hostname"
message: "hostname must be valid"
// this validates that field `hostname` is a valid hostname.
expression: "this.isHostname()"
}];
Expand Down
Loading

0 comments on commit 86e238e

Please sign in to comment.