Skip to content

Commit 0dc7cfe

Browse files
author
Luke Sneeringer
committed
feat: AIP-214 – Resource expiration
1 parent 3055d2b commit 0dc7cfe

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

aip/general/0214/aip.md.j2

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Resource expiration
2+
3+
Customers often want to provide the time that a given resource or attribute of
4+
a resource is no longer useful or should be deleted. Currently we recommend
5+
that customers do this by specifying an exact "expiration time" into a
6+
`expire_time` field with a timestamp type; however, this adds additional strain
7+
on the user when they want to specify a relative time offset until expiration
8+
rather than a specific time until expiration.
9+
10+
Furthermore, the world understands the concept of a "time-to-live", often
11+
abbreviated to TTL, but the typical format of this field (an integer, measured
12+
in seconds) results in a sub-par experience when using an auto-generated client
13+
library.
14+
15+
## Guidance
16+
17+
Services wishing to convey an expiration **must** rely on a timestamp field
18+
called `expire_time`. Services wishing to allow a relative expiration time
19+
**must** define a `oneof` called `expiration` (or `{something}_expiration`)
20+
containing both the `expire_time` field and a separate [duration][aip-142]
21+
field called `ttl`, the latter marked as input only:
22+
23+
{% tab proto %}
24+
25+
{% sample 'expiry.proto', 'message Book' %}
26+
27+
{% tab oas %}
28+
29+
{% sample 'expiry.oas.yaml', 'schema' %}
30+
31+
{% endtabs %}
32+
33+
Services **must** always return the expiration time in the `expire_time` field
34+
and leave the `ttl` field blank when retrieving the resource.
35+
36+
Services that rely on the specific semantics of a "time to live" (e.g., DNS
37+
which must represent the TTL as an integer) **may** use an `int64 ttl` field
38+
(and **should** provide an [aip.dev/not-precedent][aip-200] comment in this
39+
case).

aip/general/0214/aip.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: 214
3+
state: approved
4+
created: 2018-06-19
5+
placement:
6+
category: design-patterns
7+
order: 120

aip/general/0214/expiry.oas.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: Library
5+
version: 1.0.0
6+
components:
7+
schema:
8+
Book:
9+
description: This book will self-destruct.
10+
properties:
11+
name:
12+
type: string
13+
description: |
14+
The name of the book.
15+
Format: publishers/{publisher}/books/{book}
16+
expire_time:
17+
type: string
18+
format: date-time
19+
description: |
20+
Timestamp in UTC of when this resource is considered expired.
21+
This is *always* provided on output, regardless of what was sent
22+
on input.
23+
ttl_seconds:
24+
type: integer
25+
description: The TTL for this resource.
26+
writeOnly: true

aip/general/0214/expiry.proto

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
import "google/api/field_behavior.proto";
18+
import "google/api/resource.proto";
19+
import "google/protobuf/duration.proto";
20+
import "google/protobuf/timestamp.proto";
21+
22+
// This book will self-destruct.
23+
message Book {
24+
option (google.api.resource) = {
25+
type: "library.googleapis.com/Book"
26+
pattern: "publishers/{publisher}/books/{book}"
27+
};
28+
29+
// The name of the resource; the format is: ...
30+
string name = 1;
31+
32+
oneof expiration {
33+
// Timestamp in UTC of when this resource is considered expired.
34+
// This is *always* provided on output, regardless of what was sent
35+
// on input.
36+
google.protobuf.Timestamp expire_time = 2;
37+
38+
// Input only. The TTL for this resource.
39+
google.protobuf.Duration ttl = 3
40+
[(google.api.field_behavior) = INPUT_ONLY];
41+
}
42+
}

0 commit comments

Comments
 (0)