Skip to content

Commit

Permalink
fix: handle 404 in GetClusterWithoutStatus; fix 404 handling in gener…
Browse files Browse the repository at this point in the history
…al (#103)

Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored May 1, 2024
1 parent 3a42012 commit 463f908
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 58 deletions.
4 changes: 3 additions & 1 deletion client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ func (h *V1Client) ListCloudAccounts() ([]*models.V1CloudAccountSummary, error)
params := clientV1.NewV1CloudAccountsListSummaryParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0)))
resp, err := h.Client.V1CloudAccountsListSummary(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.Items, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (h *V1Client) GetCloudAccountAws(uid string) (*models.V1AwsAccount, error)
params := clientV1.NewV1CloudAccountsAwsGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsAwsGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, err
params := clientV1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsAzureGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error)
params := clientV1.NewV1CloudAccountsGcpGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsGcpGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func (h *V1Client) GetCloudAccountMaas(uid string) (*models.V1MaasAccount, error
params := clientV1.NewV1CloudAccountsMaasGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsMaasGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func (h *V1Client) GetCloudAccountOpenStack(uid string) (*models.V1OpenStackAcco
params := clientV1.NewV1CloudAccountsOpenStackGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsOpenStackGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (h *V1Client) GetCloudAccountTke(uid string) (*models.V1TencentAccount, err
params := clientV1.NewV1CloudAccountsTencentGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsTencentGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/account_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (h *V1Client) GetCloudAccountVsphere(uid string) (*models.V1VsphereAccount,
params := clientV1.NewV1CloudAccountsVsphereGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsVsphereGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
9 changes: 4 additions & 5 deletions client/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ func Ptr[T any](v T) *T {
return &v
}

func Handle404(err error) error {
// Is404 returns a boolean indicating whether an error is a 404 error.
func Is404(err error) bool {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil
} else if err != nil {
return err
return true
}
return nil
return false
}

func ToV1ErrorObj(err interface{}) *models.V1Error {
Expand Down
8 changes: 6 additions & 2 deletions client/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) {
params := clientV1.NewV1AppDeploymentsUIDGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1AppDeploymentsUIDGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand All @@ -23,7 +25,9 @@ func (h *V1Client) SearchAppDeploymentSummaries(filter *models.V1AppDeploymentFi
Sort: sortBy,
})
resp, err := h.Client.V1DashboardAppDeployments(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.AppDeployments, nil
Expand Down
16 changes: 6 additions & 10 deletions client/application_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/pkg/errors"

"github.com/spectrocloud/palette-api-go/apiutil/transport"
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
Expand Down Expand Up @@ -48,7 +47,9 @@ func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]*
params := clientV1.NewV1AppProfilesUIDTiersGetParamsWithContext(h.ctx).
WithUID(applicationProfileUID)
resp, err := h.Client.V1AppProfilesUIDTiersGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.Spec.AppTiers, nil
Expand All @@ -60,8 +61,7 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI
WithTierUID(tierUID).
WithManifestUID(manifestUID)
resp, err := h.Client.V1AppProfilesUIDTiersUIDManifestsUIDGet(params)
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
if apiutil.Is404(err) {
return "", nil
} else if err != nil {
return "", err
Expand All @@ -83,8 +83,7 @@ func (h *V1Client) SearchAppProfileSummaries(filter *models.V1AppProfileFilterSp
params.Offset = &resp.Payload.Listmeta.Offset
}
resp, err = h.Client.V1DashboardAppProfiles(params)
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
Expand Down Expand Up @@ -131,11 +130,8 @@ func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string,
WithTierUID(tierUID).
WithBody(appTier)
_, err := h.Client.V1AppProfilesUIDTiersUIDUpdate(params)
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
if apiutil.Is404(err) {
return nil
} else if err != nil {
return err
}
return err
}
Expand Down
26 changes: 15 additions & 11 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func (h *V1Client) GetCluster(uid string) (*models.V1SpectroCluster, error) {
return cluster, nil
}

func (h *V1Client) GetClusterWithoutStatus(uid string) (*models.V1SpectroCluster, error) {
params := clientV1.NewV1SpectroClustersGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1SpectroClustersGet(params)
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
}

func (h *V1Client) GetClusterByName(name string, virtual bool) (*models.V1SpectroCluster, error) {
filters := []*models.V1SearchFilterItem{clusterNameEqFilter(name)}
clusterSummaries, err := h.SearchClusterSummaries(getClusterFilter(filters, virtual), nil)
Expand Down Expand Up @@ -77,22 +89,14 @@ func (h *V1Client) SearchClusterSummaries(filter *models.V1SearchFilterSpec, sor
Sort: sort,
})
resp, err := h.Client.V1SpectroClustersSearchFilterSummary(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.Items, nil
}

func (h *V1Client) GetClusterWithoutStatus(uid string) (*models.V1SpectroCluster, error) {
params := clientV1.NewV1SpectroClustersGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1SpectroClustersGet(params)
if err != nil {
return nil, err
}
return resp.Payload, nil
}

func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) {
builder := &strings.Builder{}
params := clientV1.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.ctx).
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (h *V1Client) GetCloudConfigAks(configUid string) (*models.V1AzureCloudConf
params := clientV1.NewV1CloudConfigsAksGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsAksGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigAws(configUid string) (*models.V1AwsCloudConfig
params := clientV1.NewV1CloudConfigsAwsGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsAwsGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigAzure(configUid string) (*models.V1AzureCloudCo
params := clientV1.NewV1CloudConfigsAzureGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsAzureGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigEdge(configUid string) (*models.V1EdgeCloudConf
params := clientV1.NewV1CloudConfigsEdgeGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsEdgeGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func (h *V1Client) GetCloudConfigEdgeNative(configUid string) (*models.V1EdgeNat
params := clientV1.NewV1CloudConfigsEdgeNativeGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsEdgeNativeGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_edge_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigEdgeVsphere(configUid string) (*models.V1Vspher
params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsVsphereGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func (h *V1Client) GetCloudConfigEks(configUid string) (*models.V1EksCloudConfig
params := clientV1.NewV1CloudConfigsEksGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsEksGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigGcp(configUid string) (*models.V1GcpCloudConfig
params := clientV1.NewV1CloudConfigsGcpGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsGcpGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
12 changes: 9 additions & 3 deletions client/cluster_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (h *V1Client) GetClusterGroupWithoutStatus(uid string) (*models.V1ClusterGr
params := clientV1.NewV1ClusterGroupsUIDGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1ClusterGroupsUIDGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down Expand Up @@ -81,7 +83,9 @@ func (h *V1Client) GetClusterGroupMetadata() ([]*models.V1ObjectScopeEntity, err
func (h *V1Client) GetClusterGroupSummaries() ([]*models.V1ClusterGroupSummary, error) {
params := clientV1.NewV1ClusterGroupsHostClusterSummaryParamsWithContext(h.ctx)
resp, err := h.Client.V1ClusterGroupsHostClusterSummary(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.Summaries, nil
Expand Down Expand Up @@ -120,7 +124,9 @@ func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupUid string, cl
func (h *V1Client) getClusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) {
params := clientV1.NewV1ClusterGroupsHostClusterMetadataParamsWithContext(h.ctx)
resp, err := h.Client.V1ClusterGroupsHostClusterMetadata(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload.Items, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigLibvirt(configUid string) (*models.V1LibvirtClo
params := clientV1.NewV1CloudConfigsLibvirtGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsLibvirtGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (h *V1Client) GetCloudConfigMaas(configUid string) (*models.V1MaasCloudConf
params := clientV1.NewV1CloudConfigsMaasGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsMaasGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func (h *V1Client) GetClusterProfile(uid string) (*models.V1ClusterProfile, erro
params := clientV1.NewV1ClusterProfilesGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1ClusterProfilesGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
4 changes: 3 additions & 1 deletion client/cluster_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (h *V1Client) GetCloudConfigTke(configUid string) (*models.V1TencentCloudCo
params := clientV1.NewV1CloudConfigsTkeGetParamsWithContext(h.ctx).
WithConfigUID(configUid)
resp, err := h.Client.V1CloudConfigsTkeGet(params)
if err := apiutil.Handle404(err); err != nil {
if apiutil.Is404(err) {
return nil, nil
} else if err != nil {
return nil, err
}
return resp.Payload, nil
Expand Down
Loading

0 comments on commit 463f908

Please sign in to comment.