From c446d26f319a029e2334e93150a425ac3698311f Mon Sep 17 00:00:00 2001 From: Christian Schroer <1319445+cschroer@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:57:19 +0100 Subject: [PATCH] feat(client): add user and workspace user group clients, with list commands MeshWorkspaceUserGroupClient covers create, read, update, delete and list of meshWorkspaceUserGroup v1, addressed by workspace.group. MeshUserClient reads a meshUser v2 by username and lists users by uuid, username, email, euid, workspace, workspace role or project. Both are new fields of client.Client, so the Terraform provider's mocks keep compiling, and client.New registers both with Raw. The group listing documents no sort parameter, so it keeps meshStack's own order. meshstack user list lists the users with a role in the workspace, and meshstack workspaceusergroup list (alias wug) the groups the workspace owns. meshStack answers 400 to a group listing that filters by workspace and username at once, so --username lists the user's groups in every workspace the credential can access. The workspaceUserGroupIdentifier filter of the user listing is left out: the API docs do not say whether it takes the group name or workspace.group. Co-Authored-By: Claude Opus 5.5 --- client/client.go | 8 ++ client/client_kind.go | 4 + client/client_kind_test.go | 2 + client/user.go | 67 ++++++++++++++++ client/workspace_user_group.go | 81 ++++++++++++++++++++ cmd/internal/kind.go | 1 + cmd/meshstack/meshstack.go | 4 + cmd/user/list.go | 44 +++++++++++ cmd/user/user.go | 26 +++++++ cmd/workspaceusergroup/list.go | 47 ++++++++++++ cmd/workspaceusergroup/workspaceusergroup.go | 26 +++++++ skills/meshstack-cli/SKILL.md | 2 + 12 files changed, 312 insertions(+) create mode 100644 client/user.go create mode 100644 client/workspace_user_group.go create mode 100644 cmd/user/list.go create mode 100644 cmd/user/user.go create mode 100644 cmd/workspaceusergroup/list.go create mode 100644 cmd/workspaceusergroup/workspaceusergroup.go diff --git a/client/client.go b/client/client.go index 413ac16c..85eb785b 100644 --- a/client/client.go +++ b/client/client.go @@ -40,9 +40,11 @@ type Client struct { ServiceInstance MeshServiceInstanceClient TagDefinition MeshTagDefinitionClient Tenant MeshTenantClient + User MeshUserClient Workspace MeshWorkspaceClient WorkspaceGroupBinding MeshWorkspaceGroupBindingClient WorkspaceUserBinding MeshWorkspaceUserBindingClient + WorkspaceUserGroup MeshWorkspaceUserGroupClient Raw *RawClient // Endpoint is read by the Terraform provider's meshstack_instance data source. @@ -59,6 +61,8 @@ func New(ctx context.Context, endpoint xurl.URL, client http.Client, auth Author buildingBlockDefinitionVersion := newBuildingBlockDefinitionVersionClient(ctx, authorizedClient) buildingBlockRun := newBuildingBlockRunClient(ctx, authorizedClient) workspace := newWorkspaceClient(ctx, authorizedClient) + user := newUserClient(ctx, authorizedClient) + workspaceUserGroup := newWorkspaceUserGroupClient(ctx, authorizedClient) return Client{ ApiKey: newApiKeyClient(ctx, authorizedClient), BuildingBlockV2: buildingBlockV2, @@ -80,15 +84,19 @@ func New(ctx context.Context, endpoint xurl.URL, client http.Client, auth Author ServiceInstance: newServiceInstanceClient(ctx, authorizedClient), TagDefinition: newTagDefinitionClient(ctx, authorizedClient), Tenant: newTenantClient(ctx, authorizedClient), + User: user, Workspace: workspace, WorkspaceGroupBinding: newWorkspaceGroupBindingClient(ctx, authorizedClient), WorkspaceUserBinding: newWorkspaceUserBindingClient(ctx, authorizedClient), + WorkspaceUserGroup: workspaceUserGroup, Raw: newRawClient(authorizedClient). with(workspace.meshObject). with(buildingBlockV2.meshObject). with(buildingBlockRun.meshObject). with(buildingBlockDefinition.meshObject). withOwnOrder(buildingBlockDefinitionVersion.meshObject). + with(user.meshObject). + withOwnOrder(workspaceUserGroup.meshObject). with(newEventLogMeshObject(ctx, authorizedClient)), Endpoint: endpoint, diff --git a/client/client_kind.go b/client/client_kind.go index 608933c0..bf5236b8 100644 --- a/client/client_kind.go +++ b/client/client_kind.go @@ -21,9 +21,11 @@ type meshObjectKind struct { ServiceInstance string TagDefinition string Tenant string + User string Workspace string WorkspaceGroupBinding string WorkspaceUserBinding string + WorkspaceUserGroup string } var MeshObjectKind = meshObjectKind{ @@ -47,7 +49,9 @@ var MeshObjectKind = meshObjectKind{ ServiceInstance: "meshServiceInstance", TagDefinition: "meshTagDefinition", Tenant: "meshTenant", + User: "meshUser", Workspace: "meshWorkspace", WorkspaceGroupBinding: "meshWorkspaceGroupBinding", WorkspaceUserBinding: "meshWorkspaceUserBinding", + WorkspaceUserGroup: "meshWorkspaceUserGroup", } diff --git a/client/client_kind_test.go b/client/client_kind_test.go index 7d43cf6f..ef1ea4db 100644 --- a/client/client_kind_test.go +++ b/client/client_kind_test.go @@ -26,7 +26,9 @@ func TestKind(t *testing.T) { assert.Equal(t, internal.InferKind[MeshServiceInstance](), MeshObjectKind.ServiceInstance) assert.Equal(t, internal.InferKind[MeshTagDefinition](), MeshObjectKind.TagDefinition) assert.Equal(t, internal.InferKind[MeshTenant](), MeshObjectKind.Tenant) + assert.Equal(t, internal.InferKind[MeshUser](), MeshObjectKind.User) assert.Equal(t, internal.InferKind[MeshWorkspace](), MeshObjectKind.Workspace) assert.Equal(t, internal.InferKind[MeshWorkspaceGroupBinding](), MeshObjectKind.WorkspaceGroupBinding) assert.Equal(t, internal.InferKind[MeshWorkspaceUserBinding](), MeshObjectKind.WorkspaceUserBinding) + assert.Equal(t, internal.InferKind[MeshWorkspaceUserGroup](), MeshObjectKind.WorkspaceUserGroup) } diff --git a/client/user.go b/client/user.go new file mode 100644 index 00000000..14c95684 --- /dev/null +++ b/client/user.go @@ -0,0 +1,67 @@ +package client + +import ( + "context" + + "github.com/meshcloud/meshstack-cli/client/internal" + "github.com/meshcloud/meshstack-cli/internal/http" +) + +type MeshUser struct { + Metadata MeshUserMetadata `json:"metadata" tfsdk:"metadata"` + Spec MeshUserSpec `json:"spec" tfsdk:"spec"` + Status MeshUserStatus `json:"status" tfsdk:"status"` +} + +type MeshUserMetadata struct { + Name string `json:"name" tfsdk:"name"` + Uuid string `json:"uuid" tfsdk:"uuid"` +} + +type MeshUserSpec struct { + Email string `json:"email" tfsdk:"email"` + FirstName string `json:"firstName" tfsdk:"first_name"` + LastName string `json:"lastName" tfsdk:"last_name"` + Euid *string `json:"euid,omitzero" tfsdk:"euid"` + Tags map[string][]string `json:"tags" tfsdk:"tags"` +} + +type MeshUserStatus struct { + Lifecycle MeshUserLifecycle `json:"lifecycle" tfsdk:"lifecycle"` + LastLogin *string `json:"lastLogin,omitzero" tfsdk:"last_login"` +} + +type MeshUserLifecycle struct { + State string `json:"state" tfsdk:"state"` +} + +type MeshUserListFilter struct { + Uuid string `json:"uuid"` + Username string `json:"username"` + Email string `json:"email"` + Euid string `json:"euid"` + WorkspaceIdentifier string `json:"workspaceIdentifier"` + WorkspaceRole string `json:"workspaceRole"` + ProjectIdentifier string `json:"projectIdentifier"` +} + +type MeshUserClient interface { + List(ctx context.Context, filter MeshUserListFilter) ([]MeshUser, error) + Read(ctx context.Context, username string) (*MeshUser, error) +} + +type meshUserClient struct { + meshObject internal.MeshObjectClient[MeshUser] +} + +func newUserClient(ctx context.Context, httpClient internal.HttpClient) meshUserClient { + return meshUserClient{internal.NewMeshObjectClient[MeshUser](ctx, httpClient, "v2")} +} + +func (c meshUserClient) List(ctx context.Context, filter MeshUserListFilter) ([]MeshUser, error) { + return c.meshObject.List(ctx, http.WithUrlQuery(filter)) +} + +func (c meshUserClient) Read(ctx context.Context, username string) (*MeshUser, error) { + return c.meshObject.Get(ctx, username) +} diff --git a/client/workspace_user_group.go b/client/workspace_user_group.go new file mode 100644 index 00000000..cc9fa35d --- /dev/null +++ b/client/workspace_user_group.go @@ -0,0 +1,81 @@ +package client + +import ( + "context" + + "github.com/meshcloud/meshstack-cli/client/internal" + "github.com/meshcloud/meshstack-cli/internal/http" +) + +type MeshWorkspaceUserGroup struct { + Metadata MeshWorkspaceUserGroupMetadata `json:"metadata" tfsdk:"metadata"` + Spec MeshWorkspaceUserGroupSpec `json:"spec" tfsdk:"spec"` + Status *MeshWorkspaceUserGroupStatus `json:"status,omitzero" tfsdk:"status"` +} + +type MeshWorkspaceUserGroupMetadata struct { + Name string `json:"name" tfsdk:"name"` + OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"` + SourceSystem *string `json:"sourceSystem,omitzero" tfsdk:"source_system"` +} + +func (m MeshWorkspaceUserGroupMetadata) Identifier() string { + return MeshWorkspaceUserGroupIdentifier(m.OwnedByWorkspace, m.Name) +} + +func MeshWorkspaceUserGroupIdentifier(ownedByWorkspace, name string) string { + return ownedByWorkspace + "." + name +} + +type MeshWorkspaceUserGroupSpec struct { + DisplayName string `json:"displayName" tfsdk:"display_name"` + Egid *string `json:"egid,omitzero" tfsdk:"egid"` + Members []string `json:"members" tfsdk:"members"` + Tags map[string][]string `json:"tags" tfsdk:"tags"` +} + +type MeshWorkspaceUserGroupStatus struct { + DisabledUsernames []string `json:"disabledUsernames" tfsdk:"disabled_usernames"` +} + +type MeshWorkspaceUserGroupListFilter struct { + WorkspaceIdentifier string `json:"workspaceIdentifier"` + Username string `json:"username"` + SourceSystem string `json:"sourceSystem"` +} + +type MeshWorkspaceUserGroupClient interface { + List(ctx context.Context, filter MeshWorkspaceUserGroupListFilter) ([]MeshWorkspaceUserGroup, error) + Read(ctx context.Context, ownedByWorkspace, name string) (*MeshWorkspaceUserGroup, error) + Create(ctx context.Context, group *MeshWorkspaceUserGroup) (*MeshWorkspaceUserGroup, error) + Update(ctx context.Context, group *MeshWorkspaceUserGroup) (*MeshWorkspaceUserGroup, error) + Delete(ctx context.Context, ownedByWorkspace, name string) error +} + +type meshWorkspaceUserGroupClient struct { + meshObject internal.MeshObjectClient[MeshWorkspaceUserGroup] +} + +func newWorkspaceUserGroupClient(ctx context.Context, httpClient internal.HttpClient) meshWorkspaceUserGroupClient { + return meshWorkspaceUserGroupClient{internal.NewMeshObjectClient[MeshWorkspaceUserGroup](ctx, httpClient, "v1")} +} + +func (c meshWorkspaceUserGroupClient) List(ctx context.Context, filter MeshWorkspaceUserGroupListFilter) ([]MeshWorkspaceUserGroup, error) { + return c.meshObject.List(ctx, http.WithUrlQuery(filter)) +} + +func (c meshWorkspaceUserGroupClient) Read(ctx context.Context, ownedByWorkspace, name string) (*MeshWorkspaceUserGroup, error) { + return c.meshObject.Get(ctx, MeshWorkspaceUserGroupIdentifier(ownedByWorkspace, name)) +} + +func (c meshWorkspaceUserGroupClient) Create(ctx context.Context, group *MeshWorkspaceUserGroup) (*MeshWorkspaceUserGroup, error) { + return c.meshObject.Post(ctx, group) +} + +func (c meshWorkspaceUserGroupClient) Update(ctx context.Context, group *MeshWorkspaceUserGroup) (*MeshWorkspaceUserGroup, error) { + return c.meshObject.Put(ctx, group.Metadata.Identifier(), group) +} + +func (c meshWorkspaceUserGroupClient) Delete(ctx context.Context, ownedByWorkspace, name string) error { + return c.meshObject.Delete(ctx, MeshWorkspaceUserGroupIdentifier(ownedByWorkspace, name)) +} diff --git a/cmd/internal/kind.go b/cmd/internal/kind.go index 7feb88ef..97bb7636 100644 --- a/cmd/internal/kind.go +++ b/cmd/internal/kind.go @@ -16,6 +16,7 @@ var kindAliases = map[KindCommand][]string{ "buildingblockrun": {"bbrun"}, "eventlog": {"elog"}, "workspace": {"ws"}, + "workspaceusergroup": {"wug"}, } type KindCommand string diff --git a/cmd/meshstack/meshstack.go b/cmd/meshstack/meshstack.go index 5c1b2759..4f971167 100644 --- a/cmd/meshstack/meshstack.go +++ b/cmd/meshstack/meshstack.go @@ -22,7 +22,9 @@ import ( "github.com/meshcloud/meshstack-cli/cmd/internal" "github.com/meshcloud/meshstack-cli/cmd/internal/color" "github.com/meshcloud/meshstack-cli/cmd/profile" + "github.com/meshcloud/meshstack-cli/cmd/user" "github.com/meshcloud/meshstack-cli/cmd/workspace" + "github.com/meshcloud/meshstack-cli/cmd/workspaceusergroup" "github.com/meshcloud/meshstack-cli/pkg/io" ) @@ -93,7 +95,9 @@ The command honors NO_COLOR and FORCE_COLOR, and prints no colors into a pipe.`, cmd.AddCommand(buildingblockrun.New()) cmd.AddCommand(eventlog.New()) cmd.AddCommand(profile.New()) + cmd.AddCommand(user.New()) cmd.AddCommand(workspace.New()) + cmd.AddCommand(workspaceusergroup.New()) internal.WrapHelpToTerminal(cmd) showUsageOnMisuse(cmd) diff --git a/cmd/user/list.go b/cmd/user/list.go new file mode 100644 index 00000000..e7e42156 --- /dev/null +++ b/cmd/user/list.go @@ -0,0 +1,44 @@ +package user + +import ( + "github.com/spf13/cobra" + + "github.com/meshcloud/meshstack-cli/client" + "github.com/meshcloud/meshstack-cli/cmd/internal" +) + +func newList() *cobra.Command { + var ( + flags internal.ListFlags + filter client.MeshUserListFilter + ) + + cmd := &cobra.Command{ + Use: "list", + Short: "List the users of the workspace, newest first", + Long: `List the users who have a role in the workspace, directly or through a group, newest first. If no workspace is set, the command lists every user that your credential can access. + +The command does not list deleted users.`, + Example: ` meshstack user list + meshstack user list --email jane.doe@example.com + meshstack user list --workspace my-workspace --workspace-role "Workspace Manager" --limit unlimited -o ndjson`, + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + workspace, err := internal.ListWorkspace(cmd.Context()) + if err != nil { + return err + } + if workspace != nil { + filter.WorkspaceIdentifier = *workspace + } + return flags.Run[client.MeshUser](cmd, filter) + }, + } + + cmd.Flags().StringVar(&filter.Email, "email", "", "list only the user with this email address") + cmd.Flags().StringVar(&filter.Username, "username", "", "list only the user with this username") + cmd.Flags().StringVar(&filter.WorkspaceRole, "workspace-role", "", "list only the users with this workspace role, such as \"Workspace Manager\"") + flags.Register(cmd.Flags()) + + return cmd +} diff --git a/cmd/user/user.go b/cmd/user/user.go new file mode 100644 index 00000000..23c45e63 --- /dev/null +++ b/cmd/user/user.go @@ -0,0 +1,26 @@ +package user + +import ( + "github.com/spf13/cobra" + + "github.com/meshcloud/meshstack-cli/cmd/internal" +) + +func New() *cobra.Command { + const command internal.KindCommand = "user" + const short = "Work with meshStack users" + cmd := &cobra.Command{ + Use: string(command), + Aliases: command.Aliases(), + Short: short, + Long: command.Long(short), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + return cmd.Help() + }, + } + + cmd.AddCommand(newList()) + + return cmd +} diff --git a/cmd/workspaceusergroup/list.go b/cmd/workspaceusergroup/list.go new file mode 100644 index 00000000..41db6aaf --- /dev/null +++ b/cmd/workspaceusergroup/list.go @@ -0,0 +1,47 @@ +package workspaceusergroup + +import ( + "github.com/spf13/cobra" + + "github.com/meshcloud/meshstack-cli/client" + "github.com/meshcloud/meshstack-cli/cmd/internal" +) + +const usernameFlagName = "username" + +func newList() *cobra.Command { + var ( + flags internal.ListFlags + filter client.MeshWorkspaceUserGroupListFilter + ) + + cmd := &cobra.Command{ + Use: "list", + Short: "List the user groups of the workspace", + Long: `List the user groups that the workspace owns. If no workspace is set, the command lists every workspace user group that your credential can access. + +With --` + usernameFlagName + `, the command lists the groups of that user in every workspace that your credential can access, because meshStack does not filter by workspace and member at the same time.`, + Example: ` meshstack workspaceusergroup list + meshstack wug list --username jane.doe@example.com + meshstack wug list --source-system SCIM --limit unlimited -o ndjson`, + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + if filter.Username == "" { + workspace, err := internal.ListWorkspace(cmd.Context()) + if err != nil { + return err + } + if workspace != nil { + filter.WorkspaceIdentifier = *workspace + } + } + return flags.Run[client.MeshWorkspaceUserGroup](cmd, filter) + }, + } + + cmd.Flags().StringVar(&filter.Username, usernameFlagName, "", "list only the groups that have the user with this username as a member") + cmd.Flags().StringVar(&filter.SourceSystem, "source-system", "", "list only the groups that this system manages, such as SCIM for the groups your identity provider synchronizes") + flags.Register(cmd.Flags()) + + return cmd +} diff --git a/cmd/workspaceusergroup/workspaceusergroup.go b/cmd/workspaceusergroup/workspaceusergroup.go new file mode 100644 index 00000000..11be9f57 --- /dev/null +++ b/cmd/workspaceusergroup/workspaceusergroup.go @@ -0,0 +1,26 @@ +package workspaceusergroup + +import ( + "github.com/spf13/cobra" + + "github.com/meshcloud/meshstack-cli/cmd/internal" +) + +func New() *cobra.Command { + const command internal.KindCommand = "workspaceusergroup" + const short = "Work with meshStack workspace user groups" + cmd := &cobra.Command{ + Use: string(command), + Aliases: command.Aliases(), + Short: short, + Long: command.Long(short), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + return cmd.Help() + }, + } + + cmd.AddCommand(newList()) + + return cmd +} diff --git a/skills/meshstack-cli/SKILL.md b/skills/meshstack-cli/SKILL.md index 18e40ee1..830f0cdb 100644 --- a/skills/meshstack-cli/SKILL.md +++ b/skills/meshstack-cli/SKILL.md @@ -26,6 +26,8 @@ skill and the help disagree, trust the help. | Command | Alias | Does | |---|---|---| | `meshstack workspace list` | | workspaces this login can see | +| `meshstack user list [--email
]` | | users with a role in the workspace, newest first | +| `meshstack workspaceusergroup list [--username ]` | `wug` | user groups the workspace owns, or every group of one user | | `meshstack buildingblock list` | `bb` | building blocks (deployed instances), newest first | | `meshstack buildingblock trigger-run ` | `bb` | starts a run of one block | | `meshstack buildingblock wait --before ` | `bb` | waits until the run of one block has ended |