Skip to content

Commit

Permalink
PLT-827: Support for cloud account import API. (#70)
Browse files Browse the repository at this point in the history
* PLT-827: Support for cloud account import API.

* PLT-827: Unwrap error type cast correction.

* PLT-827: repeated types collapse.
  • Loading branch information
nikchern authored Nov 23, 2023
1 parent c7363bd commit 98d2d74
Show file tree
Hide file tree
Showing 42 changed files with 165 additions and 70 deletions.
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)
}
7 changes: 5 additions & 2 deletions client/account_aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
cloudC "github.com/spectrocloud/hapi/cloud/client/v1"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -119,8 +121,9 @@ func (h *V1Client) GetCloudAccountAws(uid, AccountContext string) (*models.V1Aws
params = clusterC.NewV1CloudAccountsAwsGetParams().WithUID(uid)
}
success, err := client.V1CloudAccountsAwsGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions client/account_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (h *V1Client) GetCloudAccountAzure(uid, AccountContext string) (*models.V1A
}

success, err := client.V1CloudAccountsAzureGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
7 changes: 5 additions & 2 deletions client/account_coxedge.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -71,8 +73,9 @@ func (h *V1Client) GetCloudAccountCoxEdge(uid, AccountContext string) (*models.V
}

success, err := client.V1CloudAccountsCoxEdgeGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions client/account_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (h *V1Client) GetCloudAccountGcp(uid, AccountContext string) (*models.V1Gcp
}

success, err := client.V1CloudAccountsGcpGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
1 change: 1 addition & 0 deletions client/account_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (h *V1Client) GetCloudAccountMaas(uid, AccountContext string) (*models.V1Ma
}

success, err := client.V1CloudAccountsMaasGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
1 change: 1 addition & 0 deletions client/account_openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (h *V1Client) GetCloudAccountOpenStack(uid, AccountContext string) (*models
}

success, err := client.V1CloudAccountsOpenStackGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
1 change: 1 addition & 0 deletions client/account_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (h *V1Client) GetCloudAccountTke(uid, AccountContext string) (*models.V1Ten
}

success, err := client.V1CloudAccountsTencentGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
8 changes: 6 additions & 2 deletions client/account_vsphere.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -120,7 +122,9 @@ func (h *V1Client) GetCloudAccountVsphere(uid, AccountContext string) (*models.V
}

success, err := client.V1CloudAccountsVsphereGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions client/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) {

params := v1.NewV1AppDeploymentsUIDGetParamsWithContext(h.Ctx).WithUID(uid)
success, err := client.V1AppDeploymentsUIDGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down Expand Up @@ -51,6 +52,7 @@ func (h *V1Client) SearchAppDeploymentSummaries(scope string, filter *models.V1A
}

resp, err := client.V1DashboardAppDeployments(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down
3 changes: 3 additions & 0 deletions client/application_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"

"github.com/spectrocloud/palette-sdk-go/client/herr"
)

Expand Down Expand Up @@ -72,6 +73,7 @@ func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]*

params := clusterC.NewV1AppProfilesUIDTiersGetParamsWithContext(h.Ctx).WithUID(applicationProfileUID)
success, err := client.V1AppProfilesUIDTiersGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down Expand Up @@ -99,6 +101,7 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI
}

success, err := client.V1AppProfilesUIDTiersUIDManifestsUIDGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return "", nil
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type V1Client struct {
DeleteOciEcrRegistryFn func(uid string) error

// Edge Native
GetCloudConfigEdgeNativeFn func(uid string, clusterContext string) (*models.V1EdgeNativeCloudConfig, error)
GetCloudConfigEdgeNativeFn func(uid, clusterContext string) (*models.V1EdgeNativeCloudConfig, error)
}

func New(hubbleHost, email, password, projectUID, apikey string, transportDebug bool, retryAttempts int) *V1Client {
Expand Down
9 changes: 7 additions & 2 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (h *V1Client) SearchClusterSummaries(clusterContext string, filter *models.
} else if err != nil {
return nil, err
}

return resp.Payload.Items, nil
}

