Skip to content
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

chore: Updated metal-go client for sub-command twofa #334

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion docs/metal_2fa.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

49 changes: 0 additions & 49 deletions docs/metal_2fa_receive.md

This file was deleted.

5 changes: 3 additions & 2 deletions internal/twofa/disable2fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package twofa

import (
"context"
"fmt"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/twofa/enable2fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package twofa

import (
"context"
"fmt"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to be able to pass in the token? Is this a spec issue that needs to be fixed?

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)
}
Expand Down
75 changes: 0 additions & 75 deletions internal/twofa/receive.go

This file was deleted.

13 changes: 7 additions & 6 deletions internal/twofa/twofa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -45,21 +45,22 @@ 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(),
)
return cmd
}

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 {
Expand Down
Loading