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

feat: add owner group to workspace data#204

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
f0ssel merged 7 commits intomainfromf0ssel/owner-groups
Apr 2, 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.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@ resource "kubernetes_pod" "dev" {
- `name` (String) Name of the workspace.
- `owner` (String) Username of the workspace owner.
- `owner_email` (String) Email address of the workspace owner.
- `owner_groups` (List of String) List of groups the workspace owner belongs to.
- `owner_id` (String) UUID of the workspace owner.
- `owner_name` (String) Name of the workspace owner.
- `owner_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.
Expand Down
17 changes: 17 additions & 0 deletionsprovider/workspace.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package provider

import (
"context"
"encoding/json"
"os"
"reflect"
"strconv"
Expand DownExpand Up@@ -36,6 +37,14 @@ func workspaceDataSource() *schema.Resource {
ownerEmail := os.Getenv("CODER_WORKSPACE_OWNER_EMAIL")
_ = rd.Set("owner_email", ownerEmail)

ownerGroupsText := os.Getenv("CODER_WORKSPACE_OWNER_GROUPS")
var ownerGroups []string
err := json.Unmarshal([]byte(ownerGroupsText), &ownerGroups)
if err != nil {
return diag.Errorf("couldn't parse owner groups %q", ownerGroupsText)
}
Comment on lines +40 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This isn't guaranteed to be set :(

_ = rd.Set("owner_groups", ownerGroups)

ownerName := os.Getenv("CODER_WORKSPACE_OWNER_NAME")
_ = rd.Set("owner_name", ownerName)

Expand DownExpand Up@@ -141,6 +150,14 @@ func workspaceDataSource() *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.",
},
"owner_groups": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
Description: "List of groups the workspace owner belongs to.",
},
"id": {
Type: schema.TypeString,
Computed: true,
Expand Down
5 changes: 5 additions & 0 deletionsprovider/workspace_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ func TestWorkspace(t *testing.T) {
t.Setenv("CODER_WORKSPACE_OWNER_NAME", "Mr Owner")
t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "owner123@example.com")
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123")
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", `["group1", "group2"]`)
t.Setenv("CODER_WORKSPACE_TEMPLATE_ID", "templateID")
t.Setenv("CODER_WORKSPACE_TEMPLATE_NAME", "template123")
t.Setenv("CODER_WORKSPACE_TEMPLATE_VERSION", "v1.2.3")
Expand DownExpand Up@@ -47,6 +48,8 @@ func TestWorkspace(t *testing.T) {
require.Equal(t, "Mr Owner", attribs["owner_name"])
require.Equal(t, "owner123@example.com", attribs["owner_email"])
require.Equal(t, "abc123", attribs["owner_session_token"])
require.Equal(t, "group1", attribs["owner_groups.0"])
require.Equal(t, "group2", attribs["owner_groups.1"])
require.Equal(t, "templateID", attribs["template_id"])
require.Equal(t, "template123", attribs["template_name"])
require.Equal(t, "v1.2.3", attribs["template_version"])
Expand DownExpand Up@@ -80,6 +83,8 @@ func TestWorkspace(t *testing.T) {
require.Equal(t, "owner123", attribs["owner"])
require.Equal(t, "Mr Owner", attribs["owner_name"])
require.Equal(t, "owner123@example.com", attribs["owner_email"])
require.Equal(t, "group1", attribs["owner_groups.0"])
require.Equal(t, "group2", attribs["owner_groups.1"])
require.Equal(t, "templateID", attribs["template_id"])
require.Equal(t, "template123", attribs["template_name"])
require.Equal(t, "v1.2.3", attribs["template_version"])
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp