Skip to content

Commit

Permalink
PLT-569: Fixing cloud accounts context.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Jul 14, 2023
1 parent 3a84892 commit c6d7da9
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 89 deletions.
14 changes: 2 additions & 12 deletions client/account_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (h *V1Client) CreateCloudAccountAws(account *models.V1AwsAccount, AccountCo
case "tenant":
params = clusterC.NewV1CloudAccountsAwsCreateParams().WithBody(account)
}

success, err := client.V1CloudAccountsAwsCreate(params)
if err != nil {
return "", err
Expand All @@ -34,13 +35,7 @@ func (h *V1Client) UpdateCloudAccountAws(account *models.V1AwsAccount) error {
}

uid := account.Metadata.UID
var params *clusterC.V1CloudAccountsAwsUpdateParams
switch account.Metadata.Annotations["scope"] {
case "project":
params = clusterC.NewV1CloudAccountsAwsUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
case "tenant":
params = clusterC.NewV1CloudAccountsAwsUpdateParams().WithBody(account)
}
params := clusterC.NewV1CloudAccountsAwsUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
_, err = client.V1CloudAccountsAwsUpdate(params)
return err
}
Expand All @@ -51,11 +46,6 @@ func (h *V1Client) DeleteCloudAccountAws(uid, AccountContext string) error {
return err
}

_, err = h.GetCloudAccountAws(uid, AccountContext)
if err != nil {
return err
}

var params *clusterC.V1CloudAccountsAwsDeleteParams
switch AccountContext {
case "project":
Expand Down
8 changes: 1 addition & 7 deletions client/account_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ func (h *V1Client) UpdateCloudAccountAzure(account *models.V1AzureAccount) error
}

uid := account.Metadata.UID
var params *clusterC.V1CloudAccountsAzureUpdateParams
switch account.Metadata.Annotations["scope"] {
case "project":
params = clusterC.NewV1CloudAccountsAzureUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
case "tenant":
params = clusterC.NewV1CloudAccountsAzureUpdateParams().WithBody(account)
}
params := clusterC.NewV1CloudAccountsAzureUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
_, err = client.V1CloudAccountsAzureUpdate(params)
return err
}
Expand Down
28 changes: 12 additions & 16 deletions client/account_coxedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,19 @@ func (h *V1Client) UpdateCloudAccountCoxEdge(account *models.V1CoxEdgeAccount) e
}

uid := account.Metadata.UID
var params *clusterC.V1CloudAccountsCoxEdgeUpdateParams
switch account.Metadata.Annotations["scope"] {
case "project":
params = clusterC.NewV1CloudAccountsCoxEdgeUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
case "tenant":
params = clusterC.NewV1CloudAccountsCoxEdgeUpdateParams().WithBody(account)
}
params := clusterC.NewV1CloudAccountsCoxEdgeUpdateParamsWithContext(h.Ctx).WithUID(uid).WithBody(account)
_, err = client.V1CloudAccountsCoxEdgeUpdate(params)
return err
}

