Repository navigation
feat(client): add user and workspace user group clients, with list co… #96
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cschroer
wants to merge
1
commit into
meshcloud:main
Choose a base branch
from
cschroer:feat/workspace-user-group
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thatmeshstack apiis already there to talk to that public api without a dedicated set of CLIlistcommands for now?