From 6997893fcc19d566e2e90b58d5c2632478ee3e59 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Mon, 1 Apr 2024 17:43:03 -0600 Subject: [PATCH 01/15] PLT-1035: replace hapi w/ palette-api-go (#87) * refactor: replace hapi w/ palette-api-go Signed-off-by: Tyler Gillson * chore: drop support for 2.6 projects list Signed-off-by: Tyler Gillson * chore: replace V1WorkspacesUIDResourceAllocationsUpdate w/ V1WorkspacesUIDClusterNamespacesUpdate Signed-off-by: Tyler Gillson * chore: revert to previous Validate logic Signed-off-by: Tyler Gillson * refactor: add edge APIs; tidy client Signed-off-by: Tyler Gillson * refactor: remove scope Signed-off-by: Tyler Gillson * chore: update palette-api-go Signed-off-by: Tyler Gillson * chore: fix error casing Signed-off-by: Tyler Gillson * chore: update to latest palette-api-go release Signed-off-by: Tyler Gillson * feat: add client.Clone Signed-off-by: Tyler Gillson * feat: add JWT transport Signed-off-by: Tyler Gillson * refactor: tidy lingering scope Signed-off-by: Tyler Gillson * chore: remove hapi Signed-off-by: Tyler Gillson * chore: use latest palette-api-go Signed-off-by: Tyler Gillson --------- Signed-off-by: Tyler Gillson --- client/account.go | 40 +-- client/account_aws.go | 100 +++---- client/account_azure.go | 99 +++---- client/account_coxedge.go | 79 ------ client/account_custom_cloud.go | 134 +++------ client/account_gcp.go | 81 ++---- client/account_maas.go | 108 +++---- client/account_openstack.go | 107 +++---- client/account_tke.go | 81 ++---- client/account_vsphere.go | 112 +++----- client/addon_deployment_update.go | 76 +++-- client/alert.go | 59 ++-- client/apiutil/apiutil.go | 70 +++++ client/appliance.go | 206 +++++++++++--- client/application.go | 83 +++--- client/application_profile.go | 200 +++++-------- client/backup_storage_location.go | 64 ++--- client/client.go | 264 +++++++----------- client/cluster.go | 377 ++++++++++--------------- client/cluster_aks.go | 121 +++----- client/cluster_aws.go | 125 +++------ client/cluster_azure.go | 129 +++------ client/cluster_backup_config.go | 72 ++--- client/cluster_coxedge.go | 110 -------- client/cluster_custom_cloud.go | 155 +++-------- client/cluster_edge.go | 117 +++----- client/cluster_edge_native.go | 178 +++++++----- client/cluster_edge_vsphere.go | 128 +++------ client/cluster_eks.go | 136 +++------ client/cluster_gcp.go | 128 +++------ client/cluster_group.go | 215 ++++---------- client/cluster_host_config.go | 32 +-- client/cluster_libvirt.go | 118 +++----- client/cluster_location_config.go | 41 +-- client/cluster_maas.go | 127 +++------ client/cluster_metadata_config.go | 35 +-- client/cluster_namespace_config.go | 48 ++-- client/cluster_openstack.go | 120 +++----- client/cluster_ospatch_config.go | 19 +- client/cluster_profile.go | 254 +++++++++++------ client/cluster_profile_import.go | 40 +-- client/cluster_rbac_config.go | 72 ++--- client/cluster_scan_config.go | 69 ++--- client/cluster_tke.go | 117 +++----- client/cluster_virtual.go | 92 +++--- client/cluster_vsphere.go | 171 ++++-------- client/constants.go | 10 + client/datavolume.go | 79 ++---- client/events.go | 20 +- client/filter.go | 55 ++-- client/herr/errors.go | 2 +- client/herr/errors_test.go | 6 +- client/macro.go | 113 ++++---- client/macros.go | 99 +++---- client/management.go | 20 -- client/node_actions.go | 418 +++++++++------------------- client/organization.go | 73 +---- client/pack.go | 106 +++---- client/private_cloud_gateway.go | 208 +++++++------- client/project.go | 84 ++---- client/registry.go | 183 +++++------- client/role.go | 10 +- client/search.go | 217 +-------------- client/ssh_key.go | 109 ++------ client/team.go | 137 ++++----- client/tenant.go | 10 +- client/types.go | 5 - client/user.go | 18 +- client/virtual_machine.go | 104 +++---- client/virtual_machine_clone.go | 38 +-- client/virtual_machine_common.go | 54 ++-- client/virtual_machine_lifecycle.go | 164 ++++------- client/virtual_machine_migration.go | 33 +-- client/virtual_machine_snapshot.go | 1 - client/workspace.go | 98 +++---- go.mod | 36 +-- go.sum | 245 +++++----------- 77 files changed, 2940 insertions(+), 5124 deletions(-) delete mode 100644 client/account_coxedge.go create mode 100644 client/apiutil/apiutil.go delete mode 100644 client/cluster_coxedge.go create mode 100644 client/constants.go delete mode 100644 client/management.go delete mode 100644 client/types.go delete mode 100644 client/virtual_machine_snapshot.go diff --git a/client/account.go b/client/account.go index bd0fe66c..c76e3e64 100644 --- a/client/account.go +++ b/client/account.go @@ -1,48 +1,32 @@ package client import ( - "errors" "fmt" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) ListCloudAccounts(scope string) ([]*models.V1CloudAccountSummary, error) { - 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 := h.GetClusterClient().V1CloudAccountsListSummary(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } - return resp.Payload.Items, nil } -func (h *V1Client) GetCloudAccount(scope, id string) (*models.V1CloudAccountSummary, error) { - accounts, err := h.ListCloudAccounts(scope) +func (h *V1Client) GetCloudAccount(uid string) (*models.V1CloudAccountSummary, error) { + accounts, err := h.ListCloudAccounts() if err != nil { return nil, err } - for _, account := range accounts { - if account.Metadata.UID == id { + if account.Metadata.UID == uid { return account, nil } } - - return nil, fmt.Errorf("account not found with id %s", id) + return nil, fmt.Errorf("account not found with uid %s", uid) } diff --git a/client/account_aws.go b/client/account_aws.go index 97cec4fa..1f887d21 100644 --- a/client/account_aws.go +++ b/client/account_aws.go @@ -1,12 +1,9 @@ package client import ( - "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" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func toV1AwsCloudAccount(account *models.V1AwsAccount) *models.V1AwsCloudAccount { @@ -20,99 +17,68 @@ func toV1AwsCloudAccount(account *models.V1AwsAccount) *models.V1AwsCloudAccount } } -func (h *V1Client) CreateCloudAccountAws(account *models.V1AwsAccount, AccountContext string) (string, error) { - // validate account - if err := validateCloudAccountAws(account, h); err != nil { +func (h *V1Client) CreateCloudAccountAws(account *models.V1AwsAccount) (string, error) { + if err := h.validateCloudAccountAws(account); err != nil { return "", err } + params := clientV1.NewV1CloudAccountsAwsCreateParamsWithContext(h.ctx). + WithBody(account) - var params *clusterC.V1CloudAccountsAwsCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAwsCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsAwsCreateParams().WithBody(account) - } - - success, err := h.GetClusterClient().V1CloudAccountsAwsCreate(params) + resp, err := h.Client.V1CloudAccountsAwsCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func validateCloudAccountAws(account *models.V1AwsAccount, h *V1Client) error { +func (h *V1Client) validateCloudAccountAws(account *models.V1AwsAccount) error { // check PCG if err := h.CheckPCG(account.Metadata.Annotations[OverlordUID]); err != nil { return err } // validate account - paramsValidate := cloudC.NewV1AwsAccountValidateParams() - paramsValidate = paramsValidate.WithAwsCloudAccount(toV1AwsCloudAccount(account)) - _, err := h.GetCloudClient().V1AwsAccountValidate(paramsValidate) - if err != nil { - return err - } + params := clientV1.NewV1AwsAccountValidateParamsWithContext(h.ctx). + WithAwsCloudAccount(toV1AwsCloudAccount(account)) - return nil + _, err := h.Client.V1AwsAccountValidate(params) + return err } func (h *V1Client) UpdateCloudAccountAws(account *models.V1AwsAccount) error { - // validate account - if err := validateCloudAccountAws(account, h); err != nil { + if err := h.validateCloudAccountAws(account); err != nil { return err } - - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsAwsUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsAwsUpdate(params) + params := clientV1.NewV1CloudAccountsAwsUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + _, err := h.Client.V1CloudAccountsAwsUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountAws(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsAwsDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAwsDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsAwsDeleteParams().WithUID(uid) - } - _, err := h.GetClusterClient().V1CloudAccountsAwsDelete(params) +func (h *V1Client) DeleteCloudAccountAws(uid string) error { + params := clientV1.NewV1CloudAccountsAwsDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsAwsDelete(params) return err } -func (h *V1Client) GetCloudAccountAws(uid, AccountContext string) (*models.V1AwsAccount, error) { - var params *clusterC.V1CloudAccountsAwsGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAwsGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsAwsGetParams().WithUID(uid) - } - success, err := h.GetClusterClient().V1CloudAccountsAwsGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsAws() ([]*models.V1AwsAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsAwsListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsAwsList(params) + params := clientV1.NewV1CloudAccountsAwsListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsAwsList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1AwsAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_azure.go b/client/account_azure.go index 27758b87..84863c38 100644 --- a/client/account_azure.go +++ b/client/account_azure.go @@ -1,12 +1,9 @@ package client import ( - "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" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func toV1AzureCloudAccount(account *models.V1AzureAccount) *models.V1AzureCloudAccount { @@ -20,100 +17,72 @@ func toV1AzureCloudAccount(account *models.V1AzureAccount) *models.V1AzureCloudA } } -func (h *V1Client) CreateCloudAccountAzure(account *models.V1AzureAccount, AccountContext string) (string, error) { +func (h *V1Client) CreateCloudAccountAzure(account *models.V1AzureAccount) (string, error) { // validate account - if err := validateCloudAccountAzure(account, h); err != nil { + if err := h.validateCloudAccountAzure(account); err != nil { return "", err } - var params *clusterC.V1CloudAccountsAzureCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAzureCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsAzureCreateParams().WithBody(account) - } - success, err := h.GetClusterClient().V1CloudAccountsAzureCreate(params) + params := clientV1.NewV1CloudAccountsAzureCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsAzureCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func validateCloudAccountAzure(account *models.V1AzureAccount, h *V1Client) error { +func (h *V1Client) validateCloudAccountAzure(account *models.V1AzureAccount) error { // check PCG if err := h.CheckPCG(account.Metadata.Annotations[OverlordUID]); err != nil { return err } // validate account - paramsValidate := cloudC.NewV1AzureAccountValidateParams() - paramsValidate = paramsValidate.WithAzureCloudAccount(toV1AzureCloudAccount(account)) - - _, err := h.GetCloudClient().V1AzureAccountValidate(paramsValidate) - if err != nil { - return err - } + params := clientV1.NewV1AzureAccountValidateParamsWithContext(h.ctx). + WithAzureCloudAccount(toV1AzureCloudAccount(account)) - return nil + _, err := h.Client.V1AzureAccountValidate(params) + return err } func (h *V1Client) UpdateCloudAccountAzure(account *models.V1AzureAccount) error { // validate account - if err := validateCloudAccountAzure(account, h); err != nil { + if err := h.validateCloudAccountAzure(account); err != nil { return err } - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsAzureUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsAzureUpdate(params) + params := clientV1.NewV1CloudAccountsAzureUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + + _, err := h.Client.V1CloudAccountsAzureUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountAzure(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsAzureDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAzureDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsAzureDeleteParams().WithUID(uid) - } - _, err := h.GetClusterClient().V1CloudAccountsAzureDelete(params) +func (h *V1Client) DeleteCloudAccountAzure(uid string) error { + params := clientV1.NewV1CloudAccountsAzureDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsAzureDelete(params) return err } -func (h *V1Client) GetCloudAccountAzure(uid, AccountContext string) (*models.V1AzureAccount, error) { - var params *clusterC.V1CloudAccountsAzureGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsAzureGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsAzureGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsAzureGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, error) { + params := clientV1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1CloudAccountsAzureGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsAzure() ([]*models.V1AzureAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsAzureListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsAzureList(params) + params := clientV1.NewV1CloudAccountsAzureListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsAzureList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1AzureAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_coxedge.go b/client/account_coxedge.go deleted file mode 100644 index a5efaf66..00000000 --- a/client/account_coxedge.go +++ /dev/null @@ -1,79 +0,0 @@ -package client - -import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" -) - -func (h *V1Client) CreateCloudAccountCoxEdge(account *models.V1CoxEdgeAccount, AccountContext string) (string, error) { - var params *clusterC.V1CloudAccountsCoxEdgeCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsCoxEdgeCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsCoxEdgeCreateParams().WithBody(account) - } - success, err := h.GetClusterClient().V1CloudAccountsCoxEdgeCreate(params) - if err != nil { - return "", err - } - - return *success.Payload.UID, nil -} - -func (h *V1Client) UpdateCloudAccountCoxEdge(account *models.V1CoxEdgeAccount) error { - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsCoxEdgeUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsCoxEdgeUpdate(params) - return err -} - -func (h *V1Client) DeleteCloudAccountCoxEdge(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsCoxEdgeDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsCoxEdgeDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsCoxEdgeDeleteParams().WithUID(uid) - } - _, err := h.GetClusterClient().V1CloudAccountsCoxEdgeDelete(params) - return err -} - -func (h *V1Client) GetCloudAccountCoxEdge(uid, AccountContext string) (*models.V1CoxEdgeAccount, error) { - var params *clusterC.V1CloudAccountsCoxEdgeGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsCoxEdgeGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsCoxEdgeGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsCoxEdgeGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { - return nil, err - } - - return success.Payload, nil -} - -func (h *V1Client) GetCloudAccountsCoxEdge() ([]*models.V1CoxEdgeAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsCoxEdgeListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsCoxEdgeList(params) - if err != nil { - return nil, err - } - - accounts := make([]*models.V1CoxEdgeAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil -} diff --git a/client/account_custom_cloud.go b/client/account_custom_cloud.go index f779d09b..5bff3f23 100644 --- a/client/account_custom_cloud.go +++ b/client/account_custom_cloud.go @@ -2,112 +2,62 @@ package client import ( "fmt" - cloudC "github.com/spectrocloud/hapi/cloud/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" -) -func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntity, cloudType string, accountContext string) (string, error) { - if h.CreateCustomCloudAccountFn != nil { - return h.CreateCustomCloudAccountFn(account, cloudType, accountContext) - } - var params *clusterC.V1CloudAccountsCustomCreateParams + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" +) - // check PCG - PcgId := account.Metadata.Annotations[OverlordUID] - if err := h.CheckPCG(PcgId); err != nil { +func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntity, cloudType string) (string, error) { + pcgId := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgId); err != nil { return "", err } - switch accountContext { - case "project": - params = clusterC.NewV1CloudAccountsCustomCreateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudAccountsCustomCreateParams() - } - params = params.WithBody(account).WithCloudType(cloudType) - success, err := h.GetClusterClient().V1CloudAccountsCustomCreate(params) + params := clientV1.NewV1CloudAccountsCustomCreateParamsWithContext(h.ctx). + WithBody(account). + WithCloudType(cloudType) + resp, err := h.Client.V1CloudAccountsCustomCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetCustomCloudAccount(uid, cloudType string, accountContext string) (*models.V1CustomAccount, error) { - if h.GetCustomCloudAccountFn != nil { - return h.GetCustomCloudAccountFn(uid, cloudType, accountContext) - } - var params *clusterC.V1CloudAccountsCustomGetParams - - switch accountContext { - case "project": - params = clusterC.NewV1CloudAccountsCustomGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudAccountsCustomGetParams() - } - params = params.WithCloudType(cloudType).WithUID(uid) - success, err := h.GetClusterClient().V1CloudAccountsCustomGet(params) +func (h *V1Client) GetCustomCloudAccount(uid, cloudType string) (*models.V1CustomAccount, error) { + params := clientV1.NewV1CloudAccountsCustomGetParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithUID(uid) + resp, err := h.Client.V1CloudAccountsCustomGet(params) if err != nil { return nil, err } - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1CustomAccountEntity, cloudType string, accountContext string) error { - if h.UpdateCustomCloudAccountFn != nil { - return h.UpdateCustomCloudAccountFn(uid, account, cloudType, accountContext) - } - var params *clusterC.V1CloudAccountsCustomUpdateParams - - switch accountContext { - case "project": - params = clusterC.NewV1CloudAccountsCustomUpdateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudAccountsCustomUpdateParams() - } - params = params.WithBody(account).WithCloudType(cloudType).WithUID(uid) - _, err := h.GetClusterClient().V1CloudAccountsCustomUpdate(params) - if err != nil { - return err - } - - return nil +func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1CustomAccountEntity, cloudType string) error { + params := clientV1.NewV1CloudAccountsCustomUpdateParamsWithContext(h.ctx). + WithBody(account). + WithCloudType(cloudType). + WithUID(uid) + _, err := h.Client.V1CloudAccountsCustomUpdate(params) + return err } -func (h *V1Client) DeleteCloudAccountCustomCloud(uid, cloudType string, accountContext string) error { - if h.DeleteCustomCloudAccountFn != nil { - return h.DeleteCustomCloudAccountFn(uid, cloudType, accountContext) - } - var params *clusterC.V1CloudAccountsCustomDeleteParams - - switch accountContext { - case "project": - params = clusterC.NewV1CloudAccountsCustomDeleteParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudAccountsCustomDeleteParams() - } - params = params.WithCloudType(cloudType).WithUID(uid) - _, err := h.GetClusterClient().V1CloudAccountsCustomDelete(params) +func (h *V1Client) DeleteCloudAccountCustomCloud(uid, cloudType string) error { + params := clientV1.NewV1CloudAccountsCustomDeleteParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithUID(uid) + _, err := h.Client.V1CloudAccountsCustomDelete(params) return err } -func (h *V1Client) ValidateCustomCloudType(cloudType string, cloudContext string) error { - if h.ValidateCustomCloudTypeFn != nil { - return h.ValidateCustomCloudTypeFn(cloudType, cloudContext) - } - var params *cloudC.V1CustomCloudTypesGetParams - switch cloudContext { - case "project": - params = cloudC.NewV1CustomCloudTypesGetParamsWithContext(h.Ctx) - case "tenant": - params = cloudC.NewV1CustomCloudTypesGetParams() - } - success, err := h.GetCloudClient().V1CustomCloudTypesGet(params) +func (h *V1Client) ValidateCustomCloudType(cloudType string) error { + params := clientV1.NewV1CustomCloudTypesGetParamsWithContext(h.ctx) + resp, err := h.Client.V1CustomCloudTypesGet(params) if err != nil { return err } - customCloudTypes := success.GetPayload().CloudTypes - for _, c := range customCloudTypes { + for _, c := range resp.GetPayload().CloudTypes { if c.Name == cloudType { if c.IsCustom { return nil @@ -120,18 +70,12 @@ func (h *V1Client) ValidateCustomCloudType(cloudType string, cloudContext string } func (h *V1Client) GetCustomCloudAccountList(cloudType string) ([]*models.V1CustomAccount, error) { - if h.GetCustomCloudAccountListFn != nil { - return h.GetCustomCloudAccountListFn(cloudType) - } - limit := int64(0) - params := clusterC.NewV1CloudAccountsCustomListParamsWithContext(h.Ctx).WithLimit(&limit).WithCloudType(cloudType) - response, err := h.GetClusterClient().V1CloudAccountsCustomList(params) + params := clientV1.NewV1CloudAccountsCustomListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))). + WithCloudType(cloudType) + resp, err := h.Client.V1CloudAccountsCustomList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1CustomAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_gcp.go b/client/account_gcp.go index 118f1bb5..069c853a 100644 --- a/client/account_gcp.go +++ b/client/account_gcp.go @@ -1,81 +1,52 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity, AccountContext string) (string, error) { - var params *clusterC.V1CloudAccountsGcpCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsGcpCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsGcpCreateParams().WithBody(account) - } - - success, err := h.GetClusterClient().V1CloudAccountsGcpCreate(params) +func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (string, error) { + params := clientV1.NewV1CloudAccountsGcpCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsGcpCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) UpdateCloudAccountGcp(account *models.V1GcpAccountEntity) error { - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsGcpUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsGcpUpdate(params) + params := clientV1.NewV1CloudAccountsGcpUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + _, err := h.Client.V1CloudAccountsGcpUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountGcp(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsGcpDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsGcpDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsGcpDeleteParams().WithUID(uid) - } - - _, err := h.GetClusterClient().V1CloudAccountsGcpDelete(params) +func (h *V1Client) DeleteCloudAccountGcp(uid string) error { + params := clientV1.NewV1CloudAccountsGcpDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsGcpDelete(params) return err } -func (h *V1Client) GetCloudAccountGcp(uid, AccountContext string) (*models.V1GcpAccount, error) { - var params *clusterC.V1CloudAccountsGcpGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsGcpGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsGcpGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsGcpGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsGcp() ([]*models.V1GcpAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsGcpListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsGcpList(params) + params := clientV1.NewV1CloudAccountsGcpListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsGcpList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1GcpAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_maas.go b/client/account_maas.go index 9103f47b..360448bc 100644 --- a/client/account_maas.go +++ b/client/account_maas.go @@ -1,115 +1,85 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func toV1OverlordsUIDMaasAccountValidateBody(account *models.V1MaasAccount) clusterC.V1OverlordsUIDMaasAccountValidateBody { - return clusterC.V1OverlordsUIDMaasAccountValidateBody{ +func toV1OverlordsUIDMaasAccountValidateBody(account *models.V1MaasAccount) clientV1.V1OverlordsUIDMaasAccountValidateBody { + return clientV1.V1OverlordsUIDMaasAccountValidateBody{ Account: account.Spec, } } -func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount, AccountContext string) (string, error) { +func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount) (string, error) { // validate account - if err := validateCloudAccountMaas(account, h); err != nil { + if err := h.validateCloudAccountMaas(account); err != nil { return "", err } - var params *clusterC.V1CloudAccountsMaasCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsMaasCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsMaasCreateParams().WithBody(account) - } - - success, err := h.GetClusterClient().V1CloudAccountsMaasCreate(params) + params := clientV1.NewV1CloudAccountsMaasCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsMaasCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func validateCloudAccountMaas(account *models.V1MaasAccount, h *V1Client) error { - PcgId := account.Metadata.Annotations[OverlordUID] +func (h *V1Client) validateCloudAccountMaas(account *models.V1MaasAccount) error { // check PCG - if err := h.CheckPCG(PcgId); err != nil { + pcgId := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgId); err != nil { return err } // validate account - paramsValidate := clusterC.NewV1OverlordsUIDMaasAccountValidateParams().WithUID(PcgId) - paramsValidate = paramsValidate.WithBody(toV1OverlordsUIDMaasAccountValidateBody(account)) - _, err := h.GetClusterClient().V1OverlordsUIDMaasAccountValidate(paramsValidate) - if err != nil { - return err - } + params := clientV1.NewV1OverlordsUIDMaasAccountValidateParamsWithContext(h.ctx). + WithUID(pcgId). + WithBody(toV1OverlordsUIDMaasAccountValidateBody(account)) - return nil + _, err := h.Client.V1OverlordsUIDMaasAccountValidate(params) + return err } func (h *V1Client) UpdateCloudAccountMaas(account *models.V1MaasAccount) error { // validate account - if err := validateCloudAccountMaas(account, h); err != nil { + if err := h.validateCloudAccountMaas(account); err != nil { return err } - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsMaasUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsMaasUpdate(params) + params := clientV1.NewV1CloudAccountsMaasUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + + _, err := h.Client.V1CloudAccountsMaasUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountMaas(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsMaasDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsMaasDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsMaasDeleteParams().WithUID(uid) - } - - _, err := h.GetClusterClient().V1CloudAccountsMaasDelete(params) +func (h *V1Client) DeleteCloudAccountMaas(uid string) error { + params := clientV1.NewV1CloudAccountsMaasDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsMaasDelete(params) return err } -func (h *V1Client) GetCloudAccountMaas(uid, AccountContext string) (*models.V1MaasAccount, error) { - var params *clusterC.V1CloudAccountsMaasGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsMaasGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsMaasGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsMaasGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsMaas() ([]*models.V1MaasAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsMaasListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsMaasList(params) + params := clientV1.NewV1CloudAccountsMaasListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + response, err := h.Client.V1CloudAccountsMaasList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1MaasAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return response.Payload.Items, nil } diff --git a/client/account_openstack.go b/client/account_openstack.go index 143f4e2d..c59513c7 100644 --- a/client/account_openstack.go +++ b/client/account_openstack.go @@ -1,114 +1,83 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func toV1OverlordsUIDOpenStackAccountValidateBody(account *models.V1OpenStackAccount) clusterC.V1OverlordsUIDOpenStackAccountValidateBody { - return clusterC.V1OverlordsUIDOpenStackAccountValidateBody{ +func toV1OverlordsUIDOpenStackAccountValidateBody(account *models.V1OpenStackAccount) clientV1.V1OverlordsUIDOpenStackAccountValidateBody { + return clientV1.V1OverlordsUIDOpenStackAccountValidateBody{ Account: account.Spec, } } -func (h *V1Client) CreateCloudAccountOpenStack(account *models.V1OpenStackAccount, AccountContext string) (string, error) { +func (h *V1Client) CreateCloudAccountOpenStack(account *models.V1OpenStackAccount) (string, error) { // validate account - if err := validateCloudAccountOpenStack(account, h); err != nil { + if err := h.validateCloudAccountOpenStack(account); err != nil { return "", err } - var params *clusterC.V1CloudAccountsOpenStackCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsOpenStackCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsOpenStackCreateParams().WithBody(account) - } - - success, err := h.GetClusterClient().V1CloudAccountsOpenStackCreate(params) + params := clientV1.NewV1CloudAccountsOpenStackCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsOpenStackCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func validateCloudAccountOpenStack(account *models.V1OpenStackAccount, h *V1Client) error { - PcgId := account.Metadata.Annotations[OverlordUID] +func (h *V1Client) validateCloudAccountOpenStack(account *models.V1OpenStackAccount) error { // check PCG - if err := h.CheckPCG(PcgId); err != nil { + pcgId := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgId); err != nil { return err } // validate account - paramsValidate := clusterC.NewV1OverlordsUIDOpenStackAccountValidateParams().WithUID(PcgId) - paramsValidate = paramsValidate.WithBody(toV1OverlordsUIDOpenStackAccountValidateBody(account)) - _, err := h.GetClusterClient().V1OverlordsUIDOpenStackAccountValidate(paramsValidate) - if err != nil { - return err - } + params := clientV1.NewV1OverlordsUIDOpenStackAccountValidateParamsWithContext(h.ctx). + WithUID(pcgId). + WithBody(toV1OverlordsUIDOpenStackAccountValidateBody(account)) - return nil + _, err := h.Client.V1OverlordsUIDOpenStackAccountValidate(params) + return err } func (h *V1Client) UpdateCloudAccountOpenStack(account *models.V1OpenStackAccount) error { - if err := validateCloudAccountOpenStack(account, h); err != nil { + if err := h.validateCloudAccountOpenStack(account); err != nil { return err } - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsOpenStackUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsOpenStackUpdate(params) + params := clientV1.NewV1CloudAccountsOpenStackUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + _, err := h.Client.V1CloudAccountsOpenStackUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountOpenStack(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsOpenStackDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsOpenStackDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsOpenStackDeleteParams().WithUID(uid) - } - - _, err := h.GetClusterClient().V1CloudAccountsOpenStackDelete(params) +func (h *V1Client) DeleteCloudAccountOpenStack(uid string) error { + params := clientV1.NewV1CloudAccountsOpenStackDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsOpenStackDelete(params) return err } -func (h *V1Client) GetCloudAccountOpenStack(uid, AccountContext string) (*models.V1OpenStackAccount, error) { - var params *clusterC.V1CloudAccountsOpenStackGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsOpenStackGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsOpenStackGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsOpenStackGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudAccountOpenStack(uid string) (*models.V1OpenStackAccount, error) { + params := clientV1.NewV1CloudAccountsOpenStackGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1CloudAccountsOpenStackGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsOpenStack() ([]*models.V1OpenStackAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsOpenStackListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsOpenStackList(params) + params := clientV1.NewV1CloudAccountsOpenStackListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsOpenStackList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1OpenStackAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_tke.go b/client/account_tke.go index f1c2be20..cdff5082 100644 --- a/client/account_tke.go +++ b/client/account_tke.go @@ -1,81 +1,52 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateCloudAccountTke(account *models.V1TencentAccount, AccountContext string) (string, error) { - var params *clusterC.V1CloudAccountsTencentCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsTencentCreateParamsWithContext(h.Ctx).WithBody(account) - case "tenant": - params = clusterC.NewV1CloudAccountsTencentCreateParams().WithBody(account) - } - - success, err := h.GetClusterClient().V1CloudAccountsTencentCreate(params) +func (h *V1Client) CreateCloudAccountTke(account *models.V1TencentAccount) (string, error) { + params := clientV1.NewV1CloudAccountsTencentCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsTencentCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) UpdateCloudAccountTencent(account *models.V1TencentAccount) error { - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsTencentUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsTencentUpdate(params) + params := clientV1.NewV1CloudAccountsTencentUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + _, err := h.Client.V1CloudAccountsTencentUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountTke(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsTencentDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsTencentDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsTencentDeleteParams().WithUID(uid) - } - - _, err := h.GetClusterClient().V1CloudAccountsTencentDelete(params) +func (h *V1Client) DeleteCloudAccountTke(uid string) error { + params := clientV1.NewV1CloudAccountsTencentDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsTencentDelete(params) return err } -func (h *V1Client) GetCloudAccountTke(uid, AccountContext string) (*models.V1TencentAccount, error) { - var params *clusterC.V1CloudAccountsTencentGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsTencentGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsTencentGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsTencentGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudAccountTke(uid string) (*models.V1TencentAccount, error) { + params := clientV1.NewV1CloudAccountsTencentGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1CloudAccountsTencentGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsTke() ([]*models.V1TencentAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsTencentListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsTencentList(params) + params := clientV1.NewV1CloudAccountsTencentListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsTencentList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1TencentAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/account_vsphere.go b/client/account_vsphere.go index 59d80956..be1dfd0a 100644 --- a/client/account_vsphere.go +++ b/client/account_vsphere.go @@ -1,120 +1,86 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -const OverlordUID = "overlordUid" - // convert V1VsphereAccount to V1OverlordVsphereAccountEntity -func toV1OverlordsUIDVsphereAccountValidateBody(account *models.V1VsphereAccount) clusterC.V1OverlordsUIDVsphereAccountValidateBody { - return clusterC.V1OverlordsUIDVsphereAccountValidateBody{ +func toV1OverlordsUIDVsphereAccountValidateBody(account *models.V1VsphereAccount) clientV1.V1OverlordsUIDVsphereAccountValidateBody { + return clientV1.V1OverlordsUIDVsphereAccountValidateBody{ Account: account.Spec, } } -func (h *V1Client) CreateCloudAccountVsphere(account *models.V1VsphereAccount, AccountContext string) (string, error) { +func (h *V1Client) CreateCloudAccountVsphere(account *models.V1VsphereAccount) (string, error) { // validate account - if err := validateCloudAccountVsphere(account, h); err != nil { + if err := h.validateCloudAccountVsphere(account); err != nil { return "", err } // create account - var params *clusterC.V1CloudAccountsVsphereCreateParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsVsphereCreateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudAccountsVsphereCreateParams() - } - - params = params.WithBody(account) - success, err := h.GetClusterClient().V1CloudAccountsVsphereCreate(params) + params := clientV1.NewV1CloudAccountsVsphereCreateParamsWithContext(h.ctx). + WithBody(account) + resp, err := h.Client.V1CloudAccountsVsphereCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func validateCloudAccountVsphere(account *models.V1VsphereAccount, h *V1Client) error { - PcgId := account.Metadata.Annotations[OverlordUID] +func (h *V1Client) validateCloudAccountVsphere(account *models.V1VsphereAccount) error { // check PCG - if err := h.CheckPCG(PcgId); err != nil { + pcgId := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgId); err != nil { return err } // validate account - paramsValidate := clusterC.NewV1OverlordsUIDVsphereAccountValidateParams().WithUID(PcgId) - paramsValidate = paramsValidate.WithBody(toV1OverlordsUIDVsphereAccountValidateBody(account)) - _, err := h.GetClusterClient().V1OverlordsUIDVsphereAccountValidate(paramsValidate) - if err != nil { - return err - } + params := clientV1.NewV1OverlordsUIDVsphereAccountValidateParamsWithContext(h.ctx). + WithUID(pcgId). + WithBody(toV1OverlordsUIDVsphereAccountValidateBody(account)) - return nil + _, err := h.Client.V1OverlordsUIDVsphereAccountValidate(params) + return err } -func (h *V1Client) UpdateCloudAccountVsphere(account *models.V1VsphereAccount, AccountContext string) error { +func (h *V1Client) UpdateCloudAccountVsphere(account *models.V1VsphereAccount) error { // validate account - if err := validateCloudAccountVsphere(account, h); err != nil { + if err := h.validateCloudAccountVsphere(account); err != nil { return err } - uid := account.Metadata.UID - params := clusterC.NewV1CloudAccountsVsphereUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account) - _, err := h.GetClusterClient().V1CloudAccountsVsphereUpdate(params) + params := clientV1.NewV1CloudAccountsVsphereUpdateParamsWithContext(h.ctx). + WithUID(account.Metadata.UID). + WithBody(account) + _, err := h.Client.V1CloudAccountsVsphereUpdate(params) return err } -func (h *V1Client) DeleteCloudAccountVsphere(uid, AccountContext string) error { - var params *clusterC.V1CloudAccountsVsphereDeleteParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsVsphereDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsVsphereDeleteParams().WithUID(uid) - } - - _, err := h.GetClusterClient().V1CloudAccountsVsphereDelete(params) +func (h *V1Client) DeleteCloudAccountVsphere(uid string) error { + params := clientV1.NewV1CloudAccountsVsphereDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1CloudAccountsVsphereDelete(params) return err } -func (h *V1Client) GetCloudAccountVsphere(uid, AccountContext string) (*models.V1VsphereAccount, error) { - var params *clusterC.V1CloudAccountsVsphereGetParams - switch AccountContext { - case "project": - params = clusterC.NewV1CloudAccountsVsphereGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1CloudAccountsVsphereGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1CloudAccountsVsphereGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudAccountVsphere(uid string) (*models.V1VsphereAccount, error) { + params := clientV1.NewV1CloudAccountsVsphereGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1CloudAccountsVsphereGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetCloudAccountsVsphere() ([]*models.V1VsphereAccount, error) { - limit := int64(0) - params := clusterC.NewV1CloudAccountsVsphereListParamsWithContext(h.Ctx).WithLimit(&limit) - response, err := h.GetClusterClient().V1CloudAccountsVsphereList(params) + params := clientV1.NewV1CloudAccountsVsphereListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1CloudAccountsVsphereList(params) if err != nil { return nil, err } - - accounts := make([]*models.V1VsphereAccount, len(response.Payload.Items)) - copy(accounts, response.Payload.Items) - - return accounts, nil + return resp.Payload.Items, nil } diff --git a/client/addon_deployment_update.go b/client/addon_deployment_update.go index 7a35bb5e..4e076eef 100644 --- a/client/addon_deployment_update.go +++ b/client/addon_deployment_update.go @@ -5,11 +5,11 @@ import ( "math/rand" "time" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) UpdateAddonDeployment(client clusterC.ClientService, cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles, newProfile *models.V1ClusterProfile) error { +func (h *V1Client) UpdateAddonDeployment(cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles, newProfile *models.V1ClusterProfile) error { uid := cluster.Metadata.UID // check if profile id is the same - update, otherwise, delete and create @@ -18,18 +18,14 @@ func (h *V1Client) UpdateAddonDeployment(client clusterC.ClientService, cluster body.Profiles[0].ReplaceWithProfile = replaceUID } - resolveNotification := true - var params *clusterC.V1SpectroClustersPatchProfilesParams - scope := cluster.Metadata.Annotations["scope"] - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersPatchProfilesParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersPatchProfilesParams() - } - params = params.WithUID(uid).WithBody(body).WithResolveNotification(&resolveNotification) - err := h.PatchWithRetry(client, params) - return err + resolveNotifications := true + params := clientV1.NewV1SpectroClustersPatchProfilesParams(). + WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUid)). + WithUID(uid). + WithBody(body). + WithResolveNotification(&resolveNotifications) + + return h.PatchWithRetry(params) } func IsProfileAttachedByName(cluster *models.V1SpectroCluster, newProfile *models.V1ClusterProfile) (bool, string) { @@ -41,31 +37,26 @@ func IsProfileAttachedByName(cluster *models.V1SpectroCluster, newProfile *model return false, "" } -func (h *V1Client) CreateAddonDeployment(client clusterC.ClientService, cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles) error { - resolveNotification := false // during initial creation we never need to resolve packs. - var params *clusterC.V1SpectroClustersPatchProfilesParams - scope := cluster.Metadata.Annotations["scope"] - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersPatchProfilesParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersPatchProfilesParams() - } - params = params.WithUID(cluster.Metadata.UID).WithBody(body).WithResolveNotification(&resolveNotification) - err := h.PatchWithRetry(client, params) - return err +func (h *V1Client) CreateAddonDeployment(cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles) error { + resolveNotifications := false // during initial creation we never need to resolve packs + params := clientV1.NewV1SpectroClustersPatchProfilesParams(). + WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUid)). + WithUID(cluster.Metadata.UID). + WithBody(body). + WithResolveNotification(&resolveNotifications) + + return h.PatchWithRetry(params) } -func (h *V1Client) PatchWithRetry(client clusterC.ClientService, params *clusterC.V1SpectroClustersPatchProfilesParams) error { +func (h *V1Client) PatchWithRetry(params *clientV1.V1SpectroClustersPatchProfilesParams) error { var err error - rand.NewSource(time.Now().UnixNano()) - for attempt := 0; attempt < h.RetryAttempts; attempt++ { + for attempt := 0; attempt < h.retryAttempts; attempt++ { // small jitter to prevent simultaneous retries - s := rand.Intn(h.RetryAttempts) // n will be between 0 and number of retries + s := rand.Intn(h.retryAttempts) // n will be between 0 and number of retries log.Printf("Sleeping %d seconds, retry: %d, cluster:%s, profile:%s, ", s, attempt, params.UID, params.Body.Profiles[0].UID) time.Sleep(time.Duration(s) * time.Second) - err = h.ClustersPatchProfiles(client, params) + err = h.ClustersPatchProfiles(params) if err == nil { break } @@ -73,20 +64,15 @@ func (h *V1Client) PatchWithRetry(client clusterC.ClientService, params *cluster return err } -func (h *V1Client) ClustersPatchProfiles(client clusterC.ClientService, params *clusterC.V1SpectroClustersPatchProfilesParams) error { - _, err := client.V1SpectroClustersPatchProfiles(params) +func (h *V1Client) ClustersPatchProfiles(params *clientV1.V1SpectroClustersPatchProfilesParams) error { + _, err := h.Client.V1SpectroClustersPatchProfiles(params) return err } -func (h *V1Client) DeleteAddonDeployment(client clusterC.ClientService, uid, scope string, body *models.V1SpectroClusterProfilesDeleteEntity) error { - var params *clusterC.V1SpectroClustersDeleteProfilesParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersDeleteProfilesParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersDeleteProfilesParams() - } - params = params.WithUID(uid).WithBody(body) - _, err := client.V1SpectroClustersDeleteProfiles(params) +func (h *V1Client) DeleteAddonDeployment(uid string, body *models.V1SpectroClusterProfilesDeleteEntity) error { + params := clientV1.NewV1SpectroClustersDeleteProfilesParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1SpectroClustersDeleteProfiles(params) return err } diff --git a/client/alert.go b/client/alert.go index cda5bf69..164b358c 100644 --- a/client/alert.go +++ b/client/alert.go @@ -1,30 +1,29 @@ package client import ( - "github.com/spectrocloud/hapi/models" - v1 "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) CreateAlert(body *models.V1Channel, projectUID, component string) (string, error) { - if h.CreateAlertFn != nil { - return h.CreateAlertFn(body, projectUID, component) - } - - params := v1.NewV1ProjectsUIDAlertCreateParams().WithBody(body).WithUID(projectUID).WithComponent(component) - success, err := h.GetUserClient().V1ProjectsUIDAlertCreate(params) + params := clientV1.NewV1ProjectsUIDAlertCreateParamsWithContext(h.ctx). + WithBody(body). + WithUID(projectUID). + WithComponent(component) + resp, err := h.Client.V1ProjectsUIDAlertCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) UpdateAlert(body *models.V1Channel, projectUID, component, alertUID string) (string, error) { - if h.UpdateAlertFn != nil { - return h.UpdateAlertFn(body, projectUID, component, alertUID) - } - - params := v1.NewV1ProjectsUIDAlertsUIDUpdateParams().WithBody(body).WithUID(projectUID).WithComponent(component).WithAlertUID(alertUID) - _, err := h.GetUserClient().V1ProjectsUIDAlertsUIDUpdate(params) + params := clientV1.NewV1ProjectsUIDAlertsUIDUpdateParamsWithContext(h.ctx). + WithBody(body). + WithUID(projectUID). + WithComponent(component). + WithAlertUID(alertUID) + _, err := h.Client.V1ProjectsUIDAlertsUIDUpdate(params) if err != nil { return "", err } @@ -33,29 +32,23 @@ func (h *V1Client) UpdateAlert(body *models.V1Channel, projectUID, component, al } func (h *V1Client) ReadAlert(projectUID, component, alertUID string) (*models.V1Channel, error) { - if h.ReadAlertFn != nil { - return h.ReadAlertFn(projectUID, component, alertUID) - } - - params := v1.NewV1ProjectsUIDAlertsUIDGetParams().WithUID(projectUID).WithComponent(component).WithAlertUID(alertUID) - success, err := h.GetUserClient().V1ProjectsUIDAlertsUIDGet(params) + params := clientV1.NewV1ProjectsUIDAlertsUIDGetParamsWithContext(h.ctx). + WithUID(projectUID). + WithComponent(component). + WithAlertUID(alertUID) + resp, err := h.Client.V1ProjectsUIDAlertsUIDGet(params) if err != nil { return nil, err } - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) DeleteAlerts(projectUID, component, alertUID string) error { - if h.DeleteAlertsFn != nil { - return h.DeleteAlertsFn(projectUID, component, alertUID) - } - - params := v1.NewV1ProjectsUIDAlertsUIDDeleteParams().WithUID(projectUID).WithComponent(component).WithAlertUID(alertUID) - _, err := h.GetUserClient().V1ProjectsUIDAlertsUIDDelete(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1ProjectsUIDAlertsUIDDeleteParamsWithContext(h.ctx). + WithUID(projectUID). + WithComponent(component). + WithAlertUID(alertUID) + _, err := h.Client.V1ProjectsUIDAlertsUIDDelete(params) + return err } diff --git a/client/apiutil/apiutil.go b/client/apiutil/apiutil.go new file mode 100644 index 00000000..d1f4ca6a --- /dev/null +++ b/client/apiutil/apiutil.go @@ -0,0 +1,70 @@ +package apiutil + +import ( + "encoding/base64" + "errors" + "fmt" + "hash/fnv" + "strconv" + + "github.com/spectrocloud/palette-api-go/apiutil/transport" + "github.com/spectrocloud/palette-api-go/models" +) + +func IsBase64(s string) bool { + _, err := base64.StdEncoding.DecodeString(s) + return err == nil +} + +func Base64DecodeString(s string) ([]byte, error) { + return base64.StdEncoding.DecodeString(s) +} + +func StringHash(name string) string { + return strconv.FormatUint(uint64(hash(name)), 10) +} + +func hash(s string) uint32 { + h := fnv.New32a() + _, _ = h.Write([]byte(s)) + return h.Sum32() +} + +func Ptr[T any](v T) *T { + return &v +} + +func Handle404(err error) error { + var e *transport.TransportError + if errors.As(err, &e) && e.HttpCode == 404 { + return nil + } else if err != nil { + return err + } + return nil +} + +func ToV1ErrorObj(err interface{}) *models.V1Error { + if err != nil { + tErr, ok := err.(*transport.TransportError) + if ok { + return tErr.Payload + } + + goErr, ok := err.(error) + if ok { + return &models.V1Error{ + Code: "UnknownError", + Message: goErr.Error(), + } + } + + return &models.V1Error{ + Code: "UnknownError", + Message: fmt.Sprintf("%v", err), + } + } + return &models.V1Error{ + Code: "EmptyError", + } +} diff --git a/client/appliance.go b/client/appliance.go index d3fc7ccb..1d2bb534 100644 --- a/client/appliance.go +++ b/client/appliance.go @@ -1,93 +1,211 @@ package client import ( - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + "fmt" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) SearchApplianceSummaries(applianceContext string, filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1EdgeHostsMetadata, error) { - var params *hashboardC.V1DashboardEdgehostsSearchParams - switch applianceContext { - case "project": - params = hashboardC.NewV1DashboardEdgehostsSearchParamsWithContext(h.Ctx) - case "tenant": - params = hashboardC.NewV1DashboardEdgehostsSearchParams() - } - params.Body = &models.V1SearchFilterSummarySpec{ - Filter: filter, - Sort: sort, - } - - resp, err := h.GetHashboardClient().V1DashboardEdgehostsSearch(params) +func (h *V1Client) SearchApplianceSummaries(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1EdgeHostsMetadata, error) { + params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). + WithBody(&models.V1SearchFilterSummarySpec{ + Filter: filter, + Sort: sort, + }) + resp, err := h.Client.V1DashboardEdgehostsSearch(params) if err != nil { return nil, err } - return resp.Payload.Items, nil } -func (h *V1Client) GetAppliances(applianceContext string, tags map[string]string, status, health, architecture string) ([]*models.V1EdgeHostsMetadata, error) { +func (h *V1Client) GetAppliances(tags map[string]string, status, health, architecture string) ([]*models.V1EdgeHostsMetadata, error) { filter := getApplianceFilter(nil, tags, status, health, architecture) - - appliances, err := h.SearchApplianceSummaries(applianceContext, filter, nil) + appliances, err := h.SearchApplianceSummaries(filter, nil) if err != nil { return nil, err } - return appliances, nil } func (h *V1Client) GetAppliance(uid string) (*models.V1EdgeHostDevice, error) { - params := clusterC.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.Ctx).WithUID(uid) - response, err := h.GetClusterClient().V1EdgeHostDevicesUIDGet(params) + params := clientV1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1EdgeHostDevicesUIDGet(params) if err != nil { if herr.IsNotFound(err) { return nil, nil } return nil, err } + return resp.Payload, nil +} - return response.Payload, nil +func (h *V1Client) GetApplianceByName(name string, tags map[string]string, status, health, architecture string) (*models.V1EdgeHostDevice, error) { + filters := []*models.V1SearchFilterItem{applianceNameEqFilter(name)} + applianceSummaries, err := h.SearchApplianceSummaries(getApplianceFilter(filters, tags, status, health, architecture), nil) + if err != nil { + return nil, err + } + if len(applianceSummaries) != 1 { + return nil, fmt.Errorf("expected 1 appliance, got %d", len(applianceSummaries)) + } + appliance, err := h.GetAppliance(applianceSummaries[0].Metadata.UID) + if err != nil { + return nil, err + } + return appliance, nil } func (h *V1Client) CreateAppliance(createHostDevice *models.V1EdgeHostDeviceEntity) (string, error) { - params := clusterC.NewV1EdgeHostDevicesCreateParams().WithContext(h.Ctx).WithBody(createHostDevice) - if resp, err := h.GetClusterClient().V1EdgeHostDevicesCreate(params); err != nil { + params := clientV1.NewV1EdgeHostDevicesCreateParamsWithContext(h.ctx). + WithBody(createHostDevice) + resp, err := h.Client.V1EdgeHostDevicesCreate(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } func (h *V1Client) UpdateAppliance(uid string, appliance *models.V1EdgeHostDevice) error { - params := clusterC.NewV1EdgeHostDevicesUIDUpdateParams().WithContext(h.Ctx).WithBody(appliance).WithUID(uid) - _, err := h.GetClusterClient().V1EdgeHostDevicesUIDUpdate(params) + params := clientV1.NewV1EdgeHostDevicesUIDUpdateParamsWithContext(h.ctx). + WithBody(appliance). + WithUID(uid) + _, err := h.Client.V1EdgeHostDevicesUIDUpdate(params) if err != nil && !herr.IsEdgeHostDeviceNotRegistered(err) { return err } - return nil } func (h *V1Client) UpdateApplianceMeta(uid string, appliance *models.V1EdgeHostDeviceMetaUpdateEntity) error { - params := clusterC.NewV1EdgeHostDevicesUIDMetaUpdateParams().WithContext(h.Ctx).WithBody(appliance).WithUID(uid) - _, err := h.GetClusterClient().V1EdgeHostDevicesUIDMetaUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1EdgeHostDevicesUIDMetaUpdateParamsWithContext(h.ctx). + WithBody(appliance). + WithUID(uid) + _, err := h.Client.V1EdgeHostDevicesUIDMetaUpdate(params) + return err } func (h *V1Client) DeleteAppliance(uid string) error { - params := clusterC.NewV1EdgeHostDevicesUIDDeleteParams().WithContext(h.Ctx).WithUID(uid) - _, err := h.GetClusterClient().V1EdgeHostDevicesUIDDelete(params) - if err != nil { - return err + params := clientV1.NewV1EdgeHostDevicesUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1EdgeHostDevicesUIDDelete(params) + return err +} + +func getApplianceFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]string, state, healthState, architecture string) *models.V1SearchFilterSpec { + filter := &models.V1SearchFilterSpec{ + Conjunction: and(), + FilterGroups: []*models.V1SearchFilterGroup{ + { + Conjunction: and(), + Filters: []*models.V1SearchFilterItem{}, + }, + }, } - return nil + // Tags filter + if len(tags) > 0 { + var tagValues []string + for key, value := range tags { + tagValues = append(tagValues, fmt.Sprintf("%s:%s", key, value)) + } + tagsFilter := &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: tagValues, + }, + Operator: models.V1SearchFilterStringOperatorEq, + Negation: false, + IgnoreCase: false, + }, + }, + Property: "tags", + Type: models.V1SearchFilterPropertyTypeString, + } + filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, tagsFilter) + } + + // State filter + if state != "" { + stateFilter := &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{state}, + }, + Operator: models.V1SearchFilterStringOperatorEq, + }, + }, + Property: "state", + Type: models.V1SearchFilterPropertyTypeString, + } + filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, stateFilter) + } + + // Health state filter + if healthState != "" { + healthStateFilter := &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{healthState}, + }, + Operator: models.V1SearchFilterStringOperatorEq, + }, + }, + Property: "healthState", + Type: models.V1SearchFilterPropertyTypeString, + } + filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, healthStateFilter) + } + + // Architecture filter + if architecture != "" { + architectureFilter := &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{architecture}, + }, + Operator: models.V1SearchFilterStringOperatorEq, + }, + }, + Property: "architecture", + Type: models.V1SearchFilterPropertyTypeString, + } + filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, architectureFilter) + } + + // Append extra filters if provided + if extraFilters != nil { + filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters}) + } + + return filter +} + +func applianceNameEqFilter(name string) *models.V1SearchFilterItem { + return &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{name}, + }, + Operator: models.V1SearchFilterStringOperatorEq, + Negation: false, + IgnoreCase: false, + }, + }, + Property: "name", + Type: models.V1SearchFilterPropertyTypeString, + } } diff --git a/client/application.go b/client/application.go index 265eb51e..3a17d16b 100644 --- a/client/application.go +++ b/client/application.go @@ -1,86 +1,65 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - v1 "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) { - if h.GetApplicationFn != nil { - return h.GetApplicationFn(uid) - } - - params := v1.NewV1AppDeploymentsUIDGetParamsWithContext(h.Ctx).WithUID(uid) - success, err := h.GetClusterClient().V1AppDeploymentsUIDGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1AppDeploymentsUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1AppDeploymentsUIDGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - // special check if the cluster is marked deleted - application := success.Payload //success.Payload.Spec.Config.Target.ClusterRef.UID - return application, nil + return resp.Payload, nil } -func (h *V1Client) SearchAppDeploymentSummaries(scope string, filter *models.V1AppDeploymentFilterSpec, sortBy []*models.V1AppDeploymentSortSpec) ([]*models.V1AppDeploymentSummary, error) { - var params *hashboardC.V1DashboardAppDeploymentsParams - switch scope { - case "project": - params = hashboardC.NewV1DashboardAppDeploymentsParams().WithContext(h.Ctx) - case "tenant": - params = hashboardC.NewV1DashboardAppDeploymentsParams() - } - params.Body = &models.V1AppDeploymentsFilterSpec{ - Filter: filter, - Sort: sortBy, - } - - resp, err := h.GetHashboardClient().V1DashboardAppDeployments(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) SearchAppDeploymentSummaries(filter *models.V1AppDeploymentFilterSpec, sortBy []*models.V1AppDeploymentSortSpec) ([]*models.V1AppDeploymentSummary, error) { + params := clientV1.NewV1DashboardAppDeploymentsParamsWithContext(h.ctx). + WithBody(&models.V1AppDeploymentsFilterSpec{ + Filter: filter, + Sort: sortBy, + }) + resp, err := h.Client.V1DashboardAppDeployments(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - return resp.Payload.AppDeployments, nil } func (h *V1Client) CreateApplicationWithNewSandboxCluster(body *models.V1AppDeploymentClusterGroupEntity) (string, error) { - params := v1.NewV1AppDeploymentsClusterGroupCreateParams().WithContext(h.Ctx).WithBody(body) - success, err := h.GetClusterClient().V1AppDeploymentsClusterGroupCreate(params) + params := clientV1.NewV1AppDeploymentsClusterGroupCreateParamsWithContext(h.ctx). + WithBody(body) + resp, err := h.Client.V1AppDeploymentsClusterGroupCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) CreateApplicationWithExistingSandboxCluster(body *models.V1AppDeploymentVirtualClusterEntity) (string, error) { - params := v1.NewV1AppDeploymentsVirtualClusterCreateParams().WithContext(h.Ctx).WithBody(body) - success, err := h.GetClusterClient().V1AppDeploymentsVirtualClusterCreate(params) + params := clientV1.NewV1AppDeploymentsVirtualClusterCreateParamsWithContext(h.ctx). + WithBody(body) + resp, err := h.Client.V1AppDeploymentsVirtualClusterCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) DeleteApplication(uid string) error { - params := v1.NewV1AppDeploymentsUIDDeleteParamsWithContext(h.Ctx).WithUID(uid) - _, err := h.GetClusterClient().V1AppDeploymentsUIDDelete(params) + params := clientV1.NewV1AppDeploymentsUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1AppDeploymentsUIDDelete(params) return err } func (h *V1Client) ApplyApplicationUpdate(uid, notificationUid string) error { - params := v1.NewV1AppDeploymentsUIDProfileApplyParamsWithContext(h.Ctx).WithUID(uid).WithNotify(¬ificationUid) - _, err := h.GetClusterClient().V1AppDeploymentsUIDProfileApply(params) + params := clientV1.NewV1AppDeploymentsUIDProfileApplyParamsWithContext(h.ctx). + WithUID(uid). + WithNotify(¬ificationUid) + _, err := h.Client.V1AppDeploymentsUIDProfileApply(params) return err } diff --git a/client/application_profile.go b/client/application_profile.go index 1d3f6d83..2bb8b819 100644 --- a/client/application_profile.go +++ b/client/application_profile.go @@ -5,22 +5,20 @@ import ( "github.com/pkg/errors" - "github.com/spectrocloud/hapi/apiutil/transport" - 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-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" "github.com/spectrocloud/palette-sdk-go/client/herr" ) func (h *V1Client) GetApplicationProfileByNameAndVersion(profileName, version string) (*models.V1AppProfileSummary, string, string, error) { - limit := int64(0) - params := hashboardC.NewV1DashboardAppProfilesParamsWithContext(h.Ctx).WithLimit(&limit) - profiles, err := h.GetHashboardClient().V1DashboardAppProfiles(params) + params := clientV1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + profiles, err := h.Client.V1DashboardAppProfiles(params) if err != nil { return nil, "", "", err } - for _, profile := range profiles.Payload.AppProfiles { if profile.Metadata.Name == profileName { for i := range profile.Spec.Versions { @@ -34,86 +32,57 @@ func (h *V1Client) GetApplicationProfileByNameAndVersion(profileName, version st } func (h *V1Client) GetApplicationProfile(uid string) (*models.V1AppProfile, error) { - // Unit test mock handler - if h.GetApplicationProfileFn != nil { - return h.GetApplicationProfileFn(uid) - } - - params := clusterC.NewV1AppProfilesUIDGetParamsWithContext(h.Ctx).WithUID(uid) - response, err := h.GetClusterClient().V1AppProfilesUIDGet(params) + params := clientV1.NewV1AppProfilesUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1AppProfilesUIDGet(params) if err != nil { if herr.IsNotFound(err) { return nil, nil } return nil, err } - - return response.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]*models.V1AppTier, error) { - if h.GetApplicationProfileTiersFn != nil { - return h.GetApplicationProfileTiersFn(applicationProfileUID) - } - - params := clusterC.NewV1AppProfilesUIDTiersGetParamsWithContext(h.Ctx).WithUID(applicationProfileUID) - success, err := h.GetClusterClient().V1AppProfilesUIDTiersGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1AppProfilesUIDTiersGetParamsWithContext(h.ctx). + WithUID(applicationProfileUID) + resp, err := h.Client.V1AppProfilesUIDTiersGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload.Spec.AppTiers, nil + return resp.Payload.Spec.AppTiers, nil } func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUID, tierUID, manifestUID string) (string, error) { - if h.GetApplicationProfileTierManifestContentFn != nil { - return h.GetApplicationProfileTierManifestContentFn(applicationProfileUID, tierUID, manifestUID) - } - - params := &clusterC.V1AppProfilesUIDTiersUIDManifestsUIDGetParams{ - UID: applicationProfileUID, - TierUID: tierUID, - ManifestUID: manifestUID, - Context: h.Ctx, - } - - success, err := h.GetClusterClient().V1AppProfilesUIDTiersUIDManifestsUIDGet(params) - + params := clientV1.NewV1AppProfilesUIDTiersUIDManifestsUIDGetParamsWithContext(h.ctx). + WithUID(applicationProfileUID). + WithTierUID(tierUID). + WithManifestUID(manifestUID) + resp, err := h.Client.V1AppProfilesUIDTiersUIDManifestsUIDGet(params) var e *transport.TransportError if errors.As(err, &e) && e.HttpCode == 404 { return "", nil } else if err != nil { return "", err } - - return success.Payload.Spec.Published.Content, nil + return resp.Payload.Spec.Published.Content, nil } -func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec) ([]*models.V1AppProfileSummary, error) { - var params *hashboardC.V1DashboardAppProfilesParams - switch scope { - case "project": - params = hashboardC.NewV1DashboardAppProfilesParamsWithContext(h.Ctx) - case "tenant": - params = hashboardC.NewV1DashboardAppProfilesParams() - } - params.Body = &models.V1AppProfilesFilterSpec{ - Filter: filter, - Sort: sortBy, - } - - var appProfile []*models.V1AppProfileSummary - var resp *hashboardC.V1DashboardAppProfilesOK +func (h *V1Client) SearchAppProfileSummaries(filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec) ([]*models.V1AppProfileSummary, error) { + params := clientV1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). + WithBody(&models.V1AppProfilesFilterSpec{ + Filter: filter, + Sort: sortBy, + }) + var appProfiles []*models.V1AppProfileSummary + var resp *clientV1.V1DashboardAppProfilesOK var err error for { if resp != nil { params.Offset = &resp.Payload.Listmeta.Offset } - resp, err = h.GetHashboardClient().V1DashboardAppProfiles(params) + resp, err = h.Client.V1DashboardAppProfiles(params) var e *transport.TransportError if errors.As(err, &e) && e.HttpCode == 404 { return nil, nil @@ -122,7 +91,7 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP } if resp != nil && resp.Payload != nil { if resp.Payload.AppProfiles != nil { - appProfile = append(appProfile, resp.Payload.AppProfiles...) + appProfiles = append(appProfiles, resp.Payload.AppProfiles...) } if resp.Payload.Listmeta == nil || len(resp.Payload.Listmeta.Continue) == 0 { break @@ -131,34 +100,24 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP break } } - return appProfile, nil + return appProfiles, nil } -func (h *V1Client) PatchApplicationProfile(appProfileUID string, metadata *models.V1AppProfileMetaEntity, ProfileContext string) error { - var params *clusterC.V1AppProfilesUIDMetadataUpdateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1AppProfilesUIDMetadataUpdateParamsWithContext(h.Ctx).WithUID(appProfileUID).WithBody(metadata) - case "tenant": - params = clusterC.NewV1AppProfilesUIDMetadataUpdateParams().WithUID(appProfileUID).WithBody(metadata) - } - - _, err := h.GetClusterClient().V1AppProfilesUIDMetadataUpdate(params) +func (h *V1Client) PatchApplicationProfile(appProfileUID string, metadata *models.V1AppProfileMetaEntity) error { + params := clientV1.NewV1AppProfilesUIDMetadataUpdateParamsWithContext(h.ctx). + WithUID(appProfileUID). + WithBody(metadata) + _, err := h.Client.V1AppProfilesUIDMetadataUpdate(params) return err } -func (h *V1Client) CreateApplicationProfileTiers(appProfileUID string, appTiers []*models.V1AppTierEntity, ProfileContext string) error { +func (h *V1Client) CreateApplicationProfileTiers(appProfileUID string, appTiers []*models.V1AppTierEntity) error { var err error for _, appTier := range appTiers { - var params *clusterC.V1AppProfilesUIDTiersCreateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1AppProfilesUIDTiersCreateParamsWithContext(h.Ctx).WithUID(appProfileUID).WithBody(appTier) - case "tenant": - params = clusterC.NewV1AppProfilesUIDTiersCreateParams().WithUID(appProfileUID).WithBody(appTier) - } - - _, tmpErr := h.GetClusterClient().V1AppProfilesUIDTiersCreate(params) + params := clientV1.NewV1AppProfilesUIDTiersCreateParamsWithContext(h.ctx). + WithUID(appProfileUID). + WithBody(appTier) + _, tmpErr := h.Client.V1AppProfilesUIDTiersCreate(params) if tmpErr != nil { err = errors.Wrap(err, tmpErr.Error()) } @@ -166,38 +125,28 @@ func (h *V1Client) CreateApplicationProfileTiers(appProfileUID string, appTiers return err } -func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string, appTier *models.V1AppTierUpdateEntity, ProfileContext string) error { - var params *clusterC.V1AppProfilesUIDTiersUIDUpdateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1AppProfilesUIDTiersUIDUpdateParamsWithContext(h.Ctx).WithUID(appProfileUID).WithTierUID(tierUID).WithBody(appTier) - case "tenant": - params = clusterC.NewV1AppProfilesUIDTiersUIDUpdateParams().WithUID(appProfileUID).WithTierUID(tierUID).WithBody(appTier) - } - - _, err := h.GetClusterClient().V1AppProfilesUIDTiersUIDUpdate(params) +func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string, appTier *models.V1AppTierUpdateEntity) error { + params := clientV1.NewV1AppProfilesUIDTiersUIDUpdateParamsWithContext(h.ctx). + WithUID(appProfileUID). + WithTierUID(tierUID). + WithBody(appTier) + _, err := h.Client.V1AppProfilesUIDTiersUIDUpdate(params) var e *transport.TransportError if errors.As(err, &e) && e.HttpCode == 404 { return nil } else if err != nil { return err } - return err } -func (h *V1Client) DeleteApplicationProfileTiers(appProfileUID string, appTiers []string, ProfileContext string) error { +func (h *V1Client) DeleteApplicationProfileTiers(appProfileUID string, appTiers []string) error { var err error for _, appTierUID := range appTiers { - var params *clusterC.V1AppProfilesUIDTiersUIDDeleteParams - switch ProfileContext { - case "project": - params = clusterC.NewV1AppProfilesUIDTiersUIDDeleteParamsWithContext(h.Ctx).WithUID(appProfileUID).WithTierUID(appTierUID) - case "tenant": - params = clusterC.NewV1AppProfilesUIDTiersUIDDeleteParams().WithUID(appProfileUID).WithTierUID(appTierUID) - } - - _, tmpErr := h.GetClusterClient().V1AppProfilesUIDTiersUIDDelete(params) + params := clientV1.NewV1AppProfilesUIDTiersUIDDeleteParamsWithContext(h.ctx). + WithUID(appProfileUID). + WithTierUID(appTierUID) + _, tmpErr := h.Client.V1AppProfilesUIDTiersUIDDelete(params) if tmpErr != nil { err = errors.Wrap(err, tmpErr.Error()) } @@ -205,47 +154,24 @@ func (h *V1Client) DeleteApplicationProfileTiers(appProfileUID string, appTiers return err } -func (h *V1Client) CreateApplicationProfile(appProfile *models.V1AppProfileEntity, ProfileContext string) (string, error) { - // Unit test mock handler - if h.CreateApplicationProfileFn != nil { - return h.CreateApplicationProfileFn(appProfile, ProfileContext) - } - - var params *clusterC.V1AppProfilesCreateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1AppProfilesCreateParams().WithContext(h.Ctx).WithBody(appProfile) - case "tenant": - params = clusterC.NewV1AppProfilesCreateParams().WithBody(appProfile) - } - - success, err := h.GetClusterClient().V1AppProfilesCreate(params) +func (h *V1Client) CreateApplicationProfile(appProfile *models.V1AppProfileEntity) (string, error) { + params := clientV1.NewV1AppProfilesCreateParamsWithContext(h.ctx). + WithBody(appProfile) + resp, err := h.Client.V1AppProfilesCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) DeleteApplicationProfile(uid string) error { - // Unit test mock handler - if h.DeleteApplicationProfileFn != nil { - return h.DeleteApplicationProfileFn(uid) - } - profile, err := h.GetApplicationProfile(uid) if err != nil { return err } - - var params *clusterC.V1AppProfilesUIDDeleteParams - switch profile.Metadata.Annotations["scope"] { - case "project": - params = clusterC.NewV1AppProfilesUIDDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1AppProfilesUIDDeleteParams().WithUID(uid) - } - - _, err = h.GetClusterClient().V1AppProfilesUIDDelete(params) + params := clientV1.NewV1AppProfilesUIDDeleteParams(). + WithContext(ContextForScope(profile.Metadata.Annotations[Scope], h.projectUid)). + WithUID(uid) + _, err = h.Client.V1AppProfilesUIDDelete(params) return err } diff --git a/client/backup_storage_location.go b/client/backup_storage_location.go index 4dcb817e..0bf36ece 100644 --- a/client/backup_storage_location.go +++ b/client/backup_storage_location.go @@ -1,72 +1,64 @@ package client import ( - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) ListBackupStorageLocation(projectScope bool) ([]*models.V1UserAssetsLocation, error) { - params := userC.NewV1UsersAssetsLocationGetParams() - if projectScope { - params.WithContext(h.Ctx) - } - response, err := h.GetUserClient().V1UsersAssetsLocationGet(params) +func (h *V1Client) ListBackupStorageLocation() ([]*models.V1UserAssetsLocation, error) { + params := clientV1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) + resp, err := h.Client.V1UsersAssetsLocationGet(params) if err != nil { return nil, err } - - bsls := make([]*models.V1UserAssetsLocation, len(response.Payload.Items)) - copy(bsls, response.Payload.Items) - - return bsls, nil + return resp.Payload.Items, nil } func (h *V1Client) GetBackupStorageLocation(uid string) (*models.V1UserAssetsLocation, error) { - params := userC.NewV1UsersAssetsLocationGetParamsWithContext(h.Ctx) - response, err := h.GetUserClient().V1UsersAssetsLocationGet(params) + params := clientV1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) + resp, err := h.Client.V1UsersAssetsLocationGet(params) if err != nil { return nil, err } - - for _, account := range response.Payload.Items { + for _, account := range resp.Payload.Items { if account.Metadata.UID == uid { return account, nil } } - return nil, nil } func (h *V1Client) GetS3BackupStorageLocation(uid string) (*models.V1UserAssetsLocationS3, error) { - params := userC.NewV1UsersAssetsLocationS3GetParamsWithContext(h.Ctx).WithUID(uid) - if response, err := h.GetUserClient().V1UsersAssetsLocationS3Get(params); err != nil { + params := clientV1.NewV1UsersAssetsLocationS3GetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1UsersAssetsLocationS3Get(params) + if err != nil { return nil, err - } else { - return response.Payload, nil } + return resp.Payload, nil } func (h *V1Client) CreateS3BackupStorageLocation(bsl *models.V1UserAssetsLocationS3) (string, error) { - params := userC.NewV1UsersAssetsLocationS3CreateParamsWithContext(h.Ctx).WithBody(bsl) - if resp, err := h.GetUserClient().V1UsersAssetsLocationS3Create(params); err != nil { + params := clientV1.NewV1UsersAssetsLocationS3CreateParamsWithContext(h.ctx). + WithBody(bsl) + resp, err := h.Client.V1UsersAssetsLocationS3Create(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } func (h *V1Client) UpdateS3BackupStorageLocation(uid string, bsl *models.V1UserAssetsLocationS3) error { - params := userC.NewV1UsersAssetsLocationS3UpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(bsl) - if _, err := h.GetUserClient().V1UsersAssetsLocationS3Update(params); err != nil { - return err - } - return nil + params := clientV1.NewV1UsersAssetsLocationS3UpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(bsl) + _, err := h.Client.V1UsersAssetsLocationS3Update(params) + return err } func (h *V1Client) DeleteS3BackupStorageLocation(uid string) error { - params := userC.NewV1UsersAssetsLocationS3DeleteParamsWithContext(h.Ctx).WithUID(uid) - if _, err := h.GetUserClient().V1UsersAssetsLocationS3Delete(params); err != nil { - return err - } - return nil + params := clientV1.NewV1UsersAssetsLocationS3DeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1UsersAssetsLocationS3Delete(params) + return err } diff --git a/client/client.go b/client/client.go index 99d22cc2..49b8818b 100644 --- a/client/client.go +++ b/client/client.go @@ -2,142 +2,40 @@ package client import ( "context" + "crypto/tls" + "net/http" openapiclient "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" - "github.com/spectrocloud/hapi/apiutil/transport" - authC "github.com/spectrocloud/hapi/auth/client/v1" - cloudC "github.com/spectrocloud/hapi/cloud/client/v1" - eventC "github.com/spectrocloud/hapi/event/client/v1" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - mgmtC "github.com/spectrocloud/hapi/mgmt/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - userC "github.com/spectrocloud/hapi/user/client/v1" -) - -const ( - authTokenInput string = "header" - authApiKey string = "ApiKey" + "github.com/spectrocloud/palette-api-go/apiutil/transport" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" ) type V1Client struct { - Ctx context.Context - apikey string - hubbleUri string - schemes []string - transportDebug bool - RetryAttempts int - - ClusterC clusterC.ClientService - - // Cluster generic - GetClusterWithoutStatusFn func(string) (*models.V1SpectroCluster, error) - GetClusterFn func(scope, uid string) (*models.V1SpectroCluster, error) - GetClusterAdminConfigFn func(uid string) (string, error) - GetClusterKubeConfigFn func(uid string) (string, error) - GetClusterBackupConfigFn func(uid string) (*models.V1ClusterBackup, error) - GetClusterScanConfigFn func(uid string) (*models.V1ClusterComplianceScan, error) - GetClusterRbacConfigFn func(uid string) (*models.V1ClusterRbacs, error) - GetClusterNamespaceConfigFn func(uid string) (*models.V1ClusterNamespaceResources, error) - ApproveClusterRepaveFn func(context, clusterUID string) error - GetRepaveReasonsFn func(context, clusterUID string) ([]string, error) - UpdatePauseAgentUpgradeSettingClusterFn func(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string, context string) error - UpdatePauseAgentUpgradeSettingContextFn func(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, context string) error - GetPauseAgentUpgradeSettingContextFn func(context string) (string, error) - - // Cluster Groups - CreateClusterGroupFn func(*models.V1ClusterGroupEntity) (string, error) - GetClusterGroupFn func(string) (*models.V1ClusterGroup, error) - UpdateClusterGroupFn func(string, *models.V1ClusterGroupHostClusterEntity) error - DeleteClusterGroupFn func(string) error - - // Application - GetApplicationFn func(string) (*models.V1AppDeployment, error) - - // Application Profile - GetApplicationProfileTiersFn func(string) ([]*models.V1AppTier, error) - CreateApplicationProfileFn func(*models.V1AppProfileEntity, string) (string, error) - GetApplicationProfileTierManifestContentFn func(string, string, string) (string, error) - GetApplicationProfileFn func(string) (*models.V1AppProfile, error) - DeleteApplicationProfileFn func(string) error - - // special function for virtual cluster mock - V1ClusterProfilesDeleteFn func(params *clusterC.V1ClusterProfilesDeleteParams) (*clusterC.V1ClusterProfilesDeleteNoContent, error) - V1ClusterProfilesUIDMetadataUpdateFn func(params *clusterC.V1ClusterProfilesUIDMetadataUpdateParams) (*clusterC.V1ClusterProfilesUIDMetadataUpdateNoContent, error) - V1ClusterProfilesUpdateFn func(params *clusterC.V1ClusterProfilesUpdateParams) (*clusterC.V1ClusterProfilesUpdateNoContent, error) - V1ClusterProfilesCreateFn func(params *clusterC.V1ClusterProfilesCreateParams) (*clusterC.V1ClusterProfilesCreateCreated, error) - V1ClusterProfilesPublishFn func(params *clusterC.V1ClusterProfilesPublishParams) (*models.V1ClusterProfile, error) - - // Registry - GetPackRegistryCommonByNameFn func(string) (*models.V1RegistryMetadata, error) - - // VSphere Cluster - CreateClusterVsphereFn func(*models.V1SpectroVsphereClusterEntity) (string, error) - GetCloudConfigVsphereFn func(cloudConfigUid string) (*models.V1VsphereCloudConfig, error) - GetCloudConfigVsphereValuesFn func(uid string) (*models.V1VsphereCloudConfig, error) - - // Project - GetProjectUIDFn func(projectName string) (string, error) - - // Alert - CreateAlertFn func(body *models.V1Channel, projectUID, component string) (string, error) - UpdateAlertFn func(body *models.V1Channel, projectUID, component, alertUID string) (string, error) - ReadAlertFn func(projectUID, component, alertUID string) (*models.V1Channel, error) - DeleteAlertsFn func(projectUID, component, alertUID string) error - - // Virtual Machines - GetVirtualMachineWithoutStatusFn func(string) (*models.V1ClusterVirtualMachine, error) - GetVirtualMachineFn func(uid string) (*models.V1ClusterVirtualMachine, error) - - // Data Volumes - CreateDataVolumeFn func(uid, name string, body *models.V1VMAddVolumeEntity) (string, error) - DeleteDataVolumeFn func(uid, namespace, name string, body *models.V1VMRemoveVolumeEntity) error - - // Registry - CreateOciEcrRegistryFn func(registry *models.V1EcrRegistry) (string, error) - UpdateEcrRegistryFn func(uid string, registry *models.V1EcrRegistry) error - GetOciRegistryFn func(uid string) (*models.V1EcrRegistry, error) - DeleteOciEcrRegistryFn func(uid string) error - - // Edge Native - GetCloudConfigEdgeNativeFn func(uid, clusterContext string) (*models.V1EdgeNativeCloudConfig, error) + Client clientV1.ClientService - // Macros - CreateMacrosFn func(uid string, macros *models.V1Macros) (string, error) - GetTFMacrosV2Fn func(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) - GetExistMacrosFn func(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) - UpdateMacrosFn func(uid string, macros *models.V1Macros) error - DeleteMacrosFn func(uid string, body *models.V1Macros) error - GetMacrosIdFn func(uid string) (string, error) - - // Custom Cloud Accounts - CreateCustomCloudAccountFn func(account *models.V1CustomAccountEntity, cloudType string, accountContext string) (string, error) - GetCustomCloudAccountFn func(uid, cloudType string, accountContext string) (*models.V1CustomAccount, error) - UpdateCustomCloudAccountFn func(uid string, account *models.V1CustomAccountEntity, cloudType string, accountContext string) error - DeleteCustomCloudAccountFn func(uid, cloudType string, accountContext string) error - ValidateCustomCloudTypeFn func(cloudType string, cloudContext string) error - GetCustomCloudAccountListFn func(cloudType string) ([]*models.V1CustomAccount, error) - - // Custom Cloud Cluster - GetCloudConfigCustomCloudFn func(configUID string, cloudType string, clusterContext string) (*models.V1CustomCloudConfig, error) - CreateClusterCustomCloudFn func(cluster *models.V1SpectroCustomClusterEntity, cloudType string, clusterContext string) (string, error) - UpdateCloudConfigCustomCloudFn func(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUID string, cloudType string, clusterContext string) error - CreateMachinePoolCustomCloudFn func(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error - UpdateMachinePoolCustomCloudFn func(mpEntity *models.V1CustomMachinePoolConfigEntity, machinePoolName string, configUID string, cloudType string, clusterContext string) error - DeleteMachinePoolCustomCloudFn func(mpName string, configUID string, cloudType string, clusterContext string) error + ctx context.Context + apikey string + jwt string + hubbleUri string + projectUid string + schemes []string + insecureSkipVerify bool + transportDebug bool + retryAttempts int } func New(options ...func(*V1Client)) *V1Client { client := &V1Client{ - Ctx: context.Background(), - RetryAttempts: 0, + ctx: context.Background(), + retryAttempts: 0, schemes: []string{"https"}, } for _, o := range options { o(client) } + client.Client = clientV1.New(client.getTransport(), strfmt.Default) return client } @@ -147,21 +45,40 @@ func WithAPIKey(apiKey string) func(*V1Client) { } } +func WithJWTToken(jwt string) func(*V1Client) { + return func(v *V1Client) { + v.jwt = jwt + } +} + func WithHubbleURI(hubbleUri string) func(*V1Client) { return func(v *V1Client) { v.hubbleUri = hubbleUri } } -func WithProjectUID(projectUid string) func(*V1Client) { +func WithInsecureSkipVerify(insecureSkipVerify bool) func(*V1Client) { + return func(v *V1Client) { + v.insecureSkipVerify = insecureSkipVerify + } +} + +func WithScopeProject(projectUid string) func(*V1Client) { + return func(v *V1Client) { + v.projectUid = projectUid + v.ctx = ContextForScope("project", projectUid) + } +} + +func WithScopeTenant() func(*V1Client) { return func(v *V1Client) { - v.Ctx = ContextWithProject(v.Ctx, projectUid) + v.ctx = ContextForScope("tenant", "") } } func WithRetries(retries int) func(*V1Client) { return func(v *V1Client) { - v.RetryAttempts = retries + v.retryAttempts = retries } } @@ -177,64 +94,87 @@ func WithTransportDebug() func(*V1Client) { } } +func ContextForScope(scope, projectUid string) context.Context { + ctx := context.Background() + if scope == "project" { + ctx = context.WithValue(ctx, transport.CUSTOM_HEADERS, transport.Values{ + HeaderMap: map[string]string{ + "ProjectUid": projectUid, + }}, + ) + } + return ctx +} + +func (h *V1Client) Clone() *V1Client { + opts := []func(*V1Client){ + WithHubbleURI(h.hubbleUri), + WithInsecureSkipVerify(h.insecureSkipVerify), + WithRetries(h.retryAttempts), + WithSchemes(h.schemes), + WithScopeTenant(), + } + if h.apikey != "" { + opts = append(opts, WithAPIKey(h.apikey)) + } + if h.jwt != "" { + opts = append(opts, WithJWTToken(h.jwt)) + } + if h.projectUid != "" { + opts = append(opts, WithScopeProject(h.projectUid)) + } + if h.transportDebug { + opts = append(opts, WithTransportDebug()) + } + return New(opts...) +} + func (h *V1Client) getTransport() *transport.Runtime { var httpTransport *transport.Runtime if h.apikey != "" { - httpTransport = h.getAuthenticatedTransport() + httpTransport = h.apiKeyTransport() + } else if h.jwt != "" { + httpTransport = h.jwtTransport() } else { httpTransport = h.baseTransport() } return httpTransport } -func (h *V1Client) baseTransport() *transport.Runtime { - httpTransport := transport.New(h.hubbleUri, "", h.schemes) - httpTransport.RetryAttempts = h.RetryAttempts - httpTransport.Debug = h.transportDebug - return httpTransport -} - -func (h *V1Client) getAuthenticatedTransport() *transport.Runtime { +func (h *V1Client) apiKeyTransport() *transport.Runtime { httpTransport := h.baseTransport() httpTransport.DefaultAuthentication = openapiclient.APIKeyAuth(authApiKey, authTokenInput, h.apikey) return httpTransport } -// Clients - -func (h *V1Client) GetAuthClient() authC.ClientService { - return authC.New(h.getTransport(), strfmt.Default) -} - -func (h *V1Client) GetClusterClient() clusterC.ClientService { - return clusterC.New(h.getTransport(), strfmt.Default) -} - -func (h *V1Client) GetUserClient() userC.ClientService { - return userC.New(h.getTransport(), strfmt.Default) -} - -func (h *V1Client) GetHashboardClient() hashboardC.ClientService { - return hashboardC.New(h.getTransport(), strfmt.Default) -} - -func (h *V1Client) GetMgmtClient() mgmtC.ClientService { - return mgmtC.New(h.getTransport(), strfmt.Default) +func (h *V1Client) jwtTransport() *transport.Runtime { + httpTransport := h.baseTransport() + httpTransport.DefaultAuthentication = openapiclient.APIKeyAuth(authJwt, authTokenInput, h.jwt) + return httpTransport } -func (h *V1Client) GetCloudClient() cloudC.ClientService { - return cloudC.New(h.getTransport(), strfmt.Default) +func (h *V1Client) baseTransport() *transport.Runtime { + httpTransport := transport.NewWithClient(h.hubbleUri, "", h.schemes, h.httpClient()) + httpTransport.RetryAttempts = h.retryAttempts + httpTransport.Debug = h.transportDebug + return httpTransport } -func (h *V1Client) GetEventClient() eventC.ClientService { - return eventC.New(h.getTransport(), strfmt.Default) +func (h *V1Client) httpClient() *http.Client { + return &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: h.insecureSkipVerify, + }, + }, + } } func (h *V1Client) Validate() error { // API key can only be validated by making an API call if h.apikey != "" { - c := h.GetUserClient() - _, err := c.V1ProjectsList(nil) + _, err := h.Client.V1ProjectsMetadata(nil) if err != nil { return err } @@ -245,18 +185,10 @@ func (h *V1Client) Validate() error { func (h *V1Client) ValidateTenantAdmin() error { // API key can only be validated by making an API call if h.apikey != "" { - c := h.GetUserClient() - _, err := c.V1UsersList(nil) + _, err := h.Client.V1UsersList(nil) if err != nil { return err } } return nil } - -func ContextWithProject(c context.Context, projectUid string) context.Context { - return context.WithValue(c, transport.CUSTOM_HEADERS, transport.Values{ - HeaderMap: map[string]string{ - "ProjectUid": projectUid, - }}) -} diff --git a/client/cluster.go b/client/cluster.go index fcfb9a3a..235f9872 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -1,326 +1,245 @@ package client import ( - "errors" "fmt" "strings" - "github.com/spectrocloud/hapi/apiutil/transport" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) DeleteCluster(scope, uid string) error { - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) DeleteCluster(uid string) error { + cluster, err := h.GetCluster(uid) if err != nil || cluster == nil { return err } - - var params *clusterC.V1SpectroClustersDeleteParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersDeleteParams().WithUID(uid) - } - - _, err = h.GetClusterClient().V1SpectroClustersDelete(params) + params := clientV1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err = h.Client.V1SpectroClustersDelete(params) return err } -func (h *V1Client) ForceDeleteCluster(scope, uid string, forceDelete bool) error { - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) ForceDeleteCluster(uid string, forceDelete bool) error { + cluster, err := h.GetCluster(uid) if err != nil || cluster == nil { return err } - - var params *clusterC.V1SpectroClustersDeleteParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersDeleteParamsWithContext(h.Ctx).WithUID(uid).WithForceDelete(&forceDelete) - case "tenant": - params = clusterC.NewV1SpectroClustersDeleteParams().WithUID(uid).WithForceDelete(&forceDelete) - } - - _, err = h.GetClusterClient().V1SpectroClustersDelete(params) + params := clientV1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). + WithUID(uid). + WithForceDelete(&forceDelete) + _, err = h.Client.V1SpectroClustersDelete(params) return err } -func (h *V1Client) GetCluster(scope, uid string) (*models.V1SpectroCluster, error) { - if h.GetClusterFn != nil { - return h.GetClusterFn(scope, uid) - } - cluster, err := h.GetClusterWithoutStatus(scope, uid) +func (h *V1Client) GetCluster(uid string) (*models.V1SpectroCluster, error) { + cluster, err := h.GetClusterWithoutStatus(uid) if err != nil { return nil, err } - if cluster == nil || cluster.Status.State == "Deleted" { return nil, nil } - return cluster, nil } -func (h *V1Client) SearchClusterSummaries(clusterContext string, filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1SpectroClusterSummary, error) { - var params *hashboardC.V1SpectroClustersSearchFilterSummaryParams - switch clusterContext { - case "project": - params = hashboardC.NewV1SpectroClustersSearchFilterSummaryParamsWithContext(h.Ctx) - case "tenant": - params = hashboardC.NewV1SpectroClustersSearchFilterSummaryParams() +func (h *V1Client) GetClusterByName(name string, virtual bool) (*models.V1SpectroCluster, error) { + filters := []*models.V1SearchFilterItem{clusterNameEqFilter(name)} + clusterSummaries, err := h.SearchClusterSummaries(getClusterFilter(filters, virtual), nil) + if err != nil { + return nil, err } - params.Body = &models.V1SearchFilterSummarySpec{ - Filter: filter, - Sort: sort, + if len(clusterSummaries) != 1 { + return nil, fmt.Errorf("expected 1 cluster: got %d", len(clusterSummaries)) } - - resp, err := h.GetHashboardClient().V1SpectroClustersSearchFilterSummary(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + cluster, err := h.GetCluster(clusterSummaries[0].Metadata.UID) + if err != nil { return nil, err } - - return resp.Payload.Items, nil + return cluster, nil } -func (h *V1Client) GetClusterWithoutStatus(scope, uid string) (*models.V1SpectroCluster, error) { - if h.GetClusterWithoutStatusFn != nil { - return h.GetClusterWithoutStatusFn(uid) - } - - var params *clusterC.V1SpectroClustersGetParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersGetParams().WithUID(uid) - default: - return nil, fmt.Errorf("invalid scope %s", scope) - } - - success, err := h.GetClusterClient().V1SpectroClustersGet(params) +func (h *V1Client) GetClusterSummary(clusterId string) (*models.V1SpectroClusterUIDSummary, error) { + params := clientV1.NewV1SpectroClustersSummaryUIDParamsWithContext(h.ctx). + WithUID(clusterId) + resp, err := h.Client.V1SpectroClustersSummaryUID(params) if err != nil { return nil, err } - - // special check if the cluster is marked deleted - cluster := success.Payload - return cluster, nil + return resp.Payload, nil } -func (h *V1Client) GetClusterKubeConfig(uid, ClusterContext string) (string, error) { - if h.GetClusterKubeConfigFn != nil { - return h.GetClusterKubeConfigFn(uid) +func (h *V1Client) SearchClusterSummaries(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1SpectroClusterSummary, error) { + params := clientV1.NewV1SpectroClustersSearchFilterSummaryParamsWithContext(h.ctx). + WithBody(&models.V1SearchFilterSummarySpec{ + Filter: filter, + Sort: sort, + }) + resp, err := h.Client.V1SpectroClustersSearchFilterSummary(params) + if err := apiutil.Handle404(err); err != nil { + return nil, err } + return resp.Payload.Items, nil +} - var params *clusterC.V1SpectroClustersUIDKubeConfigParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDKubeConfigParams().WithUID(uid) - default: - return "", errors.New("invalid cluster scope specified") +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 +} - builder := new(strings.Builder) - _, err := h.GetClusterClient().V1SpectroClustersUIDKubeConfig(params, builder) +func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) { + builder := &strings.Builder{} + params := clientV1.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1SpectroClustersUIDKubeConfig(params, builder) if err != nil { if herr.IsNotFound(err) { return "", nil } return "", err } - - return builder.String(), nil + return parseKubeconfig(builder) } -func (h *V1Client) GetClusterAdminKubeConfig(uid, ClusterContext string) (string, error) { - if h.GetClusterAdminConfigFn != nil { - return h.GetClusterAdminConfigFn(uid) - } - - var params *clusterC.V1SpectroClustersUIDAdminKubeConfigParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDAdminKubeConfigParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDAdminKubeConfigParams().WithUID(uid) - default: - return "", errors.New("invalid cluster scope specified") - } - - builder := new(strings.Builder) - _, err := h.GetClusterClient().V1SpectroClustersUIDAdminKubeConfig(params, builder) +func (h *V1Client) GetClusterAdminKubeConfig(uid string) (string, error) { + builder := &strings.Builder{} + params := clientV1.NewV1SpectroClustersUIDAdminKubeConfigParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1SpectroClustersUIDAdminKubeConfig(params, builder) if err != nil { if herr.IsNotFound(err) { return "", nil } return "", err } - - return builder.String(), nil + return parseKubeconfig(builder) } -func (h *V1Client) GetClusterImportManifest(uid, clusterContext string) (string, error) { - builder := new(strings.Builder) - var params *clusterC.V1SpectroClustersUIDImportManifestParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDImportManifestParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDImportManifestParams().WithUID(uid) +func parseKubeconfig(builder *strings.Builder) (string, error) { + kubeconfig := builder.String() + if apiutil.IsBase64(kubeconfig) { + bytes, err := apiutil.Base64DecodeString(kubeconfig) + if err != nil { + return "", err + } + return string(bytes), nil } + return kubeconfig, nil +} - _, err := h.GetClusterClient().V1SpectroClustersUIDImportManifest(params, builder) +func (h *V1Client) GetClusterImportManifest(uid string) (string, error) { + builder := &strings.Builder{} + params := clientV1.NewV1SpectroClustersUIDImportManifestParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1SpectroClustersUIDImportManifest(params, builder) if err != nil { return "", err } - return builder.String(), nil } func (h *V1Client) UpdateClusterProfileValues(uid, context string, profiles *models.V1SpectroClusterProfiles) error { - var params *clusterC.V1SpectroClustersUpdateProfilesParams - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.Ctx).WithUID(uid). - WithBody(profiles).WithResolveNotification(Ptr(true)) - case "tenant": - params = clusterC.NewV1SpectroClustersUpdateProfilesParams().WithUID(uid). - WithBody(profiles).WithResolveNotification(Ptr(true)) - } - - _, err := h.GetClusterClient().V1SpectroClustersUpdateProfiles(params) + params := clientV1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). + WithUID(uid). + WithBody(profiles). + WithResolveNotification(apiutil.Ptr(true)) + _, err := h.Client.V1SpectroClustersUpdateProfiles(params) return err } func (h *V1Client) ImportClusterGeneric(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersGenericImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroGenericClusterImportEntity{ + params := clientV1.NewV1SpectroClustersGenericImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroGenericClusterImportEntity{ Metadata: meta, - }, - ) - success, err := h.GetClusterClient().V1SpectroClustersGenericImport(params) + }) + resp, err := h.Client.V1SpectroClustersGenericImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) ApproveClusterRepave(context, clusterUID string) error { - if h.ApproveClusterRepaveFn != nil { - return h.ApproveClusterRepaveFn(clusterUID, context) - } - - var params *clusterC.V1SpectroClustersUIDRepaveApproveUpdateParams - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUIDRepaveApproveUpdateParamsWithContext(h.Ctx).WithUID(clusterUID) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDRepaveApproveUpdateParams().WithUID(clusterUID) - default: - return fmt.Errorf("invalid context: %s", context) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDRepaveApproveUpdate(params) +func (h *V1Client) ApproveClusterRepave(clusterUid string) error { + params := clientV1.NewV1SpectroClustersUIDRepaveApproveUpdateParamsWithContext(h.ctx). + WithUID(clusterUid) + _, err := h.Client.V1SpectroClustersUIDRepaveApproveUpdate(params) return err } -func (h *V1Client) GetRepaveReasons(context, clusterUID string) ([]string, error) { - if h.GetRepaveReasonsFn != nil { - return h.GetRepaveReasonsFn(context, clusterUID) - } - - var params *clusterC.V1SpectroClustersUIDRepaveGetParams - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUIDRepaveGetParamsWithContext(h.Ctx).WithUID(clusterUID) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDRepaveGetParams().WithUID(clusterUID) - default: - return nil, fmt.Errorf("invalid context: %s", context) - } - - res, err := h.GetClusterClient().V1SpectroClustersUIDRepaveGet(params) +func (h *V1Client) GetRepaveReasons(clusterUid string) ([]string, error) { + params := clientV1.NewV1SpectroClustersUIDRepaveGetParamsWithContext(h.ctx). + WithUID(clusterUid) + resp, err := h.Client.V1SpectroClustersUIDRepaveGet(params) if err != nil { return nil, err } var reasons []string - for _, r := range res.Payload.Spec.Reasons { - reasons = append(reasons, fmt.Sprintf("Repave Reason Code - %s , Reason - %s.", r.Code, r.Message)) + for _, r := range resp.Payload.Spec.Reasons { + reasons = append(reasons, fmt.Sprintf("Repave - Code: %s, Reason: %s", r.Code, r.Message)) } - return reasons, err + return reasons, nil } -func (h *V1Client) UpdatePauseAgentUpgradeSettingCluster(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string, context string) error { - if h.UpdatePauseAgentUpgradeSettingClusterFn != nil { - return h.UpdatePauseAgentUpgradeSettingClusterFn(upgradeSetting, clusterUID, context) - } - var params *clusterC.V1SpectroClustersUIDUpgradeSettingsParams - - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUIDUpgradeSettingsParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDUpgradeSettingsParams() - default: - return fmt.Errorf("invalid context: %s", context) - } - params = params.WithUID(clusterUID).WithBody(upgradeSetting) - _, err := h.GetClusterClient().V1SpectroClustersUIDUpgradeSettings(params) - if err != nil { - return err +func getClusterFilter(extraFilters []*models.V1SearchFilterItem, virtual bool) *models.V1SearchFilterSpec { + filter := &models.V1SearchFilterSpec{ + Conjunction: and(), + FilterGroups: []*models.V1SearchFilterGroup{ + { + Conjunction: and(), + Filters: []*models.V1SearchFilterItem{ + { + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{"nested"}, + }, + Negation: !virtual, + Operator: models.V1SearchFilterStringOperatorEq, + }, + }, + Property: "environment", + Type: models.V1SearchFilterPropertyTypeString, + }, + { + Condition: &models.V1SearchFilterCondition{ + Bool: &models.V1SearchFilterBoolCondition{ + Value: false, + }, + }, + Property: "isDeleted", + Type: models.V1SearchFilterPropertyTypeBool, + }, + }, + }, + }, } - return nil -} -func (h *V1Client) UpdatePauseAgentUpgradeSettingContext(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, context string) error { - if h.UpdatePauseAgentUpgradeSettingContextFn != nil { - return h.UpdatePauseAgentUpgradeSettingContextFn(upgradeSetting, context) - } - var params *clusterC.V1SpectroClustersUpgradeSettingsParams + filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters}) - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUpgradeSettingsParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersUpgradeSettingsParams() - default: - return fmt.Errorf("invalid context: %s", context) - } - params = params.WithBody(upgradeSetting) - _, err := h.GetClusterClient().V1SpectroClustersUpgradeSettings(params) - if err != nil { - return err - } - return nil + return filter } -func (h *V1Client) GetPauseAgentUpgradeSettingContext(context string) (string, error) { - if h.GetPauseAgentUpgradeSettingContextFn != nil { - return h.GetPauseAgentUpgradeSettingContextFn(context) - } - var params *clusterC.V1SpectroClustersUpgradeSettingsGetParams - - switch context { - case "project": - params = clusterC.NewV1SpectroClustersUpgradeSettingsGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersUpgradeSettingsGetParams() - default: - return "", fmt.Errorf("invalid context: %s", context) - } - resp, err := h.GetClusterClient().V1SpectroClustersUpgradeSettingsGet(params) - if err != nil { - return "", err +func clusterNameEqFilter(name string) *models.V1SearchFilterItem { + return &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: []string{name}, + }, + Operator: models.V1SearchFilterStringOperatorEq, + Negation: false, + IgnoreCase: false, + }, + }, + Property: "clusterName", + Type: models.V1SearchFilterPropertyTypeString, } - return resp.Payload.SpectroComponents, nil } diff --git a/client/cluster_aks.go b/client/cluster_aks.go index 5b72d7a6..112550d5 100644 --- a/client/cluster_aks.go +++ b/client/cluster_aks.go @@ -1,111 +1,74 @@ package client import ( - "errors" "time" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterAks(cluster *models.V1SpectroAzureClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersAksCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersAksCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersAksCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersAksCreate(params.WithTimeout(90 * time.Second)) +func (h *V1Client) CreateClusterAks(cluster *models.V1SpectroAzureClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersAksCreateParamsWithContext(h.ctx). + WithBody(cluster). + WithTimeout(90 * time.Second) + resp, err := h.Client.V1SpectroClustersAksCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolAks(cloudConfigId string, machinePool *models.V1AzureMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAksMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAksMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAksMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolAks(cloudConfigUid string, machinePool *models.V1AzureMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAksMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAksMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolAks(cloudConfigId string, machinePool *models.V1AzureMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAksMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAksMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAksMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolAks(cloudConfigUid string, machinePool *models.V1AzureMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAksMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAksMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolAks(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAksMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAksMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsAksMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolAks(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsAksMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsAksMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigAks(configUID, ClusterContext string) (*models.V1AzureCloudConfig, error) { - var params *clusterC.V1CloudConfigsAksGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsAksGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsAksGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigAks(configUid string) (*models.V1AzureCloudConfig, error) { + params := clientV1.NewV1CloudConfigsAksGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsAksGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetNodeStatusMapAks(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsAksPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAksPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapAks(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsAksPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsAksPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsAksPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { - nMap[node.Metadata.UID] = *node.Status + if node.Status.MaintenanceStatus.Action != "" { + nMap[node.Metadata.UID] = *node.Status + } } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_aws.go b/client/cluster_aws.go index b0f66741..fc08b789 100644 --- a/client/cluster_aws.go +++ b/client/cluster_aws.go @@ -1,117 +1,74 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersAwsCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersAwsCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersAwsCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersAwsCreate(params) +func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersAwsCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersAwsCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolAws(cloudConfigId string, machinePool *models.V1AwsMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAwsMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAwsMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolAws(cloudConfigUid string, machinePool *models.V1AwsMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAwsMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAwsMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolAws(cloudConfigId string, machinePool *models.V1AwsMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAwsMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsMachinePoolUpdateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsMachinePoolUpdateParams().WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAwsMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolAws(cloudConfigUid string, machinePool *models.V1AwsMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAwsMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAwsMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolAws(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAwsMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsAwsMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolAws(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsAwsMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsAwsMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigAws(configUID, ClusterContext string) (*models.V1AwsCloudConfig, error) { - var params *clusterC.V1CloudConfigsAwsGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsAwsGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigAws(configUid string) (*models.V1AwsCloudConfig, error) { + params := clientV1.NewV1CloudConfigsAwsGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsAwsGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) ImportClusterAws(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersAwsImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroAwsClusterImportEntity{ + params := clientV1.NewV1SpectroClustersAwsImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroAwsClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersAwsImport(params) + ) + resp, err := h.Client.V1SpectroClustersAwsImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapAws(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsAwsPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - } - - mpList, err := h.GetClusterClient().V1CloudConfigsAwsPoolMachinesList(params) +func (h *V1Client) GetNodeStatusMapAws(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsAwsPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsAwsPoolMachinesList(params) if err != nil { return nil, err } @@ -123,5 +80,5 @@ func (h *V1Client) GetNodeStatusMapAws(configUID, machinePoolName, ClusterContex } } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_azure.go b/client/cluster_azure.go index 0219a605..c9ff5914 100644 --- a/client/cluster_azure.go +++ b/client/cluster_azure.go @@ -1,125 +1,82 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterAzure(cluster *models.V1SpectroAzureClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersAzureCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersAzureCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersAzureCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersAzureCreate(params) +func (h *V1Client) CreateClusterAzure(cluster *models.V1SpectroAzureClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersAzureCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersAzureCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolAzure(cloudConfigId, ClusterContext string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsAzureMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzureMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAzureMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAzureMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolAzure(cloudConfigUid string, machinePool *models.V1AzureMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAzureMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAzureMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolAzure(cloudConfigId, ClusterContext string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsAzureMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzureMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsAzureMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsAzureMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolAzure(cloudConfigUid string, machinePool *models.V1AzureMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsAzureMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsAzureMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolAzure(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsAzureMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzureMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAzureMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsAzureMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolAzure(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsAzureMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsAzureMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigAzure(configUID, ClusterContext string) (*models.V1AzureCloudConfig, error) { - var params *clusterC.V1CloudConfigsAzureGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzureGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsAzureGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsAzureGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigAzure(configUid string) (*models.V1AzureCloudConfig, error) { + params := clientV1.NewV1CloudConfigsAzureGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsAzureGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) ImportClusterAzure(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersAzureImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroAzureClusterImportEntity{ + params := clientV1.NewV1SpectroClustersAzureImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroAzureClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersAzureImport(params) + ) + resp, err := h.Client.V1SpectroClustersAzureImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapAzure(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsAzurePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzurePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsAzurePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapAzure(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsAzurePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsAzurePoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsAzurePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_backup_config.go b/client/cluster_backup_config.go index 6271948a..0ab8104a 100644 --- a/client/cluster_backup_config.go +++ b/client/cluster_backup_config.go @@ -1,71 +1,47 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) GetClusterBackupConfig(uid, ClusterContext string) (*models.V1ClusterBackup, error) { - if h.GetClusterBackupConfigFn != nil { - return h.GetClusterBackupConfigFn(uid) - } - var params *clusterC.V1ClusterFeatureBackupGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureBackupGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterFeatureBackupGetParams().WithUID(uid) - default: - return nil, errors.New("invalid cluster scope specified") - - } - - success, err := h.GetClusterClient().V1ClusterFeatureBackupGet(params) +func (h *V1Client) GetClusterBackupConfig(uid string) (*models.V1ClusterBackup, error) { + params := clientV1.NewV1ClusterFeatureBackupGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureBackupGet(params) if err != nil { if herr.IsNotFound(err) || herr.IsBackupNotConfigured(err) { return nil, nil } return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) CreateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig, ClusterContext string) error { - var params *clusterC.V1ClusterFeatureBackupCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureBackupCreateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1ClusterFeatureBackupCreateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1ClusterFeatureBackupCreate(params) +func (h *V1Client) CreateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { + params := clientV1.NewV1ClusterFeatureBackupCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1ClusterFeatureBackupCreate(params) return err } -func (h *V1Client) UpdateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig, ClusterContext string) error { - var params *clusterC.V1ClusterFeatureBackupUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureBackupUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1ClusterFeatureBackupUpdateParams().WithUID(uid).WithBody(config) - } - _, err := h.GetClusterClient().V1ClusterFeatureBackupUpdate(params) +func (h *V1Client) UpdateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { + params := clientV1.NewV1ClusterFeatureBackupUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1ClusterFeatureBackupUpdate(params) return err } -func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig, ClusterContext string) error { - if policy, err := h.GetClusterBackupConfig(uid, ClusterContext); err != nil { +func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { + policy, err := h.GetClusterBackupConfig(uid) + if err != nil { return err - } else if policy == nil { - return h.CreateClusterBackupConfig(uid, config, ClusterContext) - } else { - return h.UpdateClusterBackupConfig(uid, config, ClusterContext) } + if policy == nil { + return h.CreateClusterBackupConfig(uid, config) + } + return h.UpdateClusterBackupConfig(uid, config) } diff --git a/client/cluster_coxedge.go b/client/cluster_coxedge.go deleted file mode 100644 index 61760c69..00000000 --- a/client/cluster_coxedge.go +++ /dev/null @@ -1,110 +0,0 @@ -package client - -import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" -) - -func (h *V1Client) CreateClusterCoxEdge(cluster *models.V1SpectroCoxEdgeClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersCoxEdgeCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersCoxEdgeCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersCoxEdgeCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersCoxEdgeCreate(params) - if err != nil { - return "", err - } - - return *success.Payload.UID, nil -} - -func (h *V1Client) CreateMachinePoolCoxEdge(cloudConfigId string, machinePool *models.V1CoxEdgeMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsCoxEdgeMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsCoxEdgeMachinePoolCreate(params) - return err -} - -func (h *V1Client) UpdateMachinePoolCoxEdge(cloudConfigId string, machinePool *models.V1CoxEdgeMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsCoxEdgeMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsCoxEdgeMachinePoolUpdate(params) - return err -} - -func (h *V1Client) DeleteMachinePoolCoxEdge(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsCoxEdgeMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgeMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsCoxEdgeMachinePoolDelete(params) - return err -} - -func (h *V1Client) GetCloudConfigCoxEdge(configUID, ClusterContext string) (*models.V1CoxEdgeCloudConfig, error) { - var params *clusterC.V1CloudConfigsCoxEdgeGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgeGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgeGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsCoxEdgeGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { - return nil, err - } - - return success.Payload, nil -} - -func (h *V1Client) GetNodeStatusMapCoxEdge(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsCoxEdgePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - } - - mpList, err := h.GetClusterClient().V1CloudConfigsCoxEdgePoolMachinesList(params) - nMap := map[string]models.V1CloudMachineStatus{} - if len(mpList.Payload.Items) > 0 { - for _, node := range mpList.Payload.Items { - nMap[node.Metadata.UID] = *node.Status - } - } - return nMap, err -} diff --git a/client/cluster_custom_cloud.go b/client/cluster_custom_cloud.go index 6a44a20b..59afd79f 100644 --- a/client/cluster_custom_cloud.go +++ b/client/cluster_custom_cloud.go @@ -1,134 +1,65 @@ package client import ( - "fmt" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) CreateClusterCustomCloud(cluster *models.V1SpectroCustomClusterEntity, cloudType string, clusterContext string) (string, error) { - if h.CreateClusterCustomCloudFn != nil { - return h.CreateClusterCustomCloudFn(cluster, cloudType, clusterContext) - } - - var params *clusterC.V1SpectroClustersCustomCreateParams - - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersCustomCreateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersCustomCreateParams() - } - params = params.WithCloudType(cloudType).WithBody(cluster) - success, err := h.GetClusterClient().V1SpectroClustersCustomCreate(params) +func (h *V1Client) CreateClusterCustomCloud(cluster *models.V1SpectroCustomClusterEntity, cloudType string) (string, error) { + params := clientV1.NewV1SpectroClustersCustomCreateParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersCustomCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetCloudConfigCustomCloud(configUID string, cloudType string, clusterContext string) (*models.V1CustomCloudConfig, error) { - if h.GetCloudConfigCustomCloudFn != nil { - return h.GetCloudConfigCustomCloudFn(configUID, cloudType, clusterContext) - } - var params *clusterC.V1CloudConfigsCustomGetParams - switch clusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCustomGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCustomGetParams() - default: - return nil, fmt.Errorf("invalid scope %s", clusterContext) - } - params = params.WithCloudType(cloudType).WithConfigUID(configUID) - success, err := h.GetClusterClient().V1CloudConfigsCustomGet(params) +func (h *V1Client) GetCloudConfigCustomCloud(configUid, cloudType string) (*models.V1CustomCloudConfig, error) { + params := clientV1.NewV1CloudConfigsCustomGetParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsCustomGet(params) if err != nil { return nil, err } - - // special check if the cluster is marked deleted - cluster := success.Payload - return cluster, nil - + return resp.Payload, nil } -func (h *V1Client) UpdateCloudConfigCustomCloud(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUID string, cloudType string, clusterContext string) error { - if h.UpdateCloudConfigCustomCloudFn != nil { - return h.UpdateCloudConfigCustomCloudFn(updatedConfig, configUID, cloudType, clusterContext) - } - - var params *clusterC.V1CloudConfigsCustomUIDClusterConfigParams - switch clusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCustomUIDClusterConfigParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCustomUIDClusterConfigParams() - } - params = params.WithCloudType(cloudType).WithBody(updatedConfig).WithConfigUID(configUID) - _, err := h.GetClusterClient().V1CloudConfigsCustomUIDClusterConfig(params) - if err != nil { - return err - } - return nil +func (h *V1Client) UpdateCloudConfigCustomCloud(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUid, cloudType string) error { + params := clientV1.NewV1CloudConfigsCustomUIDClusterConfigParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithBody(updatedConfig). + WithConfigUID(configUid) + _, err := h.Client.V1CloudConfigsCustomUIDClusterConfig(params) + return err } -func (h *V1Client) CreateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error { - if h.CreateMachinePoolCustomCloudFn != nil { - return h.CreateMachinePoolCustomCloudFn(mpEntity, configUID, cloudType, clusterContext) - } - - var params *clusterC.V1CloudConfigsCustomMachinePoolCreateParams - switch clusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCustomMachinePoolCreateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCustomMachinePoolCreateParams() - } - params = params.WithCloudType(cloudType).WithBody(mpEntity).WithConfigUID(configUID) - _, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolCreate(params) - if err != nil { - return err - } - return nil +func (h *V1Client) CreateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, configUid, cloudType string) error { + params := clientV1.NewV1CloudConfigsCustomMachinePoolCreateParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithBody(mpEntity). + WithConfigUID(configUid) + _, err := h.Client.V1CloudConfigsCustomMachinePoolCreate(params) + return err } -func (h *V1Client) UpdateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, machinePoolName, configUID string, cloudType string, clusterContext string) error { - if h.UpdateMachinePoolCustomCloudFn != nil { - return h.UpdateMachinePoolCustomCloudFn(mpEntity, machinePoolName, configUID, cloudType, clusterContext) - } - - var params *clusterC.V1CloudConfigsCustomMachinePoolUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCustomMachinePoolUpdateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCustomMachinePoolUpdateParams() - } - params = params.WithCloudType(cloudType).WithBody(mpEntity).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - _, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolUpdate(params) - if err != nil { - return err - } - return nil +func (h *V1Client) UpdateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, machinePoolName, configUid, cloudType string) error { + params := clientV1.NewV1CloudConfigsCustomMachinePoolUpdateParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithBody(mpEntity). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsCustomMachinePoolUpdate(params) + return err } -func (h *V1Client) DeleteMachinePoolCustomCloud(mpName string, configUID string, cloudType string, clusterContext string) error { - if h.DeleteMachinePoolCustomCloudFn != nil { - return h.DeleteMachinePoolCustomCloudFn(mpName, configUID, cloudType, clusterContext) - } - - var params *clusterC.V1CloudConfigsCustomMachinePoolDeleteParams - switch clusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCustomMachinePoolDeleteParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCustomMachinePoolDeleteParams() - } - params = params.WithCloudType(cloudType).WithConfigUID(configUID).WithMachinePoolName(mpName) - _, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolDelete(params) - if err != nil { - return err - } - return nil +func (h *V1Client) DeleteMachinePoolCustomCloud(mpName string, configUid, cloudType string) error { + params := clientV1.NewV1CloudConfigsCustomMachinePoolDeleteParamsWithContext(h.ctx). + WithCloudType(cloudType). + WithConfigUID(configUid). + WithMachinePoolName(mpName) + _, err := h.Client.V1CloudConfigsCustomMachinePoolDelete(params) + return err } diff --git a/client/cluster_edge.go b/client/cluster_edge.go index fe63d35c..156edd24 100644 --- a/client/cluster_edge.go +++ b/client/cluster_edge.go @@ -1,110 +1,69 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterEdge(cluster *models.V1SpectroEdgeClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersEdgeCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersEdgeCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersEdgeCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersEdgeCreate(params) +func (h *V1Client) CreateClusterEdge(cluster *models.V1SpectroEdgeClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersEdgeCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersEdgeCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolEdge(cloudConfigId string, machinePool *models.V1EdgeMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsEdgeMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsEdgeMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolEdge(cloudConfigUid string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEdgeMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEdgeMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolEdge(cloudConfigId string, machinePool *models.V1EdgeMachinePoolConfigEntity, ClusterContext string) error { - var params *clusterC.V1CloudConfigsEdgeMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsEdgeMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolEdge(cloudConfigUid string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEdgeMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEdgeMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolEdge(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsEdgeMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsEdgeMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolEdge(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsEdgeMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsEdgeMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigEdge(configUID, ClusterContext string) (*models.V1EdgeCloudConfig, error) { - var params *clusterC.V1CloudConfigsEdgeGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsEdgeGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigEdge(configUid string) (*models.V1EdgeCloudConfig, error) { + params := clientV1.NewV1CloudConfigsEdgeGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsEdgeGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetNodeStatusMapEdge(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsEdgePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapEdge(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsEdgePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsEdgePoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsEdgePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index cab434d5..4a5ee6d1 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -3,111 +3,149 @@ package client import ( "errors" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersEdgeNativeCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersEdgeNativeCreateParams().WithBody(cluster) +func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { + params := clientV1.NewV1EdgeTokensListParamsWithContext(h.ctx) + resp, err := h.Client.V1EdgeTokensList(params) + if err != nil { + return "", err + } + tokens := resp.GetPayload() + if tokens == nil { + return "", errors.New("failed to list registration tokens") + } + for _, token := range tokens.Items { + if token.Status.IsActive && token.Metadata.Name == tokenName { + return token.Spec.Token, nil + } } + return "", nil +} - success, err := h.GetClusterClient().V1SpectroClustersEdgeNativeCreate(params) +func (h *V1Client) CreateRegistrationToken(tokenName string, body *models.V1EdgeTokenEntity) (string, error) { + params := clientV1.NewV1EdgeTokensCreateParamsWithContext(h.ctx). + WithBody(body) + _, err := h.Client.V1EdgeTokensCreate(params) if err != nil { return "", err } + return h.GetRegistrationToken(tokenName) - return *success.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolEdgeNative(cloudConfigId, ClusterContext string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsEdgeNativeMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) +func (h *V1Client) GetEdgeHost(edgeHostId string) (*models.V1EdgeHostDevice, error) { + params := clientV1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). + WithUID(edgeHostId) + resp, err := h.Client.V1EdgeHostDevicesUIDGet(params) + if err != nil { + return nil, err } + return resp.Payload, nil +} - _, err := h.GetClusterClient().V1CloudConfigsEdgeNativeMachinePoolCreate(params) - return err +func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) { + params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx) + resp, err := h.Client.V1DashboardEdgehostsSearch(params) + if err != nil { + return nil, err + } + return resp.Payload.Items, nil } -func (h *V1Client) UpdateMachinePoolEdgeNative(cloudConfigId, ClusterContext string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsEdgeNativeMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) +func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersEdgeNativeCreate(params) + if err != nil { + return "", err } + return *resp.Payload.UID, nil +} - _, err := h.GetClusterClient().V1CloudConfigsEdgeNativeMachinePoolUpdate(params) +func (h *V1Client) CreateMachinePoolEdgeNative(cloudConfigUid string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEdgeNativeMachinePoolCreate(params) return err } -func (h *V1Client) DeleteMachinePoolEdgeNative(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsEdgeNativeMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativeMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsEdgeNativeMachinePoolDelete(params) +func (h *V1Client) UpdateMachinePoolEdgeNative(cloudConfigUid string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEdgeNativeMachinePoolUpdate(params) return err } -func (h *V1Client) GetCloudConfigEdgeNative(configUID, ClusterContext string) (*models.V1EdgeNativeCloudConfig, error) { - if h.GetCloudConfigEdgeNativeFn != nil { - return h.GetCloudConfigEdgeNativeFn(configUID, ClusterContext) - } - var params *clusterC.V1CloudConfigsEdgeNativeGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativeGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativeGetParams().WithConfigUID(configUID) +func (h *V1Client) GetMachineEdgeNative(machineUid, machinePoolName, cloudConfigUid string) (*models.V1EdgeNativeMachine, error) { + params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName). + WithMachineUID(machineUid) + resp, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesUIDGet(params) + if err != nil { + return nil, err } + return resp.Payload, nil +} + +func (h *V1Client) DeleteMachineEdgeNative(clusterUid, edgeHostUid, machinePool, cloudConfigUid string) error { + params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePool). + WithMachineUID(edgeHostUid) + _, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesUIDDelete(params) + return err +} - success, err := h.GetClusterClient().V1CloudConfigsEdgeNativeGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) ListMachinesInPoolEdgeNative(machinePoolName, cloudConfigUid string) ([]*models.V1EdgeNativeMachine, error) { + params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + resp, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesList(params) + if err != nil { return nil, err } + return resp.Payload.Items, nil +} - return success.Payload, nil +func (h *V1Client) DeleteMachinePoolEdgeNative(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsEdgeNativeMachinePoolDelete(params) + return err } -func (h *V1Client) GetNodeStatusMapEdgeNative(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsEdgeNativePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetCloudConfigEdgeNative(configUid string) (*models.V1EdgeNativeCloudConfig, error) { + params := clientV1.NewV1CloudConfigsEdgeNativeGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsEdgeNativeGet(params) + if err := apiutil.Handle404(err); err != nil { + return nil, err } + return resp.Payload, nil +} - mpList, err := h.GetClusterClient().V1CloudConfigsEdgeNativePoolMachinesList(params) +func (h *V1Client) GetNodeStatusMapEdgeNative(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesList(params) + if err != nil { + return nil, err + } nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_edge_vsphere.go b/client/cluster_edge_vsphere.go index 9a7881d3..a8cc7e3f 100644 --- a/client/cluster_edge_vsphere.go +++ b/client/cluster_edge_vsphere.go @@ -1,124 +1,82 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterEdgeVsphere(cluster *models.V1SpectroVsphereClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersVsphereCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersVsphereCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersVsphereCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersVsphereCreate(params) +func (h *V1Client) CreateClusterEdgeVsphere(cluster *models.V1SpectroVsphereClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersVsphereCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolEdgeVsphere(cloudConfigId, ClusterContext string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolEdgeVsphere(cloudConfigUid string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolEdgeVsphere(cloudConfigId, ClusterContext string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolEdgeVsphere(cloudConfigUid string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolEdgeVsphere(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolEdgeVsphere(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigEdgeVsphere(configUID, ClusterContext string) (*models.V1VsphereCloudConfig, error) { - var params *clusterC.V1CloudConfigsVsphereGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsVsphereGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigEdgeVsphere(configUid string) (*models.V1VsphereCloudConfig, error) { + params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsVsphereGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) ImportClusterEdgeVsphere(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersVsphereImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroVsphereClusterImportEntity{ + params := clientV1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroVsphereClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersVsphereImport(params) + ) + resp, err := h.Client.V1SpectroClustersVsphereImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapEdgeVsphere(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsVspherePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapEdgeVsphere(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsVspherePoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsVspherePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_eks.go b/client/cluster_eks.go index 935ec078..07867266 100644 --- a/client/cluster_eks.go +++ b/client/cluster_eks.go @@ -1,128 +1,80 @@ package client import ( - "errors" "time" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterEks(cluster *models.V1SpectroEksClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersEksCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersEksCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersEksCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersEksCreate(params.WithTimeout(90 * time.Second)) +func (h *V1Client) CreateClusterEks(cluster *models.V1SpectroEksClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersEksCreateParamsWithContext(h.ctx). + WithBody(cluster). + WithTimeout(90 * time.Second) + resp, err := h.Client.V1SpectroClustersEksCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolEks(cloudConfigId, ClusterContext string, machinePool *models.V1EksMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsEksMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEksMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsEksMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolEks(cloudConfigUid string, machinePool *models.V1EksMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEksMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEksMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolEks(cloudConfigId, ClusterContext string, machinePool *models.V1EksMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsEksMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsEksMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsEksMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolEks(cloudConfigUid string, machinePool *models.V1EksMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsEksMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsEksMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolEks(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsEksMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEksMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsEksMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolEks(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsEksMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsEksMachinePoolDelete(params) return err } -func (h *V1Client) UpdateFargateProfilesEks(cloudConfigId, ClusterContext string, fargateProfiles *models.V1EksFargateProfiles) error { - var params *clusterC.V1CloudConfigsEksUIDFargateProfilesUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksUIDFargateProfilesUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithBody(fargateProfiles) - case "tenant": - params = clusterC.NewV1CloudConfigsEksUIDFargateProfilesUpdateParams(). - WithConfigUID(cloudConfigId). - WithBody(fargateProfiles) - } - - _, err := h.GetClusterClient().V1CloudConfigsEksUIDFargateProfilesUpdate(params) +func (h *V1Client) UpdateFargateProfilesEks(cloudConfigUid string, fargateProfiles *models.V1EksFargateProfiles) error { + params := clientV1.NewV1CloudConfigsEksUIDFargateProfilesUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(fargateProfiles) + _, err := h.Client.V1CloudConfigsEksUIDFargateProfilesUpdate(params) return err } -func (h *V1Client) GetCloudConfigEks(configUID, ClusterContext string) (*models.V1EksCloudConfig, error) { - var params *clusterC.V1CloudConfigsEksGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsEksGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsEksGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigEks(configUid string) (*models.V1EksCloudConfig, error) { + params := clientV1.NewV1CloudConfigsEksGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsEksGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetNodeStatusMapEks(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsEksPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsEksPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapEks(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsEksPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsEksPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsEksPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_gcp.go b/client/cluster_gcp.go index 91e79309..d72741bd 100644 --- a/client/cluster_gcp.go +++ b/client/cluster_gcp.go @@ -1,124 +1,82 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterGcp(cluster *models.V1SpectroGcpClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersGcpCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersGcpCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersGcpCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersGcpCreate(params) +func (h *V1Client) CreateClusterGcp(cluster *models.V1SpectroGcpClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersGcpCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersGcpCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolGcp(cloudConfigId, ClusterContext string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsGcpMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsGcpMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolGcp(cloudConfigUid string, machinePool *models.V1GcpMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsGcpMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsGcpMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolGcp(cloudConfigId, ClusterContext string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsGcpMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsGcpMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolGcp(cloudConfigUid string, machinePool *models.V1GcpMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsGcpMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsGcpMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolGcp(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsGcpMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsGcpMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolGcp(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsGcpMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsGcpMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigGcp(configUID, ClusterContext string) (*models.V1GcpCloudConfig, error) { - var params *clusterC.V1CloudConfigsGcpGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsGcpGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigGcp(configUid string) (*models.V1GcpCloudConfig, error) { + params := clientV1.NewV1CloudConfigsGcpGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsGcpGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) ImportClusterGcp(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersGcpImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroGcpClusterImportEntity{ + params := clientV1.NewV1SpectroClustersGcpImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroGcpClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersGcpImport(params) + ) + resp, err := h.Client.V1SpectroClustersGcpImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapGcp(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsGcpPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapGcp(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsGcpPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsGcpPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsGcpPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_group.go b/client/cluster_group.go index 4a1fa95c..ca739c1f 100644 --- a/client/cluster_group.go +++ b/client/cluster_group.go @@ -1,60 +1,30 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterGroup(cluster *models.V1ClusterGroupEntity, scope string) (string, error) { - if h.CreateClusterGroupFn != nil { - return h.CreateClusterGroupFn(cluster) - } - - var params *clusterC.V1ClusterGroupsCreateParams - switch scope { - case "project": - params = clusterC.NewV1ClusterGroupsCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1ClusterGroupsCreateParams().WithBody(cluster) - default: - return "", errors.New("invalid scope " + scope) - } - - success, err := h.GetClusterClient().V1ClusterGroupsCreate(params) +func (h *V1Client) CreateClusterGroup(cluster *models.V1ClusterGroupEntity) (string, error) { + params := clientV1.NewV1ClusterGroupsCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1ClusterGroupsCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) DeleteClusterGroup(uid, scope string) error { - if h.DeleteClusterGroupFn != nil { - return h.DeleteClusterGroupFn(uid) - } - - var params *clusterC.V1ClusterGroupsUIDDeleteParams - switch scope { - case "project": - params = clusterC.NewV1ClusterGroupsUIDDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterGroupsUIDDeleteParams().WithUID(uid) - default: - return errors.New("invalid scope " + scope) - } - - _, err := h.GetClusterClient().V1ClusterGroupsUIDDelete(params) +func (h *V1Client) DeleteClusterGroup(uid string) error { + params := clientV1.NewV1ClusterGroupsUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1ClusterGroupsUIDDelete(params) return err } -func (h *V1Client) GetClusterGroup(uid, scope string) (*models.V1ClusterGroup, error) { - if h.GetClusterGroupFn != nil { - return h.GetClusterGroupFn(uid) - } - - group, err := h.GetClusterGroupWithoutStatus(uid, scope) +func (h *V1Client) GetClusterGroup(uid string) (*models.V1ClusterGroup, error) { + group, err := h.GetClusterGroupWithoutStatus(uid) if err != nil { return nil, err } @@ -64,164 +34,93 @@ func (h *V1Client) GetClusterGroup(uid, scope string) (*models.V1ClusterGroup, e return group, nil } -func (h *V1Client) GetClusterGroupWithoutStatus(uid, scope string) (*models.V1ClusterGroup, error) { - var params *clusterC.V1ClusterGroupsUIDGetParams - switch scope { - case "project": - params = clusterC.NewV1ClusterGroupsUIDGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterGroupsUIDGetParams().WithUID(uid) - default: - return nil, errors.New("invalid scope " + scope) - } - - success, err := h.GetClusterClient().V1ClusterGroupsUIDGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetClusterGroupWithoutStatus(uid string) (*models.V1ClusterGroup, error) { + params := clientV1.NewV1ClusterGroupsUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterGroupsUIDGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - cluster := success.Payload - return cluster, nil + return resp.Payload, nil } -func (h *V1Client) GetClusterGroupByName(name, clusterGroupContext string) (*models.V1ObjectScopeEntity, error) { - metadata, err := h.getClusterGroupMetadata(clusterGroupContext) +func (h *V1Client) GetClusterGroupByName(name string) (*models.V1ObjectScopeEntity, error) { + metadata, err := h.getClusterGroupMetadata() if err != nil { return nil, err } - for _, groupMeta := range metadata { - if groupMeta.Name == name && groupMeta.Scope == clusterGroupContext { + if groupMeta.Name == name { return groupMeta, nil } } return nil, nil } -func (h *V1Client) GetClusterGroupByNameForProject(name, clusterGroupContext string) (*models.V1ClusterGroupSummary, error) { - summaries, err := h.GetClusterGroupSummaries(clusterGroupContext) +func (h *V1Client) GetClusterGroupByNameForProject(name string) (*models.V1ClusterGroupSummary, error) { + summaries, err := h.GetClusterGroupSummaries() if err != nil { return nil, err } - for _, groupSummary := range summaries { - if groupSummary.Metadata.Name == name && groupSummary.Spec.Scope == clusterGroupContext { + if groupSummary.Metadata.Name == name { return groupSummary, nil } } return nil, nil } -func (h *V1Client) GetClusterGroupMetadata(clusterGroupContext string) ([]*models.V1ObjectScopeEntity, error) { - metadata, err := h.getClusterGroupMetadata(clusterGroupContext) +func (h *V1Client) GetClusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) { + metadata, err := h.getClusterGroupMetadata() if err != nil { return nil, err } return metadata, nil } -func (h *V1Client) GetClusterGroupSummaries(clusterGroupContext string) ([]*models.V1ClusterGroupSummary, error) { - var params *clusterC.V1ClusterGroupsHostClusterSummaryParams - switch clusterGroupContext { - case "system": - params = clusterC.NewV1ClusterGroupsHostClusterSummaryParams() - case "project": - fallthrough - case "tenant": - params = clusterC.NewV1ClusterGroupsHostClusterSummaryParamsWithContext(h.Ctx) - default: - return nil, errors.New("invalid scope " + clusterGroupContext) - } - - resp, err := h.GetClusterClient().V1ClusterGroupsHostClusterSummary(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } return resp.Payload.Summaries, nil } -// Update cluster group metadata by invoking V1ClusterGroupsUIDMetaUpdate hapi api -func (h *V1Client) UpdateClusterGroupMeta(clusterGroup *models.V1ClusterGroupEntity, scope string) error { - var params *clusterC.V1ClusterGroupsUIDMetaUpdateParams - switch scope { - case "project": - params = clusterC.NewV1ClusterGroupsUIDMetaUpdateParamsWithContext(h.Ctx).WithUID(clusterGroup.Metadata.UID) - case "tenant": - params = clusterC.NewV1ClusterGroupsUIDMetaUpdateParams().WithUID(clusterGroup.Metadata.UID) - default: - return errors.New("invalid scope " + scope) - } - - params = params.WithBody(&models.V1ObjectMeta{ - Name: clusterGroup.Metadata.Name, - Labels: clusterGroup.Metadata.Labels, - Annotations: clusterGroup.Metadata.Annotations, - }) - _, err := h.GetClusterClient().V1ClusterGroupsUIDMetaUpdate(params) +// Update cluster group metadata by invoking V1ClusterGroupsUIDMetaUpdate API +func (h *V1Client) UpdateClusterGroupMeta(clusterGroup *models.V1ClusterGroupEntity) error { + params := clientV1.NewV1ClusterGroupsUIDMetaUpdateParamsWithContext(h.ctx). + WithUID(clusterGroup.Metadata.UID). + WithBody(&models.V1ObjectMeta{ + Name: clusterGroup.Metadata.Name, + Labels: clusterGroup.Metadata.Labels, + Annotations: clusterGroup.Metadata.Annotations, + }) + _, err := h.Client.V1ClusterGroupsUIDMetaUpdate(params) return err } -// Update cluster group by invoking V1ClusterGroupsUIDHostClusterUpdate hapi api -func (h *V1Client) UpdateClusterGroup(uid string, clusterGroup *models.V1ClusterGroupHostClusterEntity, scope string) error { - if h.UpdateClusterGroupFn != nil { - return h.UpdateClusterGroupFn(uid, clusterGroup) - } - - var params *clusterC.V1ClusterGroupsUIDHostClusterUpdateParams - switch scope { - case "project": - params = clusterC.NewV1ClusterGroupsUIDHostClusterUpdateParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterGroupsUIDHostClusterUpdateParams().WithUID(uid) - default: - return errors.New("invalid scope " + scope) - } - params = params.WithBody(clusterGroup) - - _, err := h.GetClusterClient().V1ClusterGroupsUIDHostClusterUpdate(params) +// Update cluster group by invoking V1ClusterGroupsUIDHostClusterUpdate API +func (h *V1Client) UpdateClusterGroup(uid string, clusterGroup *models.V1ClusterGroupHostClusterEntity) error { + params := clientV1.NewV1ClusterGroupsUIDHostClusterUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(clusterGroup) + _, err := h.Client.V1ClusterGroupsUIDHostClusterUpdate(params) return err } -func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupContext, clusterGroupUid string, clusterProfiles *models.V1SpectroClusterProfiles) error { - var params *clusterC.V1ClusterGroupsUIDProfilesUpdateParams - switch clusterGroupContext { - case "project": - params = clusterC.NewV1ClusterGroupsUIDProfilesUpdateParamsWithContext(h.Ctx).WithUID(clusterGroupUid) - case "tenant": - params = clusterC.NewV1ClusterGroupsUIDProfilesUpdateParams().WithUID(clusterGroupUid) - default: - return errors.New("invalid scope " + clusterGroupContext) - } - params = params.WithBody(clusterProfiles) - - _, err := h.GetClusterClient().V1ClusterGroupsUIDProfilesUpdate(params) +func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupUid string, clusterProfiles *models.V1SpectroClusterProfiles) error { + params := clientV1.NewV1ClusterGroupsUIDProfilesUpdateParamsWithContext(h.ctx). + WithUID(clusterGroupUid). + WithBody(clusterProfiles) + _, err := h.Client.V1ClusterGroupsUIDProfilesUpdate(params) return err } -func (h *V1Client) getClusterGroupMetadata(clusterGroupContext string) ([]*models.V1ObjectScopeEntity, error) { - var params *clusterC.V1ClusterGroupsHostClusterMetadataParams - switch clusterGroupContext { - case "system": - params = clusterC.NewV1ClusterGroupsHostClusterMetadataParams() - case "project": - fallthrough - case "tenant": - params = clusterC.NewV1ClusterGroupsHostClusterMetadataParamsWithContext(h.Ctx) - default: - return nil, errors.New("invalid scope " + clusterGroupContext) - } - - resp, err := h.GetClusterClient().V1ClusterGroupsHostClusterMetadata(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +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 { return nil, err } return resp.Payload.Items, nil diff --git a/client/cluster_host_config.go b/client/cluster_host_config.go index 9d0507c5..05259216 100644 --- a/client/cluster_host_config.go +++ b/client/cluster_host_config.go @@ -1,29 +1,25 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) UpdateClusterHostConfig(uid, clusterContext string, config *models.V1HostClusterConfigEntity) error { - var params *clusterC.V1HostClusterConfigUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1HostClusterConfigUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1HostClusterConfigUpdateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1HostClusterConfigUpdate(params) +func (h *V1Client) UpdateClusterHostConfig(uid string, config *models.V1HostClusterConfigEntity) error { + params := clientV1.NewV1HostClusterConfigUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1HostClusterConfigUpdate(params) return err } -func (h *V1Client) ApplyClusterHostConfig(uid, clusterContext string, config *models.V1HostClusterConfigEntity) error { - if policy, err := h.GetClusterScanConfig(uid, clusterContext); err != nil { +func (h *V1Client) ApplyClusterHostConfig(uid string, config *models.V1HostClusterConfigEntity) error { + policy, err := h.GetClusterScanConfig(uid) + if err != nil { return err - } else if policy == nil { - return h.UpdateClusterHostConfig(uid, clusterContext, config) - } else { - return h.UpdateClusterHostConfig(uid, clusterContext, config) } + if policy == nil { + return h.UpdateClusterHostConfig(uid, config) + } + return h.UpdateClusterHostConfig(uid, config) } diff --git a/client/cluster_libvirt.go b/client/cluster_libvirt.go index b026c532..215bb473 100644 --- a/client/cluster_libvirt.go +++ b/client/cluster_libvirt.go @@ -1,111 +1,69 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterLibvirt(cluster *models.V1SpectroLibvirtClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersLibvirtCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersLibvirtCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersLibvirtCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersLibvirtCreate(params) +func (h *V1Client) CreateClusterLibvirt(cluster *models.V1SpectroLibvirtClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersLibvirtCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersLibvirtCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolLibvirt(cloudConfigId, ClusterContext string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsLibvirtMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsLibvirtMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolLibvirt(cloudConfigUid string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsLibvirtMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsLibvirtMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolLibvirt(cloudConfigId, ClusterContext string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsLibvirtMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsLibvirtMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolLibvirt(cloudConfigUid string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsLibvirtMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsLibvirtMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolLibvirt(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsLibvirtMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsLibvirtMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolLibvirt(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsLibvirtMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsLibvirtMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigLibvirt(configUID, ClusterContext string) (*models.V1LibvirtCloudConfig, error) { - var params *clusterC.V1CloudConfigsLibvirtGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsLibvirtGet(params) - - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigLibvirt(configUid string) (*models.V1LibvirtCloudConfig, error) { + params := clientV1.NewV1CloudConfigsLibvirtGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsLibvirtGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetNodeStatusMapLibvirt(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsLibvirtPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapLibvirt(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsLibvirtPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsLibvirtPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsLibvirtPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_location_config.go b/client/cluster_location_config.go index 1e81caae..d6b57795 100644 --- a/client/cluster_location_config.go +++ b/client/cluster_location_config.go @@ -1,41 +1,30 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) GetClusterLocationConfig(scope, uid string) (*models.V1ClusterLocation, error) { - if clusterStatus, err := h.GetClusterWithoutStatus(scope, uid); err != nil { +func (h *V1Client) GetClusterLocationConfig(uid string) (*models.V1ClusterLocation, error) { + clusterStatus, err := h.GetClusterWithoutStatus(uid) + if err != nil { return nil, err - } else if clusterStatus != nil && clusterStatus.Status != nil && clusterStatus.Status.Location != nil { - return clusterStatus.Status.Location, nil } - - return nil, errors.New("failed to read cluster location") + return clusterStatus.Status.Location, nil } -func (h *V1Client) UpdateClusterLocationConfig(uid, clusterContext string, config *models.V1SpectroClusterLocationInputEntity) error { - var params *clusterC.V1SpectroClustersUIDLocationPutParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDLocationPutParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDLocationPutParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDLocationPut(params) +func (h *V1Client) UpdateClusterLocationConfig(uid string, config *models.V1SpectroClusterLocationInputEntity) error { + params := clientV1.NewV1SpectroClustersUIDLocationPutParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1SpectroClustersUIDLocationPut(params) return err } -func (h *V1Client) ApplyClusterLocationConfig(scope, uid string, config *models.V1SpectroClusterLocationInputEntity) error { - if curentConfig, err := h.GetClusterLocationConfig(scope, uid); err != nil { +func (h *V1Client) ApplyClusterLocationConfig(uid string, config *models.V1SpectroClusterLocationInputEntity) error { + _, err := h.GetClusterLocationConfig(uid) + if err != nil { return err - } else if curentConfig == nil { - return h.UpdateClusterLocationConfig(uid, scope, config) - } else { - return h.UpdateClusterLocationConfig(uid, scope, config) } + return h.UpdateClusterLocationConfig(uid, config) // update method is same as create } diff --git a/client/cluster_maas.go b/client/cluster_maas.go index 8833b050..dd60f120 100644 --- a/client/cluster_maas.go +++ b/client/cluster_maas.go @@ -1,131 +1,90 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) // Cluster -func (h *V1Client) CreateClusterMaas(cluster *models.V1SpectroMaasClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersMaasCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersMaasCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersMaasCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersMaasCreate(params) +func (h *V1Client) CreateClusterMaas(cluster *models.V1SpectroMaasClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersMaasCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersMaasCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } // Machine Pool -func (h *V1Client) CreateMachinePoolMaas(cloudConfigId, ClusterContext string, machinePool *models.V1MaasMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsMaasMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsMaasMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolMaas(cloudConfigUid string, machinePool *models.V1MaasMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsMaasMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsMaasMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolMaas(cloudConfigId, ClusterContext string, machinePool *models.V1MaasMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsMaasMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsMaasMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolMaas(cloudConfigUid string, machinePool *models.V1MaasMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsMaasMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsMaasMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolMaas(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsMaasMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsMaasMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolMaas(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsMaasMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsMaasMachinePoolDelete(params) return err } // Cloud Config -func (h *V1Client) GetCloudConfigMaas(configUID, ClusterContext string) (*models.V1MaasCloudConfig, error) { - var params *clusterC.V1CloudConfigsMaasGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsMaasGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigMaas(configUid string) (*models.V1MaasCloudConfig, error) { + params := clientV1.NewV1CloudConfigsMaasGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsMaasGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } // Import func (h *V1Client) ImportClusterMaas(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersMaasImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroMaasClusterImportEntity{ + params := clientV1.NewV1SpectroClustersMaasImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroMaasClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersMaasImport(params) + ) + resp, err := h.Client.V1SpectroClustersMaasImport(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapMaas(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsMaasPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapMaas(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsMaasPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsMaasPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsMaasPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_metadata_config.go b/client/cluster_metadata_config.go index a700f002..0610e144 100644 --- a/client/cluster_metadata_config.go +++ b/client/cluster_metadata_config.go @@ -1,33 +1,22 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) UpdateClusterMetadata(uid, clusterContext string, config *models.V1ObjectMetaInputEntitySchema) error { - var params *clusterC.V1SpectroClustersUIDMetadataUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDMetadataUpdateParams().WithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDMetadataUpdateParams().WithUID(uid).WithBody(config) - } - - //params := clusterC.NewV1SpectroClustersUIDMetadataUpdateParams().WithContext(h.Ctx).WithUID(uid).WithBody(config) - _, err := h.GetClusterClient().V1SpectroClustersUIDMetadataUpdate(params) +func (h *V1Client) UpdateClusterMetadata(uid string, config *models.V1ObjectMetaInputEntitySchema) error { + params := clientV1.NewV1SpectroClustersUIDMetadataUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1SpectroClustersUIDMetadataUpdate(params) return err } -func (h *V1Client) UpdateAdditionalClusterMetadata(uid, clusterContext string, additionalMeta *models.V1ClusterMetaAttributeEntity) error { - var params *clusterC.V1SpectroClustersUIDClusterMetaAttributeUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDClusterMetaAttributeUpdateParams().WithContext(h.Ctx).WithUID(uid).WithBody(additionalMeta) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDClusterMetaAttributeUpdateParams().WithUID(uid).WithBody(additionalMeta) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDClusterMetaAttributeUpdate(params) +func (h *V1Client) UpdateAdditionalClusterMetadata(uid string, additionalMeta *models.V1ClusterMetaAttributeEntity) error { + params := clientV1.NewV1SpectroClustersUIDClusterMetaAttributeUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(additionalMeta) + _, err := h.Client.V1SpectroClustersUIDClusterMetaAttributeUpdate(params) return err } diff --git a/client/cluster_namespace_config.go b/client/cluster_namespace_config.go index 3b96b10c..5bc319bd 100644 --- a/client/cluster_namespace_config.go +++ b/client/cluster_namespace_config.go @@ -1,55 +1,39 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) GetClusterNamespaceConfig(uid, clusterContext string) (*models.V1ClusterNamespaceResources, error) { - if h.GetClusterNamespaceConfigFn != nil { - return h.GetClusterNamespaceConfigFn(uid) - } - - var params *clusterC.V1SpectroClustersUIDConfigNamespacesGetParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDConfigNamespacesGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDConfigNamespacesGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1SpectroClustersUIDConfigNamespacesGet(params) +func (h *V1Client) GetClusterNamespaceConfig(uid string) (*models.V1ClusterNamespaceResources, error) { + params := clientV1.NewV1SpectroClustersUIDConfigNamespacesGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1SpectroClustersUIDConfigNamespacesGet(params) if err != nil { if herr.IsNotFound(err) { return nil, nil } return nil, err } - - return success.Payload, nil + return resp.Payload, nil } // UpdateClusterNamespaceConfig no create for namespaces, there is only update. -func (h *V1Client) UpdateClusterNamespaceConfig(uid, clusterContext string, config *models.V1ClusterNamespaceResourcesUpdateEntity) error { - var params *clusterC.V1SpectroClustersUIDConfigNamespacesUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDConfigNamespacesUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDConfigNamespacesUpdateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDConfigNamespacesUpdate(params) +func (h *V1Client) UpdateClusterNamespaceConfig(uid string, config *models.V1ClusterNamespaceResourcesUpdateEntity) error { + params := clientV1.NewV1SpectroClustersUIDConfigNamespacesUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1SpectroClustersUIDConfigNamespacesUpdate(params) return err } -func (h *V1Client) ApplyClusterNamespaceConfig(uid, clusterContext string, config []*models.V1ClusterNamespaceResourceInputEntity) error { - if _, err := h.GetClusterNamespaceConfig(uid, clusterContext); err != nil { +func (h *V1Client) ApplyClusterNamespaceConfig(uid string, config []*models.V1ClusterNamespaceResourceInputEntity) error { + _, err := h.GetClusterNamespaceConfig(uid) + if err != nil { return err - } else { - return h.UpdateClusterNamespaceConfig(uid, clusterContext, toUpdateNamespace(config)) // update method is same as create } + return h.UpdateClusterNamespaceConfig(uid, toUpdateNamespace(config)) // update method is same as create } func toUpdateNamespace(config []*models.V1ClusterNamespaceResourceInputEntity) *models.V1ClusterNamespaceResourcesUpdateEntity { diff --git a/client/cluster_openstack.go b/client/cluster_openstack.go index 14c013b0..2cf5c832 100644 --- a/client/cluster_openstack.go +++ b/client/cluster_openstack.go @@ -1,130 +1,92 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) // Cluster -func (h *V1Client) CreateClusterOpenStack(cluster *models.V1SpectroOpenStackClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersOpenStackCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersOpenStackCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersOpenStackCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersOpenStackCreate(params) +func (h *V1Client) CreateClusterOpenStack(cluster *models.V1SpectroOpenStackClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersOpenStackCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersOpenStackCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } // Machine Pool -func (h *V1Client) CreateMachinePoolOpenStack(cloudConfigId, ClusterContext string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsOpenStackMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsOpenStackMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolOpenStack(cloudConfigUid string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsOpenStackMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsOpenStackMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolOpenStack(cloudConfigId, ClusterContext string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsOpenStackMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsOpenStackMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolOpenStack(cloudConfigUid string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsOpenStackMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsOpenStackMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolOpenStack(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsOpenStackMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsOpenStackMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolOpenStack(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsOpenStackMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsOpenStackMachinePoolDelete(params) return err } // Cloud Config -func (h *V1Client) GetCloudConfigOpenStack(configUID, ClusterContext string) (*models.V1OpenStackCloudConfig, error) { - var params *clusterC.V1CloudConfigsOpenStackGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsOpenStackGet(params) - +func (h *V1Client) GetCloudConfigOpenStack(configUid string) (*models.V1OpenStackCloudConfig, error) { + params := clientV1.NewV1CloudConfigsOpenStackGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsOpenStackGet(params) if herr.IsNotFound(err) { return nil, nil } else if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } // Import func (h *V1Client) ImportClusterOpenStack(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersOpenStackImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroOpenStackClusterImportEntity{ + params := clientV1.NewV1SpectroClustersOpenStackImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroOpenStackClusterImportEntity{ Metadata: meta, }, - ) - success, err := h.GetClusterClient().V1SpectroClustersOpenStackImport(params) + ) + resp, err := h.Client.V1SpectroClustersOpenStackImport(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapOpenStack(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsOpenStackPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapOpenStack(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsOpenStackPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsOpenStackPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsOpenStackPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_ospatch_config.go b/client/cluster_ospatch_config.go index 1aa9ff6e..8d18c5eb 100644 --- a/client/cluster_ospatch_config.go +++ b/client/cluster_ospatch_config.go @@ -1,19 +1,14 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) UpdateClusterOsPatchConfig(uid, clusterContext string, config *models.V1OsPatchEntity) error { - var params *clusterC.V1SpectroClustersUIDOsPatchUpdateParams - switch clusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDOsPatchUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDOsPatchUpdateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDOsPatchUpdate(params) +func (h *V1Client) UpdateClusterOsPatchConfig(uid string, config *models.V1OsPatchEntity) error { + params := clientV1.NewV1SpectroClustersUIDOsPatchUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1SpectroClustersUIDOsPatchUpdate(params) return err } diff --git a/client/cluster_profile.go b/client/cluster_profile.go index b221900b..a99383c5 100644 --- a/client/cluster_profile.go +++ b/client/cluster_profile.go @@ -1,135 +1,205 @@ package client import ( - "errors" + "fmt" + "os" - "github.com/spectrocloud/hapi/apiutil/transport" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) DeleteClusterProfile(client clusterC.ClientService, uid string) error { - profile, err := h.GetClusterProfile(client, uid) - if err != nil || profile == nil { - return err +func (h *V1Client) GetClusterProfileSummary(uid string) (*models.V1ClusterProfileSummary, error) { + params := clientV1.NewV1ClusterProfilesUIDSummaryParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterProfilesUIDSummary(params) + if err != nil { + return nil, err } + return resp.Payload, nil +} - var params *clusterC.V1ClusterProfilesDeleteParams - switch profile.Metadata.Annotations["scope"] { - case "project": - params = clusterC.NewV1ClusterProfilesDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterProfilesDeleteParams().WithUID(uid) - default: - return errors.New("invalid scope") +func (h *V1Client) GetClusterProfileUid(profileName, profileVersion string) (string, error) { + params := clientV1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) + resp, err := h.Client.V1ClusterProfilesMetadata(params) + if err != nil { + return "", err + } + for _, profile := range resp.Payload.Items { + if profile.Metadata.Name == profileName && profile.Spec.Version == profileVersion { + return profile.Metadata.UID, nil + } } + return "", fmt.Errorf("cluster profile %s not found", profileName) +} - _, err = client.V1ClusterProfilesDelete(params) +func (h *V1Client) ImportClusterProfile(profileContent string) (string, error) { + tmpFile, err := os.CreateTemp(os.TempDir(), "profile-import") + if err != nil { + return "", err + } + defer os.Remove(tmpFile.Name()) + if _, err = tmpFile.Write([]byte(profileContent)); err != nil { + return "", err + } + f, err := os.Open(tmpFile.Name()) + if err != nil { + return "", err + } + params := clientV1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). + WithPublish(apiutil.Ptr(true)). + WithImportFile(f) + resp, err := h.Client.V1ClusterProfilesImportFile(params) + if err != nil { + return "", err + } + return *resp.Payload.UID, nil + +} + +func (h *V1Client) UpgradeClusterProfile(clusterUid string, body *models.V1SpectroClusterProfiles) error { + params := clientV1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). + WithUID(clusterUid). + WithBody(body) + _, err := h.Client.V1SpectroClustersUpdateProfiles(params) return err } -func (h *V1Client) GetClusterProfile(client clusterC.ClientService, uid string) (*models.V1ClusterProfile, error) { - // no need to switch request context here as /v1/clusterprofiles/{uid} works for profile in any scope. - params := clusterC.NewV1ClusterProfilesGetParamsWithContext(h.Ctx).WithUID(uid) - success, err := client.V1ClusterProfilesGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { - return nil, err +func (h *V1Client) AttachAddonToCluster(clusterUid, profileUid string, profileUids []string) error { + // get existing cluster profile uid list on the cluster + currentClusterInfo, err := h.GetCluster(clusterUid) + if err != nil { + return err + } + + profileList := make([]*models.V1SpectroClusterProfileEntity, 0, len(profileUid)) + packList := make([]*models.V1PackValuesEntity, 0, len(currentClusterInfo.Spec.ClusterProfileTemplates)) + + for _, clusterProfile := range currentClusterInfo.Spec.ClusterProfileTemplates { + for _, value := range clusterProfile.Packs { + packList = append(packList, &models.V1PackValuesEntity{ + Manifests: nil, + Name: value.Name, + Tag: value.Tag, + //Type: models.NewV1PackType(models.V1PackType(value.Type)), + Type: models.V1PackType(value.Type), + Values: value.Values, + }) + } + profileList = append(profileList, &models.V1SpectroClusterProfileEntity{ + PackValues: packList, + UID: clusterProfile.UID, + }) } - return success.Payload, nil + + for _, uid := range profileUids { + packs, err := h.GetPacksByProfile(uid) + if err != nil { + return err + } + packList = make([]*models.V1PackValuesEntity, 0, len(packs)) + for _, value := range packs { + packList = append(packList, &models.V1PackValuesEntity{ + Manifests: nil, + Name: &value.Spec.Name, + Tag: value.Spec.Version, + Type: value.Spec.Type, + Values: value.Spec.Values, + }) + } + profileList = append(profileList, &models.V1SpectroClusterProfileEntity{ + PackValues: packList, + UID: uid, + }) + } + profiles := &models.V1SpectroClusterProfiles{ + Profiles: profileList, + } + if err := h.UpgradeClusterProfile(clusterUid, profiles); err != nil { + return err + } + + return nil } -func (h *V1Client) GetClusterProfiles(client hashboardC.ClientService) ([]*models.V1ClusterProfileMetadata, error) { - params := hashboardC.NewV1ClusterProfilesMetadataParamsWithContext(h.Ctx) - response, err := client.V1ClusterProfilesMetadata(params) +func (h *V1Client) DeleteClusterProfile(uid string) error { + profile, err := h.GetClusterProfile(uid) if err != nil { - return nil, err + return err + } else if profile == nil { + return fmt.Errorf("cluster profile %s not found", uid) } - return response.Payload.Items, nil + params := clientV1.NewV1ClusterProfilesDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err = h.Client.V1ClusterProfilesDelete(params) + return err } -func (h *V1Client) PatchClusterProfile(client clusterC.ClientService, clusterProfile *models.V1ClusterProfileUpdateEntity, metadata *models.V1ProfileMetaEntity, ProfileContext string) error { - uid := clusterProfile.Metadata.UID - var params *clusterC.V1ClusterProfilesUIDMetadataUpdateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1ClusterProfilesUIDMetadataUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(metadata) - case "tenant": - params = clusterC.NewV1ClusterProfilesUIDMetadataUpdateParams().WithUID(uid).WithBody(metadata) - default: - return errors.New("invalid scope") +func (h *V1Client) GetClusterProfile(uid string) (*models.V1ClusterProfile, error) { + params := clientV1.NewV1ClusterProfilesGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterProfilesGet(params) + if err := apiutil.Handle404(err); err != nil { + return nil, err } - - _, err := client.V1ClusterProfilesUIDMetadataUpdate(params) - return err + return resp.Payload, nil } -func (h *V1Client) UpdateClusterProfile(client clusterC.ClientService, clusterProfile *models.V1ClusterProfileUpdateEntity, ProfileContext string) error { - uid := clusterProfile.Metadata.UID - var params *clusterC.V1ClusterProfilesUpdateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1ClusterProfilesUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(clusterProfile) - case "tenant": - params = clusterC.NewV1ClusterProfilesUpdateParams().WithUID(uid).WithBody(clusterProfile) - default: - return errors.New("invalid scope") +func (h *V1Client) GetClusterProfiles() ([]*models.V1ClusterProfileMetadata, error) { + params := clientV1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) + resp, err := h.Client.V1ClusterProfilesMetadata(params) + if err != nil { + return nil, err } + return resp.Payload.Items, nil +} - _, err := client.V1ClusterProfilesUpdate(params) +func (h *V1Client) PatchClusterProfile(clusterProfile *models.V1ClusterProfileUpdateEntity, metadata *models.V1ProfileMetaEntity) error { + params := clientV1.NewV1ClusterProfilesUIDMetadataUpdateParamsWithContext(h.ctx). + WithUID(clusterProfile.Metadata.UID). + WithBody(metadata) + _, err := h.Client.V1ClusterProfilesUIDMetadataUpdate(params) return err } -func (h *V1Client) CreateClusterProfile(client clusterC.ClientService, clusterProfile *models.V1ClusterProfileEntity, ProfileContext string) (string, error) { - var params *clusterC.V1ClusterProfilesCreateParams - switch ProfileContext { - case "project": - params = clusterC.NewV1ClusterProfilesCreateParamsWithContext(h.Ctx).WithBody(clusterProfile) - case "tenant": - params = clusterC.NewV1ClusterProfilesCreateParams().WithBody(clusterProfile) - default: - return "", errors.New("invalid scope") - } +func (h *V1Client) UpdateClusterProfile(clusterProfile *models.V1ClusterProfileUpdateEntity) error { + params := clientV1.NewV1ClusterProfilesUpdateParamsWithContext(h.ctx). + WithUID(clusterProfile.Metadata.UID). + WithBody(clusterProfile) + _, err := h.Client.V1ClusterProfilesUpdate(params) + return err +} - success, err := client.V1ClusterProfilesCreate(params) +func (h *V1Client) CreateClusterProfile(clusterProfile *models.V1ClusterProfileEntity) (string, error) { + params := clientV1.NewV1ClusterProfilesCreateParamsWithContext(h.ctx). + WithBody(clusterProfile) + resp, err := h.Client.V1ClusterProfilesCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) PublishClusterProfile(client clusterC.ClientService, uid, ProfileContext string) error { - var params *clusterC.V1ClusterProfilesPublishParams - switch ProfileContext { - case "project": - params = clusterC.NewV1ClusterProfilesPublishParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterProfilesPublishParams().WithUID(uid) - default: - return errors.New("invalid scope") - } - - _, err := client.V1ClusterProfilesPublish(params) +func (h *V1Client) PublishClusterProfile(uid string) error { + params := clientV1.NewV1ClusterProfilesPublishParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1ClusterProfilesPublish(params) return err } -func (h *V1Client) GetProfileVariables(client clusterC.ClientService, uid string) ([]*models.V1Variable, error) { - params := clusterC.NewV1ClusterProfilesUIDVariablesGetParamsWithContext(h.Ctx).WithUID(uid) - success, err := client.V1ClusterProfilesUIDVariablesGet(params) +func (h *V1Client) GetProfileVariables(uid string) ([]*models.V1Variable, error) { + params := clientV1.NewV1ClusterProfilesUIDVariablesGetParamsWithContext(h.ctx).WithUID(uid) + resp, err := h.Client.V1ClusterProfilesUIDVariablesGet(params) if err != nil { return nil, err } - return success.Payload.Variables, nil + return resp.Payload.Variables, nil } -func (h *V1Client) UpdateProfileVariables(client clusterC.ClientService, variables *models.V1Variables, uid string) error { - params := clusterC.NewV1ClusterProfilesUIDVariablesPutParamsWithContext(h.Ctx).WithUID(uid).WithBody(variables) - _, err := client.V1ClusterProfilesUIDVariablesPut(params) - if err != nil { - return err - } - return nil +func (h *V1Client) UpdateProfileVariables(variables *models.V1Variables, uid string) error { + params := clientV1.NewV1ClusterProfilesUIDVariablesPutParamsWithContext(h.ctx). + WithUID(uid). + WithBody(variables) + _, err := h.Client.V1ClusterProfilesUIDVariablesPut(params) + return err } diff --git a/client/cluster_profile_import.go b/client/cluster_profile_import.go index 1babc81a..137c6216 100644 --- a/client/cluster_profile_import.go +++ b/client/cluster_profile_import.go @@ -1,43 +1,19 @@ package client import ( - "errors" - "github.com/go-openapi/runtime" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterProfileImport(importFile runtime.NamedReadCloser, ProfileContext string) (string, error) { - var params *clusterC.V1ClusterProfilesImportFileParams - switch ProfileContext { - case "project": - params = clusterC.NewV1ClusterProfilesImportFileParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1ClusterProfilesImportFileParams() - } - - params = params.WithPublish(Ptr(true)).WithImportFile(importFile) - success, err := h.GetClusterClient().V1ClusterProfilesImportFile(params) +func (h *V1Client) CreateClusterProfileImport(importFile runtime.NamedReadCloser) (string, error) { + params := clientV1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). + WithPublish(apiutil.Ptr(true)). + WithImportFile(importFile) + resp, err := h.Client.V1ClusterProfilesImportFile(params) if err != nil { return "", err } - - return *success.Payload.UID, nil -} - -func (h *V1Client) ClusterProfileExport(uid string) (*models.V1ClusterProfile, error) { - // no need to switch request context here as /v1/clusterprofiles/{uid} works for profile in any scope. - params := clusterC.NewV1ClusterProfilesGetParamsWithContext(h.Ctx).WithUID(uid) - success, err := h.GetClusterClient().V1ClusterProfilesGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { - return nil, err - } - - return success.Payload, nil + return *resp.Payload.UID, nil } diff --git a/client/cluster_rbac_config.go b/client/cluster_rbac_config.go index e47ba04b..ac2b6a04 100644 --- a/client/cluster_rbac_config.go +++ b/client/cluster_rbac_config.go @@ -1,80 +1,56 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) GetClusterRbacConfig(uid, ClusterContext string) (*models.V1ClusterRbacs, error) { - if h.GetClusterRbacConfigFn != nil { - return h.GetClusterRbacConfigFn(uid) - } - var params *clusterC.V1SpectroClustersUIDConfigRbacsGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDConfigRbacsGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDConfigRbacsGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1SpectroClustersUIDConfigRbacsGet(params) +func (h *V1Client) GetClusterRbacConfig(uid string) (*models.V1ClusterRbacs, error) { + params := clientV1.NewV1SpectroClustersUIDConfigRbacsGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1SpectroClustersUIDConfigRbacsGet(params) if err != nil { if herr.IsNotFound(err) { return nil, nil } return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) CreateClusterRbacConfig(uid, ClusterContext string, config *models.V1ClusterRbac) error { - var params *clusterC.V1WorkspacesClusterRbacCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1WorkspacesClusterRbacCreateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1WorkspacesClusterRbacCreateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1WorkspacesClusterRbacCreate(params) +func (h *V1Client) CreateClusterRbacConfig(uid string, config *models.V1ClusterRbac) error { + params := clientV1.NewV1WorkspacesClusterRbacCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1WorkspacesClusterRbacCreate(params) return err } -func (h *V1Client) UpdateClusterRbacConfig(uid, ClusterContext string, config *models.V1ClusterRbacResourcesUpdateEntity) error { - var params *clusterC.V1SpectroClustersUIDConfigRbacsUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersUIDConfigRbacsUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1SpectroClustersUIDConfigRbacsUpdateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1SpectroClustersUIDConfigRbacsUpdate(params) +func (h *V1Client) UpdateClusterRbacConfig(uid string, config *models.V1ClusterRbacResourcesUpdateEntity) error { + params := clientV1.NewV1SpectroClustersUIDConfigRbacsUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1SpectroClustersUIDConfigRbacsUpdate(params) return err } -func (h *V1Client) ApplyClusterRbacConfig(uid, ClusterContext string, config []*models.V1ClusterRbacInputEntity) error { - if rbac, err := h.GetClusterRbacConfig(uid, ClusterContext); err != nil { +func (h *V1Client) ApplyClusterRbacConfig(uid string, config []*models.V1ClusterRbacInputEntity) error { + rbac, err := h.GetClusterRbacConfig(uid) + if err != nil { return err - } else if rbac == nil { - return h.CreateClusterRbacConfig(uid, ClusterContext, toCreateClusterRbac(config)) - } else { - return h.UpdateClusterRbacConfig(uid, ClusterContext, &models.V1ClusterRbacResourcesUpdateEntity{ - Rbacs: config, - }) } + if rbac == nil { + return h.CreateClusterRbacConfig(uid, toCreateClusterRbac(config)) + } + return h.UpdateClusterRbacConfig(uid, &models.V1ClusterRbacResourcesUpdateEntity{Rbacs: config}) } func toCreateClusterRbac(rbacs []*models.V1ClusterRbacInputEntity) *models.V1ClusterRbac { bindings := make([]*models.V1ClusterRbacBinding, 0) - for _, rbac := range rbacs { bindings = append(bindings, rbac.Spec.Bindings...) } - return &models.V1ClusterRbac{ Spec: &models.V1ClusterRbacSpec{ Bindings: bindings, diff --git a/client/cluster_scan_config.go b/client/cluster_scan_config.go index ec3b6858..ed6964b4 100644 --- a/client/cluster_scan_config.go +++ b/client/cluster_scan_config.go @@ -1,68 +1,47 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) GetClusterScanConfig(uid, clusterContext string) (*models.V1ClusterComplianceScan, error) { - if h.GetClusterScanConfigFn != nil { - return h.GetClusterScanConfigFn(uid) - } - - var params *clusterC.V1ClusterFeatureComplianceScanGetParams - switch clusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureComplianceScanGetParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = clusterC.NewV1ClusterFeatureComplianceScanGetParams().WithUID(uid) - } - - success, err := h.GetClusterClient().V1ClusterFeatureComplianceScanGet(params) +func (h *V1Client) GetClusterScanConfig(uid string) (*models.V1ClusterComplianceScan, error) { + params := clientV1.NewV1ClusterFeatureComplianceScanGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureComplianceScanGet(params) if err != nil { if herr.IsNotFound(err) { return nil, nil } return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) CreateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig, ClusterContext string) error { - var params *clusterC.V1ClusterFeatureComplianceScanCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureComplianceScanCreateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1ClusterFeatureComplianceScanCreateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1ClusterFeatureComplianceScanCreate(params) +func (h *V1Client) CreateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { + params := clientV1.NewV1ClusterFeatureComplianceScanCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1ClusterFeatureComplianceScanCreate(params) return err } -func (h *V1Client) UpdateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig, ClusterContext string) error { - var params *clusterC.V1ClusterFeatureComplianceScanUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1ClusterFeatureComplianceScanUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(config) - case "tenant": - params = clusterC.NewV1ClusterFeatureComplianceScanUpdateParams().WithUID(uid).WithBody(config) - } - - _, err := h.GetClusterClient().V1ClusterFeatureComplianceScanUpdate(params) +func (h *V1Client) UpdateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { + params := clientV1.NewV1ClusterFeatureComplianceScanUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1ClusterFeatureComplianceScanUpdate(params) return err } -func (h *V1Client) ApplyClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig, ClusterContext string) error { - if policy, err := h.GetClusterScanConfig(uid, ClusterContext); err != nil { +func (h *V1Client) ApplyClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { + policy, err := h.GetClusterScanConfig(uid) + if err != nil { return err - } else if policy == nil { - return h.CreateClusterScanConfig(uid, config, ClusterContext) - } else { - return h.UpdateClusterScanConfig(uid, config, ClusterContext) } + if policy == nil { + return h.CreateClusterScanConfig(uid, config) + } + return h.UpdateClusterScanConfig(uid, config) } diff --git a/client/cluster_tke.go b/client/cluster_tke.go index 5c63690a..e882d3a3 100644 --- a/client/cluster_tke.go +++ b/client/cluster_tke.go @@ -1,110 +1,69 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func (h *V1Client) CreateClusterTke(cluster *models.V1SpectroTencentClusterEntity, ClusterContext string) (string, error) { - var params *clusterC.V1SpectroClustersTkeCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersTkeCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersTkeCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersTkeCreate(params) +func (h *V1Client) CreateClusterTke(cluster *models.V1SpectroTencentClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersTkeCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersTkeCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) CreateMachinePoolTke(cloudConfigId, ClusterContext string, machinePool *models.V1TencentMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsTkeMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkeMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsTkeMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsTkeMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolTke(cloudConfigUid string, machinePool *models.V1TencentMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsTkeMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsTkeMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolTke(cloudConfigId, ClusterContext string, machinePool *models.V1TencentMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsTkeMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkeMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsTkeMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsTkeMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolTke(cloudConfigUid string, machinePool *models.V1TencentMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsTkeMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsTkeMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolTke(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsTkeMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkeMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsTkeMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsTkeMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolTke(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsTkeMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsTkeMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigTke(configUID, ClusterContext string) (*models.V1TencentCloudConfig, error) { - var params *clusterC.V1CloudConfigsTkeGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkeGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsTkeGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsTkeGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigTke(configUid string) (*models.V1TencentCloudConfig, error) { + params := clientV1.NewV1CloudConfigsTkeGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsTkeGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetNodeStatusMapTke(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsTkePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsTkePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapTke(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsTkePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsTkePoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsTkePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_virtual.go b/client/cluster_virtual.go index c11d0098..bc205367 100644 --- a/client/cluster_virtual.go +++ b/client/cluster_virtual.go @@ -1,89 +1,87 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) CreateClusterVirtual(cluster *models.V1SpectroVirtualClusterEntity) (string, error) { - params := clusterC.NewV1SpectroClustersVirtualCreateParamsWithContext(h.Ctx).WithBody(cluster) - success, err := h.GetClusterClient().V1SpectroClustersVirtualCreate(params) + params := clientV1.NewV1SpectroClustersVirtualCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersVirtualCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) ResizeClusterVirtual(configUID string, body *models.V1VirtualClusterResize) error { - params := clusterC.NewV1CloudConfigsVirtualUIDUpdateParamsWithContext(h.Ctx).WithConfigUID(configUID).WithBody(body) - _, err := h.GetClusterClient().V1CloudConfigsVirtualUIDUpdate(params) - if err != nil { - return err - } - return nil +func (h *V1Client) ResizeClusterVirtual(configUid string, body *models.V1VirtualClusterResize) error { + params := clientV1.NewV1CloudConfigsVirtualUIDUpdateParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithBody(body) + _, err := h.Client.V1CloudConfigsVirtualUIDUpdate(params) + return err } -func (h *V1Client) CreateMachinePoolVirtual(cloudConfigId string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { - params := clusterC.NewV1CloudConfigsVirtualMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - _, err := h.GetClusterClient().V1CloudConfigsVirtualMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolVirtual(cloudConfigUid string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVirtualMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsVirtualMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolVirtual(cloudConfigId string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { - params := clusterC.NewV1CloudConfigsVirtualMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). +func (h *V1Client) UpdateMachinePoolVirtual(cloudConfigUid string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVirtualMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). WithBody(machinePool) - _, err := h.GetClusterClient().V1CloudConfigsVirtualMachinePoolUpdate(params) + _, err := h.Client.V1CloudConfigsVirtualMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolVirtual(cloudConfigId, machinePoolName string) error { - params := clusterC.NewV1CloudConfigsVirtualMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - _, err := h.GetClusterClient().V1CloudConfigsVirtualMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolVirtual(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsVirtualMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsVirtualMachinePoolDelete(params) return err } -func (h *V1Client) GetCloudConfigVirtual(configUID string) (*models.V1VirtualCloudConfig, error) { - params := clusterC.NewV1CloudConfigsVirtualGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - success, err := h.GetClusterClient().V1CloudConfigsVirtualGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigVirtual(configUid string) (*models.V1VirtualCloudConfig, error) { + params := clientV1.NewV1CloudConfigsVirtualGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsVirtualGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) VirtualClusterLifecycleConfigChange(uid string, body *models.V1LifecycleConfigEntity) (string, error) { - params := clusterC.NewV1SpectroClustersUIDLifecycleConfigUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(body) - _, err := h.GetClusterClient().V1SpectroClustersUIDLifecycleConfigUpdate(params) + params := clientV1.NewV1SpectroClustersUIDLifecycleConfigUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1SpectroClustersUIDLifecycleConfigUpdate(params) if err != nil { return "Fail", err } return "Success", nil } -func (h *V1Client) GetNodeStatusMapVirtual(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsVirtualPoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVirtualPoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsVirtualPoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapVirtual(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsVirtualPoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsVirtualPoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsVirtualPoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/cluster_vsphere.go b/client/cluster_vsphere.go index 720bb469..d9472892 100644 --- a/client/cluster_vsphere.go +++ b/client/cluster_vsphere.go @@ -1,173 +1,108 @@ package client import ( - "errors" - - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) // Cluster -func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterEntity, ClusterContext string) (string, error) { - if h.CreateClusterVsphereFn != nil { - return h.CreateClusterVsphereFn(cluster) - } - var params *clusterC.V1SpectroClustersVsphereCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1SpectroClustersVsphereCreateParamsWithContext(h.Ctx).WithBody(cluster) - case "tenant": - params = clusterC.NewV1SpectroClustersVsphereCreateParams().WithBody(cluster) - } - - success, err := h.GetClusterClient().V1SpectroClustersVsphereCreate(params) +func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterEntity) (string, error) { + params := clientV1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). + WithBody(cluster) + resp, err := h.Client.V1SpectroClustersVsphereCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } // Machine Pool -func (h *V1Client) CreateMachinePoolVsphere(cloudConfigId, ClusterContext string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolCreateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolCreate(params) +func (h *V1Client) CreateMachinePoolVsphere(cloudConfigUid string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolVsphere(cloudConfigId, ClusterContext string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.Ctx). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolUpdateParams(). - WithConfigUID(cloudConfigId). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolUpdate(params) +func (h *V1Client) UpdateMachinePoolVsphere(cloudConfigUid string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(*machinePool.PoolConfig.Name). + WithBody(machinePool) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolUpdate(params) return err } -func (h *V1Client) DeleteMachinePoolVsphere(cloudConfigId, machinePoolName, ClusterContext string) error { - var params *clusterC.V1CloudConfigsVsphereMachinePoolDeleteParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereMachinePoolDelete(params) +func (h *V1Client) DeleteMachinePoolVsphere(cloudConfigUid, machinePoolName string) error { + params := clientV1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). + WithConfigUID(cloudConfigUid). + WithMachinePoolName(machinePoolName) + _, err := h.Client.V1CloudConfigsVsphereMachinePoolDelete(params) return err } // Cloud Config -func (h *V1Client) GetCloudConfigVsphere(configUID, ClusterContext string) (*models.V1VsphereCloudConfig, error) { - if h.GetCloudConfigVsphereFn != nil { - return h.GetCloudConfigVsphereFn(configUID) - } - var params *clusterC.V1CloudConfigsVsphereGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereGetParamsWithContext(h.Ctx).WithConfigUID(configUID) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereGetParams().WithConfigUID(configUID) - } - - success, err := h.GetClusterClient().V1CloudConfigsVsphereGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetCloudConfigVsphere(configUid string) (*models.V1VsphereCloudConfig, error) { + params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). + WithConfigUID(configUid) + resp, err := h.Client.V1CloudConfigsVsphereGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetCloudConfigVsphereValues(uid, ClusterContext string) (*models.V1VsphereCloudConfig, error) { - if h.GetCloudConfigVsphereValuesFn != nil { - return h.GetCloudConfigVsphereValuesFn(uid) - } - - var params *clusterC.V1CloudConfigsVsphereGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereGetParamsWithContext(h.Ctx).WithConfigUID(uid) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereGetParams().WithConfigUID(uid) - } - - cloudConfig, err := h.GetClusterClient().V1CloudConfigsVsphereGet(params) +func (h *V1Client) GetCloudConfigVsphereValues(uid string) (*models.V1VsphereCloudConfig, error) { + params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). + WithConfigUID(uid) + resp, err := h.Client.V1CloudConfigsVsphereGet(params) if err != nil { return nil, err } - - return cloudConfig.Payload, nil + return resp.Payload, nil } -func (h *V1Client) UpdateCloudConfigVsphereValues(uid, ClusterContext string, clusterConfig *models.V1VsphereCloudClusterConfigEntity) error { - var params *clusterC.V1CloudConfigsVsphereUIDClusterConfigParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVsphereUIDClusterConfigParamsWithContext(h.Ctx).WithConfigUID(uid).WithBody(clusterConfig) - case "tenant": - params = clusterC.NewV1CloudConfigsVsphereUIDClusterConfigParams().WithConfigUID(uid).WithBody(clusterConfig) - } - - _, err := h.GetClusterClient().V1CloudConfigsVsphereUIDClusterConfig(params) +func (h *V1Client) UpdateCloudConfigVsphereValues(uid string, cloudConfig *models.V1VsphereCloudClusterConfigEntity) error { + params := clientV1.NewV1CloudConfigsVsphereUIDClusterConfigParamsWithContext(h.ctx). + WithConfigUID(uid). + WithBody(cloudConfig) + _, err := h.Client.V1CloudConfigsVsphereUIDClusterConfig(params) return err } // Import func (h *V1Client) ImportClusterVsphere(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clusterC.NewV1SpectroClustersVsphereImportParamsWithContext(h.Ctx).WithBody( - &models.V1SpectroVsphereClusterImportEntity{ + params := clientV1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). + WithBody(&models.V1SpectroVsphereClusterImportEntity{ Metadata: meta, }, - ) - - success, err := h.GetClusterClient().V1SpectroClustersVsphereImport(params) + ) + resp, err := h.Client.V1SpectroClustersVsphereImport(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetNodeStatusMapVsphere(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) { - var params *clusterC.V1CloudConfigsVspherePoolMachinesListParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) - case "tenant": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName) +func (h *V1Client) GetNodeStatusMapVsphere(configUid, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { + params := clientV1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machinePoolName) + mpList, err := h.Client.V1CloudConfigsVspherePoolMachinesList(params) + if err != nil { + return nil, err } - - mpList, err := h.GetClusterClient().V1CloudConfigsVspherePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} if len(mpList.Payload.Items) > 0 { for _, node := range mpList.Payload.Items { nMap[node.Metadata.UID] = *node.Status } } - return nMap, err + return nMap, nil } diff --git a/client/constants.go b/client/constants.go new file mode 100644 index 00000000..6b9f7734 --- /dev/null +++ b/client/constants.go @@ -0,0 +1,10 @@ +package client + +const ( + authTokenInput = "header" + authApiKey = "ApiKey" + authJwt = "Authorization" + + OverlordUID = "overlordUid" + Scope = "scope" +) diff --git a/client/datavolume.go b/client/datavolume.go index 74ea3959..a1090b5f 100644 --- a/client/datavolume.go +++ b/client/datavolume.go @@ -1,75 +1,44 @@ package client import ( - "errors" "fmt" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) CreateDataVolume(scope, uid, name string, body *models.V1VMAddVolumeEntity) (string, error) { - if h.CreateDataVolumeFn != nil { - return h.CreateDataVolumeFn(uid, name, body) - } - - // get cluster - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) CreateDataVolume(uid, name string, body *models.V1VMAddVolumeEntity) (string, error) { + cluster, err := h.GetCluster(uid) if err != nil { return "", err - } - - // if cluster is nil(deleted or not found), return error - if cluster == nil { - return "", fmt.Errorf("cluster not found for uid %s", uid) - } - - // get cluster scope - var params *clusterC.V1SpectroClustersVMAddVolumeParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMAddVolumeParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMAddVolumeParams() - default: - return "", errors.New("invalid cluster scope specified") - } - - params = params.WithUID(uid).WithBody(body).WithVMName(name).WithNamespace(body.DataVolumeTemplate.Metadata.Namespace) - - volume, err := h.GetClusterClient().V1SpectroClustersVMAddVolume(params) + } else if cluster == nil { + return "", fmt.Errorf("cluster with uid %s not found", uid) + } + params := clientV1.NewV1SpectroClustersVMAddVolumeParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body). + WithVMName(name). + WithNamespace(body.DataVolumeTemplate.Metadata.Namespace) + resp, err := h.Client.V1SpectroClustersVMAddVolume(params) if err != nil { return "", err } - return volume.AuditUID, nil + return resp.AuditUID, nil } -func (h *V1Client) DeleteDataVolume(scope, uid, namespace, name string, body *models.V1VMRemoveVolumeEntity) error { - if h.DeleteDataVolumeFn != nil { - return h.DeleteDataVolumeFn(uid, namespace, name, body) - } - - // get cluster - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) DeleteDataVolume(uid, namespace, name string, body *models.V1VMRemoveVolumeEntity) error { + cluster, err := h.GetCluster(uid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, uid) - } - - // get cluster scope - var params *clusterC.V1SpectroClustersVMRemoveVolumeParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMRemoveVolumeParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMRemoveVolumeParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(uid).WithVMName(name).WithNamespace(namespace).WithBody(body) - - _, err = h.GetClusterClient().V1SpectroClustersVMRemoveVolume(params) + return fmt.Errorf("cluster with uid %s not found", uid) + } + params := clientV1.NewV1SpectroClustersVMRemoveVolumeParamsWithContext(h.ctx). + WithUID(uid). + WithVMName(name). + WithNamespace(namespace). + WithBody(body) + _, err = h.Client.V1SpectroClustersVMRemoveVolume(params) return err } diff --git a/client/events.go b/client/events.go index 8eff2db7..3fd6c756 100644 --- a/client/events.go +++ b/client/events.go @@ -3,12 +3,14 @@ package client import ( "time" - event "github.com/spectrocloud/hapi/event/client/v1" - "github.com/spectrocloud/hapi/models" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) GetEvents(kind, uid string, continueVar, fields, filters, orderBy *string, limit, offset *int64, timeout *time.Duration) ([]*models.V1Event, error) { - params := event.NewV1EventsComponentsObjTypeUIDListParamsWithContext(h.Ctx).WithObjectKind(kind).WithObjectUID(uid) + params := clientV1.NewV1EventsComponentsObjTypeUIDListParamsWithContext(h.ctx). + WithObjectKind(kind). + WithObjectUID(uid) if continueVar != nil { params = params.WithContinue(continueVar) } @@ -30,17 +32,17 @@ func (h *V1Client) GetEvents(kind, uid string, continueVar, fields, filters, ord if timeout != nil { params = params.WithTimeout(*timeout) } - - resp, err := h.GetEventClient().V1EventsComponentsObjTypeUIDList(params) + resp, err := h.Client.V1EventsComponentsObjTypeUIDList(params) if err != nil { return nil, err } - return resp.Payload.Items, nil } func (h *V1Client) GetNotifications(kind, uid string, continueVar, fields, filters, isDone, orderBy *string, limit, offset *int64, timeout *time.Duration) ([]*models.V1Notification, error) { - params := event.NewV1NotificationsObjTypeUIDListParamsWithContext(h.Ctx).WithObjectKind(kind).WithObjectUID(uid) + params := clientV1.NewV1NotificationsObjTypeUIDListParamsWithContext(h.ctx). + WithObjectKind(kind). + WithObjectUID(uid) if continueVar != nil { params = params.WithContinue(continueVar) } @@ -65,11 +67,9 @@ func (h *V1Client) GetNotifications(kind, uid string, continueVar, fields, filte if timeout != nil { params = params.WithTimeout(*timeout) } - - resp, err := h.GetEventClient().V1NotificationsObjTypeUIDList(params) + resp, err := h.Client.V1NotificationsObjTypeUIDList(params) if err != nil { return nil, err } - return resp.Payload.Items, nil } diff --git a/client/filter.go b/client/filter.go index 44a6cad5..ca1bffec 100644 --- a/client/filter.go +++ b/client/filter.go @@ -3,49 +3,47 @@ package client import ( "fmt" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) CreateTagFilter(body *models.V1TagFilter) (*models.V1UID, error) { - params := hashboardC.NewV1TagFiltersCreateParams().WithBody(body) - tag, err := h.GetHashboardClient().V1TagFiltersCreate(params) + params := clientV1.NewV1TagFiltersCreateParamsWithContext(h.ctx). + WithBody(body) + resp, err := h.Client.V1TagFiltersCreate(params) if err != nil { return nil, err } - - return tag.Payload, nil + return resp.Payload, nil } func (h *V1Client) UpdateTagFilter(uid string, body *models.V1TagFilter) error { - params := hashboardC.NewV1TagFilterUIDUpdateParams().WithUID(uid).WithBody(body) - _, err := h.GetHashboardClient().V1TagFilterUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TagFilterUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1TagFilterUIDUpdate(params) + return err } func (h *V1Client) GetTagFilter(uid string) (*models.V1TagFilterSummary, error) { - params := hashboardC.NewV1TagFilterUIDGetParams().WithUID(uid) - success, err := h.GetHashboardClient().V1TagFilterUIDGet(params) + params := clientV1.NewV1TagFilterUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1TagFilterUIDGet(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) ListTagFilters() (*models.V1FiltersSummary, error) { - limit := int64(0) - params := hashboardC.NewV1FiltersListParams().WithLimit(&limit) - success, err := h.GetHashboardClient().V1FiltersList(params) + params := clientV1.NewV1FiltersListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1FiltersList(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetTagFilterByName(name string) (*models.V1FilterSummary, error) { @@ -53,22 +51,17 @@ func (h *V1Client) GetTagFilterByName(name string) (*models.V1FilterSummary, err if err != nil { return nil, err } - for _, filter := range filters.Items { if filter.Metadata.Name == name { return filter, nil } } - return nil, fmt.Errorf("filter not found for name %s", name) } func (h *V1Client) DeleteTag(uid string) error { - params := hashboardC.NewV1TagFilterUIDDeleteParams().WithUID(uid) - _, err := h.GetHashboardClient().V1TagFilterUIDDelete(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TagFilterUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1TagFilterUIDDelete(params) + return err } diff --git a/client/herr/errors.go b/client/herr/errors.go index 3194dcfd..5aa32e12 100644 --- a/client/herr/errors.go +++ b/client/herr/errors.go @@ -1,6 +1,6 @@ package herr -import "github.com/spectrocloud/hapi/apiutil" +import "github.com/spectrocloud/palette-sdk-go/client/apiutil" func IsNotFound(err error) bool { return apiutil.ToV1ErrorObj(err).Code == "ResourceNotFound" diff --git a/client/herr/errors_test.go b/client/herr/errors_test.go index 616835f4..bfbded96 100644 --- a/client/herr/errors_test.go +++ b/client/herr/errors_test.go @@ -4,10 +4,10 @@ import ( "fmt" "testing" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - "github.com/stretchr/testify/assert" + + "github.com/spectrocloud/palette-api-go/apiutil/transport" + "github.com/spectrocloud/palette-api-go/models" ) func TestIsNotFound(t *testing.T) { diff --git a/client/macro.go b/client/macro.go index 19291924..26522997 100644 --- a/client/macro.go +++ b/client/macro.go @@ -1,95 +1,81 @@ package client import ( - "hash/fnv" - "strconv" - - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) CreateMacro(uid string, macros *models.V1Macros) error { if uid != "" { - params := userC.NewV1ProjectsUIDMacrosCreateParams().WithContext(h.Ctx).WithUID(uid).WithBody(macros) - _, err := h.GetUserClient().V1ProjectsUIDMacrosCreate(params) - if err != nil { - return err - } - } else { - tenantUID, err := h.GetTenantUID() - if err != nil { - return err - } - // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosCreateParams().WithTenantUID(tenantUID).WithBody(macros) - _, err = h.GetUserClient().V1TenantsUIDMacrosCreate(params) - if err != nil { - return err - } + params := clientV1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(macros) + _, err := h.Client.V1ProjectsUIDMacrosCreate(params) + return err } - - return nil + tenantUID, err := h.GetTenantUID() + if err != nil { + return err + } + // As discussed with hubble team, we should not set context for tenant macros. + params := clientV1.NewV1TenantsUIDMacrosCreateParams(). + WithTenantUID(tenantUID). + WithBody(macros) + _, err = h.Client.V1TenantsUIDMacrosCreate(params) + return err } -func (h *V1Client) GetMacro(name, projectUID string) (*models.V1Macro, error) { - macros, err := h.GetMacros(projectUID) +func (h *V1Client) GetMacro(name, projectUid string) (*models.V1Macro, error) { + macros, err := h.GetMacros(projectUid) if err != nil { return nil, err } - id := h.GetMacroId(projectUID, name) + id := h.GetMacroId(projectUid, name) for _, macro := range macros { - if h.GetMacroId(projectUID, macro.Name) == id { + if h.GetMacroId(projectUid, macro.Name) == id { return macro, nil } } - return nil, nil } -func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) { +func (h *V1Client) GetMacros(projectUid string) ([]*models.V1Macro, error) { var macros []*models.V1Macro - if projectUID != "" { - params := userC.NewV1ProjectsUIDMacrosListParams().WithContext(h.Ctx).WithUID(projectUID) - macrosListOk, err := h.GetUserClient().V1ProjectsUIDMacrosList(params) + if projectUid != "" { + params := clientV1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). + WithUID(projectUid) + resp, err := h.Client.V1ProjectsUIDMacrosList(params) if err != nil { return nil, err } - macros = macrosListOk.Payload.Macros - + macros = resp.Payload.Macros } else { tenantUID, err := h.GetTenantUID() if err != nil || tenantUID == "" { return nil, err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosListParams().WithTenantUID(tenantUID) - macrosListOk, err := h.GetUserClient().V1TenantsUIDMacrosList(params) + params := clientV1.NewV1TenantsUIDMacrosListParams(). + WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantsUIDMacrosList(params) if err != nil { return nil, err } - macros = macrosListOk.Payload.Macros - + macros = resp.Payload.Macros } return macros, nil } -func (h *V1Client) StringHash(name string) string { - return strconv.FormatUint(uint64(hash(name)), 10) -} - -func hash(s string) uint32 { - h := fnv.New32a() - _, _ = h.Write([]byte(s)) - return h.Sum32() -} - func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error { if uid != "" { - params := userC.NewV1ProjectsUIDMacrosUpdateByMacroNameParams().WithContext(h.Ctx).WithUID(uid).WithBody(macros) - _, err := h.GetUserClient().V1ProjectsUIDMacrosUpdateByMacroName(params) + params := clientV1.NewV1ProjectsUIDMacrosUpdateByMacroNameParamsWithContext(h.ctx). + WithUID(uid). + WithBody(macros) + _, err := h.Client.V1ProjectsUIDMacrosUpdateByMacroName(params) return err } else { tenantUID, err := h.GetTenantUID() @@ -97,16 +83,20 @@ func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosUpdateByMacroNameParams().WithTenantUID(tenantUID).WithBody(macros) - _, err = h.GetUserClient().V1TenantsUIDMacrosUpdateByMacroName(params) + params := clientV1.NewV1TenantsUIDMacrosUpdateByMacroNameParams(). + WithTenantUID(tenantUID). + WithBody(macros) + _, err = h.Client.V1TenantsUIDMacrosUpdateByMacroName(params) return err } } func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { if uid != "" { - params := userC.NewV1ProjectsUIDMacrosDeleteByMacroNameParams().WithContext(h.Ctx).WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1ProjectsUIDMacrosDeleteByMacroName(params) + params := clientV1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params) if err != nil { return err } @@ -116,25 +106,24 @@ func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosDeleteByMacroNameParams().WithTenantUID(tenantUID).WithBody(body) - _, err = h.GetUserClient().V1TenantsUIDMacrosDeleteByMacroName(params) + params := clientV1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). + WithTenantUID(tenantUID). + WithBody(body) + _, err = h.Client.V1TenantsUIDMacrosDeleteByMacroName(params) if err != nil { return err } } _, err := h.GetMacros(uid) - if err != nil { - return err - } - return nil + return err } func (h *V1Client) GetMacroId(uid, name string) string { var hash string if uid != "" { - hash = h.StringHash(name + uid) + hash = apiutil.StringHash(name + uid) } else { - hash = h.StringHash(name + "%tenant") + hash = apiutil.StringHash(name + "%tenant") } return hash } diff --git a/client/macros.go b/client/macros.go index f4887af8..230280e9 100644 --- a/client/macros.go +++ b/client/macros.go @@ -2,17 +2,17 @@ package client import ( "fmt" - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, error) { - if h.CreateMacrosFn != nil { - return h.CreateMacrosFn(uid, macros) - } if uid != "" { - params := userC.NewV1ProjectsUIDMacrosCreateParams().WithContext(h.Ctx).WithUID(uid).WithBody(macros) - _, err := h.GetUserClient().V1ProjectsUIDMacrosCreate(params) + params := clientV1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(macros) + _, err := h.Client.V1ProjectsUIDMacrosCreate(params) if err != nil { return "", err } @@ -21,8 +21,11 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er if err != nil { return "", err } - params := userC.NewV1TenantsUIDMacrosCreateParams().WithTenantUID(tenantUID).WithBody(macros) - _, err = h.GetUserClient().V1TenantsUIDMacrosCreate(params) + // As discussed with hubble team, we should not set context for tenant macros. + params := clientV1.NewV1TenantsUIDMacrosCreateParams(). + WithTenantUID(tenantUID). + WithBody(macros) + _, err = h.Client.V1TenantsUIDMacrosCreate(params) if err != nil { return "", err } @@ -34,17 +37,13 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er return macrosId, nil } -func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) { - if h.GetTFMacrosV2Fn != nil { - return h.GetTFMacrosV2Fn(tfMacrosMap, projectUID) - } - allMacros, err := h.GetMacrosV2(projectUID) - +func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]interface{}, projectUid string) ([]*models.V1Macro, error) { + allMacros, err := h.GetMacrosV2(projectUid) if err != nil { return nil, err } - var tfMacros []*models.V1Macro + var tfMacros []*models.V1Macro for _, v := range allMacros { if value, ok := tfMacrosMap[v.Name]; ok && value != nil { tfMacros = append(tfMacros, &models.V1Macro{ @@ -57,15 +56,13 @@ func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]interface{}, projectUID return tfMacros, nil } -func (h *V1Client) GetExistMacros(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) { - if h.GetExistMacrosFn != nil { - return h.GetExistMacrosFn(tfMacrosMap, projectUID) - } - allMacros, err := h.GetMacrosV2(projectUID) - var existMacros []*models.V1Macro +func (h *V1Client) GetExistMacros(tfMacrosMap map[string]interface{}, projectUid string) ([]*models.V1Macro, error) { + allMacros, err := h.GetMacrosV2(projectUid) if err != nil { return nil, err } + + var existMacros []*models.V1Macro for _, v := range allMacros { if _, ok := tfMacrosMap[v.Name]; !ok { existMacros = append(existMacros, &models.V1Macro{ @@ -79,42 +76,41 @@ func (h *V1Client) GetExistMacros(tfMacrosMap map[string]interface{}, projectUID } -func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) { +func (h *V1Client) GetMacrosV2(projectUid string) ([]*models.V1Macro, error) { var macros []*models.V1Macro - if projectUID != "" { - params := userC.NewV1ProjectsUIDMacrosListParams().WithContext(h.Ctx).WithUID(projectUID) - macrosListOk, err := h.GetUserClient().V1ProjectsUIDMacrosList(params) + if projectUid != "" { + params := clientV1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). + WithUID(projectUid) + macrosListOk, err := h.Client.V1ProjectsUIDMacrosList(params) if err != nil { return nil, err } macros = macrosListOk.Payload.Macros - } else { tenantUID, err := h.GetTenantUID() if err != nil || tenantUID == "" { return nil, err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosListParams().WithTenantUID(tenantUID) - macrosListOk, err := h.GetUserClient().V1TenantsUIDMacrosList(params) + params := clientV1.NewV1TenantsUIDMacrosListParams(). + WithTenantUID(tenantUID) + macrosListOk, err := h.Client.V1TenantsUIDMacrosList(params) if err != nil { return nil, err } macros = macrosListOk.Payload.Macros - } return macros, nil } func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error { - if h.UpdateMacrosFn != nil { - return h.UpdateMacrosFn(uid, macros) - } if uid != "" { - params := userC.NewV1ProjectsUIDMacrosUpdateParams().WithContext(h.Ctx).WithUID(uid).WithBody(macros) - _, err := h.GetUserClient().V1ProjectsUIDMacrosUpdate(params) + params := clientV1.NewV1ProjectsUIDMacrosUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(macros) + _, err := h.Client.V1ProjectsUIDMacrosUpdate(params) return err } else { tenantUID, err := h.GetTenantUID() @@ -122,41 +118,36 @@ func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosUpdateParams().WithTenantUID(tenantUID).WithBody(macros) - _, err = h.GetUserClient().V1TenantsUIDMacrosUpdate(params) + params := clientV1.NewV1TenantsUIDMacrosUpdateParams(). + WithTenantUID(tenantUID). + WithBody(macros) + _, err = h.Client.V1TenantsUIDMacrosUpdate(params) return err } } func (h *V1Client) DeleteMacros(uid string, body *models.V1Macros) error { - if h.DeleteMacrosFn != nil { - return h.DeleteMacrosFn(uid, body) - } if uid != "" { - params := userC.NewV1ProjectsUIDMacrosDeleteByMacroNameParams().WithContext(h.Ctx).WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1ProjectsUIDMacrosDeleteByMacroName(params) - if err != nil { - return err - } + params := clientV1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params) + return err } else { tenantUID, err := h.GetTenantUID() if err != nil { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := userC.NewV1TenantsUIDMacrosDeleteByMacroNameParams().WithTenantUID(tenantUID).WithBody(body) - _, err = h.GetUserClient().V1TenantsUIDMacrosDeleteByMacroName(params) - if err != nil { - return err - } + params := clientV1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). + WithTenantUID(tenantUID). + WithBody(body) + _, err = h.Client.V1TenantsUIDMacrosDeleteByMacroName(params) + return err } - return nil } func (h *V1Client) GetMacrosId(uid string) (string, error) { - if h.GetMacrosIdFn != nil { - return h.GetMacrosIdFn(uid) - } hashId := "" if uid != "" { hashId = fmt.Sprintf("%s-%s-%s", "project", "macros", uid) diff --git a/client/management.go b/client/management.go deleted file mode 100644 index d23f643c..00000000 --- a/client/management.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "errors" - - mgmtC "github.com/spectrocloud/hapi/mgmt/client/v1" - "github.com/spectrocloud/hapi/models" -) - -func (h *V1Client) GetMgmtAppVersion() (*models.V1MgmtAppVersionVersion, error) { - params := mgmtC.NewV1MgmtAppVersionGetParams().WithContext(h.Ctx) - resp, err := h.GetMgmtClient().V1MgmtAppVersionGet(params) - if err != nil || resp == nil { - return nil, err - } - if resp.Payload == nil || (resp.Payload != nil && resp.Payload.Version == nil) { - return nil, errors.New("failed to detect mgmt app version") - } - return resp.Payload.Version, nil -} diff --git a/client/node_actions.go b/client/node_actions.go index fd11ae07..004b66fd 100644 --- a/client/node_actions.go +++ b/client/node_actions.go @@ -1,397 +1,245 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -type GetMaintenanceStatus func(string, string, string, string) (*models.V1MachineMaintenanceStatus, error) +type GetMaintenanceStatus func(string, string, string) (*models.V1MachineMaintenanceStatus, error) -func (h *V1Client) ToggleMaintenanceOnNode(nodeMaintenance *models.V1MachineMaintenance, CloudType, ClusterContext, ConfigUID, MachineName, NodeId string) error { - var params *clusterC.V1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParamsWithContext(h.Ctx).WithBody(nodeMaintenance) - case "tenant": - params = clusterC.NewV1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParams().WithBody(nodeMaintenance) - } - params.WithCloudType(CloudType) - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) - - _, err := h.GetClusterClient().V1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdate(params) - if err != nil { - return err - } +func (h *V1Client) ToggleMaintenanceOnNode(nodeMaintenance *models.V1MachineMaintenance, cloudType, configUid, machineName, nodeId string) error { + params := clientV1.NewV1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParamsWithContext(h.ctx). + WithBody(nodeMaintenance). + WithCloudType(cloudType). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - return nil + _, err := h.Client.V1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdate(params) + return err } -func (h *V1Client) GetNodeValue(nodeId, action string) map[string]interface{} { - return map[string]interface{}{ - "node_id": nodeId, - "action": action, - } +func (h *V1Client) GetNodeMaintenanceStatus(fn GetMaintenanceStatus, configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + return fn(configUid, machineName, nodeId) } -func (h *V1Client) GetNodeMaintenanceStatus(fn GetMaintenanceStatus, ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - return fn(ClusterContext, ConfigUID, MachineName, NodeId) -} +func (h *V1Client) GetNodeMaintenanceStatusAws(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsAwsPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) -func (h *V1Client) GetNodeMaintenanceStatusAws(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsAwsPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAwsPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsAwsPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) - - s, err := h.GetClusterClient().V1CloudConfigsAwsPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsAwsPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusMaas(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsMaasPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsMaasPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsMaasPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusMaas(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsMaasPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsMaasPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsMaasPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusAks(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsAksPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAksPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsAksPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusAks(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsAksPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsAksPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsAksPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusAzure(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsAzurePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsAzurePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsAzurePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusAzure(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsAzurePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsAzurePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsAzurePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusCoxEdge(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsCoxEdgePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusCoxEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsCoxEdgePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsCoxEdgePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsEdgeNativePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsEdgeNativePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusEdge(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsEdgePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsEdgePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsEdgePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsEdgePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsVspherePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsVspherePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsVspherePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusEks(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsEksPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsEksPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsEksPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusEks(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsEksPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsEksPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsEksPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusGcp(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsGcpPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGcpPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsGcpPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusGcp(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsGcpPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsGcpPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsGcpPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusGeneric(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsGenericPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGenericPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsGenericPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusGeneric(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsGenericPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsGenericPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsGenericPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusGke(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsGkePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsGkePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsGkePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusGke(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsGkePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsGkePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsGkePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusLibvirt(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsLibvirtPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusLibvirt(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsLibvirtPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsLibvirtPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusOpenStack(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsOpenStackPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusOpenStack(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsOpenStackPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsOpenStackPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusTke(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsTkePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsTkePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsTkePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusTke(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsTkePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsTkePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsTkePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeVirtualMaintenanceStatusVirtual(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsVirtualPoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVirtualPoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsVirtualPoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeVirtualMaintenanceStatusVirtual(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsVirtualPoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsVirtualPoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsVirtualPoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusVsphere(ClusterContext, ConfigUID, MachineName, NodeId string) (*models.V1MachineMaintenanceStatus, error) { - var params *clusterC.V1CloudConfigsVspherePoolMachinesUIDGetParams - switch ClusterContext { - case "project": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1CloudConfigsVspherePoolMachinesUIDGetParams() - } - params.WithConfigUID(ConfigUID) - params.WithMachinePoolName(MachineName) - params.WithMachineUID(NodeId) +func (h *V1Client) GetNodeMaintenanceStatusVsphere(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) { + params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). + WithConfigUID(configUid). + WithMachinePoolName(machineName). + WithMachineUID(nodeId) - s, err := h.GetClusterClient().V1CloudConfigsVspherePoolMachinesUIDGet(params) - print(s) + resp, err := h.Client.V1CloudConfigsVspherePoolMachinesUIDGet(params) if err != nil { return nil, err } - - return s.Payload.Status.MaintenanceStatus, nil + return resp.Payload.Status.MaintenanceStatus, nil } diff --git a/client/organization.go b/client/organization.go index b6b1d4ee..f73f16f8 100644 --- a/client/organization.go +++ b/client/organization.go @@ -1,82 +1,35 @@ package client import ( - "fmt" - - authC "github.com/spectrocloud/hapi/auth/client/v1" - "github.com/spectrocloud/hapi/models" - "github.com/spectrocloud/palette-sdk-go/client/herr" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) GetOrganizationByName(name string) (*models.V1LoginResponse, error) { - params := authC.NewV1AuthOrgParams().WithOrgName(&name) - resp, err := h.GetAuthClient().V1AuthOrg(params) + params := clientV1.NewV1AuthOrgParamsWithContext(h.ctx). + WithOrgName(&name) + resp, err := h.Client.V1AuthOrg(params) if err != nil || resp == nil { return nil, err } - return resp.Payload, nil } -func (h *V1Client) ListOrganizations(scope string) ([]*models.V1Organization, error) { - var params *authC.V1AuthOrgsParams - switch scope { - case "project": - params = authC.NewV1AuthOrgsParams().WithContext(h.Ctx) - case "tenant": - params = authC.NewV1AuthOrgsParams() - } - - resp, err := h.GetAuthClient().V1AuthOrgs(params) - if err != nil || resp == nil { +func (h *V1Client) ListOrganizations() ([]*models.V1Organization, error) { + params := clientV1.NewV1AuthOrgsParamsWithContext(h.ctx) + resp, err := h.Client.V1AuthOrgs(params) + if err != nil { return nil, err - } else if len(resp.Payload.Organizations) == 0 { - return nil, fmt.Errorf("no Organizations found in scope: %s", scope) } - return resp.Payload.Organizations, nil } -func (h *V1Client) SwitchOrganization(scope, orgName string) (string, error) { - var params *authC.V1AuthOrgSwitchParams - switch scope { - case "project": - params = authC.NewV1AuthOrgSwitchParams().WithContext(h.Ctx).WithOrgName(orgName) - case "tenant": - params = authC.NewV1AuthOrgSwitchParams().WithOrgName(orgName) - } - - resp, err := h.GetAuthClient().V1AuthOrgSwitch(params) +func (h *V1Client) SwitchOrganization(orgName string) (string, error) { + params := clientV1.NewV1AuthOrgSwitchParamsWithContext(h.ctx). + WithOrgName(orgName) + resp, err := h.Client.V1AuthOrgSwitch(params) if err != nil || resp == nil { return "", err } - return resp.Payload.Authorization, nil } - -func (h *V1Client) GetOrgLoginBanner(orgName string) (*models.V1LoginBannerSettings, error) { - params := authC.NewV1AuthOrgLoginBannerGetParams().WithOrgName(orgName) - resp, err := h.GetAuthClient().V1AuthOrgLoginBannerGet(params) - if err != nil || resp == nil { - if herr.IsNotFound(err) { - return nil, fmt.Errorf("invalid Organization: %s", orgName) - } - return nil, err - } else if !resp.Payload.IsEnabled { - return nil, nil - } - - return resp.Payload, nil -} - -func (h *V1Client) GetSystemLoginBanner() (*models.V1LoginBannerSettings, error) { - params := authC.NewV1AuthSystemLoginBannerGetParams() - resp, err := h.GetAuthClient().V1AuthSystemLoginBannerGet(params) - if err != nil || resp == nil { - return nil, err - } else if !resp.Payload.IsEnabled { - return nil, nil - } - - return resp.Payload, nil -} diff --git a/client/pack.go b/client/pack.go index 7fa6d07f..3ccb0edd 100644 --- a/client/pack.go +++ b/client/pack.go @@ -1,114 +1,98 @@ package client import ( - "errors" - "fmt" "strings" - "github.com/spectrocloud/hapi/apiutil/transport" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) SearchPacks(filter *models.V1PackFilterSpec, sortBy []*models.V1PackSortSpec) ([]*models.V1PackMetadata, error) { - body := &models.V1PacksFilterSpec{ - Filter: filter, - Sort: sortBy, - } - params := clusterC.NewV1PacksSearchParams().WithContext(h.Ctx).WithBody(body) - - resp, err := h.GetClusterClient().V1PacksSearch(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1PacksSearchParamsWithContext(h.ctx). + WithBody(&models.V1PacksFilterSpec{ + Filter: filter, + Sort: sortBy, + }) + resp, err := h.Client.V1PacksSearch(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - return resp.Payload.Items, nil } -func (h *V1Client) GetClusterProfileManifestPack(clusterProfileUID, packName string) ([]*models.V1ManifestEntity, error) { - //params := clusterC.NewV1ClusterProfilesGetParamsWithContext(h.ctx).WithUID(uid) - params := clusterC.NewV1ClusterProfilesUIDPacksUIDManifestsParamsWithContext(h.Ctx). - WithUID(clusterProfileUID).WithPackName(packName) - - success, err := h.GetClusterClient().V1ClusterProfilesUIDPacksUIDManifests(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { +func (h *V1Client) GetClusterProfileManifestPack(clusterProfileUid, packName string) ([]*models.V1ManifestEntity, error) { + params := clientV1.NewV1ClusterProfilesUIDPacksUIDManifestsParamsWithContext(h.ctx). + WithUID(clusterProfileUid). + WithPackName(packName) + resp, err := h.Client.V1ClusterProfilesUIDPacksUIDManifests(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - return success.Payload.Items, nil + return resp.Payload.Items, nil } -func (h *V1Client) GetPacks(filters []string, registryUID string) ([]*models.V1PackSummary, error) { - params := clusterC.NewV1PacksSummaryListParamsWithContext(h.Ctx) +func (h *V1Client) GetPacks(filters []string, registryUid string) ([]*models.V1PackSummary, error) { + params := clientV1.NewV1PacksSummaryListParamsWithContext(h.ctx) if filters != nil { - filterString := Ptr(strings.Join(filters, "AND")) + filterString := apiutil.Ptr(strings.Join(filters, "AND")) params = params.WithFilters(filterString) } - - response, err := h.GetClusterClient().V1PacksSummaryList(params) + resp, err := h.Client.V1PacksSummaryList(params) if err != nil { return nil, err } - packs := make([]*models.V1PackSummary, 0) - for _, pack := range response.Payload.Items { - if registryUID == "" || pack.Spec.RegistryUID == registryUID { + for _, pack := range resp.Payload.Items { + if registryUid == "" || pack.Spec.RegistryUID == registryUid { packs = append(packs, pack) } } - return packs, nil } -func (h *V1Client) GetPacksByNameAndRegistry(name, registryUID, packContext string) (*models.V1PackTagEntity, error) { - var params *clusterC.V1PacksNameRegistryUIDListParams - switch packContext { - case "project": - params = clusterC.NewV1PacksNameRegistryUIDListParamsWithContext(h.Ctx).WithPackName(name).WithRegistryUID(registryUID) - case "tenant": - params = clusterC.NewV1PacksNameRegistryUIDListParams().WithPackName(name).WithRegistryUID(registryUID) - default: - return nil, fmt.Errorf("invalid pack context %s", packContext) - +func (h *V1Client) GetPacksByProfile(profileUid string) ([]*models.V1ClusterProfilePacksEntity, error) { + params := clientV1.NewV1ClusterProfilesUIDPacksGetParamsWithContext(h.ctx). + WithUID(profileUid) + resp, err := h.Client.V1ClusterProfilesUIDPacksGet(params) + if err != nil { + return nil, err } + return resp.Payload.Items, nil +} - response, err := h.GetClusterClient().V1PacksNameRegistryUIDList(params) +func (h *V1Client) GetPacksByNameAndRegistry(name, registryUid string) (*models.V1PackTagEntity, error) { + params := clientV1.NewV1PacksNameRegistryUIDListParamsWithContext(h.ctx). + WithPackName(name). + WithRegistryUID(registryUid) + resp, err := h.Client.V1PacksNameRegistryUIDList(params) if err != nil { return nil, err } - - return response.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetPack(uid string) (*models.V1PackTagEntity, error) { - params := clusterC.NewV1PacksUIDParamsWithContext(h.Ctx).WithUID(uid) - response, err := h.GetClusterClient().V1PacksUID(params) + params := clientV1.NewV1PacksUIDParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1PacksUID(params) if err != nil { return nil, err } - - return response.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetPackRegistry(packUID, packType string) string { - if packUID == "uid" || packType == "manifest" { +func (h *V1Client) GetPackRegistry(packUid, packType string) string { + if packUid == "uid" || packType == "manifest" { registry, err := h.GetPackRegistryCommonByName("Public Repo") if err != nil { return "" } return registry.UID } - - PackTagEntity, err := h.GetPack(packUID) + packTagEntity, err := h.GetPack(packUid) if err != nil { return "" } - - return PackTagEntity.RegistryUID + return packTagEntity.RegistryUID } diff --git a/client/private_cloud_gateway.go b/client/private_cloud_gateway.go index 2c880fa8..ef9d1c64 100644 --- a/client/private_cloud_gateway.go +++ b/client/private_cloud_gateway.go @@ -4,22 +4,20 @@ import ( "errors" "fmt" - "github.com/spectrocloud/hapi/apiutil" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) // PCG - Generic func (h *V1Client) GetPCGId(name *string) (string, error) { - params := clusterC.NewV1OverlordsListParams() - listResp, err := h.GetClusterClient().V1OverlordsList(params) + params := clientV1.NewV1OverlordsListParamsWithContext(h.ctx) + resp, err := h.Client.V1OverlordsList(params) if err != nil { return "", err } - - for _, pcg := range listResp.Payload.Items { + for _, pcg := range resp.Payload.Items { if pcg.Metadata.Name == *name { return pcg.Metadata.UID, nil } @@ -28,92 +26,97 @@ func (h *V1Client) GetPCGId(name *string) (string, error) { } func (h *V1Client) GetPCGById(uid string) (*models.V1Overlord, error) { - params := clusterC.NewV1OverlordsUIDGetParams().WithUID(uid) - overlord, err := h.GetClusterClient().V1OverlordsUIDGet(params) + params := clientV1.NewV1OverlordsUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1OverlordsUIDGet(params) if err != nil { return nil, err } - return overlord.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetPCGByName(name *string) (*models.V1Overlord, error) { - params := clusterC.NewV1OverlordsListParamsWithContext(h.Ctx).WithName(name) - overlordList, err := h.GetClusterClient().V1OverlordsList(params) +func (h *V1Client) GetPCGByName(name string) (*models.V1Overlord, error) { + params := clientV1.NewV1OverlordsListParamsWithContext(h.ctx). + WithName(&name) + resp, err := h.Client.V1OverlordsList(params) if err != nil { return nil, err } - - var overlord *models.V1Overlord - if len(overlordList.Payload.Items) > 0 { - overlord = overlordList.Payload.Items[0] + if len(resp.Payload.Items) > 0 { + return resp.Payload.Items[0], nil } - return overlord, nil + return nil, nil } func (h *V1Client) GetPairingCode(cloudType string) (string, error) { - codeParams := clusterC.NewV1OverlordsPairingCodeParams().WithContext(h.Ctx).WithCloudType(&cloudType) - ret, err := h.GetClusterClient().V1OverlordsPairingCode(codeParams) + params := clientV1.NewV1OverlordsPairingCodeParamsWithContext(h.ctx). + WithCloudType(&cloudType) + resp, err := h.Client.V1OverlordsPairingCode(params) if err != nil { return "", err } - - return ret.Payload.PairingCode, nil + return resp.Payload.PairingCode, nil } -func (h *V1Client) CheckPCG(PcgId string) error { - if PcgId == "" { +func (h *V1Client) CheckPCG(pcgId string) error { + if pcgId == "" { return nil // no pcg to check } - pcg, err := h.GetPCGById(PcgId) + pcg, err := h.GetPCGById(pcgId) if err != nil { return err } if pcg == nil { - return fmt.Errorf("Private Cloud Gateway not found: %s", PcgId) + return fmt.Errorf("private cloud gateway not found: %s", pcgId) } if pcg.Status == nil { - return fmt.Errorf("Private Cloud Gateway status not found: %s", PcgId) + return fmt.Errorf("private cloud gateway status not found: %s", pcgId) } if pcg.Status.State != "Running" { - return fmt.Errorf("Private Cloud Gateway is not running: %s", PcgId) - } else { - return nil // pcg is running + return fmt.Errorf("private cloud gateway is not running: %s", pcgId) } + return nil // pcg is running } // PCG - vSphere func (h *V1Client) CreatePCGVsphere(uid string, cloudConfig *models.V1OverlordVsphereCloudConfig) (string, error) { - params := clusterC.NewV1OverlordsUIDVsphereCloudConfigCreateParamsWithContext(h.Ctx).WithBody(cloudConfig).WithUID(uid) - success, err := h.GetClusterClient().V1OverlordsUIDVsphereCloudConfigCreate(params) + params := clientV1.NewV1OverlordsUIDVsphereCloudConfigCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(cloudConfig) + resp, err := h.Client.V1OverlordsUIDVsphereCloudConfigCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) CreatePCGCloudAccountVsphere(uid string, account *models.V1OverlordVsphereAccountCreate) (string, error) { - params := clusterC.NewV1OverlordsUIDVsphereAccountCreateParamsWithContext(h.Ctx).WithBody(account).WithUID(uid) - success, err := h.GetClusterClient().V1OverlordsUIDVsphereAccountCreate(params) + params := clientV1.NewV1OverlordsUIDVsphereAccountCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(account) + resp, err := h.Client.V1OverlordsUIDVsphereAccountCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) GetPCGManifestVsphere(pairingCode string) (string, error) { - params := clusterC.NewV1OverlordsVsphereManifestParamsWithContext(h.Ctx).WithPairingCode(pairingCode) - success, err := h.GetClusterClient().V1OverlordsVsphereManifest(params) + params := clientV1.NewV1OverlordsVsphereManifestParamsWithContext(h.ctx). + WithPairingCode(pairingCode) + resp, err := h.Client.V1OverlordsVsphereManifest(params) if err != nil { return "", err } - return success.Payload.Manifest, nil + return resp.Payload.Manifest, nil } func (h *V1Client) GetPCGClusterProfileVsphere(uid string) (*models.V1ClusterProfile, error) { - params := clusterC.NewV1OverlordsUIDVsphereClusterProfileParams().WithUID(uid) - resp, err := h.GetClusterClient().V1OverlordsUIDVsphereClusterProfile(params) + params := clientV1.NewV1OverlordsUIDVsphereClusterProfileParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1OverlordsUIDVsphereClusterProfile(params) if err != nil { return nil, err } @@ -121,49 +124,50 @@ func (h *V1Client) GetPCGClusterProfileVsphere(uid string) (*models.V1ClusterPro } func (h *V1Client) CreateDDNSSearchDomainVsphere(vsphereDnsMapping *models.V1VsphereDNSMapping) error { - params := userC.NewV1VsphereDNSMappingCreateParamsWithContext(h.Ctx).WithBody(vsphereDnsMapping) - if _, err := h.GetUserClient().V1VsphereDNSMappingCreate(params); err != nil { - return err - } - return nil + params := clientV1.NewV1VsphereDNSMappingCreateParamsWithContext(h.ctx). + WithBody(vsphereDnsMapping) + _, err := h.Client.V1VsphereDNSMappingCreate(params) + return err } // PCG - OpenStack func (h *V1Client) CreatePCGCloudAccountOpenStack(overlordUid string, account *models.V1OverlordOpenStackAccountCreate) (string, error) { - params := clusterC.NewV1OverlordsUIDOpenStackAccountCreateParamsWithContext(h.Ctx). - WithBody(account). - WithUID(overlordUid) - success, err := h.GetClusterClient().V1OverlordsUIDOpenStackAccountCreate(params) + params := clientV1.NewV1OverlordsUIDOpenStackAccountCreateParamsWithContext(h.ctx). + WithUID(overlordUid). + WithBody(account) + resp, err := h.Client.V1OverlordsUIDOpenStackAccountCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) CreatePCGOpenStack(overlordUid string, cloudConfig *models.V1OverlordOpenStackCloudConfig) (string, error) { - params := clusterC.NewV1OverlordsUIDOpenStackCloudConfigCreateParamsWithContext(h.Ctx). - WithBody(cloudConfig). - WithUID(overlordUid) - success, err := h.GetClusterClient().V1OverlordsUIDOpenStackCloudConfigCreate(params) + params := clientV1.NewV1OverlordsUIDOpenStackCloudConfigCreateParamsWithContext(h.ctx). + WithUID(overlordUid). + WithBody(cloudConfig) + resp, err := h.Client.V1OverlordsUIDOpenStackCloudConfigCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) GetPCGManifestOpenStack(pairingCode string) (string, error) { - params := clusterC.NewV1OverlordsOpenStackManifestParamsWithContext(h.Ctx).WithPairingCode(pairingCode) - success, err := h.GetClusterClient().V1OverlordsOpenStackManifest(params) + params := clientV1.NewV1OverlordsOpenStackManifestParamsWithContext(h.ctx). + WithPairingCode(pairingCode) + resp, err := h.Client.V1OverlordsOpenStackManifest(params) if err != nil { return "", err } - return success.Payload.Manifest, nil + return resp.Payload.Manifest, nil } func (h *V1Client) GetPCGClusterProfileOpenStack(uid string) (*models.V1ClusterProfile, error) { - params := clusterC.NewV1OverlordsUIDOpenStackClusterProfileParams().WithUID(uid) - resp, err := h.GetClusterClient().V1OverlordsUIDOpenStackClusterProfile(params) + params := clientV1.NewV1OverlordsUIDOpenStackClusterProfileParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1OverlordsUIDOpenStackClusterProfile(params) if err != nil { return nil, err } @@ -173,39 +177,41 @@ func (h *V1Client) GetPCGClusterProfileOpenStack(uid string) (*models.V1ClusterP // PCG - MAAS func (h *V1Client) CreatePCGCloudAccountMaas(overlordUid string, account *models.V1OverlordMaasAccountCreate) (string, error) { - params := clusterC.NewV1OverlordsUIDMaasAccountCreateParamsWithContext(h.Ctx). - WithBody(account). - WithUID(overlordUid) - success, err := h.GetClusterClient().V1OverlordsUIDMaasAccountCreate(params) + params := clientV1.NewV1OverlordsUIDMaasAccountCreateParamsWithContext(h.ctx). + WithUID(overlordUid). + WithBody(account) + resp, err := h.Client.V1OverlordsUIDMaasAccountCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) CreatePCGMaas(overlordUid string, cloudConfig *models.V1OverlordMaasCloudConfig) (string, error) { - params := clusterC.NewV1OverlordsUIDMaasCloudConfigCreateParamsWithContext(h.Ctx). - WithBody(cloudConfig). - WithUID(overlordUid) - success, err := h.GetClusterClient().V1OverlordsUIDMaasCloudConfigCreate(params) + params := clientV1.NewV1OverlordsUIDMaasCloudConfigCreateParamsWithContext(h.ctx). + WithUID(overlordUid). + WithBody(cloudConfig) + resp, err := h.Client.V1OverlordsUIDMaasCloudConfigCreate(params) if err != nil { return "", err } - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) GetPCGManifestMaas(pairingCode string) (string, error) { - params := clusterC.NewV1OverlordsMaasManifestParamsWithContext(h.Ctx).WithPairingCode(pairingCode) - success, err := h.GetClusterClient().V1OverlordsMaasManifest(params) + params := clientV1.NewV1OverlordsMaasManifestParamsWithContext(h.ctx). + WithPairingCode(pairingCode) + resp, err := h.Client.V1OverlordsMaasManifest(params) if err != nil { return "", err } - return success.Payload.Manifest, nil + return resp.Payload.Manifest, nil } func (h *V1Client) GetPCGClusterProfileMaas(uid string) (*models.V1ClusterProfile, error) { - params := clusterC.NewV1OverlordsUIDMaasClusterProfileParams().WithUID(uid) - resp, err := h.GetClusterClient().V1OverlordsUIDMaasClusterProfile(params) + params := clientV1.NewV1OverlordsUIDMaasClusterProfileParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1OverlordsUIDMaasClusterProfile(params) if err != nil { return nil, err } @@ -215,29 +221,31 @@ func (h *V1Client) GetPCGClusterProfileMaas(uid string) (*models.V1ClusterProfil // IP Pool func (h *V1Client) CreateIpPool(pcgUID string, pool *models.V1IPPoolInputEntity) (string, error) { - params := clusterC.NewV1OverlordsUIDPoolCreateParams().WithUID(pcgUID).WithBody(pool) - if resp, err := h.GetClusterClient().V1OverlordsUIDPoolCreate(params); err != nil { + params := clientV1.NewV1OverlordsUIDPoolCreateParamsWithContext(h.ctx). + WithUID(pcgUID). + WithBody(pool) + resp, err := h.Client.V1OverlordsUIDPoolCreate(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } -func (h *V1Client) GetIpPool(pcgUID, poolUID string) (*models.V1IPPoolEntity, error) { - pools, err := h.GetIpPools(pcgUID) +func (h *V1Client) GetIpPool(pcgUid, poolUid string) (*models.V1IPPoolEntity, error) { + pools, err := h.GetIpPools(pcgUid) if err != nil { return nil, err } for _, pool := range pools { - if pool.Metadata.UID == poolUID { + if pool.Metadata.UID == poolUid { return pool, nil } } return nil, nil } -func (h *V1Client) GetIpPoolByName(pcgUID, poolName string) (*models.V1IPPoolEntity, error) { - pools, err := h.GetIpPools(pcgUID) +func (h *V1Client) GetIpPoolByName(pcgUid, poolName string) (*models.V1IPPoolEntity, error) { + pools, err := h.GetIpPools(pcgUid) if err != nil { return nil, err } @@ -249,29 +257,31 @@ func (h *V1Client) GetIpPoolByName(pcgUID, poolName string) (*models.V1IPPoolEnt return nil, errors.New("ip pool not found: " + poolName) } -func (h *V1Client) GetIpPools(pcgUID string) ([]*models.V1IPPoolEntity, error) { - params := clusterC.NewV1OverlordsUIDPoolsListParams().WithUID(pcgUID) - listResp, err := h.GetClusterClient().V1OverlordsUIDPoolsList(params) +func (h *V1Client) GetIpPools(pcgUid string) ([]*models.V1IPPoolEntity, error) { + params := clientV1.NewV1OverlordsUIDPoolsListParamsWithContext(h.ctx). + WithUID(pcgUid) + resp, err := h.Client.V1OverlordsUIDPoolsList(params) if err != nil { if v1Err := apiutil.ToV1ErrorObj(err); v1Err.Code != "ResourceNotFound" { return nil, err } } - return listResp.Payload.Items, nil + return resp.Payload.Items, nil } -func (h *V1Client) UpdateIpPool(pcgUID, poolUID string, pool *models.V1IPPoolInputEntity) error { - params := clusterC.NewV1OverlordsUIDPoolUpdateParams(). - WithUID(pcgUID). +func (h *V1Client) UpdateIpPool(pcgUid, poolUid string, pool *models.V1IPPoolInputEntity) error { + params := clientV1.NewV1OverlordsUIDPoolUpdateParamsWithContext(h.ctx). + WithUID(pcgUid). WithBody(pool). - WithPoolUID(poolUID) - - _, err := h.GetClusterClient().V1OverlordsUIDPoolUpdate(params) + WithPoolUID(poolUid) + _, err := h.Client.V1OverlordsUIDPoolUpdate(params) return err } -func (h *V1Client) DeleteIpPool(pcgUID, poolUID string) error { - params := clusterC.NewV1OverlordsUIDPoolDeleteParams().WithUID(pcgUID).WithPoolUID(poolUID) - _, err := h.GetClusterClient().V1OverlordsUIDPoolDelete(params) +func (h *V1Client) DeleteIpPool(pcgUid, poolUid string) error { + params := clientV1.NewV1OverlordsUIDPoolDeleteParamsWithContext(h.ctx). + WithUID(pcgUid). + WithPoolUID(poolUid) + _, err := h.Client.V1OverlordsUIDPoolDelete(params) return err } diff --git a/client/project.go b/client/project.go index 782094e2..67bd4ab7 100644 --- a/client/project.go +++ b/client/project.go @@ -1,30 +1,23 @@ package client import ( - "errors" "fmt" - "github.com/spectrocloud/hapi/apiutil/transport" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) CreateProject(body *models.V1ProjectEntity) (string, error) { - params := userC.NewV1ProjectsCreateParams().WithBody(body) - success, err := h.GetUserClient().V1ProjectsCreate(params) + params := clientV1.NewV1ProjectsCreateParamsWithContext(h.ctx). + WithBody(body) + resp, err := h.Client.V1ProjectsCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) GetProjectUID(projectName string) (string, error) { - if h.GetProjectUIDFn != nil { - return h.GetProjectUIDFn(projectName) - } - projects, err := h.GetProjects() if err != nil { return "", err @@ -40,64 +33,35 @@ func (h *V1Client) GetProjectUID(projectName string) (string, error) { } func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) { - params := userC.NewV1ProjectsUIDGetParams().WithUID(uid) - project, err := h.GetUserClient().V1ProjectsUIDGet(params) - if err != nil || project == nil { + params := clientV1.NewV1ProjectsUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ProjectsUIDGet(params) + if err != nil { return nil, err } - - return project.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetProjects() (*models.V1ProjectsMetadata, error) { - params := hashboardC.NewV1ProjectsMetadataParams() - - projects, err := h.GetHashboardClient().V1ProjectsMetadata(params) - if err != nil || projects == nil { - // to support 2.6 projects list - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - limit := int64(0) - oldParams := userC.NewV1ProjectsListParams().WithLimit(&limit) - oldProjects, err := h.GetUserClient().V1ProjectsList(oldParams) - if err != nil || oldProjects == nil { - return nil, err - } - ret := make([]*models.V1ProjectMetadata, 0) - for _, pr := range oldProjects.Payload.Items { - ret = append(ret, &models.V1ProjectMetadata{ - Metadata: &models.V1ObjectEntity{ - UID: pr.Metadata.UID, - Name: pr.Metadata.Name, - }, - }) - } - return &models.V1ProjectsMetadata{ - Items: ret, - }, nil - } + params := clientV1.NewV1ProjectsMetadataParamsWithContext(h.ctx) + resp, err := h.Client.V1ProjectsMetadata(params) + if err != nil { return nil, err } - - return projects.Payload, nil + return resp.Payload, nil } func (h *V1Client) UpdateProject(uid string, body *models.V1ProjectEntity) error { - params := userC.NewV1ProjectsUIDUpdateParams().WithBody(body).WithUID(uid) - _, err := h.GetUserClient().V1ProjectsUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1ProjectsUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1ProjectsUIDUpdate(params) + return err } func (h *V1Client) DeleteProject(uid string) error { - params := userC.NewV1ProjectsUIDDeleteParams().WithUID(uid) - _, err := h.GetUserClient().V1ProjectsUIDDelete(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1ProjectsUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1ProjectsUIDDelete(params) + return err } diff --git a/client/registry.go b/client/registry.go index d4def90f..65642680 100644 --- a/client/registry.go +++ b/client/registry.go @@ -3,8 +3,9 @@ package client import ( "fmt" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) SearchPackRegistryCommon() ([]*models.V1RegistryMetadata, error) { @@ -12,15 +13,10 @@ func (h *V1Client) SearchPackRegistryCommon() ([]*models.V1RegistryMetadata, err } func (h *V1Client) GetPackRegistryCommonByName(registryName string) (*models.V1RegistryMetadata, error) { - if h.GetPackRegistryCommonByNameFn != nil { - return h.GetPackRegistryCommonByNameFn(registryName) - } - registries, err := h.getRegistryCommon() if err != nil { return nil, err } - for _, registry := range registries { if registry.Name == registryName { return registry, nil @@ -30,204 +26,177 @@ func (h *V1Client) GetPackRegistryCommonByName(registryName string) (*models.V1R } func (h *V1Client) getRegistryCommon() ([]*models.V1RegistryMetadata, error) { - params := clusterC.NewV1RegistriesMetadataParams().WithScope(Ptr("")) - registries, err := h.GetClusterClient().V1RegistriesMetadata(params) + params := clientV1.NewV1RegistriesMetadataParamsWithContext(h.ctx). + WithScope(apiutil.Ptr("")) + resp, err := h.Client.V1RegistriesMetadata(params) if err != nil { return nil, err } - return registries.Payload.Items, nil + return resp.Payload.Items, nil } func (h *V1Client) GetPackRegistryByName(registryName string) (*models.V1PackRegistry, error) { - params := clusterC.NewV1RegistriesPackListParams() - registries, err := h.GetClusterClient().V1RegistriesPackList(params) + params := clientV1.NewV1RegistriesPackListParamsWithContext(h.ctx) + resp, err := h.Client.V1RegistriesPackList(params) if err != nil { return nil, err } - - for _, registry := range registries.Payload.Items { + for _, registry := range resp.Payload.Items { if registry.Metadata.Name == registryName { return registry, nil } } - return nil, fmt.Errorf("registry '%s' not found", registryName) } func (h *V1Client) ListHelmRegistries(scope string) ([]*models.V1HelmRegistrySummary, error) { - params := clusterC.NewV1RegistriesHelmSummaryListParams().WithScope(&scope) - helmRegistries, err := h.GetClusterClient().V1RegistriesHelmSummaryList(params) + params := clientV1.NewV1RegistriesHelmSummaryListParamsWithContext(h.ctx). + WithScope(&scope) + resp, err := h.Client.V1RegistriesHelmSummaryList(params) if err != nil { return nil, err } - - return helmRegistries.Payload.Items, nil + return resp.Payload.Items, nil } func (h *V1Client) GetHelmRegistryByName(registryName string) (*models.V1HelmRegistry, error) { - params := clusterC.NewV1RegistriesHelmListParams() - registries, err := h.GetClusterClient().V1RegistriesHelmList(params) + params := clientV1.NewV1RegistriesHelmListParamsWithContext(h.ctx) + resp, err := h.Client.V1RegistriesHelmList(params) if err != nil { return nil, err } - - for _, registry := range registries.Payload.Items { + for _, registry := range resp.Payload.Items { if registry.Metadata.Name == registryName { return registry, nil } } - return nil, fmt.Errorf("registry '%s' not found", registryName) } func (h *V1Client) GetHelmRegistry(uid string) (*models.V1HelmRegistry, error) { - params := clusterC.NewV1RegistriesHelmUIDGetParams().WithUID(uid) - response, err := h.GetClusterClient().V1RegistriesHelmUIDGet(params) + params := clientV1.NewV1RegistriesHelmUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1RegistriesHelmUIDGet(params) if err != nil { return nil, err } - - return response.Payload, nil + return resp.Payload, nil } func (h *V1Client) CreateHelmRegistry(registry *models.V1HelmRegistryEntity) (string, error) { - params := clusterC.NewV1RegistriesHelmCreateParams().WithBody(registry) - if resp, err := h.GetClusterClient().V1RegistriesHelmCreate(params); err != nil { + params := clientV1.NewV1RegistriesHelmCreateParamsWithContext(h.ctx). + WithBody(registry) + resp, err := h.Client.V1RegistriesHelmCreate(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } func (h *V1Client) UpdateHelmRegistry(uid string, registry *models.V1HelmRegistry) error { - params := clusterC.NewV1RegistriesHelmUIDUpdateParams().WithBody(registry).WithUID(uid) - if _, err := h.GetClusterClient().V1RegistriesHelmUIDUpdate(params); err != nil { - return err - } else { - return nil - } + params := clientV1.NewV1RegistriesHelmUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(registry) + _, err := h.Client.V1RegistriesHelmUIDUpdate(params) + return err } func (h *V1Client) DeleteHelmRegistry(uid string) error { - params := clusterC.NewV1RegistriesHelmUIDDeleteParams().WithUID(uid) - if _, err := h.GetClusterClient().V1RegistriesHelmUIDDelete(params); err != nil { - return err - } else { - return nil - } + params := clientV1.NewV1RegistriesHelmUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1RegistriesHelmUIDDelete(params) + return err } func (h *V1Client) ListOCIRegistries() ([]*models.V1OciRegistry, error) { - params := clusterC.NewV1OciRegistriesSummaryParams() - ociRegistries, err := h.GetClusterClient().V1OciRegistriesSummary(params) + params := clientV1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) + resp, err := h.Client.V1OciRegistriesSummary(params) if err != nil { return nil, err } - - return ociRegistries.Payload.Items, nil + return resp.Payload.Items, nil } func (h *V1Client) GetOciRegistryByName(registryName string) (*models.V1OciRegistry, error) { - params := clusterC.NewV1OciRegistriesSummaryParams() - registries, err := h.GetClusterClient().V1OciRegistriesSummary(params) + params := clientV1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) + resp, err := h.Client.V1OciRegistriesSummary(params) if err != nil { return nil, err } - - for _, registry := range registries.Payload.Items { + for _, registry := range resp.Payload.Items { if registry.Metadata.Name == registryName { return registry, nil } } - return nil, fmt.Errorf("registry '%s' not found", registryName) } func (h *V1Client) GetOciBasicRegistry(uid string) (*models.V1BasicOciRegistry, error) { - params := clusterC.NewV1BasicOciRegistriesUIDGetParams().WithUID(uid) - response, err := h.GetClusterClient().V1BasicOciRegistriesUIDGet(params) + params := clientV1.NewV1BasicOciRegistriesUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1BasicOciRegistriesUIDGet(params) if err != nil { return nil, err } - - return response.Payload, nil + return resp.Payload, nil } func (h *V1Client) CreateOciBasicRegistry(registry *models.V1BasicOciRegistry) (string, error) { - params := clusterC.NewV1BasicOciRegistriesCreateParams().WithBody(registry) - if resp, err := h.GetClusterClient().V1BasicOciRegistriesCreate(params); err != nil { + params := clientV1.NewV1BasicOciRegistriesCreateParamsWithContext(h.ctx). + WithBody(registry) + resp, err := h.Client.V1BasicOciRegistriesCreate(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } func (h *V1Client) UpdateOciBasicRegistry(uid string, registry *models.V1BasicOciRegistry) error { - params := clusterC.NewV1BasicOciRegistriesUIDUpdateParams().WithBody(registry).WithUID(uid) - _, err := h.GetClusterClient().V1BasicOciRegistriesUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1BasicOciRegistriesUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(registry) + _, err := h.Client.V1BasicOciRegistriesUIDUpdate(params) + return err } func (h *V1Client) DeleteOciBasicRegistry(uid string) error { - params := clusterC.NewV1BasicOciRegistriesUIDDeleteParams().WithUID(uid) - _, err := h.GetClusterClient().V1BasicOciRegistriesUIDDelete(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1BasicOciRegistriesUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1BasicOciRegistriesUIDDelete(params) + return err } func (h *V1Client) GetOciEcrRegistry(uid string) (*models.V1EcrRegistry, error) { - if h.GetOciRegistryFn != nil { - return h.GetOciRegistryFn(uid) - } - - params := clusterC.NewV1EcrRegistriesUIDGetParams().WithUID(uid) - response, err := h.GetClusterClient().V1EcrRegistriesUIDGet(params) + params := clientV1.NewV1EcrRegistriesUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1EcrRegistriesUIDGet(params) if err != nil { return nil, err } - - return response.Payload, nil + return resp.Payload, nil } func (h *V1Client) CreateOciEcrRegistry(registry *models.V1EcrRegistry) (string, error) { - if h.CreateOciEcrRegistryFn != nil { - return h.CreateOciEcrRegistryFn(registry) - } - - params := clusterC.NewV1EcrRegistriesCreateParams().WithBody(registry) - if resp, err := h.GetClusterClient().V1EcrRegistriesCreate(params); err != nil { + params := clientV1.NewV1EcrRegistriesCreateParamsWithContext(h.ctx). + WithBody(registry) + resp, err := h.Client.V1EcrRegistriesCreate(params) + if err != nil { return "", err - } else { - return *resp.Payload.UID, nil } + return *resp.Payload.UID, nil } func (h *V1Client) UpdateEcrRegistry(uid string, registry *models.V1EcrRegistry) error { - if h.UpdateEcrRegistryFn != nil { - return h.UpdateEcrRegistryFn(uid, registry) - } - params := clusterC.NewV1EcrRegistriesUIDUpdateParams().WithBody(registry).WithUID(uid) - _, err := h.GetClusterClient().V1EcrRegistriesUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1EcrRegistriesUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(registry) + _, err := h.Client.V1EcrRegistriesUIDUpdate(params) + return err } func (h *V1Client) DeleteOciEcrRegistry(uid string) error { - if h.DeleteOciEcrRegistryFn != nil { - return h.DeleteOciEcrRegistryFn(uid) - } - - params := clusterC.NewV1EcrRegistriesUIDDeleteParams().WithUID(uid) - _, err := h.GetClusterClient().V1EcrRegistriesUIDDelete(params) + params := clientV1.NewV1EcrRegistriesUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1EcrRegistriesUIDDelete(params) return err } diff --git a/client/role.go b/client/role.go index 5fb4a32e..43a97ecf 100644 --- a/client/role.go +++ b/client/role.go @@ -3,18 +3,18 @@ package client import ( "fmt" - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) GetRole(roleName string) (*models.V1Role, error) { - params := userC.NewV1RolesListParams() - roles, err := h.GetUserClient().V1RolesList(params) + params := clientV1.NewV1RolesListParamsWithContext(h.ctx) + resp, err := h.Client.V1RolesList(params) if err != nil { return nil, err } - for _, role := range roles.Payload.Items { + for _, role := range resp.Payload.Items { if role.Metadata.Name == roleName { return role, nil } diff --git a/client/search.go b/client/search.go index 518090f9..f51337e1 100644 --- a/client/search.go +++ b/client/search.go @@ -1,9 +1,7 @@ package client import ( - "fmt" - - "github.com/spectrocloud/hapi/models" + "github.com/spectrocloud/palette-api-go/models" ) func and() *models.V1SearchFilterConjunctionOperator { @@ -15,216 +13,3 @@ func or() *models.V1SearchFilterConjunctionOperator { or := models.V1SearchFilterConjunctionOperatorOr return &or } - -func getClusterFilter(extraFilters []*models.V1SearchFilterItem, virtual bool) *models.V1SearchFilterSpec { - filter := &models.V1SearchFilterSpec{ - Conjunction: and(), - FilterGroups: []*models.V1SearchFilterGroup{ - { - Conjunction: and(), - Filters: []*models.V1SearchFilterItem{ - { - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{"nested"}, - }, - Negation: !virtual, - Operator: models.V1SearchFilterStringOperatorEq, - }, - }, - Property: "environment", - Type: models.V1SearchFilterPropertyTypeString, - }, - { - Condition: &models.V1SearchFilterCondition{ - Bool: &models.V1SearchFilterBoolCondition{ - Value: false, - }, - }, - Property: "isDeleted", - Type: models.V1SearchFilterPropertyTypeBool, - }, - }, - }, - }, - } - - filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters}) - - return filter -} - -func clusterNameEqFilter(name string) *models.V1SearchFilterItem { - return &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{name}, - }, - Operator: models.V1SearchFilterStringOperatorEq, - Negation: false, - IgnoreCase: false, - }, - }, - Property: "clusterName", - Type: models.V1SearchFilterPropertyTypeString, - } -} - -func (h *V1Client) GetClusterByName(name, clusterContext string, virtual bool) (*models.V1SpectroCluster, error) { - filters := []*models.V1SearchFilterItem{clusterNameEqFilter(name)} - var clusterSummaries []*models.V1SpectroClusterSummary - var err error - if virtual { - clusterSummaries, err = h.SearchClusterSummaries(clusterContext, getClusterFilter(filters, virtual), nil) - } else { - clusterSummaries, err = h.SearchClusterSummaries("tenant", getClusterFilter(filters, virtual), nil) // regular clusters search is working only in tenant context. - } - if err != nil { - return nil, err - } - if len(clusterSummaries) != 1 { - return nil, fmt.Errorf("expected 1 cluster: %v in %v, got %d", name, clusterContext, len(clusterSummaries)) - } - - cluster, err := h.GetCluster(clusterSummaries[0].Metadata.Annotations["scope"], clusterSummaries[0].Metadata.UID) - if err != nil { - return nil, err - } - return cluster, nil -} - -func getApplianceFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]string, state, healthState, architecture string) *models.V1SearchFilterSpec { - filter := &models.V1SearchFilterSpec{ - Conjunction: and(), - FilterGroups: []*models.V1SearchFilterGroup{ - { - Conjunction: and(), - Filters: []*models.V1SearchFilterItem{}, - }, - }, - } - - // Tags filter - if len(tags) > 0 { - var tagValues []string - for key, value := range tags { - tagValues = append(tagValues, fmt.Sprintf("%s:%s", key, value)) - } - tagsFilter := &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: tagValues, - }, - Operator: models.V1SearchFilterStringOperatorEq, - Negation: false, - IgnoreCase: false, - }, - }, - Property: "tags", - Type: models.V1SearchFilterPropertyTypeString, - } - filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, tagsFilter) - } - - // State filter - if state != "" { - stateFilter := &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{state}, - }, - Operator: models.V1SearchFilterStringOperatorEq, - }, - }, - Property: "state", - Type: models.V1SearchFilterPropertyTypeString, - } - filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, stateFilter) - } - - // Health state filter - if healthState != "" { - healthStateFilter := &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{healthState}, - }, - Operator: models.V1SearchFilterStringOperatorEq, - }, - }, - Property: "healthState", - Type: models.V1SearchFilterPropertyTypeString, - } - filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, healthStateFilter) - } - - // Architecture filter - if architecture != "" { - architectureFilter := &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{architecture}, - }, - Operator: models.V1SearchFilterStringOperatorEq, - }, - }, - Property: "architecture", - Type: models.V1SearchFilterPropertyTypeString, - } - filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, architectureFilter) - } - - // Append extra filters if provided - if extraFilters != nil { - filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters}) - } - - return filter -} - -func applianceNameEqFilter(name string) *models.V1SearchFilterItem { - return &models.V1SearchFilterItem{ - Condition: &models.V1SearchFilterCondition{ - String: &models.V1SearchFilterStringCondition{ - Match: &models.V1SearchFilterStringConditionMatch{ - Conjunction: or(), - Values: []string{name}, - }, - Operator: models.V1SearchFilterStringOperatorEq, - Negation: false, - IgnoreCase: false, - }, - }, - Property: "name", - Type: models.V1SearchFilterPropertyTypeString, - } -} - -func (h *V1Client) GetApplianceByName(name, applianceContext string, tags map[string]string, status, health, architecture string) (*models.V1EdgeHostDevice, error) { - filters := []*models.V1SearchFilterItem{applianceNameEqFilter(name)} - applianceSummaries, err := h.SearchApplianceSummaries(applianceContext, getApplianceFilter(filters, tags, status, health, architecture), nil) - if err != nil { - return nil, err - } - if len(applianceSummaries) != 1 { - return nil, fmt.Errorf("expected 1 appliance: %v in %v, got %d", name, applianceContext, len(applianceSummaries)) - } - - appliance, err := h.GetAppliance(applianceSummaries[0].Metadata.UID) - if err != nil { - return nil, err - } - return appliance, nil -} diff --git a/client/ssh_key.go b/client/ssh_key.go index 9b4fb0b4..1bf6afae 100644 --- a/client/ssh_key.go +++ b/client/ssh_key.go @@ -1,14 +1,13 @@ package client import ( - "errors" "fmt" - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH, scope string) (string, error) { +func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH) (string, error) { sshEntity := &models.V1UserAssetSSHEntity{ Metadata: &models.V1ObjectMetaInputEntity{ Annotations: nil, @@ -18,100 +17,50 @@ func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH, scope string) (stri Spec: &models.V1UserAssetSSHSpec{PublicKey: body.Spec.PublicKey}, } - var params *userC.V1UserAssetsSSHCreateParams - switch scope { - case "project": - params = userC.NewV1UserAssetsSSHCreateParamsWithContext(h.Ctx).WithBody(sshEntity) - case "tenant": - params = userC.NewV1UserAssetsSSHCreateParams().WithBody(sshEntity) - default: - return "", errors.New("invalid scope") - } - - success, err := h.GetUserClient().V1UserAssetsSSHCreate(params) + params := clientV1.NewV1UserAssetsSSHCreateParamsWithContext(h.ctx). + WithBody(sshEntity) + resp, err := h.Client.V1UserAssetsSSHCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } -func (h *V1Client) GetSSHKeyByName(name, scope string) (*models.V1UserAssetSSH, error) { - var params *userC.V1UsersAssetsSSHGetParams - switch scope { - case "project": - params = userC.NewV1UsersAssetsSSHGetParamsWithContext(h.Ctx) - case "tenant": - params = userC.NewV1UsersAssetsSSHGetParams() - default: - return nil, errors.New("invalid scope") - } - - sshKeys, err := h.GetUserClient().V1UsersAssetsSSHGet(params) +func (h *V1Client) GetSSHKeyByName(name string) (*models.V1UserAssetSSH, error) { + params := clientV1.NewV1UsersAssetsSSHGetParamsWithContext(h.ctx) + resp, err := h.Client.V1UsersAssetsSSHGet(params) if err != nil { return nil, err } - for _, key := range sshKeys.Payload.Items { + for _, key := range resp.Payload.Items { if key.Metadata.Name == name { return key, nil } } - return nil, fmt.Errorf("project '%s' not found", name) + return nil, fmt.Errorf("ssh key '%s' not found", name) } -func (h *V1Client) GetSSHKeyByUID(uid, scope string) (*models.V1UserAssetSSH, error) { - var params *userC.V1UsersAssetSSHGetUIDParams - switch scope { - case "project": - params = userC.NewV1UsersAssetSSHGetUIDParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = userC.NewV1UsersAssetSSHGetUIDParams().WithUID(uid) - default: - return nil, errors.New("invalid scope") - } - - sshKey, err := h.GetUserClient().V1UsersAssetSSHGetUID(params) - if err != nil || sshKey == nil { +func (h *V1Client) GetSSHKeyByUID(uid string) (*models.V1UserAssetSSH, error) { + params := clientV1.NewV1UsersAssetSSHGetUIDParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1UsersAssetSSHGetUID(params) + if err != nil { return nil, err } - - return sshKey.Payload, nil + return resp.Payload, nil } -func (h *V1Client) UpdateSSHKey(uid string, body *models.V1UserAssetSSH, scope string) error { - var params *userC.V1UsersAssetSSHUpdateParams - switch scope { - case "project": - params = userC.NewV1UsersAssetSSHUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(body) - case "tenant": - params = userC.NewV1UsersAssetSSHUpdateParams().WithUID(uid).WithBody(body) - default: - return errors.New("invalid scope") - } - - _, err := h.GetUserClient().V1UsersAssetSSHUpdate(params) - if err != nil { - return err - } - - return nil +func (h *V1Client) UpdateSSHKey(uid string, body *models.V1UserAssetSSH) error { + params := clientV1.NewV1UsersAssetSSHUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1UsersAssetSSHUpdate(params) + return err } -func (h *V1Client) DeleteSSHKey(uid, scope string) error { - var params *userC.V1UsersAssetSSHDeleteParams - switch scope { - case "project": - params = userC.NewV1UsersAssetSSHDeleteParamsWithContext(h.Ctx).WithUID(uid) - case "tenant": - params = userC.NewV1UsersAssetSSHDeleteParams().WithUID(uid) - default: - return errors.New("invalid scope") - } - - _, err := h.GetUserClient().V1UsersAssetSSHDelete(params) - if err != nil { - return err - } - - return nil +func (h *V1Client) DeleteSSHKey(uid string) error { + params := clientV1.NewV1UsersAssetSSHDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1UsersAssetSSHDelete(params) + return err } diff --git a/client/team.go b/client/team.go index 679661a9..3d180fae 100644 --- a/client/team.go +++ b/client/team.go @@ -1,145 +1,128 @@ package client import ( - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) func (h *V1Client) CreateTeam(team *models.V1Team) (string, error) { - params := userC.NewV1TeamsCreateParams().WithBody(team) - success, err := h.GetUserClient().V1TeamsCreate(params) + params := clientV1.NewV1TeamsCreateParamsWithContext(h.ctx). + WithBody(team) + resp, err := h.Client.V1TeamsCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) UpdateTeam(uid string, team *models.V1Team) error { - params := userC.NewV1TeamsUIDUpdateParams().WithBody(team).WithUID(uid) - _, err := h.GetUserClient().V1TeamsUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(team) + _, err := h.Client.V1TeamsUIDUpdate(params) + return err } func (h *V1Client) GetTeam(uid string) (*models.V1Team, error) { - params := userC.NewV1TeamsUIDGetParams().WithUID(uid) - success, err := h.GetUserClient().V1TeamsUIDGet(params) + params := clientV1.NewV1TeamsUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1TeamsUIDGet(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) DeleteTeam(uid string) error { - params := userC.NewV1TeamsUIDDeleteParams().WithUID(uid) - _, err := h.GetUserClient().V1TeamsUIDDelete(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1TeamsUIDDelete(params) + return err } func (h *V1Client) AssociateTeamProjectRole(uid string, body *models.V1ProjectRolesPatch) error { - params := userC.NewV1TeamsProjectRolesPutParams().WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1TeamsProjectRolesPut(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsProjectRolesPutParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1TeamsProjectRolesPut(params) + return err } func (h *V1Client) GetTeamProjectRoleAssociation(uid string) (*models.V1ProjectRolesEntity, error) { - params := userC.NewV1TeamsProjectRolesParams().WithUID(uid) - success, err := h.GetUserClient().V1TeamsProjectRoles(params) + params := clientV1.NewV1TeamsProjectRolesParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1TeamsProjectRoles(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) AssociateTeamTenantRole(uid string, body *models.V1TeamTenantRolesUpdate) error { - params := userC.NewV1TeamsUIDTenantRolesUpdateParams().WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1TeamsUIDTenantRolesUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsUIDTenantRolesUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1TeamsUIDTenantRolesUpdate(params) + return err } func (h *V1Client) GetTeamTenantRoleAssociation(uid string) (*models.V1TeamTenantRolesEntity, error) { - params := userC.NewV1TeamsUIDTenantRolesGetParams().WithUID(uid) - success, err := h.GetUserClient().V1TeamsUIDTenantRolesGet(params) + params := clientV1.NewV1TeamsUIDTenantRolesGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1TeamsUIDTenantRolesGet(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) AssociateTeamWorkspaceRole(uid string, body *models.V1WorkspacesRolesPatch) error { - params := clusterC.NewV1TeamsWorkspaceRolesPutParams().WithTeamUID(uid).WithBody(body) - _, err := h.GetClusterClient().V1TeamsWorkspaceRolesPut(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsWorkspaceRolesPutParamsWithContext(h.ctx). + WithTeamUID(uid). + WithBody(body) + _, err := h.Client.V1TeamsWorkspaceRolesPut(params) + return err } func (h *V1Client) GetTeamWorkspaceRoleAssociation(uid string) (*models.V1WorkspaceScopeRoles, error) { - params := clusterC.NewV1TeamsWorkspaceGetRolesParams().WithTeamUID(uid) - success, err := h.GetClusterClient().V1TeamsWorkspaceGetRoles(params) + params := clientV1.NewV1TeamsWorkspaceGetRolesParamsWithContext(h.ctx). + WithTeamUID(uid) + resp, err := h.Client.V1TeamsWorkspaceGetRoles(params) if err != nil { return nil, err } - - return success.Payload, nil + return resp.Payload, nil } func (h *V1Client) AssociateTeamResourceRole(uid string, body *models.V1ResourceRolesUpdateEntity) error { - params := userC.NewV1TeamsUIDResourceRolesCreateParams().WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1TeamsUIDResourceRolesCreate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsUIDResourceRolesCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1TeamsUIDResourceRolesCreate(params) + return err } func (h *V1Client) UpdateTeamResourceRole(uid string, body *models.V1ResourceRolesUpdateEntity) error { - params := userC.NewV1TeamsResourceRolesUIDUpdateParams().WithUID(uid).WithBody(body) - _, err := h.GetUserClient().V1TeamsResourceRolesUIDUpdate(params) - if err != nil { - return err - } - - return nil + params := clientV1.NewV1TeamsResourceRolesUIDUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body) + _, err := h.Client.V1TeamsResourceRolesUIDUpdate(params) + return err } func (h *V1Client) GetTeamResourceRole(uid, name string) (*models.V1UIDSummary, error) { - params := userC.NewV1TeamsUIDResourceRolesParams().WithUID(uid) - success, err := h.GetUserClient().V1TeamsUIDResourceRoles(params) + params := clientV1.NewV1TeamsUIDResourceRolesParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1TeamsUIDResourceRoles(params) if err != nil { return nil, err } - - for _, roles := range success.Payload.ResourceRoles { + for _, roles := range resp.Payload.ResourceRoles { for _, role := range roles.Roles { if role.Name == name { return role, nil } } } - return nil, nil } diff --git a/client/tenant.go b/client/tenant.go index 177d9d20..de442201 100644 --- a/client/tenant.go +++ b/client/tenant.go @@ -1,14 +1,14 @@ package client import ( - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" ) func (h *V1Client) GetTenantUID() (string, error) { - params := userC.NewV1UsersMeGetParams() - me, err := h.GetUserClient().V1UsersMeGet(params) - if err != nil || me == nil { + params := clientV1.NewV1UsersMeGetParamsWithContext(h.ctx) + resp, err := h.Client.V1UsersMeGet(params) + if err != nil { return "", err } - return me.Payload.Status.Tenant.TenantUID, nil + return resp.Payload.Status.Tenant.TenantUID, nil } diff --git a/client/types.go b/client/types.go deleted file mode 100644 index ef3abf81..00000000 --- a/client/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package client - -func Ptr[T any](v T) *T { - return &v -} diff --git a/client/user.go b/client/user.go index 4c11823b..2bdb26e0 100644 --- a/client/user.go +++ b/client/user.go @@ -3,19 +3,19 @@ package client import ( "fmt" - "github.com/spectrocloud/hapi/models" - userC "github.com/spectrocloud/hapi/user/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) GetUsers() (*models.V1Users, error) { - limit := int64(0) - params := userC.NewV1UsersListParams().WithLimit(&limit) - users, err := h.GetUserClient().V1UsersList(params) + params := clientV1.NewV1UsersListParamsWithContext(h.ctx). + WithLimit(apiutil.Ptr(int64(0))) + resp, err := h.Client.V1UsersList(params) if err != nil { return nil, err } - - return users.Payload, nil + return resp.Payload, nil } func (h *V1Client) GetUserByName(name string) (*models.V1User, error) { @@ -23,13 +23,11 @@ func (h *V1Client) GetUserByName(name string) (*models.V1User, error) { if err != nil { return nil, err } - for _, user := range users.Items { if user.Metadata.Name == name { return user, nil } } - return nil, fmt.Errorf("user with name '%s' not found", name) } @@ -38,12 +36,10 @@ func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) { if err != nil { return nil, err } - for _, user := range users.Items { if user.Spec.EmailID == email { return user, nil } } - return nil, fmt.Errorf("user with email '%s' not found", email) } diff --git a/client/virtual_machine.go b/client/virtual_machine.go index 862c2075..2e1478de 100644 --- a/client/virtual_machine.go +++ b/client/virtual_machine.go @@ -4,47 +4,31 @@ import ( "errors" "fmt" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) CreateVirtualMachine(scope, uid string, body *models.V1ClusterVirtualMachine) (*models.V1ClusterVirtualMachine, error) { - // get cluster - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) CreateVirtualMachine(uid string, body *models.V1ClusterVirtualMachine) (*models.V1ClusterVirtualMachine, error) { + cluster, err := h.GetCluster(uid) if err != nil { return nil, err } - - // if cluster is nil(deleted or not found), return error if cluster == nil { - return nil, fmt.Errorf("cluster not found for uid %s", uid) - } - - // get cluster scope - var params *clusterC.V1SpectroClustersVMCreateParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMCreateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMCreateParams() - default: - return nil, errors.New("invalid cluster scope specified") + return nil, fmt.Errorf("cluster with uid %s not found", uid) } - - params = params.WithUID(uid).WithBody(body).WithNamespace(params.Body.Metadata.Namespace) - - vm, err := h.GetClusterClient().V1SpectroClustersVMCreate(params) + params := clientV1.NewV1SpectroClustersVMCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(body). + WithNamespace(body.Metadata.Namespace) + resp, err := h.Client.V1SpectroClustersVMCreate(params) if err != nil { return nil, err } - return vm.Payload, nil + return resp.Payload, nil } -func (h *V1Client) GetVirtualMachine(scope, uid, namespace, name string) (*models.V1ClusterVirtualMachine, error) { - if h.GetVirtualMachineFn != nil { - return h.GetVirtualMachineFn(uid) - } - vm, err := h.GetVirtualMachineWithoutStatus(scope, uid, name, namespace) +func (h *V1Client) GetVirtualMachine(uid, namespace, name string) (*models.V1ClusterVirtualMachine, error) { + vm, err := h.GetVirtualMachineWithoutStatus(uid, name, namespace) if err != nil { return nil, err } @@ -53,63 +37,41 @@ func (h *V1Client) GetVirtualMachine(scope, uid, namespace, name string) (*model func (h *V1Client) UpdateVirtualMachine(cluster *models.V1SpectroCluster, vmName string, body *models.V1ClusterVirtualMachine) (*models.V1ClusterVirtualMachine, error) { clusterUid := cluster.Metadata.UID - scope := cluster.Metadata.Annotations["scope"] - // get cluster scope - var params *clusterC.V1SpectroClustersVMUpdateParams - - // switch cluster scope - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMUpdateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMUpdateParams() - default: - return nil, errors.New("invalid cluster scope specified") - } - - params = params.WithUID(clusterUid).WithBody(body).WithNamespace(body.Metadata.Namespace).WithVMName(vmName) - - // check if vm exists, return error - exists, err := h.IsVMExists(scope, clusterUid, vmName, body.Metadata.Namespace) + params := clientV1.NewV1SpectroClustersVMUpdateParams(). + WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUid)). + WithUID(clusterUid). + WithBody(body). + WithNamespace(body.Metadata.Namespace). + WithVMName(vmName) + + // check if vm exists + exists, err := h.IsVMExists(clusterUid, vmName, body.Metadata.Namespace) if err != nil { return nil, err } if !exists { - // cannot update vm as another with same name exists - return nil, errors.New("VM not exists") + return nil, errors.New("VM does not exist") } - vm, err := h.GetClusterClient().V1SpectroClustersVMUpdate(params) + resp, err := h.Client.V1SpectroClustersVMUpdate(params) if err != nil { return nil, err } - return vm.Payload, nil - - //return nil, nil + return resp.Payload, nil } -func (h *V1Client) DeleteVirtualMachine(scope, uid, namespace, name string) error { - // get cluster - cluster, err := h.GetCluster(scope, uid) +func (h *V1Client) DeleteVirtualMachine(uid, namespace, name string) error { + cluster, err := h.GetCluster(uid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, uid) + return fmt.Errorf("cluster with uid %s not found", uid) } - - // get cluster scope - var params *clusterC.V1SpectroClustersVMDeleteParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMDeleteParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMDeleteParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(uid).WithVMName(name).WithNamespace(namespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMDelete(params) + params := clientV1.NewV1SpectroClustersVMDeleteParamsWithContext(h.ctx). + WithUID(uid). + WithVMName(name). + WithNamespace(namespace) + _, err = h.Client.V1SpectroClustersVMDelete(params) return err } diff --git a/client/virtual_machine_clone.go b/client/virtual_machine_clone.go index cd07eed1..5dcbfd6d 100644 --- a/client/virtual_machine_clone.go +++ b/client/virtual_machine_clone.go @@ -3,37 +3,25 @@ package client import ( "errors" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) CloneVirtualMachine(scope, clusterUid, cloneVMFromName, vmName, vmNamespace string) error { - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) CloneVirtualMachine(clusterUid, sourceVmName, cloneVmName, namespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { return errors.New("cluster not found") } - - body := &models.V1SpectroClusterVMCloneEntity{ - CloneName: &vmName, - } - - var params *clusterC.V1SpectroClustersVMCloneParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMCloneParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMCloneParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(cloneVMFromName).WithNamespace(vmNamespace).WithBody(body) - - _, err = h.GetClusterClient().V1SpectroClustersVMClone(params) - if err != nil { - return err - } - return nil + params := clientV1.NewV1SpectroClustersVMCloneParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(sourceVmName). + WithNamespace(namespace). + WithBody(&models.V1SpectroClusterVMCloneEntity{ + CloneName: &cloneVmName, + }) + _, err = h.Client.V1SpectroClustersVMClone(params) + return err } diff --git a/client/virtual_machine_common.go b/client/virtual_machine_common.go index 128ad89d..d19846a3 100644 --- a/client/virtual_machine_common.go +++ b/client/virtual_machine_common.go @@ -1,15 +1,12 @@ package client import ( - "errors" - "fmt" - - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) -func (h *V1Client) IsVMExists(scope, clusterUid, vmName, vmNamespace string) (bool, error) { - vm, err := h.GetVirtualMachine(scope, clusterUid, vmNamespace, vmName) +func (h *V1Client) IsVMExists(clusterUid, name, namespace string) (bool, error) { + vm, err := h.GetVirtualMachine(clusterUid, namespace, name) if err != nil { return false, err } @@ -19,44 +16,25 @@ func (h *V1Client) IsVMExists(scope, clusterUid, vmName, vmNamespace string) (bo return false, nil } -func (h *V1Client) GetVirtualMachineWithoutStatus(scope, uid, name, namespace string) (*models.V1ClusterVirtualMachine, error) { - if h.GetVirtualMachineWithoutStatusFn != nil { - return h.GetVirtualMachineWithoutStatusFn(uid) - } - - var params *clusterC.V1SpectroClustersVMGetParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMGetParamsWithContext(h.Ctx).WithUID(uid).WithVMName(name).WithNamespace(namespace) - case "tenant": - params = clusterC.NewV1SpectroClustersVMGetParams().WithUID(uid).WithVMName(name).WithNamespace(namespace) - default: - return nil, fmt.Errorf("invalid scope %s", scope) - } - - success, err := h.GetClusterClient().V1SpectroClustersVMGet(params) +func (h *V1Client) GetVirtualMachineWithoutStatus(uid, name, namespace string) (*models.V1ClusterVirtualMachine, error) { + params := clientV1.NewV1SpectroClustersVMGetParamsWithContext(h.ctx). + WithUID(uid). + WithVMName(name). + WithNamespace(namespace) + resp, err := h.Client.V1SpectroClustersVMGet(params) if err != nil { return nil, err } - - vm := success.Payload - return vm, nil + return resp.Payload, nil } func (h *V1Client) GetVirtualMachines(cluster *models.V1SpectroCluster) ([]*models.V1ClusterVirtualMachine, error) { - var params *clusterC.V1SpectroClustersVMListParams - switch cluster.Metadata.Annotations["scope"] { - case "project": - params = clusterC.NewV1SpectroClustersVMListParamsWithContext(h.Ctx).WithUID(cluster.Metadata.UID) - case "tenant": - params = clusterC.NewV1SpectroClustersVMListParams().WithUID(cluster.Metadata.UID) - default: - return nil, errors.New("invalid cluster scope specified") - } - - vms, err := h.GetClusterClient().V1SpectroClustersVMList(params) + params := clientV1.NewV1SpectroClustersVMListParams(). + WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUid)). + WithUID(cluster.Metadata.UID) + resp, err := h.Client.V1SpectroClustersVMList(params) if err != nil { return nil, err } - return vms.Payload.Items, nil + return resp.Payload.Items, nil } diff --git a/client/virtual_machine_lifecycle.go b/client/virtual_machine_lifecycle.go index 74249c0a..1b04ece0 100644 --- a/client/virtual_machine_lifecycle.go +++ b/client/virtual_machine_lifecycle.go @@ -1,149 +1,87 @@ package client import ( - "errors" "fmt" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" ) -func (h *V1Client) StartVirtualMachine(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) StartVirtualMachine(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) - } - - // get cluster scope - var params *clusterC.V1SpectroClustersVMStartParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMStartParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMStartParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMStart(params) - if err != nil { - return err - } - return nil + return fmt.Errorf("cluster with uid %s not found", clusterUid) + } + params := clientV1.NewV1SpectroClustersVMStartParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMStart(params) + return err } -func (h *V1Client) StopVirtualMachine(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) StopVirtualMachine(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) - } - - var params *clusterC.V1SpectroClustersVMStopParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMStopParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMStopParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMStop(params) - if err != nil { - return err - } - return nil + return fmt.Errorf("cluster with uid %s not found", clusterUid) + } + params := clientV1.NewV1SpectroClustersVMStopParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMStop(params) + return err } -func (h *V1Client) PauseVirtualMachine(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) PauseVirtualMachine(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) - } - - var params *clusterC.V1SpectroClustersVMPauseParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMPauseParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMPauseParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMPause(params) - if err != nil { - return err - } - return nil + return fmt.Errorf("cluster with uid %s not found", clusterUid) + } + params := clientV1.NewV1SpectroClustersVMPauseParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMPause(params) + return err } -func (h *V1Client) ResumeVirtualMachine(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) ResumeVirtualMachine(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) - } - - var params *clusterC.V1SpectroClustersVMResumeParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMResumeParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMResumeParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMResume(params) - if err != nil { - return err - } - return nil + return fmt.Errorf("cluster with uid %s not found", clusterUid) + } + params := clientV1.NewV1SpectroClustersVMResumeParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMResume(params) + return err } -func (h *V1Client) RestartVirtualMachine(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) RestartVirtualMachine(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) - } - - var params *clusterC.V1SpectroClustersVMRestartParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMRestartParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMRestartParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMRestart(params) - if err != nil { - return err - } - return nil + return fmt.Errorf("cluster with uid %s not found", clusterUid) + } + params := clientV1.NewV1SpectroClustersVMRestartParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMRestart(params) + return err } diff --git a/client/virtual_machine_migration.go b/client/virtual_machine_migration.go index 39de0d99..9dc95484 100644 --- a/client/virtual_machine_migration.go +++ b/client/virtual_machine_migration.go @@ -1,36 +1,23 @@ package client import ( - "errors" "fmt" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" ) -func (h *V1Client) MigrateVirtualMachineNodeToNode(scope, clusterUid, vmName, vmNamespace string) error { - // get cluster - cluster, err := h.GetCluster(scope, clusterUid) +func (h *V1Client) MigrateVirtualMachineNodeToNode(clusterUid, vmName, vmNamespace string) error { + cluster, err := h.GetCluster(clusterUid) if err != nil { return err } if cluster == nil { - return fmt.Errorf("cluster not found for scope %s and uid %s", scope, clusterUid) + return fmt.Errorf("cluster with uid %s not found", clusterUid) } - - var params *clusterC.V1SpectroClustersVMMigrateParams - switch scope { - case "project": - params = clusterC.NewV1SpectroClustersVMMigrateParamsWithContext(h.Ctx) - case "tenant": - params = clusterC.NewV1SpectroClustersVMMigrateParams() - default: - return errors.New("invalid cluster scope specified") - } - params = params.WithUID(clusterUid).WithVMName(vmName).WithNamespace(vmNamespace) - - _, err = h.GetClusterClient().V1SpectroClustersVMMigrate(params) - if err != nil { - return err - } - return nil + params := clientV1.NewV1SpectroClustersVMMigrateParamsWithContext(h.ctx). + WithUID(clusterUid). + WithVMName(vmName). + WithNamespace(vmNamespace) + _, err = h.Client.V1SpectroClustersVMMigrate(params) + return err } diff --git a/client/virtual_machine_snapshot.go b/client/virtual_machine_snapshot.go deleted file mode 100644 index da13c8ef..00000000 --- a/client/virtual_machine_snapshot.go +++ /dev/null @@ -1 +0,0 @@ -package client diff --git a/client/workspace.go b/client/workspace.go index d61a9601..4c1fa6bb 100644 --- a/client/workspace.go +++ b/client/workspace.go @@ -3,99 +3,85 @@ package client import ( "errors" - "github.com/spectrocloud/hapi/apiutil/transport" - hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" - "github.com/spectrocloud/hapi/models" - clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" + "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) func (h *V1Client) CreateWorkspace(workspace *models.V1WorkspaceEntity) (string, error) { - params := clusterC.NewV1WorkspacesCreateParamsWithContext(h.Ctx).WithBody(workspace) - success, err := h.GetClusterClient().V1WorkspacesCreate(params) + params := clientV1.NewV1WorkspacesCreateParamsWithContext(h.ctx). + WithBody(workspace) + resp, err := h.Client.V1WorkspacesCreate(params) if err != nil { return "", err } - - return *success.Payload.UID, nil + return *resp.Payload.UID, nil } func (h *V1Client) GetWorkspace(uid string) (*models.V1Workspace, error) { - params := clusterC.NewV1WorkspacesUIDGetParamsWithContext(h.Ctx).WithUID(uid) - success, err := h.GetClusterClient().V1WorkspacesUIDGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1WorkspacesUIDGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1WorkspacesUIDGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - workspace := success.Payload - - return workspace, nil + return resp.Payload, nil } func (h *V1Client) GetWorkspaceByName(name string) (*models.V1DashboardWorkspace, error) { - params := hashboardC.NewV1DashboardWorkspacesListParamsWithContext(h.Ctx) - success, err := h.GetHashboardClient().V1DashboardWorkspacesList(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1DashboardWorkspacesListParamsWithContext(h.ctx) + resp, err := h.Client.V1DashboardWorkspacesList(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - for _, workspace := range success.Payload.Items { + for _, workspace := range resp.Payload.Items { if workspace.Metadata.Name == name { return workspace, nil } } - return nil, nil } -func (h *V1Client) UpdateWorkspaceResourceAllocation(uid string, wo *models.V1WorkspaceResourceAllocationsEntity) error { - params := clusterC.NewV1WorkspacesUIDResourceAllocationsUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(wo) - if _, err := h.GetClusterClient().V1WorkspacesUIDResourceAllocationsUpdate(params); err != nil { - return err - } - return nil +func (h *V1Client) UpdateWorkspaceResourceAllocation(uid string, we *models.V1WorkspaceClusterNamespacesEntity) error { + params := clientV1.NewV1WorkspacesUIDClusterNamespacesUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(we) + _, err := h.Client.V1WorkspacesUIDClusterNamespacesUpdate(params) + return err } -func (h *V1Client) UpdateWorkspaceRBACS(uid, rbac_uid string, wo *models.V1ClusterRbac) error { - params := clusterC.NewV1WorkspacesUIDClusterRbacUpdateParamsWithContext(h.Ctx).WithUID(uid).WithClusterRbacUID(rbac_uid).WithBody(wo) - if _, err := h.GetClusterClient().V1WorkspacesUIDClusterRbacUpdate(params); err != nil { - return err - } - return nil +func (h *V1Client) UpdateWorkspaceRBACS(uid, rbacUid string, r *models.V1ClusterRbac) error { + params := clientV1.NewV1WorkspacesUIDClusterRbacUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithClusterRbacUID(rbacUid). + WithBody(r) + _, err := h.Client.V1WorkspacesUIDClusterRbacUpdate(params) + return err } func (h *V1Client) UpdateWorkspaceBackupConfig(uid string, config *models.V1WorkspaceBackupConfigEntity) error { - params := clusterC.NewV1WorkspaceOpsBackupUpdateParams().WithContext(h.Ctx).WithUID(uid).WithBody(config) - _, err := h.GetClusterClient().V1WorkspaceOpsBackupUpdate(params) + params := clientV1.NewV1WorkspaceOpsBackupUpdateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1WorkspaceOpsBackupUpdate(params) return err } func (h *V1Client) DeleteWorkspace(uid string) error { - params := clusterC.NewV1WorkspacesUIDDeleteParamsWithContext(h.Ctx).WithUID(uid) - if _, err := h.GetClusterClient().V1WorkspacesUIDDelete(params); err != nil { - return err - } - return nil + params := clientV1.NewV1WorkspacesUIDDeleteParamsWithContext(h.ctx). + WithUID(uid) + _, err := h.Client.V1WorkspacesUIDDelete(params) + return err } func (h *V1Client) GetWorkspaceBackup(uid string) (*models.V1WorkspaceBackup, error) { - params := clusterC.NewV1WorkspaceOpsBackupGetParams().WithContext(h.Ctx).WithUID(uid) - success, err := h.GetClusterClient().V1WorkspaceOpsBackupGet(params) - var e *transport.TransportError - if errors.As(err, &e) && e.HttpCode == 404 { - return nil, nil - } else if err != nil { + params := clientV1.NewV1WorkspaceOpsBackupGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1WorkspaceOpsBackupGet(params) + if err := apiutil.Handle404(err); err != nil { return nil, err } - - workspace := success.Payload - - return workspace, nil + return resp.Payload, nil } func (h *V1Client) WorkspaceBackupDelete() error { diff --git a/go.mod b/go.mod index a48a95e3..fb9797bb 100644 --- a/go.mod +++ b/go.mod @@ -5,39 +5,39 @@ go 1.21 toolchain go1.21.1 require ( - github.com/go-openapi/runtime v0.19.26 - github.com/go-openapi/strfmt v0.21.3 + github.com/go-openapi/runtime v0.26.0 + github.com/go-openapi/strfmt v0.21.7 github.com/pkg/errors v0.9.1 - github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d + github.com/spectrocloud/palette-api-go v0.2.3 github.com/stretchr/testify v1.8.4 ) require ( - github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-errors/errors v1.4.2 // indirect + github.com/go-errors/errors v1.5.1 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/analysis v0.21.4 // indirect - github.com/go-openapi/errors v0.20.2 // indirect - github.com/go-openapi/jsonpointer v0.19.6 // indirect - github.com/go-openapi/jsonreference v0.20.1 // indirect + github.com/go-openapi/errors v0.20.4 // indirect + github.com/go-openapi/jsonpointer v0.20.0 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/loads v0.21.2 // indirect - github.com/go-openapi/spec v0.20.6 // indirect - github.com/go-openapi/swag v0.22.3 // indirect - github.com/go-openapi/validate v0.20.2 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/go-openapi/spec v0.20.9 // indirect + github.com/go-openapi/swag v0.22.4 // indirect + github.com/go-openapi/validate v0.22.1 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/kr/pretty v0.3.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368 // indirect - go.mongodb.org/mongo-driver v1.10.0 // indirect - golang.org/x/sys v0.13.0 // indirect + go.mongodb.org/mongo-driver v1.12.1 // indirect + go.opentelemetry.io/otel v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.18.0 // indirect + golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -//replace github.com/spectrocloud/hapi => ../hapi diff --git a/go.sum b/go.sum index 2a86dde9..8d71c13d 100644 --- a/go.sum +++ b/go.sum @@ -1,129 +1,59 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= -github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= -github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= -github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= -github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= -github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= -github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= -github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk= -github.com/go-openapi/analysis v0.19.4/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk= -github.com/go-openapi/analysis v0.19.5/go.mod h1:hkEAkxagaIvIP7VTn8ygJNkd4kAYON2rCu0v0ObL0AU= -github.com/go-openapi/analysis v0.19.10/go.mod h1:qmhS3VNFxBlquFJ0RGoDtylO9y4pgTAUNE9AEEMdlJQ= -github.com/go-openapi/analysis v0.19.16/go.mod h1:GLInF007N83Ad3m8a/CbQ5TPzdnGT7workfHwuVjNVk= -github.com/go-openapi/analysis v0.20.0/go.mod h1:BMchjvaHDykmRMsK40iPtvyOfFdMMxlOmQr9FBZk+Og= +github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= +github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-openapi/analysis v0.21.2/go.mod h1:HZwRk4RRisyG8vx2Oe6aqeSQcoxRp47Xkp3+K6q+LdY= github.com/go-openapi/analysis v0.21.4 h1:ZDFLvSNxpDaomuCueM0BlSXxpANBlFYiBvr+GXrvIHc= github.com/go-openapi/analysis v0.21.4/go.mod h1:4zQ35W4neeZTqh3ol0rv/O8JBbka9QyAgQRPp9y3pfo= -github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= -github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= -github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= -github.com/go-openapi/errors v0.19.3/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= -github.com/go-openapi/errors v0.19.6/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.19.7/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.20.2 h1:dxy7PGTqEh94zj2E3h1cUmQQWiM1+aeCROfAr02EmK8= github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= +github.com/go-openapi/errors v0.20.4 h1:unTcVm6PispJsMECE3zWgvG4xTiKda1LIR5rCRWLG6M= +github.com/go-openapi/errors v0.20.4/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= -github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= -github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= +github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= +github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= -github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8= -github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.19.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.19.2/go.mod h1:QAskZPMX5V0C2gvfkGZzJlINuP7Hx/4+ix5jWFxsNPs= -github.com/go-openapi/loads v0.19.3/go.mod h1:YVfqhUCdahYwR3f3iiwQLhicVRvLlU/WO5WPaZvcvSI= -github.com/go-openapi/loads v0.19.5/go.mod h1:dswLCAdonkRufe/gSUC3gN8nTSaB9uaS2es0x5/IbjY= -github.com/go-openapi/loads v0.19.6/go.mod h1:brCsvE6j8mnbmGBh103PT/QLHfbyDxA4hsKvYBNEGVc= -github.com/go-openapi/loads v0.19.7/go.mod h1:brCsvE6j8mnbmGBh103PT/QLHfbyDxA4hsKvYBNEGVc= -github.com/go-openapi/loads v0.20.0/go.mod h1:2LhKquiE513rN5xC6Aan6lYOSddlL8Mp20AW9kpviM4= -github.com/go-openapi/loads v0.20.2/go.mod h1:hTVUotJ+UonAMMZsvakEgmWKgtulweO9vYP2bQYKA/o= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/loads v0.21.1/go.mod h1:/DtAMXXneXFjbQMGEtbamCZb+4x7eGwkvZCvBmwUG+g= github.com/go-openapi/loads v0.21.2 h1:r2a/xFIYeZ4Qd2TnGpWDIQNcP80dIaZgf704za8enro= github.com/go-openapi/loads v0.21.2/go.mod h1:Jq58Os6SSGz0rzh62ptiu8Z31I+OTHqmULx5e/gJbNw= -github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA= -github.com/go-openapi/runtime v0.19.0/go.mod h1:OwNfisksmmaZse4+gpV3Ne9AyMOlP1lt4sK4FXt0O64= -github.com/go-openapi/runtime v0.19.4/go.mod h1:X277bwSUBxVlCYR3r7xgZZGKVvBd/29gLDlFGtJ8NL4= -github.com/go-openapi/runtime v0.19.15/go.mod h1:dhGWCTKRXlAfGnQG0ONViOZpjfg0m2gUt9nTQPQZuoo= -github.com/go-openapi/runtime v0.19.16/go.mod h1:5P9104EJgYcizotuXhEuUrzVc+j1RiSjahULvYmlv98= -github.com/go-openapi/runtime v0.19.24/go.mod h1:Lm9YGCeecBnUUkFTxPC4s1+lwrkJ0pthx8YvyjCfkgk= -github.com/go-openapi/runtime v0.19.26 h1:K/6PoVNj5WJXUnMk+VEbELeXjtBkCS1UxTDa04tdXE0= -github.com/go-openapi/runtime v0.19.26/go.mod h1:BvrQtn6iVb2QmiVXRsFAm6ZCAZBpbVKFfN6QWCp582M= -github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= -github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= -github.com/go-openapi/spec v0.19.6/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= -github.com/go-openapi/spec v0.19.8/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= -github.com/go-openapi/spec v0.19.15/go.mod h1:+81FIL1JwC5P3/Iuuozq3pPE9dXdIEGxFutcFKaVbmU= -github.com/go-openapi/spec v0.20.0/go.mod h1:+81FIL1JwC5P3/Iuuozq3pPE9dXdIEGxFutcFKaVbmU= -github.com/go-openapi/spec v0.20.1/go.mod h1:93x7oh+d+FQsmsieroS4cmR3u0p/ywH649a3qwC9OsQ= -github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg= -github.com/go-openapi/spec v0.20.6 h1:ich1RQ3WDbfoeTqTAb+5EIxNmpKVJZWBNah9RAT0jIQ= +github.com/go-openapi/runtime v0.26.0 h1:HYOFtG00FM1UvqrcxbEJg/SwvDRvYLQKGhw2zaQjTcc= +github.com/go-openapi/runtime v0.26.0/go.mod h1:QgRGeZwrUcSHdeh4Ka9Glvo0ug1LC5WyE+EV88plZrQ= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= -github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= -github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= -github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY= -github.com/go-openapi/strfmt v0.19.2/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6+bY1AVL9LU= -github.com/go-openapi/strfmt v0.19.3/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6+bY1AVL9LU= -github.com/go-openapi/strfmt v0.19.4/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk= -github.com/go-openapi/strfmt v0.19.5/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk= -github.com/go-openapi/strfmt v0.19.11/go.mod h1:UukAYgTaQfqJuAFlNxxMWNvMYiwiXtLsF2VwmoFtbtc= -github.com/go-openapi/strfmt v0.20.0/go.mod h1:UukAYgTaQfqJuAFlNxxMWNvMYiwiXtLsF2VwmoFtbtc= -github.com/go-openapi/strfmt v0.21.3 h1:xwhj5X6CjXEZZHMWy1zKJxvW9AfHC9pkyUjLvHtKG7o= +github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= +github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+WaRADcS5iNg= +github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg= -github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/strfmt v0.21.7 h1:rspiXgNWgeUzhjo1YU01do6qsahtJNByjLVbPLNHb8k= +github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.7/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= -github.com/go-openapi/swag v0.19.9/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= -github.com/go-openapi/swag v0.19.12/go.mod h1:eFdyEBkTdoAf/9RXBvj4cr1nH7GD8Kzo5HTt47gr72M= -github.com/go-openapi/swag v0.19.13/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= -github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= -github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7vS9k0lo6zwJo= -github.com/go-openapi/validate v0.19.10/go.mod h1:RKEZTUWDkxKQxN2jDT7ZnZi2bhZlbNMAuKvKB+IaGx8= -github.com/go-openapi/validate v0.19.12/go.mod h1:Rzou8hA/CBw8donlS6WNEUQupNvUZ0waH08tGe6kAQ4= -github.com/go-openapi/validate v0.19.15/go.mod h1:tbn/fdOwYHgrhPBzidZfJC2MIVvs9GA7monOmWBbeCI= -github.com/go-openapi/validate v0.20.1/go.mod h1:b60iJT+xNNLfaQJUqLI7946tYiFEOuE9E4k54HpKcJ0= -github.com/go-openapi/validate v0.20.2 h1:AhqDegYV3J3iQkMPJSXkvzymHKMTw0BST3RK3hTT4ts= -github.com/go-openapi/validate v0.20.2/go.mod h1:e7OJoKNgd0twXZwIn0A43tHbvIcr/rZIVCbJBpTUoY0= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU= +github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= @@ -150,25 +80,18 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -177,24 +100,17 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= @@ -204,10 +120,7 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -217,28 +130,23 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368 h1:eY0BOyEbGuNZcLtILVQrh7D7oEu+UezpLkuCzlK6Ae4= -github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368/go.mod h1:LlZ9We4kDaELYi7Is0SVmnySuDhwphJLS6ZT4wXxFIk= -github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d h1:OMRbHxMJ1a+G1BYzvUYuMM0wLkYJPdnEOFx16faQ/UY= -github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d/go.mod h1:MktpRPnSXDTHsQrFSD+daJFQ1zMLSR+1gWOL31jVvWE= +github.com/spectrocloud/palette-api-go v0.2.3 h1:U2SikdUA9iGo1N/OkpnO61T2Dxlz70yfur1YFiLDZb8= +github.com/spectrocloud/palette-api-go v0.2.3/go.mod h1:9ebu529ThhudXje/65A2kjdngBN0sf1ei/DDrXgYPQM= 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= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -246,86 +154,82 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= -github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= -github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= -go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= -go.mongodb.org/mongo-driver v1.3.0/go.mod h1:MSWZXKOynuguX+JSvwP8i+58jYCXxbia8HS3gZBapIE= -go.mongodb.org/mongo-driver v1.3.4/go.mod h1:MSWZXKOynuguX+JSvwP8i+58jYCXxbia8HS3gZBapIE= -go.mongodb.org/mongo-driver v1.4.3/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= -go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= -go.mongodb.org/mongo-driver v1.4.6/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= -go.mongodb.org/mongo-driver v1.10.0 h1:UtV6N5k14upNp4LTduX0QCufG124fSu25Wz9tu94GLg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= +go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= +go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= +go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= +go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs= +go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI= +go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ= +go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k= +go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= +go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= +go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10= +go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= -golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -333,11 +237,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 97baf124a9aba460c5ccc88f9e0a6852fa262565 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Tue, 2 Apr 2024 17:51:21 -0600 Subject: [PATCH 02/15] feat: export, bulk delete cps (#96) Signed-off-by: Tyler Gillson --- client/cluster_profile.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/cluster_profile.go b/client/cluster_profile.go index a99383c5..e5cbbc2b 100644 --- a/client/cluster_profile.go +++ b/client/cluster_profile.go @@ -1,7 +1,9 @@ package client import ( + "bytes" "fmt" + "io" "os" clientV1 "github.com/spectrocloud/palette-api-go/client/v1" @@ -203,3 +205,25 @@ func (h *V1Client) UpdateProfileVariables(variables *models.V1Variables, uid str _, err := h.Client.V1ClusterProfilesUIDVariablesPut(params) return err } + +func (h *V1Client) ExportClusterProfile(uid, format string) (bytes.Buffer, error) { + var buf bytes.Buffer + writer := io.Writer(&buf) + params := clientV1.NewV1ClusterProfilesUIDExportParamsWithContext(h.ctx). + WithUID(uid). + WithFormat(&format) + _, err := h.Client.V1ClusterProfilesUIDExport(params, writer) + return buf, err +} + +func (h *V1Client) BulkDeleteClusterProfiles(uids []string) (*models.V1BulkDeleteResponse, error) { + params := clientV1.NewV1ClusterProfilesBulkDeleteParamsWithContext(h.ctx). + WithBody(&models.V1BulkDeleteRequest{ + Uids: uids, + }) + resp, err := h.Client.V1ClusterProfilesBulkDelete(params) + if err != nil { + return nil, err + } + return resp.GetPayload(), nil +} From bc3a3e36b51664227e2f0e64f412f3ead5058be7 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 3 Apr 2024 14:55:53 -0600 Subject: [PATCH 03/15] fix: document & handle all APIs w/o project scope (#97) Signed-off-by: Tyler Gillson --- client/api_key.go | 4 ++++ client/cluster_edge_native.go | 9 +++++++-- client/filter.go | 18 +++++++++++++----- client/project.go | 18 +++++++++++++----- client/role.go | 6 +++++- client/team.go | 15 +++++++++++---- client/user.go | 6 +++++- 7 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 client/api_key.go diff --git a/client/api_key.go b/client/api_key.go new file mode 100644 index 00000000..5aac8829 --- /dev/null +++ b/client/api_key.go @@ -0,0 +1,4 @@ +package client + +// CRUDL operations on API keys are all tenant scoped. +// See: hubble/services/service/user/internal/service/apikey/apikey_acl.go diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index 4a5ee6d1..1f51502f 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -8,8 +8,12 @@ import ( "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CRUDL operations on edge registration tokens are all tenant scoped. +// See: hubble/services/svccore/perms/edgetoken_acl.go + func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { - params := clientV1.NewV1EdgeTokensListParamsWithContext(h.ctx) + // ACL scoped to tenant only + params := clientV1.NewV1EdgeTokensListParams() resp, err := h.Client.V1EdgeTokensList(params) if err != nil { return "", err @@ -27,7 +31,8 @@ func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { } func (h *V1Client) CreateRegistrationToken(tokenName string, body *models.V1EdgeTokenEntity) (string, error) { - params := clientV1.NewV1EdgeTokensCreateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1EdgeTokensCreateParams(). WithBody(body) _, err := h.Client.V1EdgeTokensCreate(params) if err != nil { diff --git a/client/filter.go b/client/filter.go index ca1bffec..5f8dd69a 100644 --- a/client/filter.go +++ b/client/filter.go @@ -8,8 +8,12 @@ import ( "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CRUDL operations on tag filters are all tenant scoped. +// See: hubble/services/svccore/perms/filter_acl.go + func (h *V1Client) CreateTagFilter(body *models.V1TagFilter) (*models.V1UID, error) { - params := clientV1.NewV1TagFiltersCreateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TagFiltersCreateParams(). WithBody(body) resp, err := h.Client.V1TagFiltersCreate(params) if err != nil { @@ -19,7 +23,8 @@ func (h *V1Client) CreateTagFilter(body *models.V1TagFilter) (*models.V1UID, err } func (h *V1Client) UpdateTagFilter(uid string, body *models.V1TagFilter) error { - params := clientV1.NewV1TagFilterUIDUpdateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TagFilterUIDUpdateParams(). WithUID(uid). WithBody(body) _, err := h.Client.V1TagFilterUIDUpdate(params) @@ -27,7 +32,8 @@ func (h *V1Client) UpdateTagFilter(uid string, body *models.V1TagFilter) error { } func (h *V1Client) GetTagFilter(uid string) (*models.V1TagFilterSummary, error) { - params := clientV1.NewV1TagFilterUIDGetParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TagFilterUIDGetParams(). WithUID(uid) resp, err := h.Client.V1TagFilterUIDGet(params) if err != nil { @@ -37,7 +43,8 @@ func (h *V1Client) GetTagFilter(uid string) (*models.V1TagFilterSummary, error) } func (h *V1Client) ListTagFilters() (*models.V1FiltersSummary, error) { - params := clientV1.NewV1FiltersListParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1FiltersListParams(). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1FiltersList(params) if err != nil { @@ -60,7 +67,8 @@ func (h *V1Client) GetTagFilterByName(name string) (*models.V1FilterSummary, err } func (h *V1Client) DeleteTag(uid string) error { - params := clientV1.NewV1TagFilterUIDDeleteParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TagFilterUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1TagFilterUIDDelete(params) return err diff --git a/client/project.go b/client/project.go index 67bd4ab7..86a12ff6 100644 --- a/client/project.go +++ b/client/project.go @@ -7,8 +7,12 @@ import ( "github.com/spectrocloud/palette-api-go/models" ) +// CRUDL operations on projects are all tenant scoped. +// See: hubble/services/svccore/perms/user_acl.go + func (h *V1Client) CreateProject(body *models.V1ProjectEntity) (string, error) { - params := clientV1.NewV1ProjectsCreateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1ProjectsCreateParams(). WithBody(body) resp, err := h.Client.V1ProjectsCreate(params) if err != nil { @@ -33,7 +37,8 @@ func (h *V1Client) GetProjectUID(projectName string) (string, error) { } func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) { - params := clientV1.NewV1ProjectsUIDGetParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1ProjectsUIDGetParams(). WithUID(uid) resp, err := h.Client.V1ProjectsUIDGet(params) if err != nil { @@ -43,7 +48,8 @@ func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) { } func (h *V1Client) GetProjects() (*models.V1ProjectsMetadata, error) { - params := clientV1.NewV1ProjectsMetadataParamsWithContext(h.ctx) + // ACL scoped to tenant only + params := clientV1.NewV1ProjectsMetadataParams() resp, err := h.Client.V1ProjectsMetadata(params) if err != nil { return nil, err @@ -52,7 +58,8 @@ func (h *V1Client) GetProjects() (*models.V1ProjectsMetadata, error) { } func (h *V1Client) UpdateProject(uid string, body *models.V1ProjectEntity) error { - params := clientV1.NewV1ProjectsUIDUpdateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1ProjectsUIDUpdateParams(). WithUID(uid). WithBody(body) _, err := h.Client.V1ProjectsUIDUpdate(params) @@ -60,7 +67,8 @@ func (h *V1Client) UpdateProject(uid string, body *models.V1ProjectEntity) error } func (h *V1Client) DeleteProject(uid string) error { - params := clientV1.NewV1ProjectsUIDDeleteParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1ProjectsUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1ProjectsUIDDelete(params) return err diff --git a/client/role.go b/client/role.go index 43a97ecf..d22d8914 100644 --- a/client/role.go +++ b/client/role.go @@ -7,8 +7,12 @@ import ( "github.com/spectrocloud/palette-api-go/models" ) +// CRUDL operations on roles are all tenant scoped. +// See: hubble/services/service/user/internal/service/role/role_acl.go + func (h *V1Client) GetRole(roleName string) (*models.V1Role, error) { - params := clientV1.NewV1RolesListParamsWithContext(h.ctx) + // ACL scoped to tenant only + params := clientV1.NewV1RolesListParams() resp, err := h.Client.V1RolesList(params) if err != nil { return nil, err diff --git a/client/team.go b/client/team.go index 3d180fae..c41a028b 100644 --- a/client/team.go +++ b/client/team.go @@ -5,8 +5,12 @@ import ( "github.com/spectrocloud/palette-api-go/models" ) +// CRUDL operations on teams are all tenant scoped. +// See: hubble/services/svccore/perms/user_acl.go + func (h *V1Client) CreateTeam(team *models.V1Team) (string, error) { - params := clientV1.NewV1TeamsCreateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TeamsCreateParams(). WithBody(team) resp, err := h.Client.V1TeamsCreate(params) if err != nil { @@ -16,7 +20,8 @@ func (h *V1Client) CreateTeam(team *models.V1Team) (string, error) { } func (h *V1Client) UpdateTeam(uid string, team *models.V1Team) error { - params := clientV1.NewV1TeamsUIDUpdateParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TeamsUIDUpdateParams(). WithUID(uid). WithBody(team) _, err := h.Client.V1TeamsUIDUpdate(params) @@ -24,7 +29,8 @@ func (h *V1Client) UpdateTeam(uid string, team *models.V1Team) error { } func (h *V1Client) GetTeam(uid string) (*models.V1Team, error) { - params := clientV1.NewV1TeamsUIDGetParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TeamsUIDGetParams(). WithUID(uid) resp, err := h.Client.V1TeamsUIDGet(params) if err != nil { @@ -34,7 +40,8 @@ func (h *V1Client) GetTeam(uid string) (*models.V1Team, error) { } func (h *V1Client) DeleteTeam(uid string) error { - params := clientV1.NewV1TeamsUIDDeleteParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1TeamsUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1TeamsUIDDelete(params) return err diff --git a/client/user.go b/client/user.go index 2bdb26e0..49f342b7 100644 --- a/client/user.go +++ b/client/user.go @@ -8,8 +8,12 @@ import ( "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CRUDL operations on users are all tenant scoped. +// See: hubble/services/svccore/perms/user_acl.go + func (h *V1Client) GetUsers() (*models.V1Users, error) { - params := clientV1.NewV1UsersListParamsWithContext(h.ctx). + // ACL scoped to tenant only + params := clientV1.NewV1UsersListParams(). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1UsersList(params) if err != nil { From 7f3b75ec5467a45dcf3c115fe93cf80ed375f4a3 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Thu, 4 Apr 2024 14:06:21 -0600 Subject: [PATCH 04/15] fix: nil pointer dereference in GetCluster (#98) Signed-off-by: Tyler Gillson --- client/cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cluster.go b/client/cluster.go index 235f9872..0a41f18d 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -38,7 +38,7 @@ func (h *V1Client) GetCluster(uid string) (*models.V1SpectroCluster, error) { if err != nil { return nil, err } - if cluster == nil || cluster.Status.State == "Deleted" { + if cluster == nil || cluster.Status == nil || cluster.Status.State == "Deleted" { return nil, nil } return cluster, nil From bcf980d42e9c8424b162099928b7750a3a27719f Mon Sep 17 00:00:00 2001 From: Pavithra Pandiyan <138559457+pavithrapgithub@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:38:31 +0530 Subject: [PATCH 05/15] Code for PLT-1137 (#99) * BackupOnDemandCreate API * backup delete API * delete cluster backup * adding restore API * Api Name change * remove print statements * Addressed review comments --- client/cluster_backup_config.go | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/client/cluster_backup_config.go b/client/cluster_backup_config.go index 0ab8104a..0d76d695 100644 --- a/client/cluster_backup_config.go +++ b/client/cluster_backup_config.go @@ -45,3 +45,44 @@ func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1Cluster } return h.UpdateClusterBackupConfig(uid, config) } + +func (h *V1Client) CreateClusterBackupConfigOnDemand(uid string, config *models.V1ClusterBackupConfig) (*models.V1UID, error) { + params := clientV1.NewV1ClusterFeatureBackupOnDemandCreateParamsWithContext(h.ctx). + WithBody(config). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureBackupOnDemandCreate(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + +func (h *V1Client) DeleteClusterBackupConfigOnDemand(uid string, config *models.V1ClusterBackupConfig) error { + params := clientV1.NewV1ClusterFeatureBackupDeleteParamsWithContext(h.ctx). + WithUID(uid). + WithRequestUID(config.BackupLocationUID). + WithBackupName(config.BackupName) + _, err := h.Client.V1ClusterFeatureBackupDelete(params) + return err +} + +func (h *V1Client) CreateClusterRestoreConfigOnDemand(uid string, config *models.V1ClusterRestoreConfig) (*models.V1UID, error) { + params := clientV1.NewV1ClusterFeatureRestoreOnDemandCreateParamsWithContext(h.ctx). + WithBody(config). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureRestoreOnDemandCreate(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + +func (h *V1Client) GetClusterRestoreConfigOnDemand(uid string) (*models.V1ClusterRestore, error) { + params := clientV1.NewV1ClusterFeatureRestoreGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureRestoreGet(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} From 8435517eea458dfe3bf93794e04637a74e7d9989 Mon Sep 17 00:00:00 2001 From: will <30413278+wcrum@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:58:06 -0600 Subject: [PATCH 06/15] adds user functions (#100) * feat: add user functions fix: lint err return fix: user.go fix: update get tenant uid * fix: add ctx to getme --- client/tenant.go | 9 ++------- client/user.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/client/tenant.go b/client/tenant.go index de442201..7823dafa 100644 --- a/client/tenant.go +++ b/client/tenant.go @@ -1,14 +1,9 @@ package client -import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" -) - func (h *V1Client) GetTenantUID() (string, error) { - params := clientV1.NewV1UsersMeGetParamsWithContext(h.ctx) - resp, err := h.Client.V1UsersMeGet(params) + resp, err := h.GetMe() if err != nil { return "", err } - return resp.Payload.Status.Tenant.TenantUID, nil + return resp.Status.Tenant.TenantUID, nil } diff --git a/client/user.go b/client/user.go index 49f342b7..4aed2c65 100644 --- a/client/user.go +++ b/client/user.go @@ -8,6 +8,15 @@ import ( "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +func (h *V1Client) GetMe() (*models.V1UserMe, error) { + params := clientV1.NewV1UsersMeGetParamsWithContext(h.ctx) + resp, err := h.Client.V1UsersMeGet(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + // CRUDL operations on users are all tenant scoped. // See: hubble/services/svccore/perms/user_acl.go @@ -47,3 +56,25 @@ func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) { } return nil, fmt.Errorf("user with email '%s' not found", email) } + +func (h *V1Client) DeleteUserByUID(uid string) error { + params := clientV1.NewV1UsersUIDDeleteParams().WithUID(uid) + _, err := h.Client.V1UsersUIDDelete(params) + if err != nil { + return err + } + return nil +} + +func (h *V1Client) DeleteUserByName(name string) error { + users, err := h.GetUsers() + if err != nil { + return err + } + for _, user := range users.Items { + if user.Metadata.Name == name { + return h.DeleteUserByUID(user.Metadata.UID) + } + } + return fmt.Errorf("user with name '%s' not found", name) +} From dc66ca852c5ea8fa1714f304c158ac26036d3ea3 Mon Sep 17 00:00:00 2001 From: Pavithra Pandiyan <138559457+pavithrapgithub@users.noreply.github.com> Date: Thu, 25 Apr 2024 19:03:01 +0530 Subject: [PATCH 07/15] Create and get api for on demand scan (#101) * Create and get api for on demand scan * Update cluster_scan_config.go Updated to follow current SDK convention. The SDK typically returns nil + err when an error is encountered. --------- Co-authored-by: Tyler Gillson --- client/cluster_scan_config.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/cluster_scan_config.go b/client/cluster_scan_config.go index ed6964b4..cdbad84d 100644 --- a/client/cluster_scan_config.go +++ b/client/cluster_scan_config.go @@ -45,3 +45,21 @@ func (h *V1Client) ApplyClusterScanConfig(uid string, config *models.V1ClusterCo } return h.UpdateClusterScanConfig(uid, config) } + +func (h *V1Client) GetComplianceScanOnDemandScanLogs(uid string) (*models.V1ClusterComplianceScanLogs, error) { + params := clientV1.NewV1ClusterFeatureComplianceScanLogsGetParamsWithContext(h.ctx). + WithUID(uid) + resp, err := h.Client.V1ClusterFeatureComplianceScanLogsGet(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + +func (h *V1Client) CreateComplianceScanOnDemandCreateClusterScanConfig(uid string, config *models.V1ClusterComplianceOnDemandConfig) error { + params := clientV1.NewV1ClusterFeatureComplianceScanOnDemandCreateParamsWithContext(h.ctx). + WithUID(uid). + WithBody(config) + _, err := h.Client.V1ClusterFeatureComplianceScanOnDemandCreate(params) + return err +} From 3a42012a6fd62b2787cfeee95564cac8d00f909a Mon Sep 17 00:00:00 2001 From: will <30413278+wcrum@users.noreply.github.com> Date: Wed, 1 May 2024 15:20:09 -0600 Subject: [PATCH 08/15] feat: add create user (#102) --- client/user.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/user.go b/client/user.go index 4aed2c65..1dd654ac 100644 --- a/client/user.go +++ b/client/user.go @@ -78,3 +78,12 @@ func (h *V1Client) DeleteUserByName(name string) error { } return fmt.Errorf("user with name '%s' not found", name) } + +func (h *V1Client) CreateUser(user *models.V1UserEntity) (string, error) { + param := clientV1.NewV1UsersCreateParams().WithBody(user) + resp, err := h.Client.V1UsersCreate(param) + if err != nil { + return "", err + } + return *resp.Payload.UID, nil +} From 463f908a03c64ac8213e30559289d1cc456f3bc6 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 1 May 2024 15:22:24 -0600 Subject: [PATCH 09/15] fix: handle 404 in GetClusterWithoutStatus; fix 404 handling in general (#103) Signed-off-by: Tyler Gillson --- client/account.go | 4 +++- client/account_aws.go | 4 +++- client/account_azure.go | 4 +++- client/account_gcp.go | 4 +++- client/account_maas.go | 4 +++- client/account_openstack.go | 4 +++- client/account_tke.go | 4 +++- client/account_vsphere.go | 4 +++- client/apiutil/apiutil.go | 9 ++++----- client/application.go | 8 ++++++-- client/application_profile.go | 16 ++++++---------- client/cluster.go | 26 +++++++++++++++----------- client/cluster_aks.go | 4 +++- client/cluster_aws.go | 4 +++- client/cluster_azure.go | 4 +++- client/cluster_edge.go | 4 +++- client/cluster_edge_native.go | 4 +++- client/cluster_edge_vsphere.go | 4 +++- client/cluster_eks.go | 4 +++- client/cluster_gcp.go | 4 +++- client/cluster_group.go | 12 +++++++++--- client/cluster_libvirt.go | 4 +++- client/cluster_maas.go | 4 +++- client/cluster_profile.go | 4 +++- client/cluster_tke.go | 4 +++- client/cluster_virtual.go | 4 +++- client/cluster_vsphere.go | 4 +++- client/pack.go | 8 ++++++-- client/workspace.go | 12 +++++++++--- 29 files changed, 121 insertions(+), 58 deletions(-) diff --git a/client/account.go b/client/account.go index c76e3e64..7b94b874 100644 --- a/client/account.go +++ b/client/account.go @@ -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 diff --git a/client/account_aws.go b/client/account_aws.go index 1f887d21..238e7b44 100644 --- a/client/account_aws.go +++ b/client/account_aws.go @@ -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 diff --git a/client/account_azure.go b/client/account_azure.go index 84863c38..513dff51 100644 --- a/client/account_azure.go +++ b/client/account_azure.go @@ -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 diff --git a/client/account_gcp.go b/client/account_gcp.go index 069c853a..373917c4 100644 --- a/client/account_gcp.go +++ b/client/account_gcp.go @@ -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 diff --git a/client/account_maas.go b/client/account_maas.go index 360448bc..0555848c 100644 --- a/client/account_maas.go +++ b/client/account_maas.go @@ -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 diff --git a/client/account_openstack.go b/client/account_openstack.go index c59513c7..327fbfe8 100644 --- a/client/account_openstack.go +++ b/client/account_openstack.go @@ -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 diff --git a/client/account_tke.go b/client/account_tke.go index cdff5082..8fbd8e1a 100644 --- a/client/account_tke.go +++ b/client/account_tke.go @@ -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 diff --git a/client/account_vsphere.go b/client/account_vsphere.go index be1dfd0a..495ade2c 100644 --- a/client/account_vsphere.go +++ b/client/account_vsphere.go @@ -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 diff --git a/client/apiutil/apiutil.go b/client/apiutil/apiutil.go index d1f4ca6a..590575a9 100644 --- a/client/apiutil/apiutil.go +++ b/client/apiutil/apiutil.go @@ -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 { diff --git a/client/application.go b/client/application.go index 3a17d16b..f8d00f7a 100644 --- a/client/application.go +++ b/client/application.go @@ -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 @@ -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 diff --git a/client/application_profile.go b/client/application_profile.go index 2bb8b819..d7e3e350 100644 --- a/client/application_profile.go +++ b/client/application_profile.go @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 } diff --git a/client/cluster.go b/client/cluster.go index 0a41f18d..42ce15f4 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -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) @@ -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). diff --git a/client/cluster_aks.go b/client/cluster_aks.go index 112550d5..1d328ac5 100644 --- a/client/cluster_aks.go +++ b/client/cluster_aks.go @@ -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 diff --git a/client/cluster_aws.go b/client/cluster_aws.go index fc08b789..919de254 100644 --- a/client/cluster_aws.go +++ b/client/cluster_aws.go @@ -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 diff --git a/client/cluster_azure.go b/client/cluster_azure.go index c9ff5914..d7769564 100644 --- a/client/cluster_azure.go +++ b/client/cluster_azure.go @@ -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 diff --git a/client/cluster_edge.go b/client/cluster_edge.go index 156edd24..85d919d4 100644 --- a/client/cluster_edge.go +++ b/client/cluster_edge.go @@ -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 diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index 1f51502f..cd85e44b 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -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 diff --git a/client/cluster_edge_vsphere.go b/client/cluster_edge_vsphere.go index a8cc7e3f..0bf563b8 100644 --- a/client/cluster_edge_vsphere.go +++ b/client/cluster_edge_vsphere.go @@ -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 diff --git a/client/cluster_eks.go b/client/cluster_eks.go index 07867266..652e7366 100644 --- a/client/cluster_eks.go +++ b/client/cluster_eks.go @@ -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 diff --git a/client/cluster_gcp.go b/client/cluster_gcp.go index d72741bd..34602e94 100644 --- a/client/cluster_gcp.go +++ b/client/cluster_gcp.go @@ -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 diff --git a/client/cluster_group.go b/client/cluster_group.go index ca739c1f..27ab5a5c 100644 --- a/client/cluster_group.go +++ b/client/cluster_group.go @@ -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 @@ -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 @@ -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 diff --git a/client/cluster_libvirt.go b/client/cluster_libvirt.go index 215bb473..4900a9dd 100644 --- a/client/cluster_libvirt.go +++ b/client/cluster_libvirt.go @@ -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 diff --git a/client/cluster_maas.go b/client/cluster_maas.go index dd60f120..252ee52b 100644 --- a/client/cluster_maas.go +++ b/client/cluster_maas.go @@ -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 diff --git a/client/cluster_profile.go b/client/cluster_profile.go index e5cbbc2b..18a6ba74 100644 --- a/client/cluster_profile.go +++ b/client/cluster_profile.go @@ -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 diff --git a/client/cluster_tke.go b/client/cluster_tke.go index e882d3a3..ce0e0324 100644 --- a/client/cluster_tke.go +++ b/client/cluster_tke.go @@ -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 diff --git a/client/cluster_virtual.go b/client/cluster_virtual.go index bc205367..f7d2ccf6 100644 --- a/client/cluster_virtual.go +++ b/client/cluster_virtual.go @@ -52,7 +52,9 @@ func (h *V1Client) GetCloudConfigVirtual(configUid string) (*models.V1VirtualClo params := clientV1.NewV1CloudConfigsVirtualGetParamsWithContext(h.ctx). WithConfigUID(configUid) resp, err := h.Client.V1CloudConfigsVirtualGet(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 diff --git a/client/cluster_vsphere.go b/client/cluster_vsphere.go index d9472892..c712da55 100644 --- a/client/cluster_vsphere.go +++ b/client/cluster_vsphere.go @@ -51,7 +51,9 @@ func (h *V1Client) GetCloudConfigVsphere(configUid string) (*models.V1VsphereClo 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 diff --git a/client/pack.go b/client/pack.go index 3ccb0edd..0ea97fc5 100644 --- a/client/pack.go +++ b/client/pack.go @@ -15,7 +15,9 @@ func (h *V1Client) SearchPacks(filter *models.V1PackFilterSpec, sortBy []*models Sort: sortBy, }) resp, err := h.Client.V1PacksSearch(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 @@ -26,7 +28,9 @@ func (h *V1Client) GetClusterProfileManifestPack(clusterProfileUid, packName str WithUID(clusterProfileUid). WithPackName(packName) resp, err := h.Client.V1ClusterProfilesUIDPacksUIDManifests(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 diff --git a/client/workspace.go b/client/workspace.go index 4c1fa6bb..86cef305 100644 --- a/client/workspace.go +++ b/client/workspace.go @@ -22,7 +22,9 @@ func (h *V1Client) GetWorkspace(uid string) (*models.V1Workspace, error) { params := clientV1.NewV1WorkspacesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1WorkspacesUIDGet(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 @@ -31,7 +33,9 @@ func (h *V1Client) GetWorkspace(uid string) (*models.V1Workspace, error) { func (h *V1Client) GetWorkspaceByName(name string) (*models.V1DashboardWorkspace, error) { params := clientV1.NewV1DashboardWorkspacesListParamsWithContext(h.ctx) resp, err := h.Client.V1DashboardWorkspacesList(params) - if err := apiutil.Handle404(err); err != nil { + if apiutil.Is404(err) { + return nil, nil + } else if err != nil { return nil, err } for _, workspace := range resp.Payload.Items { @@ -78,7 +82,9 @@ func (h *V1Client) GetWorkspaceBackup(uid string) (*models.V1WorkspaceBackup, er params := clientV1.NewV1WorkspaceOpsBackupGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1WorkspaceOpsBackupGet(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 From 21b9d24e6e0fe90e402cbbb853bc73adc2ea87da Mon Sep 17 00:00:00 2001 From: spectro-prow Date: Tue, 7 May 2024 19:34:22 +0000 Subject: [PATCH 10/15] Creating Release 4.5.0 --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 00000000..5d99b60f --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,4 @@ +Version 4.5.0 +Tue May 7 19:34:22 UTC 2024 + Initial Release + From 6d5477ca7e241790f1e3fe3d3302adc0e3a90bd9 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Mon, 20 May 2024 08:39:45 -0600 Subject: [PATCH 11/15] feat: support basic auth (#106) Signed-off-by: Tyler Gillson --- client/client.go | 57 +++++++++++++++++++++++++++++++++++++++++------- client/user.go | 10 +++++++++ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index 49b8818b..d907ae9b 100644 --- a/client/client.go +++ b/client/client.go @@ -10,6 +10,7 @@ import ( "github.com/spectrocloud/palette-api-go/apiutil/transport" clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + "github.com/spectrocloud/palette-api-go/models" ) type V1Client struct { @@ -18,6 +19,8 @@ type V1Client struct { ctx context.Context apikey string jwt string + username string + password string hubbleUri string projectUid string schemes []string @@ -45,12 +48,24 @@ func WithAPIKey(apiKey string) func(*V1Client) { } } -func WithJWTToken(jwt string) func(*V1Client) { +func WithJWT(jwt string) func(*V1Client) { return func(v *V1Client) { v.jwt = jwt } } +func WithUsername(username string) func(*V1Client) { + return func(v *V1Client) { + v.username = username + } +} + +func WithPassword(password string) func(*V1Client) { + return func(v *V1Client) { + v.password = password + } +} + func WithHubbleURI(hubbleUri string) func(*V1Client) { return func(v *V1Client) { v.hubbleUri = hubbleUri @@ -118,7 +133,10 @@ func (h *V1Client) Clone() *V1Client { opts = append(opts, WithAPIKey(h.apikey)) } if h.jwt != "" { - opts = append(opts, WithJWTToken(h.jwt)) + opts = append(opts, WithJWT(h.jwt)) + } + if h.username != "" && h.password != "" { + opts = append(opts, WithUsername(h.username), WithPassword(h.password)) } if h.projectUid != "" { opts = append(opts, WithScopeProject(h.projectUid)) @@ -129,16 +147,20 @@ func (h *V1Client) Clone() *V1Client { return New(opts...) } -func (h *V1Client) getTransport() *transport.Runtime { - var httpTransport *transport.Runtime +func (h *V1Client) getTransport() (t *transport.Runtime) { + if h.username != "" && h.password != "" { + if err := h.authenticate(); err != nil { + return nil + } + } if h.apikey != "" { - httpTransport = h.apiKeyTransport() + t = h.apiKeyTransport() } else if h.jwt != "" { - httpTransport = h.jwtTransport() + t = h.jwtTransport() } else { - httpTransport = h.baseTransport() + t = h.baseTransport() } - return httpTransport + return } func (h *V1Client) apiKeyTransport() *transport.Runtime { @@ -153,6 +175,25 @@ func (h *V1Client) jwtTransport() *transport.Runtime { return httpTransport } +func (h *V1Client) authenticate() error { + httpTransport := h.baseTransport() + c := clientV1.New(httpTransport, strfmt.Default) + + params := &clientV1.V1AuthenticateParams{ + Body: &models.V1AuthLogin{ + EmailID: h.username, + Password: strfmt.Password(h.password), + }, + } + resp, err := c.V1Authenticate(params) + if err != nil { + return err + } + h.jwt = resp.Payload.Authorization + + return nil +} + func (h *V1Client) baseTransport() *transport.Runtime { httpTransport := transport.NewWithClient(h.hubbleUri, "", h.schemes, h.httpClient()) httpTransport.RetryAttempts = h.retryAttempts diff --git a/client/user.go b/client/user.go index 1dd654ac..07dd9b59 100644 --- a/client/user.go +++ b/client/user.go @@ -8,6 +8,16 @@ import ( "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +func (h *V1Client) Authenticate(body *models.V1AuthLogin) (*models.V1UserToken, error) { + params := clientV1.NewV1AuthenticateParams(). + WithBody(body) + resp, err := h.Client.V1Authenticate(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + func (h *V1Client) GetMe() (*models.V1UserMe, error) { params := clientV1.NewV1UsersMeGetParamsWithContext(h.ctx) resp, err := h.Client.V1UsersMeGet(params) From a69f2f64230ef5048dbde45356bc523cdcad529a Mon Sep 17 00:00:00 2001 From: Mohammed Umar <117995766+mumarmd@users.noreply.github.com> Date: Mon, 27 May 2024 18:28:52 +0530 Subject: [PATCH 12/15] OPS-4460 - Github actions for pr validation (#105) * OPS-4460 added scans for pr validation * added a access config * added needed secrets GH_TOKEN * chore: address gosec issues * chore: bump go version * ci: fix ci action --------- Signed-off-by: Tyler Gillson Co-authored-by: umar Co-authored-by: Fayas Ahamed Co-authored-by: Tyler Gillson --- .github/workflows/ci.yml | 13 ++++++- ...tleaks.yml => gitleaks-pr-validation.yaml} | 21 +++++----- .../workflows/golicense-pr-validation.yaml | 26 +++++++++++++ .github/workflows/gosec-pr-validation.yaml | 38 +++++++++++++++++++ .../workflows/govulncheck-pr-validation.yaml | 28 ++++++++++++++ client/addon_deployment_update.go | 4 +- client/client.go | 2 +- go.mod | 4 +- 8 files changed, 117 insertions(+), 19 deletions(-) rename .github/workflows/{gitleaks.yml => gitleaks-pr-validation.yaml} (76%) create mode 100644 .github/workflows/golicense-pr-validation.yaml create mode 100644 .github/workflows/gosec-pr-validation.yaml create mode 100644 .github/workflows/govulncheck-pr-validation.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82fcd11b..1130e825 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,38 @@ +name: CI on: push: workflow_dispatch: +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + jobs: build-with-coverage: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 + - name: Unshallow run: git fetch --prune --unshallow + - name: Configure git for private modules env: TOKEN: ${{ secrets.SPECTRO_TOKEN }} USER: ${{ secrets.SPECTRO_USER }} run: git config --global url."https://${USER}:${TOKEN}@github.com".insteadOf "https://github.com" + - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21 + go-version-file: go.mod + - name: Vet run: make vet + - name: Lint run: make lint + - name: Test run: make test \ No newline at end of file diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks-pr-validation.yaml similarity index 76% rename from .github/workflows/gitleaks.yml rename to .github/workflows/gitleaks-pr-validation.yaml index f2614057..a36eada8 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks-pr-validation.yaml @@ -1,22 +1,19 @@ -name: GitLeaks +name: GitLeaksPRValidation +on: [pull_request] -on: - pull_request: - branches: - - main - workflow_dispatch: {} +concurrency: + group: gitleaks-${{ github.ref }} + cancel-in-progress: true jobs: - gitleaks-scan: + gitleaks-pr-scan: runs-on: ubuntu-latest container: - image: gcr.io/spectro-common-dev/fayasa/bulwark:latest + image: gcr.io/spectro-dev-public/bulwark/gitleaks:latest env: REPO: ${{ github.event.repository.name }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - credentials: - username: _json_key - password: ${{ secrets.GCR_SPCD_JSON_KEY }} + GITLEAKS_CONFIG: /workspace/config.toml steps: - name: run-bulwark-gitleaks-scan @@ -36,4 +33,4 @@ jobs: exit 1 else echo "GitLeaks validation check passed" - fi + fi \ No newline at end of file diff --git a/.github/workflows/golicense-pr-validation.yaml b/.github/workflows/golicense-pr-validation.yaml new file mode 100644 index 00000000..47f49b52 --- /dev/null +++ b/.github/workflows/golicense-pr-validation.yaml @@ -0,0 +1,26 @@ +name: GoLicensesPRValidation +on: [pull_request] + +concurrency: + group: go-licenses-${{ github.ref }} + cancel-in-progress: true + +jobs: + go-licenses-pr-scan: + runs-on: ubuntu-latest + container: + image: gcr.io/spectro-images-public/golang:1.22-alpine + steps: + - name: install-go-licenses + run: GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest + + - name: checkout + uses: actions/checkout@v3 + + - name: set-github-access + run: | + /usr/bin/git config --global --add url."https://${{ secrets.GH_TOKEN }}:x-oauth-basic@github".insteadOf https://github + /usr/bin/git config --global --add url."https://${{ secrets.GH_TOKEN }}:x-oauth-basic@github".insteadOf git@github + + - name: go-licenses-scan + run: go-licenses check --ignore github.com/spectrocloud ./... \ No newline at end of file diff --git a/.github/workflows/gosec-pr-validation.yaml b/.github/workflows/gosec-pr-validation.yaml new file mode 100644 index 00000000..e91f5167 --- /dev/null +++ b/.github/workflows/gosec-pr-validation.yaml @@ -0,0 +1,38 @@ +name: GoSecPRValidation +on: [pull_request] + +concurrency: + group: gosec-${{ github.ref }} + cancel-in-progress: true + +jobs: + gosec-pr-scan: + runs-on: ubuntu-latest + container: + image: gcr.io/spectro-dev-public/bulwark/gosec:latest + env: + REPO: ${{ github.event.repository.name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: gosec-scan + shell: sh + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + GO111MODULE: on + run: /workspace/bulwark -name CodeSASTGoSec -verbose -target $REPO -tags "branch:$BRANCH,rules:-G101" + + - name: check-result + shell: sh + run: | + resultPath=$REPO-result.json + issues=$(cat $resultPath | jq -r '.Stats.found') + echo "Found ${issues} issues" + echo "Issues by Rule ID" + jq -r '.Issues | group_by (.rule_id)[] | {rule: .[0].rule_id, count: length}' $resultPath + if [ "$issues" -gt 0 ]; then + echo "GoSec SAST scan failed with below findings..." + cat $resultPath + exit 1 + else + echo "GoSec SAST scan passed" + fi \ No newline at end of file diff --git a/.github/workflows/govulncheck-pr-validation.yaml b/.github/workflows/govulncheck-pr-validation.yaml new file mode 100644 index 00000000..848382e3 --- /dev/null +++ b/.github/workflows/govulncheck-pr-validation.yaml @@ -0,0 +1,28 @@ +name: GoVulnCheckPRValidation +on: [pull_request] + +concurrency: + group: govulncheck-${{ github.ref }} + cancel-in-progress: true + +jobs: + govulncheck-pr-scan: + runs-on: security-runner + container: + image: gcr.io/spectro-images-public/golang:1.22-alpine + steps: + - name: install-govulncheck + run: GOBIN=/usr/local/bin go install golang.org/x/vuln/cmd/govulncheck@latest + + - name: checkout + uses: actions/checkout@v3 + + - name: set-github-access + run: | + /usr/bin/git config --global --add url."https://${{ secrets.GH_TOKEN }}:x-oauth-basic@github".insteadOf https://github + /usr/bin/git config --global --add url."https://${{ secrets.GH_TOKEN }}:x-oauth-basic@github".insteadOf git@github + + - name: govulncheck-scan + run: | + go version + govulncheck -mode source ./... \ No newline at end of file diff --git a/client/addon_deployment_update.go b/client/addon_deployment_update.go index 4e076eef..be5a4ee1 100644 --- a/client/addon_deployment_update.go +++ b/client/addon_deployment_update.go @@ -52,8 +52,8 @@ func (h *V1Client) PatchWithRetry(params *clientV1.V1SpectroClustersPatchProfile var err error rand.NewSource(time.Now().UnixNano()) for attempt := 0; attempt < h.retryAttempts; attempt++ { - // small jitter to prevent simultaneous retries - s := rand.Intn(h.retryAttempts) // n will be between 0 and number of retries + // small jitter to prevent simultaneous retries. n will be between 0 and number of retries. + s := rand.Intn(h.retryAttempts) // #nosec G404 - random number is not used for security purposes log.Printf("Sleeping %d seconds, retry: %d, cluster:%s, profile:%s, ", s, attempt, params.UID, params.Body.Profiles[0].UID) time.Sleep(time.Duration(s) * time.Second) err = h.ClustersPatchProfiles(params) diff --git a/client/client.go b/client/client.go index d907ae9b..15fa84e9 100644 --- a/client/client.go +++ b/client/client.go @@ -206,7 +206,7 @@ func (h *V1Client) httpClient() *http.Client { Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{ - InsecureSkipVerify: h.insecureSkipVerify, + InsecureSkipVerify: h.insecureSkipVerify, // #nosec G402 - InsecureSkipVerify is enabled via user input }, }, } diff --git a/go.mod b/go.mod index fb9797bb..429450a0 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/spectrocloud/palette-sdk-go -go 1.21 - -toolchain go1.21.1 +go 1.22 require ( github.com/go-openapi/runtime v0.26.0 From 92d0dd224f229b6ae9c26671a2b1c5e1c6a2011e Mon Sep 17 00:00:00 2001 From: Gamya Date: Mon, 3 Jun 2024 20:10:11 +0530 Subject: [PATCH 13/15] added func for PQA-1848 (#109) * added fucntions for PQA-1848 * addressed comments * Update cluster.go * Update cluster.go --- client/cluster.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/client/cluster.go b/client/cluster.go index 42ce15f4..531c8f72 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -1,7 +1,11 @@ package client import ( + "bytes" "fmt" + "io" + "os" + "path/filepath" "strings" clientV1 "github.com/spectrocloud/palette-api-go/client/v1" @@ -247,3 +251,43 @@ func clusterNameEqFilter(name string) *models.V1SearchFilterItem { Type: models.V1SearchFilterPropertyTypeString, } } + +func (h *V1Client) GetLogFetcherStatus(uid string, logFetcherUid *string) (*models.V1ClusterLogFetcher, error) { + params := clientV1.NewV1ClusterFeatureLogFetcherGetParamsWithContext(h.ctx).WithUID(uid).WithRequestID(logFetcherUid) + resp, err := h.Client.V1ClusterFeatureLogFetcherGet(params) + if err != nil { + return nil, err + } + return resp.Payload, nil +} + +func (h *V1Client) InitiateDownloadOfClusterLogs(uid string, V1ClusterLogFetcherRequestObj *models.V1ClusterLogFetcherRequest) (*string, error) { + params := clientV1.NewV1ClusterFeatureLogFetcherCreateParamsWithContext(h.ctx).WithUID(uid).WithBody(V1ClusterLogFetcherRequestObj) + resp, err := h.Client.V1ClusterFeatureLogFetcherCreate(params) + if err != nil { + return nil, err + } + return resp.GetPayload().UID, nil +} + +func (h *V1Client) DownloadLogs(uid string, logFetcherUid string) (io.Writer, error) { + filename := "logs-" + uid + ".zip" + params := clientV1.NewV1ClusterFeatureLogFetcherLogDownloadParamsWithContext(h.ctx).WithUID(logFetcherUid).WithFileName(&filename) + var buf bytes.Buffer + writer := io.Writer(&buf) + resp, err := h.Client.V1ClusterFeatureLogFetcherLogDownload(params, writer) + if err != nil { + return nil, err + } + logfile := resp.GetPayload() + file_location := "/tmp/" + filename + fo, err := os.Create(filepath.Clean(file_location)) + if err != nil { + return nil, fmt.Errorf("error while creating a file %v", err) + } + _, err = buf.WriteTo(fo) + if err != nil { + return nil, fmt.Errorf("error while writing log content to a file %v", err) + } + return logfile, nil +} From cfbbb092d09e80a3ae4217d24cfc0907c5162ee3 Mon Sep 17 00:00:00 2001 From: Gamya Date: Thu, 6 Jun 2024 19:13:20 +0530 Subject: [PATCH 14/15] PQA-1860: get edge hosts using continue token (#110) * get edge hosts using continue token * Update cluster_edge_native.go --- client/cluster_edge_native.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index cd85e44b..e7af4e12 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -53,12 +53,19 @@ func (h *V1Client) GetEdgeHost(edgeHostId string) (*models.V1EdgeHostDevice, err } func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) { - params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx) - resp, err := h.Client.V1DashboardEdgehostsSearch(params) - if err != nil { - return nil, err + continueToken := "" + var items []*models.V1EdgeHostsMetadata + for ok := true; ok; ok = (continueToken != "") { + params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx) + resp, err := h.Client.V1DashboardEdgehostsSearch(params) + if err != nil { + return nil, err + } + continueToken = resp.Payload.Listmeta.Continue + items = append(items, resp.Payload.Items...) } - return resp.Payload.Items, nil + + return items, nil } func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity) (string, error) { From e41c4ac6954c88eb9ac81ffa4079d69f36375f98 Mon Sep 17 00:00:00 2001 From: Gamya Date: Wed, 26 Jun 2024 21:07:58 +0530 Subject: [PATCH 15/15] Pqa 1907 Edge BDD: Automation for PEM-5001 - edge host list based on tag (#111) * added func to get edge hosts using tags * added edge host filter for PEM-5001 * Update cluster_edge_native.go --- client/cluster_edge_native.go | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index e7af4e12..268c7436 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -2,6 +2,7 @@ package client import ( "errors" + "fmt" clientV1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" @@ -68,6 +69,70 @@ func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) { return items, nil } +func (h *V1Client) GetEdgeHostsByTags(tags map[string]string) ([]*models.V1EdgeHostsMetadata, error) { + continueToken := "" + var items []*models.V1EdgeHostsMetadata + filter := GetEdgeFilter(nil, tags) + for ok := true; ok; ok = (continueToken != "") { + params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). + WithBody(&models.V1SearchFilterSummarySpec{ + Filter: filter, + Sort: nil, + }) + resp, err := h.Client.V1DashboardEdgehostsSearch(params) + if err != nil { + return nil, err + } + continueToken = resp.Payload.Listmeta.Continue + items = append(items, resp.Payload.Items...) + } + + return items, nil +} + +func GetEdgeFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]string) *models.V1SearchFilterSpec { + filter := &models.V1SearchFilterSpec{ + Conjunction: and(), + FilterGroups: []*models.V1SearchFilterGroup{ + { + Conjunction: and(), + Filters: []*models.V1SearchFilterItem{}, + }, + }, + } + + // Tags filter + if len(tags) > 0 { + var tagValues []string + for key, value := range tags { + tagValues = append(tagValues, fmt.Sprintf("%s:%s", key, value)) + } + tagsFilter := &models.V1SearchFilterItem{ + Condition: &models.V1SearchFilterCondition{ + String: &models.V1SearchFilterStringCondition{ + Match: &models.V1SearchFilterStringConditionMatch{ + Conjunction: or(), + Values: tagValues, + }, + Operator: models.V1SearchFilterStringOperatorEq, + Negation: false, + IgnoreCase: false, + }, + }, + Property: "tags", + Type: models.V1SearchFilterPropertyTypeString, + } + filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, tagsFilter) + } + + // Append extra filters if provided + if extraFilters != nil { + filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters}) + } + + return filter +} + func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity) (string, error) { params := clientV1.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.ctx). WithBody(cluster)