-
Notifications
You must be signed in to change notification settings - Fork 46
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: upgrade metal-go to 0.22.2 and fix enum type errors #350
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
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) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the |
||
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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"context" | ||
"fmt" | ||
|
||
metal "github.com/equinix-labs/metal-go/metal/v1" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted to just return the error here rather than wrapping it, since the error that's thrown is already helpful: https://github.com/equinix-labs/metal-go/blob/main/metal/v1/model_plan_type.go#L60 |
||
} | ||
request = request.Type_(*validType) | ||
} | ||
|
||
if filters["slug"] != "" { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
@@ -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) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again opted to return the original error without wrapping it, since the message looks good to me: https://github.com/equinix-labs/metal-go/blob/main/metal/v1/model_invitation_roles_inner.go#L62 |
||
} | ||
validRoles = append(validRoles, *validRole) | ||
} | ||
return validRoles, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is returning the original error because that message is nicely descriptive: https://github.com/equinix-labs/metal-go/blob/main/metal/v1/model_device_create_input_billing_cycle.go#L52
The error message does make mention of the type
DeviceCreateInputBillingCycle
; it would be preferable to reference either the CLI flag name or the attribute name there, but IMO tweaking that is not worth the effort at the moment.