func (h *V1Client) DeleteCloudAccountCoxEdge(uid string) error {
func (h *V1Client) DeleteCloudAccountCoxEdge(uid, AccountContext string) error {
client, err := h.GetClusterClient()
if err != nil {
return err
}

account, err := h.GetCloudAccountCoxEdge(uid)
if err != nil {
return err
}

var params *clusterC.V1CloudAccountsCoxEdgeDeleteParams
switch account.Metadata.Annotations["scope"] {
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsCoxEdgeDeleteParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
Expand All @@ -67,13 +56,20 @@ func (h *V1Client) DeleteCloudAccountCoxEdge(uid string) error {
return err
}

func (h *V1Client) GetCloudAccountCoxEdge(uid string) (*models.V1CoxEdgeAccount, error) {
func (h *V1Client) GetCloudAccountCoxEdge(uid, AccountContext string) (*models.V1CoxEdgeAccount, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
}

params := clusterC.NewV1CloudAccountsCoxEdgeGetParamsWithContext(h.Ctx).WithUID(uid)
var params *clusterC.V1CloudAccountsCoxEdgeGetParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsCoxEdgeGetParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
params = clusterC.NewV1CloudAccountsCoxEdgeGetParams().WithUID(uid)
}

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

Expand Down
33 changes: 27 additions & 6 deletions client/account_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import (
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)

func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (string, error) {
func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity, AccountContext string) (string, error) {
client, err := h.GetClusterClient()
if err != nil {
return "", err
}

params := clusterC.NewV1CloudAccountsGcpCreateParamsWithContext(h.Ctx).WithBody(account)
var params *clusterC.V1CloudAccountsGcpCreateParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsGcpCreateParamsWithContext(h.Ctx).WithBody(account)
case "tenant":
params = clusterC.NewV1CloudAccountsGcpCreateParams().WithBody(account)
}

success, err := client.V1CloudAccountsGcpCreate(params)
if err != nil {
return "", err
Expand All @@ -33,24 +40,38 @@ func (h *V1Client) UpdateCloudAccountGcp(account *models.V1GcpAccountEntity) err
return err
}

func (h *V1Client) DeleteCloudAccountGcp(uid string) error {
func (h *V1Client) DeleteCloudAccountGcp(uid, AccountContext string) error {
client, err := h.GetClusterClient()
if err != nil {
return nil
}

params := clusterC.NewV1CloudAccountsGcpDeleteParamsWithContext(h.Ctx).WithUID(uid)
var params *clusterC.V1CloudAccountsGcpDeleteParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsGcpDeleteParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
params = clusterC.NewV1CloudAccountsGcpDeleteParams().WithUID(uid)
}

_, err = client.V1CloudAccountsGcpDelete(params)
return err
}

func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error) {
func (h *V1Client) GetCloudAccountGcp(uid, AccountContext string) (*models.V1GcpAccount, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
}

params := clusterC.NewV1CloudAccountsGcpGetParamsWithContext(h.Ctx).WithUID(uid)
var params *clusterC.V1CloudAccountsGcpGetParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsGcpGetParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
params = clusterC.NewV1CloudAccountsGcpGetParams().WithUID(uid)
}

success, err := client.V1CloudAccountsGcpGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
return nil, nil
Expand Down
69 changes: 62 additions & 7 deletions client/account_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@ import (
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)

func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount) (string, error) {
func toV1OverlordsUIDMaasAccountValidateBody(account *models.V1MaasAccount) clusterC.V1OverlordsUIDMaasAccountValidateBody {
return clusterC.V1OverlordsUIDMaasAccountValidateBody{
Account: account.Spec,
}
}

func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount, AccountContext string) (string, error) {
client, err := h.GetClusterClient()
if err != nil {
return "", err
}

params := clusterC.NewV1CloudAccountsMaasCreateParamsWithContext(h.Ctx).WithBody(account)
// validate account
err = validateCloudAccountMaas(account, h)
if 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 := client.V1CloudAccountsMaasCreate(params)
if err != nil {
return "", err
Expand All @@ -21,10 +40,32 @@ func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount) (string
return *success.Payload.UID, nil
}

func validateCloudAccountMaas(account *models.V1MaasAccount, h *V1Client) error {
client, err := h.GetClusterClient()
if err != nil {
return err
}

paramsValidate := clusterC.NewV1OverlordsUIDMaasAccountValidateParams().WithUID(account.Metadata.Annotations[OverlordUID])
paramsValidate = paramsValidate.WithBody(toV1OverlordsUIDMaasAccountValidateBody(account))
_, err = client.V1OverlordsUIDMaasAccountValidate(paramsValidate)
if err != nil {
return err
}

return nil
}

func (h *V1Client) UpdateCloudAccountMaas(account *models.V1MaasAccount) error {
client, err := h.GetClusterClient()
if err != nil {
return nil
return err
}

// validate account
err = validateCloudAccountMaas(account, h)
if err != nil {
return err
}

uid := account.Metadata.UID
Expand All @@ -33,24 +74,38 @@ func (h *V1Client) UpdateCloudAccountMaas(account *models.V1MaasAccount) error {
return err
}

func (h *V1Client) DeleteCloudAccountMaas(uid string) error {
func (h *V1Client) DeleteCloudAccountMaas(uid, AccountContext string) error {
client, err := h.GetClusterClient()
if err != nil {
return nil
}

params := clusterC.NewV1CloudAccountsMaasDeleteParamsWithContext(h.Ctx).WithUID(uid)
var params *clusterC.V1CloudAccountsMaasDeleteParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsMaasDeleteParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
params = clusterC.NewV1CloudAccountsMaasDeleteParams().WithUID(uid)
}

_, err = client.V1CloudAccountsMaasDelete(params)
return err
}

func (h *V1Client) GetCloudAccountMaas(uid string) (*models.V1MaasAccount, error) {
func (h *V1Client) GetCloudAccountMaas(uid, AccountContext string) (*models.V1MaasAccount, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, err
}

params := clusterC.NewV1CloudAccountsMaasGetParamsWithContext(h.Ctx).WithUID(uid)
var params *clusterC.V1CloudAccountsMaasGetParams
switch AccountContext {
case "project":
params = clusterC.NewV1CloudAccountsMaasGetParamsWithContext(h.Ctx).WithUID(uid)
case "tenant":
params = clusterC.NewV1CloudAccountsMaasGetParams().WithUID(uid)
}

success, err := client.V1CloudAccountsMaasGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
return nil, nil
Expand Down
Loading

0 comments on commit c6d7da9

Please sign in to comment.