From 21da5389569e6335ce39a8809c7b6dead9a243eb 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 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. 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 | 4 ++ client/client_kind.go | 4 ++ client/client_kind_test.go | 2 + client/user.go | 67 ++++++++++++++++++++++++++++ client/workspace_user_group.go | 81 ++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 client/user.go create mode 100644 client/workspace_user_group.go diff --git a/client/client.go b/client/client.go index 413ac16c..7f9525de 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. @@ -80,9 +82,11 @@ 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: newUserClient(ctx, authorizedClient), Workspace: workspace, WorkspaceGroupBinding: newWorkspaceGroupBindingClient(ctx, authorizedClient), WorkspaceUserBinding: newWorkspaceUserBindingClient(ctx, authorizedClient), + WorkspaceUserGroup: newWorkspaceUserGroupClient(ctx, authorizedClient), Raw: newRawClient(authorizedClient). with(workspace.meshObject). with(buildingBlockV2.meshObject). 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)) +}