Skip to content

Commit 8147494

Browse files
committed
feat: add owner_oidc_refresh_token to coder_workspace_owner data source
Signed-off-by: ffais <[email protected]>
1 parent 1d525fa commit 8147494

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

provider/workspace_owner.go

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func workspaceOwnerDataSource() *schema.Resource {
5252

5353
_ = rd.Set("session_token", os.Getenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN"))
5454
_ = rd.Set("oidc_access_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN"))
55+
_ = rd.Set("oidc_refresh_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN"))
5556

5657
return nil
5758
},
@@ -107,6 +108,13 @@ func workspaceOwnerDataSource() *schema.Resource {
107108
"This is only available if the workspace owner authenticated with OpenID Connect. " +
108109
"If a valid token cannot be obtained, this value will be an empty string.",
109110
},
111+
"oidc_refresh_token": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
Description: "A valid OpenID Connect refresh token of the workspace owner. Can be used to refresh access token if expired " +
115+
"This is only available if the workspace owner authenticated with OpenID Connect. " +
116+
"If a valid refresh token cannot be obtained, this value will be an empty string.",
117+
},
110118
},
111119
}
112120
}

provider/workspace_owner_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
3535
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", `["group1", "group2"]`)
3636
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", `supersecret`)
3737
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN", `alsosupersecret`)
38+
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN", `alsosupersecretrefresh`)
3839

3940
resource.Test(t, resource.TestCase{
4041
Providers: map[string]*schema.Provider{
@@ -63,6 +64,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
6364
assert.Equal(t, `group2`, attrs["groups.1"])
6465
assert.Equal(t, `supersecret`, attrs["session_token"])
6566
assert.Equal(t, `alsosupersecret`, attrs["oidc_access_token"])
67+
assert.Equal(t, `alsosupersecretrefresh`, attrs["oidc_refresh_token"])
6668
return nil
6769
},
6870
}},
@@ -80,6 +82,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
8082
"CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN",
8183
"CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY",
8284
"CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY",
85+
"CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN",
8386
} { // https://github.com/golang/go/issues/52817
8487
t.Setenv(v, "")
8588
os.Unsetenv(v)
@@ -111,6 +114,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
111114
assert.Empty(t, attrs["groups.0"])
112115
assert.Empty(t, attrs["session_token"])
113116
assert.Empty(t, attrs["oidc_access_token"])
117+
assert.Empty(t, attrs["oidc_refresh_token"])
114118
return nil
115119
},
116120
}},

0 commit comments

Comments
 (0)