Skip to content

Commit 70f9442

Browse files
authored
bugfix: fix invite-billing-account-user and billing-account-invitations (#5)
1 parent d2d39a3 commit 70f9442

6 files changed

Lines changed: 28 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/appcloud-cf-cli-plugin
22
/appcloud-cf-cli-plugin.exe
3+
bin

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: build
2+
3+
build:
4+
GOOS=linux GOARCH=386 go build -o bin/appcloud-cf-cli-plugin_linux32
5+
GOOS=linux GOARCH=amd64 go build -o bin/appcloud-cf-cli-plugin_linux64
6+
GOOS=darwin GOARCH=amd64 go build -o bin/appcloud-cf-cli-plugin_osx
7+
GOOS=windows GOARCH=386 go build -o bin/appcloud-cf-cli-plugin_win32.exe
8+
GOOS=windows GOARCH=amd64 go build -o bin/appcloud-cf-cli-plugin_win64.exe

internal/appcloud/appcloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (p *Plugin) GetMetadata() plugin.PluginMetadata {
102102
},
103103
{
104104
Name: "invite-billing-account-user",
105-
HelpText: "Invite a user to a billing account as an 'accountOwner'",
105+
HelpText: `Invite a user to a billing account as an 'account owner'. The account can be specified by number (e.g.: F26AADDL00) or full name`,
106106
UsageDetails: plugin.Usage{
107107
Usage: "invite-org-user USERNAME BILLING_ACCOUNT",
108108
},
@@ -157,7 +157,7 @@ func (p *Plugin) GetMetadata() plugin.PluginMetadata {
157157
UsageDetails: plugin.Usage{
158158
Usage: "create-ssl-certificate DOMAIN [--hostname HOSTNAME] [--key-type KEY_TYPE]",
159159
Options: map[string]string{
160-
"-hostname, -n": "Hostname for the HTTP route",
160+
"-hostname, -n": "Hostname for the HTTP route",
161161
"-key-type, -kt": "Key type for the certificate (e.g. RSA, ECDSA)",
162162
},
163163
},

internal/appcloud/billing_account.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,33 @@ type BillingAccount struct {
1818
}
1919

2020
// BillingAccountResponse is a response from the server to a billing account request.
21-
type BillingAccountResponse struct {
22-
BillingAccount
21+
type BillingAccountsResponse struct {
22+
BillingAccounts []BillingAccount `json:"resources"`
2323
ServerResponseError
2424
}
2525

26-
// getBillingAccount retrieves a billing account by name.
26+
// getBillingAccount retrieves a billing account by name or number.
2727
func getBillingAccount(c plugin.CliConnection, name string) (BillingAccount, error) {
28-
accURL := url.QueryEscape(fmt.Sprintf("/custom/accounts?q=name:%s", name))
28+
expression := url.QueryEscape("name_number:" + name)
29+
accURL := fmt.Sprintf("/custom/accounts?q=%s", expression)
2930
resLines, err := c.CliCommandWithoutTerminalOutput("curl", accURL)
3031

3132
if err != nil {
3233
return BillingAccount{}, errors.Wrap(err, "Billing Account not found")
3334
}
3435

3536
resString := strings.Join(resLines, "")
36-
var res BillingAccountResponse
37+
var res BillingAccountsResponse
3738
err = json.Unmarshal([]byte(resString), &res)
3839
if err != nil {
3940
return BillingAccount{}, errors.Wrap(err, "Couldn't read JSON response from server")
4041
}
4142

42-
return res.BillingAccount, nil
43+
if len(res.BillingAccounts) == 0 {
44+
return BillingAccount{}, errors.New("Billing account not found")
45+
} else if len(res.BillingAccounts) > 1 {
46+
return BillingAccount{}, errors.New("Multiple billing accounts found - retry with the account's number or full name")
47+
}
48+
49+
return res.BillingAccounts[0], nil
4350
}

internal/appcloud/billing_account_invitations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func (p *Plugin) BillingAccountInvitations(c plugin.CliConnection, billingAccoun
1717
return errors.Wrap(err, "Couldn't get your username")
1818
}
1919

20-
p.ui.Say("Gettings invitations to billing account %s as %s...", terminal.EntityNameColor(billingAccountName), terminal.EntityNameColor(un))
20+
p.ui.Say("Getting invitations for billing account %s as %s...", terminal.EntityNameColor(billingAccountName), terminal.EntityNameColor(un))
2121

2222
ba, err := getBillingAccount(c, billingAccountName)
2323
if err != nil {
24-
return errors.Wrap(err, "Billing account not found")
24+
return err
2525
}
2626

2727
url := fmt.Sprintf("/custom/accounts/%s/invitations", ba.Metadata.GUID)

internal/appcloud/invite_billing_account_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ func (p *Plugin) InviteBillingAccountUser(c plugin.CliConnection, invitee string
2727

2828
ba, err := getBillingAccount(c, billingAccountName)
2929
if err != nil {
30-
return errors.Wrap(err, "Billing Account not found")
30+
return err
3131
}
3232

3333
args := InviteBillingAccountUserRequest{
3434
Invitee: invitee,
3535
AccountID: ba.Metadata.GUID,
36-
Roles: []string{"accountOwner"},
36+
Roles: []string{"OWNER"},
3737
}
3838
argsData, err := json.Marshal(args)
3939
if err != nil {

0 commit comments

Comments
 (0)