-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
- Loading branch information
Showing
7 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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,48 @@ | ||
## metal user add | ||
|
||
Adds a user to an organization or project | ||
|
||
### Synopsis | ||
|
||
Adds a user, by email, to the organization or project specified by the --organization-id or --project-id flag. The user will be assigned the roles specified by the --roles flag. | ||
|
||
``` | ||
metal user add --email <email> --roles <roles> [--organization-id <organization_id>] [--project-id <project_id>] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Adds a user to a project with admin role: | ||
metal user add --email user@example.org --roles admin --project-id 3b0795ba-fd0b-4a9e-83a7-063e5e12409d | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--email string Email of the user. | ||
-h, --help help for add | ||
--organization-id string Organization to invite the user to. | ||
-p, --project-id strings Projects to invite the user to with the specified roles. | ||
--roles strings Roles to assign to the user. | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string Path to JSON or YAML configuration file | ||
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep | ||
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters. | ||
--include strings Comma separated Href references to expand in results, may be dotted three levels deep | ||
-o, --output string Output format (*table, json, yaml) | ||
--search string Search keyword for use in 'get' actions. Search is not supported by all resources. | ||
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources. | ||
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources. | ||
--token string Metal API Token (METAL_AUTH_TOKEN) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [metal user](metal_user.md) - User operations. For more information on user and account management, visit https://metal.equinix.com/developers/docs/accounts/users/ in the Equinix Metal documentation. | ||
|
This file contains 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 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 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 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,77 @@ | ||
// Copyright © 2022 Equinix Metal Developers <support@equinixmetal.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package users | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/packethost/packngo" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *Client) Add() *cobra.Command { | ||
var email string | ||
var roles []string | ||
var projectsIDs []string | ||
var organizationID string | ||
|
||
// addUserCmd represents the addUser command | ||
addUserCmd := &cobra.Command{ | ||
Use: `add --email <email> --roles <roles> [--organization-id <organization_id>] [--project-id <project_id>]`, | ||
Short: "Adds a user to an organization or project", | ||
Long: "Adds a user, by email, to the organization or project specified by the --organization-id or --project-id flag. The user will be assigned the roles specified by the --roles flag.", | ||
Example: ` # Adds a user to a project with admin role: | ||
metal user add --email user@example.org --roles admin --project-id 3b0795ba-fd0b-4a9e-83a7-063e5e12409d | ||
`, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
getOpts := c.Servicer.ListOptions(nil, nil) | ||
createRequest := &packngo.InvitationCreateRequest{ | ||
Invitee: email, | ||
Roles: roles, | ||
ProjectsIDs: projectsIDs, | ||
} | ||
invitation, _, err := c.InvitationService.Create(organizationID, createRequest, getOpts) | ||
if err != nil { | ||
return errors.Wrap(err, "Could not add Users") | ||
} | ||
|
||
data := make([][]string, 1) | ||
|
||
data[0] = []string{invitation.ID, invitation.Nonce, invitation.Invitee, invitation.Organization.Href, strconv.Itoa(len(invitation.Projects)), strings.Join(invitation.Roles, ", ")} | ||
header := []string{"ID", "Nonce", "Email", "Organization", "Projects", "Roles"} | ||
|
||
return c.Out.Output(invitation, header, &data) | ||
}, | ||
} | ||
|
||
addUserCmd.Flags().StringVar(&email, "email", "", "Email of the user.") | ||
addUserCmd.Flags().StringVar(&organizationID, "organization-id", "", "Organization to invite the user to.") | ||
addUserCmd.Flags().StringSliceVar(&roles, "roles", []string{""}, "Roles to assign to the user.") | ||
addUserCmd.Flags().StringSliceVarP(&projectsIDs, "project-id", "p", []string{""}, "Projects to invite the user to with the specified roles.") | ||
|
||
_ = addUserCmd.MarkFlagRequired("email") | ||
|
||
return addUserCmd | ||
} |
This file contains 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