Expand All @@ -119,12 +120,14 @@ func (h *V1Client) listClusters(clusterContext string) ([]*models.V1SpectroClust
var limit int64 = 0
params.Limit = &limit
resp, err := client.V1SpectroClustersList(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
}

Expand All @@ -142,12 +145,14 @@ func (h *V1Client) listClustersMetadata(clusterContext string) ([]*models.V1Obje
params = hashboardC.NewV1SpectroClustersMetadataParams()
}
resp, err := client.V1SpectroClustersMetadata(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
}

Expand Down Expand Up @@ -279,7 +284,7 @@ func (h *V1Client) GetClusterAdminKubeConfig(uid, ClusterContext string) (string
return builder.String(), nil
}

func (h *V1Client) GetClusterImportManifest(uid string, clusterContext string) (string, error) {
func (h *V1Client) GetClusterImportManifest(uid, clusterContext string) (string, error) {
client, err := h.GetClusterClient()
if err != nil {
return "", err
Expand All @@ -301,7 +306,7 @@ func (h *V1Client) GetClusterImportManifest(uid string, clusterContext string) (
return builder.String(), nil
}

func (h *V1Client) UpdateClusterProfileValues(uid string, context string, profiles *models.V1SpectroClusterProfiles) error {
func (h *V1Client) UpdateClusterProfileValues(uid, context string, profiles *models.V1SpectroClusterProfiles) error {
client, err := h.GetClusterClient()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (h *V1Client) GetCloudConfigAks(configUID, ClusterContext string) (*models.
return success.Payload, nil
}

func (h *V1Client) GetNodeStatusMapAks(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapAks(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
9 changes: 6 additions & 3 deletions client/cluster_aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -101,7 +103,8 @@ func (h *V1Client) GetCloudConfigAws(configUID, ClusterContext string) (*models.
}

success, err := client.V1CloudConfigsAwsGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down Expand Up @@ -129,7 +132,7 @@ func (h *V1Client) ImportClusterAws(meta *models.V1ObjectMetaInputEntity) (strin
return *success.Payload.UID, nil
}

func (h *V1Client) GetNodeStatusMapAws(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapAws(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion client/cluster_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (h *V1Client) GetCloudConfigAzure(configUID, ClusterContext string) (*model
}

success, err := client.V1CloudConfigsAzureGet(params)

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
Expand Down Expand Up @@ -134,7 +135,7 @@ func (h *V1Client) ImportClusterAzure(meta *models.V1ObjectMetaInputEntity) (str
return *success.Payload.UID, nil
}

func (h *V1Client) GetNodeStatusMapAzure(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapAzure(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_coxedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (h *V1Client) GetCloudConfigCoxEdge(configUID, ClusterContext string) (*mod
return success.Payload, nil
}

func (h *V1Client) GetNodeStatusMapCoxEdge(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapCoxEdge(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (h *V1Client) GetCloudConfigEdge(configUID, ClusterContext string) (*models
return success.Payload, nil
}

func (h *V1Client) GetNodeStatusMapEdge(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapEdge(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (h *V1Client) GetCloudConfigEdgeNative(configUID, ClusterContext string) (*
return success.Payload, nil
}

func (h *V1Client) GetNodeStatusMapEdgeNative(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapEdgeNative(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_edge_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (h *V1Client) ImportClusterEdgeVsphere(meta *models.V1ObjectMetaInputEntity
return *success.Payload.UID, nil
}

func (h *V1Client) GetNodeStatusMapEdgeVsphere(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapEdgeVsphere(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (h *V1Client) GetCloudConfigEks(configUID, ClusterContext string) (*models.
return success.Payload, nil
}

func (h *V1Client) GetNodeStatusMapEks(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapEks(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (h *V1Client) ImportClusterGcp(meta *models.V1ObjectMetaInputEntity) (strin
return *success.Payload.UID, nil
}

func (h *V1Client) GetNodeStatusMapGcp(configUID string, machinePoolName string, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
func (h *V1Client) GetNodeStatusMapGcp(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cluster_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (h *V1Client) UpdateClusterGroup(uid string, clusterGroup *models.V1Cluster
return err
}

func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupContext string, clusterGroupUid string, clusterProfiles *models.V1SpectroClusterProfiles) error {
func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupContext, clusterGroupUid string, clusterProfiles *models.V1SpectroClusterProfiles) error {
client, err := h.GetClusterClient()
if err != nil {
return err
Expand Down
Loading

0 comments on commit 98d2d74

Please sign in to comment.