Skip to content

Commit

Permalink
PLT-827: Support for cloud account import API.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Nov 22, 2023
1 parent 4c5cb4f commit a5d9a3b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
53 changes: 53 additions & 0 deletions client/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package client

import (
"errors"
"fmt"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)

func (h *V1Client) ListCloudAccounts(scope string) ([]*models.V1CloudAccountSummary, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
}

var params *clusterC.V1CloudAccountsListSummaryParams
switch scope {
case "project":
params = clusterC.NewV1CloudAccountsListSummaryParams().WithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudAccountsListSummaryParams()

}
var limit int64 = 0
params.Limit = &limit
resp, err := client.V1CloudAccountsListSummary(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return resp.Payload.Items, nil
}

func (h *V1Client) GetCloudAccount(scope, id string) (*models.V1CloudAccountSummary, error) {
accounts, err := h.ListCloudAccounts(scope)
if err != nil {
return nil, err
}

for _, account := range accounts {
if account.Metadata.UID == id {
return account, nil
}
}

return nil, fmt.Errorf("account not found with id %s", id)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-openapi/runtime v0.19.24
github.com/go-openapi/strfmt v0.20.0
github.com/pkg/errors v0.9.1
github.com/spectrocloud/hapi v1.14.1-0.20231107061715-d18e1e78daf8
github.com/spectrocloud/hapi v1.14.1-0.20231120161727-f0d8bd27c6ef
github.com/stretchr/testify v1.7.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08 h1:AnOC0U+Exl
github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08/go.mod h1:UnhUDpFEvtYh6m384r3xzj8/+Z6/hMp2O8whEMYVHec=
github.com/spectrocloud/hapi v1.14.1-0.20231107061715-d18e1e78daf8 h1:vSU7q/fj0vmQIh5R/+m3o5a3ppcCbCCbB34JYveM5n4=
github.com/spectrocloud/hapi v1.14.1-0.20231107061715-d18e1e78daf8/go.mod h1:Krk9mzbO1MnUTLvvzztBYpOWCFunIlSDWSGlsLh1vkk=
github.com/spectrocloud/hapi v1.14.1-0.20231120161727-f0d8bd27c6ef h1:ROS17WffaRM8yVPVYLub1MqLeeN9Jt5f/zXNwCSypjo=
github.com/spectrocloud/hapi v1.14.1-0.20231120161727-f0d8bd27c6ef/go.mod h1:Krk9mzbO1MnUTLvvzztBYpOWCFunIlSDWSGlsLh1vkk=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit a5d9a3b

Please sign in to comment.