Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add login_type to coder_workspace_owner data source #235#287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 11 commits intocoder:mainfrompmareke:main
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsdocs/data-sources/workspace_owner.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,7 @@ resource "coder_env" "git_author_email" {
- `full_name` (String) The full name of the user.
- `groups` (List of String) The groups of which the user is a member.
- `id` (String) The UUID of the workspace owner.
- `login_type` (String) The type of login the user has.
- `name` (String) The username of the user.
- `oidc_access_token` (String) A valid OpenID Connect access token of the workspace owner. This is only available if the workspace owner authenticated with OpenID Connect. If a valid token cannot be obtained, this value will be an empty string.
- `session_token` (String) Session token for authenticating with a Coder deployment. It is regenerated every time a workspace is started.
Expand Down
1 change: 1 addition & 0 deletionsintegration/integration_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,6 +112,7 @@ func TestIntegration(t *testing.T) {
"workspace_owner.session_token": `.+`,
"workspace_owner.ssh_private_key": `(?s)^.+?BEGIN OPENSSH PRIVATE KEY.+?END OPENSSH PRIVATE KEY.+?$`,
"workspace_owner.ssh_public_key": `(?s)^ssh-ed25519.+$`,
"workspace_owner.login_type": ``,
},
},
{
Expand Down
1 change: 1 addition & 0 deletionsintegration/workspace-owner/main.tf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@ locals {
"workspace_owner.session_token" : data.coder_workspace_owner.me.session_token,
"workspace_owner.ssh_private_key" : data.coder_workspace_owner.me.ssh_private_key,
"workspace_owner.ssh_public_key" : data.coder_workspace_owner.me.ssh_public_key,
"workspace_owner.login_type" : data.coder_workspace_owner.me.login_type,
}
}

Expand Down
17 changes: 16 additions & 1 deletionprovider/workspace_owner.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,8 @@ func workspaceOwnerDataSource() *schema.Resource {
return &schema.Resource{
Description: "Use this data source to fetch information about the workspace owner.",
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
diags := diag.Diagnostics{}

if idStr := os.Getenv("CODER_WORKSPACE_OWNER_ID"); idStr != "" {
rd.SetId(idStr)
} else {
Expand DownExpand Up@@ -53,7 +55,15 @@ func workspaceOwnerDataSource() *schema.Resource {
_ = rd.Set("session_token", os.Getenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN"))
_ = rd.Set("oidc_access_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN"))

return nil
if os.Getenv("CODER_WORKSPACE_OWNER_LOGIN_TYPE") == "" {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "WARNING: The CODER_WORKSPACE_OWNER_LOGIN_TYPE env variable is not set",
})
}
_ = rd.Set("login_type", os.Getenv("CODER_WORKSPACE_OWNER_LOGIN_TYPE"))

return diags
},
Schema: map[string]*schema.Schema{
"id": {
Expand DownExpand Up@@ -107,6 +117,11 @@ func workspaceOwnerDataSource() *schema.Resource {
"This is only available if the workspace owner authenticated with OpenID Connect. " +
"If a valid token cannot be obtained, this value will be an empty string.",
},
"login_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of login the user has.",
},
},
}
}
5 changes: 5 additions & 0 deletionsprovider/workspace_owner_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", `["group1", "group2"]`)
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", `supersecret`)
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN", `alsosupersecret`)
t.Setenv("CODER_WORKSPACE_OWNER_LOGIN_TYPE", `github`)

resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
Expand DownExpand Up@@ -63,6 +64,8 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
assert.Equal(t, `group2`, attrs["groups.1"])
assert.Equal(t, `supersecret`, attrs["session_token"])
assert.Equal(t, `alsosupersecret`, attrs["oidc_access_token"])
assert.Equal(t, `github`, attrs["login_type"])

return nil
},
}},
Expand All@@ -80,6 +83,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
"CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN",
"CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY",
"CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY",
"CODER_WORKSPACE_OWNER_LOGIN_TYPE",
} { // https://github.com/golang/go/issues/52817
t.Setenv(v, "")
os.Unsetenv(v)
Expand DownExpand Up@@ -111,6 +115,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
assert.Empty(t, attrs["groups.0"])
assert.Empty(t, attrs["session_token"])
assert.Empty(t, attrs["oidc_access_token"])
assert.Empty(t, attrs["login_type"])
return nil
},
}},
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp