Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions client/client_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -47,7 +49,9 @@ var MeshObjectKind = meshObjectKind{
ServiceInstance: "meshServiceInstance",
TagDefinition: "meshTagDefinition",
Tenant: "meshTenant",
User: "meshUser",
Workspace: "meshWorkspace",
WorkspaceGroupBinding: "meshWorkspaceGroupBinding",
WorkspaceUserBinding: "meshWorkspaceUserBinding",
WorkspaceUserGroup: "meshWorkspaceUserGroup",
}
2 changes: 2 additions & 0 deletions client/client_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
67 changes: 67 additions & 0 deletions client/user.go
Original file line number Diff line number Diff line change
@@ -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)
}
81 changes: 81 additions & 0 deletions client/workspace_user_group.go
Original file line number Diff line number Diff line change
@@ -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))
}
1 change: 1 addition & 0 deletions cmd/internal/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var kindAliases = map[KindCommand][]string{
"buildingblockrun": {"bbrun"},
"eventlog": {"elog"},
"workspace": {"ws"},
"workspaceusergroup": {"wug"},
}

type KindCommand string
Expand Down
4 changes: 4 additions & 0 deletions cmd/meshstack/meshstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions cmd/user/list.go
Original file line number Diff line number Diff line change
@@ -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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

d: would it be enough for now adding the client/ package changes only and the corresponding TF provider resources for now? I'm a bit reluctant to extend the CLI api here in one go, in particular considering that meshstack api is already there to talk to that public api without a dedicated set of CLI list commands for now?

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
}
26 changes: 26 additions & 0 deletions cmd/user/user.go
Original file line number Diff line number Diff line change
@@ -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
}
47 changes: 47 additions & 0 deletions cmd/workspaceusergroup/list.go
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions cmd/workspaceusergroup/workspaceusergroup.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading