Skip to content

Commit

Permalink
chore: upgrade metal-go to 0.22 and fix enum type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Sep 20, 2023
1 parent 096b47f commit a2a8f7c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/equinix/metal-cli
go 1.19

require (
github.com/equinix-labs/metal-go v0.21.0
github.com/equinix-labs/metal-go v0.22.0
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/packethost/packngo v0.30.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/equinix-labs/metal-go v0.21.0 h1:AWmciCaO+tjNKCKB0r4pMHpoGenzAqua3TbXA5VjZE8=
github.com/equinix-labs/metal-go v0.21.0/go.mod h1:SmxCklxW+KjmBLVMdEXgtFO5gD5/b4N0VxcNgUYbOH4=
github.com/equinix-labs/metal-go v0.22.0 h1:55Obk3DBSqC1qE8BK/mu1ZwMvP5SFzg0pNddlP5WH0c=
github.com/equinix-labs/metal-go v0.22.0/go.mod h1:SmxCklxW+KjmBLVMdEXgtFO5gD5/b4N0VxcNgUYbOH4=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
Expand Down
17 changes: 14 additions & 3 deletions internal/devices/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ func (c *Client) Create() *cobra.Command {
var facilityArgs []string

var request metal.ApiCreateDeviceRequest

var validBillingCycle *metal.DeviceCreateInputBillingCycle
var err error

if billingCycle != "" {
validBillingCycle, err = metal.NewDeviceCreateInputBillingCycleFromValue(billingCycle)
if err != nil {
return err
}
}

if facility != "" {
facilityArgs = append(facilityArgs, facility)

Expand All @@ -112,7 +123,7 @@ func (c *Client) Create() *cobra.Command {
}

if billingCycle != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetBillingCycle(billingCycle)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetBillingCycle(*validBillingCycle)
}
if alwaysPXE {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetAlwaysPxe(alwaysPXE)
Expand Down Expand Up @@ -151,7 +162,7 @@ func (c *Client) Create() *cobra.Command {
},
}
if billingCycle != "" {
metroDeviceRequest.DeviceCreateInMetroInput.SetBillingCycle(billingCycle)
metroDeviceRequest.DeviceCreateInMetroInput.SetBillingCycle(*validBillingCycle)
}

if alwaysPXE {
Expand Down Expand Up @@ -182,7 +193,7 @@ func (c *Client) Create() *cobra.Command {
}
header := []string{"ID", "Hostname", "OS", "State", "Created"}
data := make([][]string, 1)
data[0] = []string{device.GetId(), device.GetHostname(), *device.GetOperatingSystem().Name, device.GetState(), device.GetCreatedAt().String()}
data[0] = []string{device.GetId(), device.GetHostname(), *device.GetOperatingSystem().Name, fmt.Sprintf("%v", device.GetState()), device.GetCreatedAt().String()}

return c.Out.Output(device, header, &data)
},
Expand Down
4 changes: 2 additions & 2 deletions internal/devices/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Client) Retrieve() *cobra.Command {
header := []string{"ID", "Hostname", "OS", "State", "Created"}

data := make([][]string, 1)
data[0] = []string{device.GetId(), device.GetHostname(), device.OperatingSystem.GetName(), device.GetState(), device.GetCreatedAt().String()}
data[0] = []string{device.GetId(), device.GetHostname(), device.OperatingSystem.GetName(), fmt.Sprintf("%v", device.GetState()), device.GetCreatedAt().String()}

return c.Out.Output(device, header, &data)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *Client) Retrieve() *cobra.Command {
data := make([][]string, len(devices))

for i, dc := range devices {
data[i] = []string{dc.GetId(), dc.GetHostname(), dc.OperatingSystem.GetName(), dc.GetState(), dc.GetCreatedAt().String()}
data[i] = []string{dc.GetId(), dc.GetHostname(), dc.OperatingSystem.GetName(), fmt.Sprintf("%v", dc.GetState()), dc.GetCreatedAt().String()}
}
header := []string{"ID", "Hostname", "OS", "State", "Created"}

Expand Down
2 changes: 1 addition & 1 deletion internal/devices/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c *Client) Update() *cobra.Command {

header := []string{"ID", "Hostname", "OS", "State"}
data := make([][]string, 1)
data[0] = []string{device.GetId(), device.GetHostname(), device.OperatingSystem.GetName(), device.GetState()}
data[0] = []string{device.GetId(), device.GetHostname(), device.OperatingSystem.GetName(), fmt.Sprintf("%v", device.GetState())}

return c.Out.Output(device, header, &data)
},
Expand Down
7 changes: 3 additions & 4 deletions internal/organizations/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ func (c *Client) Retrieve() *cobra.Command {

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
include := []string{"Inner_example"}
exclude := []string{"Inner_example"}
withoutProjects := "withoutProjects_example"
include := c.Servicer.Includes(nil)
exclude := c.Servicer.Excludes(nil)

if organizationID == "" {
orgs, err := pager.GetAllOrganizations(c.Service, include, exclude, withoutProjects)
orgs, err := pager.GetAllOrganizations(c.Service, include, exclude)
if err != nil {
return fmt.Errorf("Could not list Organizations: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pagination/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ func GetAllEvents(s metal.ApiFindEventsRequest) ([]metal.Event, error) {
}
}

func GetAllOrganizations(s metal.OrganizationsApiService, include, exclude []string, withOutProjects string) ([]metal.Organization, error) {
func GetAllOrganizations(s metal.OrganizationsApiService, include, exclude []string) ([]metal.Organization, error) {
var orgs []metal.Organization
page := int32(1) // int32 | Page to return (optional) (default to 1)
perPage := int32(56) // int32 | Items returned per page (optional) (default to 10)

for {
orgPage, _, err := s.FindOrganizations(context.Background()).Include(include).Exclude(exclude).WithoutProjects(withOutProjects).Page(page).PerPage(perPage).Execute()
orgPage, _, err := s.FindOrganizations(context.Background()).Include(include).Exclude(exclude).Page(page).PerPage(perPage).Execute()
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/plans/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"fmt"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/spf13/cobra"
)

Expand All @@ -43,7 +44,11 @@ func (c *Client) Retrieve() *cobra.Command {
filters := c.Servicer.Filters()

if filters["type"] != "" {
request = request.Type_(filters["type"])
validType, err := metal.NewFindPlansTypeParameterFromValue(filters["type"])
if err != nil {
return err
}
request = request.Type_(*validType)
}

if filters["slug"] != "" {
Expand Down
24 changes: 22 additions & 2 deletions internal/users/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func (c *Client) Add() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
invitationInput := metal.NewInvitationInput(email)
invitationInput.SetRoles(roles)
validRoles, err := validateRoles(roles)
if err != nil {
return err
}
invitationInput.SetRoles(validRoles)
invitationInput.SetProjectsIds(projectsIDs)

invitation, _, err := c.InvitationService.CreateOrganizationInvitation(context.Background(), organizationID).InvitationInput(*invitationInput).Include(c.Servicer.Includes(nil)).Execute()
Expand All @@ -58,7 +62,11 @@ func (c *Client) Add() *cobra.Command {

data := make([][]string, 1)

data[0] = []string{invitation.GetId(), invitation.GetNonce(), invitation.GetInvitee(), invitation.Organization.GetHref(), strconv.Itoa(len(invitation.GetProjects())), strings.Join(invitation.GetRoles(), ", ")}
var roles []string
for _, role := range invitation.GetRoles() {
roles = append(roles, fmt.Sprintf("%v", role))
}
data[0] = []string{invitation.GetId(), invitation.GetNonce(), invitation.GetInvitee(), invitation.Organization.GetHref(), strconv.Itoa(len(invitation.GetProjects())), strings.Join(roles, ", ")}
header := []string{"ID", "Nonce", "Email", "Organization", "Projects", "Roles"}

return c.Out.Output(invitation, header, &data)
Expand All @@ -74,3 +82,15 @@ func (c *Client) Add() *cobra.Command {

return addUserCmd
}

func validateRoles(roles []string) ([]metal.InvitationRolesInner, error) {
validRoles := make([]metal.InvitationRolesInner, len(roles))
for _, role := range roles {
validRole, err := metal.NewInvitationRolesInnerFromValue(role)
if err != nil {
return nil, err
}
validRoles = append(validRoles, *validRole)
}
return validRoles, nil
}

0 comments on commit a2a8f7c

Please sign in to comment.