Skip to content

Commit

Permalink
feat(AIP-142): adding purge_time field (#1198)
Browse files Browse the repository at this point in the history
Updating checking for purge_time to align with
aip-dev/google.aip.dev#1169.

Continued to ignore expire_time for soft-deleted resources
for backwards-compatibility.
  • Loading branch information
toumorokoshi authored Jul 14, 2023
1 parent 40d1bc5 commit 183ff95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions rules/aip0142/time_field_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var fieldNames = &lint.FieldRule{
"expired": "expire_time",
"modified": "update_time",
"updated": "update_time",
"purged": "purged_time",
}
for got, want := range mistakes {
if strings.Contains(f.GetName(), got) {
Expand Down
7 changes: 6 additions & 1 deletion rules/aip0164/resource_expire_time_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ var resourceExpireTimeField = &lint.MessageRule{
return utils.FindMethod(m.GetFile(), "Undelete"+resource) != nil
},
LintMessage: func(m *desc.MessageDescriptor) []lint.Problem {
// for backwards compatibility, do not lint on expire_time.
// previously expire_time was the recommended term.
if m.FindFieldByName("expire_time") != nil {
return nil
}
if m.FindFieldByName("purge_time") != nil {
return nil
}
return []lint.Problem{{
Message: "Resources supporting soft delete must have a `google.protobuf.Timestamp expire_time` field.",
Message: "Resources supporting soft delete must have a `google.protobuf.Timestamp purge_time` field.",
Descriptor: m,
}}
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aip0164/resource_expire_time_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func TestResourceExpireTimeField(t *testing.T) {
ResourceField string
problems testutils.Problems
}{
{"Valid", `UndeleteBook`, `google.protobuf.Timestamp expire_time = 1;`, nil},
{"Valid", `UndeleteBook`, `google.protobuf.Timestamp purge_time = 1;`, nil},
{"Valid", `UndeleteBookLegacyExpireTime`, `google.protobuf.Timestamp expire_time = 1;`, nil},
{"Invalid", `UndeleteBook`, ``, testutils.Problems{{Message: "Resources supporting soft delete"}}},
{"IrrelevantNoSoftDelete", `GetBook`, ``, nil},
} {
Expand Down

0 comments on commit 183ff95

Please sign in to comment.