Skip to content

Commit

Permalink
Fix: Updated metal-go client for sub-command twofa
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Aug 16, 2023
1 parent 45b39d8 commit efdd12c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
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()
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
12 changes: 7 additions & 5 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,7 +45,7 @@ func (c *Client) NewCommand() *cobra.Command {
root.PersistentPreRun(cmd, args)
}
}
c.Service = c.Servicer.API(cmd).TwoFactorAuth
c.Service = *c.Servicer.MetalAPI(cmd).TwoFactorAuthApi
},
}

Expand All @@ -58,8 +58,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 {
Expand Down

0 comments on commit efdd12c

Please sign in to comment.