Skip to content

Commit 8dcb33e

Browse files
committed
keys: added expirySeconds, scopes & tags to the key response
Updates tailscale/terraform-provider-tailscale#515
1 parent d51fc60 commit 8dcb33e

File tree

2 files changed

+65
-43
lines changed

2 files changed

+65
-43
lines changed

keys.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ type createOAuthClientWithKeyTypeRequest struct {
4747

4848
// Key describes an authentication key within the tailnet.
4949
type Key struct {
50-
ID string `json:"id"`
51-
KeyType string `json:"keyType"`
52-
Key string `json:"key"`
53-
Description string `json:"description"`
54-
Created time.Time `json:"created"`
55-
Expires time.Time `json:"expires"`
56-
Revoked time.Time `json:"revoked"`
57-
Invalid bool `json:"invalid"`
58-
Capabilities KeyCapabilities `json:"capabilities"`
59-
UserID string `json:"userId"`
50+
ID string `json:"id"`
51+
KeyType string `json:"keyType"`
52+
Key string `json:"key"`
53+
Description string `json:"description"`
54+
ExpirySeconds *time.Duration `json:"expirySeconds"`
55+
Created time.Time `json:"created"`
56+
Expires time.Time `json:"expires"`
57+
Revoked time.Time `json:"revoked"`
58+
Invalid bool `json:"invalid"`
59+
Capabilities KeyCapabilities `json:"capabilities"`
60+
Scopes []string `json:"scopes,omitempty"`
61+
Tags []string `json:"tags,omitempty"`
62+
UserID string `json:"userId"`
6063
}
6164

6265
// Create creates a new authentication key. Returns the generated [Key] if successful.

keys_test.go

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ func TestClient_CreateAuthKey(t *testing.T) {
2525
capabilities.Devices.Create.Preauthorized = true
2626
capabilities.Devices.Create.Tags = []string{"test:test"}
2727

28+
expiry := 1440 * time.Second
29+
2830
expected := &Key{
29-
ID: "test",
30-
KeyType: "auth",
31-
Key: "thisisatestkey",
32-
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
33-
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
34-
Capabilities: capabilities,
35-
Description: "",
31+
ID: "test",
32+
KeyType: "auth",
33+
Key: "thisisatestkey",
34+
ExpirySeconds: &expiry,
35+
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
36+
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
37+
Capabilities: capabilities,
38+
Scopes: nil,
39+
Tags: nil,
40+
Description: "",
3641
}
3742

3843
server.ResponseBody = expected
@@ -64,14 +69,19 @@ func TestClient_CreateAuthKeyWithExpirySeconds(t *testing.T) {
6469
capabilities.Devices.Create.Preauthorized = true
6570
capabilities.Devices.Create.Tags = []string{"test:test"}
6671

72+
expiry := 1440 * time.Second
73+
6774
expected := &Key{
68-
ID: "test",
69-
KeyType: "auth",
70-
Key: "thisisatestkey",
71-
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
72-
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
73-
Capabilities: capabilities,
74-
Description: "",
75+
ID: "test",
76+
KeyType: "auth",
77+
Key: "thisisatestkey",
78+
ExpirySeconds: &expiry,
79+
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
80+
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
81+
Capabilities: capabilities,
82+
Scopes: nil,
83+
Tags: nil,
84+
Description: "",
7585
}
7686

7787
server.ResponseBody = expected
@@ -105,13 +115,16 @@ func TestClient_CreateAuthKeyWithDescription(t *testing.T) {
105115
capabilities.Devices.Create.Tags = []string{"test:test"}
106116

107117
expected := &Key{
108-
ID: "test",
109-
KeyType: "auth",
110-
Key: "thisisatestkey",
111-
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
112-
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
113-
Capabilities: capabilities,
114-
Description: "key description",
118+
ID: "test",
119+
KeyType: "auth",
120+
Key: "thisisatestkey",
121+
ExpirySeconds: nil,
122+
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
123+
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
124+
Capabilities: capabilities,
125+
Scopes: nil,
126+
Tags: nil,
127+
Description: "key description",
115128
}
116129

117130
server.ResponseBody = expected
@@ -139,12 +152,15 @@ func TestClient_CreateOAuthClient(t *testing.T) {
139152
server.ResponseCode = http.StatusOK
140153

141154
expected := &Key{
142-
ID: "test",
143-
KeyType: "client",
144-
Key: "thisisatestclient",
145-
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
146-
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
147-
Description: "",
155+
ID: "test",
156+
KeyType: "client",
157+
Key: "thisisatestclient",
158+
ExpirySeconds: nil,
159+
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
160+
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
161+
Scopes: []string{"all:read"},
162+
Tags: []string{"tag:test"},
163+
Description: "",
148164
}
149165

150166
server.ResponseBody = expected
@@ -181,12 +197,15 @@ func TestClient_GetKey(t *testing.T) {
181197
capabilities.Devices.Create.Tags = []string{"test:test"}
182198

183199
expected := &Key{
184-
ID: "test",
185-
KeyType: "auth",
186-
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
187-
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
188-
Capabilities: capabilities,
189-
Description: "",
200+
ID: "test",
201+
KeyType: "auth",
202+
ExpirySeconds: nil,
203+
Created: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
204+
Expires: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
205+
Capabilities: capabilities,
206+
Scopes: nil,
207+
Tags: nil,
208+
Description: "",
190209
}
191210

192211
server.ResponseBody = expected

0 commit comments

Comments
 (0)