diff --git a/docs/metal_2fa.md b/docs/metal_2fa.md index 50d1ae2e..9ae25418 100644 --- a/docs/metal_2fa.md +++ b/docs/metal_2fa.md @@ -32,5 +32,4 @@ Enable or disable two-factor authentication on your user account or receive an O * [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_receive.md b/docs/metal_2fa_receive.md deleted file mode 100644 index cff06afd..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 - --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/internal/twofa/disable2fa.go b/internal/twofa/disable2fa.go index 29c05622..16cb9f22 100644 --- a/internal/twofa/disable2fa.go +++ b/internal/twofa/disable2fa.go @@ -21,6 +21,7 @@ package twofa import ( + "context" "fmt" "github.com/spf13/cobra" @@ -49,12 +50,12 @@ func (c *Client) Disable() *cobra.Command { cmd.SilenceUsage = true if sms { - _, err := c.Service.DisableSms(token) + _, err := c.Service.DisableTfaSms(context.Background()).Execute() if err != nil { return fmt.Errorf("Could not disable Two-Factor Authentication via SMS: %w", err) } } else if app { - _, err := c.Service.DisableApp(token) + _, err := c.Service.DisableTfaApp(context.Background()).Execute() if err != nil { return fmt.Errorf("Could not disable Two-Factor Authentication via App: %w", err) } diff --git a/internal/twofa/enable2fa.go b/internal/twofa/enable2fa.go index 9a9b82a3..7eef7a1e 100644 --- a/internal/twofa/enable2fa.go +++ b/internal/twofa/enable2fa.go @@ -21,6 +21,7 @@ package twofa import ( + "context" "fmt" "github.com/spf13/cobra" @@ -48,12 +49,13 @@ func (c *Client) Enable() *cobra.Command { cmd.SilenceUsage = true if sms { - _, err := c.Service.EnableSms(token) + _, err := c.Service.EnableTfaSms(context.Background()).Execute() if err != nil { return fmt.Errorf("Could not enable Two-Factor Authentication: %w", err) } } else if app { - _, err := c.Service.EnableApp(token) + // _, err := c.Service.EnableApp(token) + _, err := c.Service.EnableTfaApp(context.Background()).Execute() if err != nil { return fmt.Errorf("Could not enable Two-Factor Authentication: %w", err) } diff --git a/internal/twofa/receive.go b/internal/twofa/receive.go deleted file mode 100644 index 64420cec..00000000 --- a/internal/twofa/receive.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 ( - "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.Service.ReceiveSms() - if err != nil { - return fmt.Errorf("Could not issue token via SMS: %w", err) - } - - fmt.Println("SMS token sent to your phone") - return nil - } - - otpURI, _, err := c.Service.SeedApp() - if err != nil { - return fmt.Errorf("Could not get the OTP Seed URI: %w", err) - } - - data := make([][]string, 1) - - data[0] = []string{otpURI} - header := []string{"OTP URI"} - return c.Out.Output(otpURI, 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 index 3dcab967..e2e7420a 100644 --- a/internal/twofa/twofa.go +++ b/internal/twofa/twofa.go @@ -21,14 +21,14 @@ package twofa import ( + metal "github.com/equinix-labs/metal-go/metal/v1" "github.com/equinix/metal-cli/internal/outputs" - "github.com/packethost/packngo" "github.com/spf13/cobra" ) type Client struct { Servicer Servicer - Service packngo.TwoFactorAuthService + Service metal.TwoFactorAuthApiService Out outputs.Outputer } @@ -45,12 +45,11 @@ func (c *Client) NewCommand() *cobra.Command { root.PersistentPreRun(cmd, args) } } - c.Service = c.Servicer.API(cmd).TwoFactorAuth + c.Service = *c.Servicer.MetalAPI(cmd).TwoFactorAuthApi }, } cmd.AddCommand( - c.Receive(), c.Enable(), c.Disable(), ) @@ -58,8 +57,10 @@ func (c *Client) NewCommand() *cobra.Command { } type Servicer interface { - API(*cobra.Command) *packngo.Client - ListOptions(defaultIncludes, defaultExcludes []string) *packngo.ListOptions + MetalAPI(*cobra.Command) *metal.APIClient + Filters() map[string]string + Includes(defaultIncludes []string) (incl []string) + Excludes(defaultExcludes []string) (excl []string) } func NewClient(s Servicer, out outputs.Outputer) *Client {