Skip to content

Commit

Permalink
name change to reflect function
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Manivannan committed Sep 6, 2023
1 parent 328814e commit 3dcd881
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/customer_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (r *runners) archiveCustomer(_ *cobra.Command, _ []string) error {
return errors.Errorf("missing or invalid parameters: customer")
}

customer, err := r.api.GetCustomerByName(r.appType, r.appID, r.args.archiveCustomerNameOrId)
customer, err := r.api.GetCustomerByNameOrId(r.appType, r.appID, r.args.archiveCustomerNameOrId)
if err != nil {
return errors.Wrapf(err, "find customer %q", r.args.archiveCustomerNameOrId)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/customer_download_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *runners) downloadCustomerLicense(_ *cobra.Command, _ []string) error {
return errors.Errorf("missing or invalid parameters: output")
}

customer, err := r.api.GetCustomerByName(r.appType, r.appID, r.args.customerLicenseInspectCustomer)
customer, err := r.api.GetCustomerByNameOrId(r.appType, r.appID, r.args.customerLicenseInspectCustomer)
if err != nil {
return errors.Wrapf(err, "find customer %q", r.args.customerLicenseInspectCustomer)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/customer_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *runners) inspectCustomer(_ *cobra.Command, _ []string) error {
return errors.Errorf("missing or invalid parameters: customer")
}

customer, err := r.api.GetCustomerByName(r.appType, r.appID, r.args.customerInspectCustomer)
customer, err := r.api.GetCustomerByNameOrId(r.appType, r.appID, r.args.customerInspectCustomer)
if err != nil {
return errors.Wrapf(err, "get customer %q", r.args.customerInspectCustomer)
}
Expand Down
4 changes: 2 additions & 2 deletions client/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func (c *Client) CreateCustomer(appType string, opts kotsclient.CreateCustomerOp

}

func (c *Client) GetCustomerByName(appType string, appID, name string) (*types.Customer, error) {
func (c *Client) GetCustomerByNameOrId(appType string, appID, nameOrId string) (*types.Customer, error) {
if appType == "platform" {
return nil, errors.New("listing customers is not supported for platform applications")
} else if appType == "kots" {
return c.KotsClient.GetCustomerByName(appID, name)
return c.KotsClient.GetCustomerByNameOrId(appID, nameOrId)
}

return nil, errors.Errorf("unknown app type %q", appType)
Expand Down
8 changes: 4 additions & 4 deletions pkg/kotsclient/customer_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,25 @@ func (c *VendorV3Client) ListCustomers(appID string, includeTest bool) ([]types.
return allCustomers, nil
}

func (c *VendorV3Client) GetCustomerByName(appID string, name string) (*types.Customer, error) {
func (c *VendorV3Client) GetCustomerByNameOrId(appID string, nameOrId string) (*types.Customer, error) {
allCustomers, err := c.ListCustomers(appID, false)
if err != nil {
return nil, err
}

matchingCustomers := make([]types.Customer, 0)
for _, customer := range allCustomers {
if customer.ID == name || customer.Name == name {
if customer.ID == nameOrId || customer.Name == nameOrId {
matchingCustomers = append(matchingCustomers, customer)
}
}

if len(matchingCustomers) == 0 {
return nil, ErrCustomerNotFound{Name: name}
return nil, ErrCustomerNotFound{Name: nameOrId}
}

if len(matchingCustomers) > 1 {
return nil, fmt.Errorf("customer %q is ambiguous, please use customer ID", name)
return nil, fmt.Errorf("customer %q is ambiguous, please use customer ID", nameOrId)
}
return &matchingCustomers[0], nil
}

0 comments on commit 3dcd881

Please sign in to comment.