diff --git a/cmd/cli.go b/cmd/cli.go index ea9875ff..5b0eee17 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -25,7 +25,6 @@ import ( "github.com/equinix/metal-cli/internal/ports" "github.com/equinix/metal-cli/internal/projects" "github.com/equinix/metal-cli/internal/ssh" - "github.com/equinix/metal-cli/internal/twofa" "github.com/equinix/metal-cli/internal/users" "github.com/equinix/metal-cli/internal/virtualcircuit" "github.com/equinix/metal-cli/internal/vlan" @@ -93,7 +92,6 @@ func (cli *Cli) RegisterCommands(client *root.Client) { projects.NewClient(client, cli.Outputer).NewCommand(), ips.NewClient(client, cli.Outputer).NewCommand(), ssh.NewClient(client, cli.Outputer).NewCommand(), - twofa.NewClient(client, cli.Outputer).NewCommand(), gateway.NewClient(client, cli.Outputer).NewCommand(), ports.NewClient(client, cli.Outputer).NewCommand(), interconnections.NewClient(client, cli.Outputer).NewCommand(), diff --git a/docs/metal.md b/docs/metal.md index 73472e66..8eed119d 100644 --- a/docs/metal.md +++ b/docs/metal.md @@ -24,7 +24,6 @@ Command line interface for Equinix Metal ### SEE ALSO -* [metal 2fa](metal_2fa.md) - Two-factor Authentication operations: receive, enable, disable. * [metal capacity](metal_capacity.md) - Capacity operations: get, check * [metal completion](metal_completion.md) - Generates completion scripts. * [metal device](metal_device.md) - Device operations: create, get, update, delete, reinstall, start, stop, and reboot. diff --git a/docs/metal_2fa.md b/docs/metal_2fa.md deleted file mode 100644 index e4da50d7..00000000 --- a/docs/metal_2fa.md +++ /dev/null @@ -1,36 +0,0 @@ -## metal 2fa - -Two-factor Authentication operations: receive, enable, disable. - -### Synopsis - -Enable or disable two-factor authentication on your user account or receive an OTP token. More information is available at https://deploy.equinix.com/developers/docs/metal/identity-access-management/users/. - -### Options - -``` - -h, --help help for 2fa -``` - -### Options inherited from parent commands - -``` - --config string Path to JSON or YAML configuration file (METAL_CONFIG) - --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. - --http-header strings Headers to add to requests (in format key=value) - --include strings Comma separated Href references to expand in results, may be dotted three levels deep - -o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp). - --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](metal.md) - Command line interface for Equinix Metal -* [metal 2fa disable](metal_2fa_disable.md) - Disables two-factor authentication. -* [metal 2fa enable](metal_2fa_enable.md) - Enables two factor authentication. -* [metal 2fa receive](metal_2fa_receive.md) - Generates a two-factor authentication token for use in enabling two-factor authentication on the current user's account. - diff --git a/docs/metal_2fa_disable.md b/docs/metal_2fa_disable.md deleted file mode 100644 index 20f575bb..00000000 --- a/docs/metal_2fa_disable.md +++ /dev/null @@ -1,50 +0,0 @@ -## metal 2fa disable - -Disables two-factor authentication. - -### Synopsis - -Disables two-factor authentication. Requires the current OTP code from either SMS or application. If you no longer have access to your two-factor authentication device, please contact support. - -``` -metal 2fa disable (-a | -s) --code [flags] -``` - -### Examples - -``` - # Disable two-factor authentication via SMS - metal 2fa disable -s -c - - # Disable two-factor authentication via APP - metal 2fa disable -a -c -``` - -### Options - -``` - -a, --app The OTP code is issued from an application. - -c, --code string The two-factor authentication OTP code. - -h, --help help for disable - -s, --sms The OTP code is issued to you via SMS. -``` - -### Options inherited from parent commands - -``` - --config string Path to JSON or YAML configuration file (METAL_CONFIG) - --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. - --http-header strings Headers to add to requests (in format key=value) - --include strings Comma separated Href references to expand in results, may be dotted three levels deep - -o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp). - --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 2fa](metal_2fa.md) - Two-factor Authentication operations: receive, enable, disable. - diff --git a/docs/metal_2fa_enable.md b/docs/metal_2fa_enable.md deleted file mode 100644 index fbd8fa95..00000000 --- a/docs/metal_2fa_enable.md +++ /dev/null @@ -1,50 +0,0 @@ -## metal 2fa enable - -Enables two factor authentication. - -### Synopsis - -Enables two-factor authentication on the current user's account. Two-factor auth is available either via SMS or an application. A current OPT code is required, which can be generated by the 2fa receive command. - -``` -metal 2fa enable (-s | -a) --code [flags] -``` - -### Examples - -``` - # Enable two factor authentication via SMS. - metal 2fa enable -s -c - - # Enable two factor authentication via an application. - metal 2fa enable -a -c -``` - -### Options - -``` - -a, --app Enables two-factor authentication using an application on the current user's account. - -c, --code string Two-factor authentication code that is provided by a request to the 2fa receive command. - -h, --help help for enable - -s, --sms Enables two-factor authentication using SMS on the current user's account. -``` - -### Options inherited from parent commands - -``` - --config string Path to JSON or YAML configuration file (METAL_CONFIG) - --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. - --http-header strings Headers to add to requests (in format key=value) - --include strings Comma separated Href references to expand in results, may be dotted three levels deep - -o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp). - --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 2fa](metal_2fa.md) - Two-factor Authentication operations: receive, enable, disable. - diff --git a/docs/metal_2fa_receive.md b/docs/metal_2fa_receive.md deleted file mode 100644 index 930fa764..00000000 --- a/docs/metal_2fa_receive.md +++ /dev/null @@ -1,49 +0,0 @@ -## metal 2fa receive - -Generates a two-factor authentication token for use in enabling two-factor authentication on the current user's account. - -### Synopsis - -Generates a two-factor authentication token for use in enabling two-factor authentication on the current user's account. In order to use SMS, a phone number must be associated with the account to receive the code. If you are using an app, a URI for the application is returned. - -``` -metal 2fa receive (-s | -a) [flags] -``` - -### Examples - -``` - # Issue the token via SMS: - metal 2fa receive -s - - # Issue the token via app: - metal 2fa receive -a -``` - -### Options - -``` - -a, --app Issues an OTP URI for an authentication application. - -h, --help help for receive - -s, --sms Issues SMS OTP token to the phone number associated with the current user account. -``` - -### Options inherited from parent commands - -``` - --config string Path to JSON or YAML configuration file (METAL_CONFIG) - --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. - --http-header strings Headers to add to requests (in format key=value) - --include strings Comma separated Href references to expand in results, may be dotted three levels deep - -o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp). - --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 2fa](metal_2fa.md) - Two-factor Authentication operations: receive, enable, disable. - diff --git a/docs/metal_organization_create.md b/docs/metal_organization_create.md index 2c27c3c6..87138ca0 100644 --- a/docs/metal_organization_create.md +++ b/docs/metal_organization_create.md @@ -7,7 +7,7 @@ Creates an organization. Creates a new organization with the current user as the organization's owner. ``` -metal organization create -n [-d ] [-w ] [-t ] [-l ] [flags] +metal organization create -n [-d ] [-w ] [-t ] [flags] ``` ### Examples @@ -25,7 +25,6 @@ metal organization create -n [-d ] [-w ] [-t [-n ] [-d ] [-w ] [-t ] [-l ] [flags] +metal organization update -i [-n ] [-d ] [-w ] [-t ] [flags] ``` ### Examples @@ -23,7 +23,6 @@ metal organization update -i [-n ] [-d ] -d, --description string User-friendly description of the organization. -h, --help help for update -i, --id string An organization UUID. - -l, --logo string A logo image URL for the organization. -n, --name string New name for the organization. -t, --twitter string A Twitter URL of the organization. -w, --website string A website URL for the organization. diff --git a/go.mod b/go.mod index 16a2748a..6d00e5d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/equinix/metal-cli go 1.22 require ( - github.com/equinix/equinix-sdk-go v0.42.0 + github.com/equinix/equinix-sdk-go v0.45.0 github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index fe418135..8fa25d88 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/equinix/equinix-sdk-go v0.42.0 h1:jjgdFs0rx6nOwsu/dLh6ImopD0M1Rn7QIn9ZSMWzWUc= -github.com/equinix/equinix-sdk-go v0.42.0/go.mod h1:hEb3XLaedz7xhl/dpPIS6eOIiXNPeqNiVoyDrT6paIg= +github.com/equinix/equinix-sdk-go v0.45.0 h1:M1moRw4Zt/nkxskDqzslfBc5TgB+QbqBiqBEfPkhl/Y= +github.com/equinix/equinix-sdk-go v0.45.0/go.mod h1:hEb3XLaedz7xhl/dpPIS6eOIiXNPeqNiVoyDrT6paIg= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= diff --git a/internal/gateway/createbgpneighbours.go b/internal/gateway/createbgpneighbours.go index c7e0b071..bd42949b 100644 --- a/internal/gateway/createbgpneighbours.go +++ b/internal/gateway/createbgpneighbours.go @@ -58,7 +58,7 @@ func (c *Client) CreateBgpNeighbors() *cobra.Command { return nil } - bgpNeighbor, _, err := c.VrfService. + bgpNeighbor, _, err := c.Service. CreateBgpDynamicNeighbor(context.Background(), gatewayId). BgpDynamicNeighborCreateInput(*metal.NewBgpDynamicNeighborCreateInput(bgpNeighborRange, asn)). Include(c.Servicer.Includes([]string{"created_by"})). diff --git a/internal/gateway/listbgpneighbours.go b/internal/gateway/listbgpneighbours.go index 3dde36c7..85545be1 100644 --- a/internal/gateway/listbgpneighbours.go +++ b/internal/gateway/listbgpneighbours.go @@ -24,7 +24,7 @@ func (c *Client) ListBgpNeighbors() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - n, _, err := c.VrfService. + n, _, err := c.Service. GetBgpDynamicNeighbors(context.Background(), gatewayId). Include(c.Servicer.Includes([]string{"created_by"})). Exclude(c.Servicer.Excludes([]string{})). diff --git a/internal/organizations/create.go b/internal/organizations/create.go index a9604d45..7ec4cbd2 100644 --- a/internal/organizations/create.go +++ b/internal/organizations/create.go @@ -32,14 +32,13 @@ func (c *Client) Create() *cobra.Command { var ( website string twitter string - logo string name string description string ) // createOrganizationCmd represents the createOrganization command createOrganizationCmd := &cobra.Command{ - Use: `create -n [-d ] [-w ] [-t ] [-l ]`, + Use: `create -n [-d ] [-w ] [-t ]`, Short: "Creates an organization.", Long: "Creates a new organization with the current user as the organization's owner. ", Example: ` # Creates a new organization named "it-backend-infra": @@ -73,10 +72,6 @@ func (c *Client) Create() *cobra.Command { req.Website = &website } - if logo != "" { - req.Logo = &logo - } - org, _, err := c.Service.CreateOrganization(context.Background()).OrganizationInput(*req).Include(include).Exclude(exclude).Execute() if err != nil { return fmt.Errorf("Could not create Organization: %w", err) @@ -95,7 +90,6 @@ func (c *Client) Create() *cobra.Command { createOrganizationCmd.Flags().StringVarP(&description, "description", "d", "", "Description of the organization.") createOrganizationCmd.Flags().StringVarP(&website, "website", "w", "", "Website URL of the organization.") createOrganizationCmd.Flags().StringVarP(&twitter, "twitter", "t", "", "Twitter URL of the organization.") - createOrganizationCmd.Flags().StringVarP(&logo, "logo", "l", "", "A Logo image URL.]") _ = createOrganizationCmd.MarkFlagRequired("name") return createOrganizationCmd diff --git a/internal/organizations/update.go b/internal/organizations/update.go index 76efb604..a8c2163b 100644 --- a/internal/organizations/update.go +++ b/internal/organizations/update.go @@ -29,12 +29,12 @@ import ( ) func (c *Client) Update() *cobra.Command { - var organizationID, name, description, twitter, logo, website string + var organizationID, name, description, twitter, website string // createOrganizationCmd represents the createOrganization command updateOrganizationCmd := &cobra.Command{ - Use: `update -i [-n ] [-d ] [-w ] [-t ] [-l ]`, + Use: `update -i [-n ] [-d ] [-w ] [-t ]`, Short: "Updates the specified organization.", - Long: "Updates the specified organization. You can update the name, website, Twitter, or logo.", + Long: "Updates the specified organization. You can update the name, website, or Twitter.", Example: ` # Updates the name of an organization: metal organization update -i 3bd5bf07-6094-48ad-bd03-d94e8712fdc8 --name test-cluster02`, @@ -61,10 +61,6 @@ func (c *Client) Update() *cobra.Command { req.Twitter = &twitter } - if logo != "" { - req.Logo = &logo - } - if website != "" { req.Website = &website } @@ -88,7 +84,6 @@ func (c *Client) Update() *cobra.Command { updateOrganizationCmd.Flags().StringVarP(&description, "description", "d", "", "User-friendly description of the organization.") updateOrganizationCmd.Flags().StringVarP(&website, "website", "w", "", "A website URL for the organization.") updateOrganizationCmd.Flags().StringVarP(&twitter, "twitter", "t", "", "A Twitter URL of the organization.") - updateOrganizationCmd.Flags().StringVarP(&logo, "logo", "l", "", "A logo image URL for the organization.") _ = updateOrganizationCmd.MarkFlagRequired("id") return updateOrganizationCmd diff --git a/internal/twofa/disable2fa.go b/internal/twofa/disable2fa.go deleted file mode 100644 index 1b614cdc..00000000 --- a/internal/twofa/disable2fa.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright © 2018 Jasmin Gacic -// -// 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 twofa - -import ( - "context" - "fmt" - - "github.com/spf13/cobra" -) - -func (c *Client) Disable() *cobra.Command { - var ( - token string - sms, app bool - ) - // disable2faCmd represents the disable2fa command - disable2faCmd := &cobra.Command{ - Use: `disable (-a | -s) --code `, - Short: "Disables two-factor authentication.", - Long: "Disables two-factor authentication. Requires the current OTP code from either SMS or application. If you no longer have access to your two-factor authentication device, please contact support.", - Example: ` # Disable two-factor authentication via SMS - metal 2fa disable -s -c - - # Disable two-factor authentication via APP - metal 2fa disable -a -c `, - - RunE: func(cmd *cobra.Command, args []string) error { - if sms == app { - return fmt.Errorf("either sms or app should be set") - } - - cmd.SilenceUsage = true - if sms { - _, err := c.TwoFAService.DisableTfaSms(context.Background()).XOtpToken(token).Execute() - if err != nil { - return fmt.Errorf("Could not disable Two-Factor Authentication via SMS: %w", err) - } - } else if app { - _, err := c.TwoFAService.DisableTfaApp(context.Background()).XOtpToken(token).Execute() - if err != nil { - return fmt.Errorf("Could not disable Two-Factor Authentication via App: %w", err) - } - } - fmt.Println("Two factor authentication successfully disabled.") - return nil - }, - } - - disable2faCmd.Flags().BoolVarP(&sms, "sms", "s", false, "The OTP code is issued to you via SMS.") - disable2faCmd.Flags().BoolVarP(&app, "app", "a", false, "The OTP code is issued from an application.") - disable2faCmd.Flags().StringVarP(&token, "code", "c", "", "The two-factor authentication OTP code.") - _ = disable2faCmd.MarkFlagRequired("code") - return disable2faCmd -} diff --git a/internal/twofa/enable2fa.go b/internal/twofa/enable2fa.go deleted file mode 100644 index 2c6b56cc..00000000 --- a/internal/twofa/enable2fa.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright © 2018 Jasmin Gacic -// -// 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 twofa - -import ( - "context" - "fmt" - - "github.com/spf13/cobra" -) - -func (c *Client) Enable() *cobra.Command { - var token string - var sms, app bool - - // enable2faCmd represents the enable2fa command - enable2faCmd := &cobra.Command{ - Use: `enable (-s | -a) --code `, - Short: "Enables two factor authentication.", - Long: "Enables two-factor authentication on the current user's account. Two-factor auth is available either via SMS or an application. A current OPT code is required, which can be generated by the 2fa receive command.", - Example: ` # Enable two factor authentication via SMS. - metal 2fa enable -s -c - - # Enable two factor authentication via an application. - metal 2fa enable -a -c `, - - RunE: func(cmd *cobra.Command, args []string) error { - if sms == app { - return fmt.Errorf("either sms or app should be set") - } - - cmd.SilenceUsage = true - if sms { - _, err := c.TwoFAService.EnableTfaSms(context.Background()).XOtpToken(token).Execute() - if err != nil { - return fmt.Errorf("Could not enable Two-Factor Authentication: %w", err) - } - } else if app { - _, err := c.TwoFAService.EnableTfaApp(context.Background()).XOtpToken(token).Execute() - if err != nil { - return fmt.Errorf("Could not enable Two-Factor Authentication: %w", err) - } - } - fmt.Println("Two factor authentication successfully enabled.") - return nil - }, - } - - enable2faCmd.Flags().BoolVarP(&sms, "sms", "s", false, "Enables two-factor authentication using SMS on the current user's account.") - enable2faCmd.Flags().BoolVarP(&app, "app", "a", false, "Enables two-factor authentication using an application on the current user's account.") - enable2faCmd.Flags().StringVarP(&token, "code", "c", "", "Two-factor authentication code that is provided by a request to the 2fa receive command.") - _ = enable2faCmd.MarkFlagRequired("code") - return enable2faCmd -} diff --git a/internal/twofa/receive.go b/internal/twofa/receive.go deleted file mode 100644 index a15eef3b..00000000 --- a/internal/twofa/receive.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright © 2018 Jasmin Gacic -// -// 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 twofa - -import ( - "context" - "fmt" - - "github.com/spf13/cobra" -) - -func (c *Client) Receive() *cobra.Command { - var app, sms bool - - // receive2faCmd represents the receive2fa command - receive2faCmd := &cobra.Command{ - Use: `receive (-s | -a)`, - Short: "Generates a two-factor authentication token for use in enabling two-factor authentication on the current user's account.", - Long: "Generates a two-factor authentication token for use in enabling two-factor authentication on the current user's account. In order to use SMS, a phone number must be associated with the account to receive the code. If you are using an app, a URI for the application is returned.", - Example: ` # Issue the token via SMS: - metal 2fa receive -s - - # Issue the token via app: - metal 2fa receive -a`, - - RunE: func(cmd *cobra.Command, args []string) error { - if sms == app { - return fmt.Errorf("either sms or app should be set") - } - - cmd.SilenceUsage = true - if sms { - _, err := c.OtpService.ReceiveCodes(context.Background()).Execute() - if err != nil { - return fmt.Errorf("Could not issue token via SMS: %w", err) - } - - fmt.Println("SMS token sent to your phone") - return nil - } - - resp, _, err := c.OtpService.SeedApp(context.Background()).Execute() - if err != nil { - return fmt.Errorf("Could not get the OTP Seed URI: %w", err) - } - - data := make([][]string, 1) - - data[0] = []string{resp.GetOtpUri()} - header := []string{"OTP URI"} - return c.Out.Output(resp, header, &data) - }, - } - - receive2faCmd.Flags().BoolVarP(&sms, "sms", "s", false, "Issues SMS OTP token to the phone number associated with the current user account.") - receive2faCmd.Flags().BoolVarP(&app, "app", "a", false, "Issues an OTP URI for an authentication application.") - return receive2faCmd -} diff --git a/internal/twofa/twofa.go b/internal/twofa/twofa.go deleted file mode 100644 index c66a4764..00000000 --- a/internal/twofa/twofa.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright © 2018 Jasmin Gacic -// -// 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 twofa - -import ( - "github.com/equinix/metal-cli/internal/outputs" - - "github.com/equinix/equinix-sdk-go/services/metalv1" - "github.com/spf13/cobra" -) - -type Client struct { - Servicer Servicer - TwoFAService *metalv1.TwoFactorAuthApiService - OtpService *metalv1.OTPsApiService - Out outputs.Outputer -} - -func (c *Client) NewCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: `2fa`, - Aliases: []string{"tfa", "mfa", "totp"}, - Short: "Two-factor Authentication operations: receive, enable, disable.", - Long: "Enable or disable two-factor authentication on your user account or receive an OTP token. More information is available at https://deploy.equinix.com/developers/docs/metal/identity-access-management/users/.", - - PersistentPreRun: func(cmd *cobra.Command, args []string) { - if root := cmd.Root(); root != nil { - if root.PersistentPreRun != nil { - root.PersistentPreRun(cmd, args) - } - } - c.TwoFAService = c.Servicer.MetalAPI(cmd).TwoFactorAuthApi - c.OtpService = c.Servicer.MetalAPI(cmd).OTPsApi - }, - } - - cmd.AddCommand( - c.Receive(), - c.Enable(), - c.Disable(), - ) - return cmd -} - -type Servicer interface { - MetalAPI(*cobra.Command) *metalv1.APIClient - Filters() map[string]string - Includes(defaultIncludes []string) (incl []string) - Excludes(defaultExcludes []string) (excl []string) -} - -func NewClient(s Servicer, out outputs.Outputer) *Client { - return &Client{ - Servicer: s, - Out: out, - } -} diff --git a/test/e2e/gateways/bgp-dynamic-neighbour/create_test.go b/test/e2e/gateways/bgp-dynamic-neighbour/create_test.go index 3de53ba8..e0ce61d8 100644 --- a/test/e2e/gateways/bgp-dynamic-neighbour/create_test.go +++ b/test/e2e/gateways/bgp-dynamic-neighbour/create_test.go @@ -44,7 +44,7 @@ func TestBgpDynamicNeighbors_Create(t *testing.T) { out := helper.ExecuteAndCaptureOutput(t, root) apiClient := helper.TestClient() - neighbors, _, err := apiClient.VRFsApi. + neighbors, _, err := apiClient.MetalGatewaysApi. GetBgpDynamicNeighbors(context.Background(), gway.GetId()). Include([]string{"created_by"}). Execute() diff --git a/test/e2e/twofa_test.go b/test/e2e/twofa_test.go deleted file mode 100644 index d6d76130..00000000 --- a/test/e2e/twofa_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package hardwaretest - -import ( - "fmt" - "io" - "log" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - root "github.com/equinix/metal-cli/internal/cli" - outputPkg "github.com/equinix/metal-cli/internal/outputs" - "github.com/equinix/metal-cli/internal/twofa" - "github.com/spf13/cobra" -) - -var mockOtpUri = "otpauth://totp/foo" - -func setupMock() *root.Client { - mockAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var responseBody string - if r.URL.Path == "/user/otp/sms/receive" { - w.WriteHeader(http.StatusNoContent) - } else if r.URL.Path == "/user/otp/app/receive" { - w.Header().Add("Content-Type", "application/json") - responseBody = fmt.Sprintf(`{"otp_uri": "%v"}`, mockOtpUri) - - } else { - responseBody = fmt.Sprintf("no mock for endpoint %v", r.URL.Path) - w.WriteHeader(http.StatusNotImplemented) - } - _, err := w.Write([]byte(responseBody)) - if err != nil { - log.Fatalf("Failed to write mock response: %v", err) - } - })) - mockClient := root.NewClient("", mockAPI.URL, "metal") - return mockClient - -} - -func TestCli_Twofa(t *testing.T) { - subCommand := "2fa" - // Adjust this response as needed for your tests. - - rootClient := setupMock() - - type fields struct { - MainCmd *cobra.Command - Outputer outputPkg.Outputer - } - tests := []struct { - name string - fields fields - want *cobra.Command - cmdFunc func(*testing.T, *cobra.Command) - }{ - { - name: "receive sms", - fields: fields{ - MainCmd: twofa.NewClient(rootClient, outputPkg.Outputer(&outputPkg.Standard{})).NewCommand(), - Outputer: outputPkg.Outputer(&outputPkg.Standard{}), - }, - want: &cobra.Command{}, - cmdFunc: func(t *testing.T, c *cobra.Command) { - root := c.Root() - root.SetArgs([]string{subCommand, "receive", "-s"}) - rescueStdout := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - if err := root.Execute(); err != nil { - t.Error(err) - } - w.Close() - out, _ := io.ReadAll(r) - - os.Stdout = rescueStdout - if !strings.Contains(string(out[:]), "SMS token sent to your phone") { - t.Error("expected output to include 'SMS token sent to your phone'.") - } - }, - }, - { - name: "receive app", - fields: fields{ - MainCmd: twofa.NewClient(rootClient, outputPkg.Outputer(&outputPkg.Standard{})).NewCommand(), - Outputer: outputPkg.Outputer(&outputPkg.Standard{}), - }, - want: &cobra.Command{}, - cmdFunc: func(t *testing.T, c *cobra.Command) { - root := c.Root() - root.SetArgs([]string{subCommand, "receive", "-a"}) - rescueStdout := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - if err := root.Execute(); err != nil { - t.Error(err) - } - w.Close() - out, _ := io.ReadAll(r) - - os.Stdout = rescueStdout - if !strings.Contains(string(out[:]), mockOtpUri) { - t.Errorf("expected output to include %v", mockOtpUri) - } - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - rootCmd := rootClient.NewCommand() - rootCmd.AddCommand(tt.fields.MainCmd) - tt.cmdFunc(t, tt.fields.MainCmd) - }) - } -} diff --git a/test/helper/helper.go b/test/helper/helper.go index 8a46d4ed..38950bcb 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -796,13 +796,13 @@ func CreateTestBgpDynamicNeighbor(t *testing.T, gatewayId, iprange string, asn i t.Helper() bgpNeighborCreateInput := metalv1.NewBgpDynamicNeighborCreateInput(iprange, asn) - neighbor, _, err := TestApiClient.VRFsApi. + neighbor, _, err := TestApiClient.MetalGatewaysApi. CreateBgpDynamicNeighbor(context.Background(), gatewayId). BgpDynamicNeighborCreateInput(*bgpNeighborCreateInput). Include([]string{"created_by"}). Execute() if err != nil { - t.Fatalf("Error when calling `VRFsApi.CreateBgpDynamicNeighbor`: %v\n", err) + t.Fatalf("Error when calling `MetalGatewaysApi.CreateBgpDynamicNeighbor`: %v\n", err) } t.Cleanup(func() {