-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSPROD-29308: Implement CloudAccount client v2 for Secure
Change summary: ----------------- Adding a new CloudAccount client v2 for making Secure BE (cloudauth) APIs to support API-only onboarding support.
- Loading branch information
1 parent
e07821e
commit 5be3781
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
cloudAccountsPathV2 = "%s/api/cloudauth/v1/accounts" | ||
cloudAccountPathV2 = "%s/api/cloudauth/v1/accounts/%s" | ||
) | ||
|
||
type CloudAccountSecureInterfaceV2 interface { | ||
Base | ||
CreateCloudAccountSecureV2(ctx context.Context, cloudAccount *CloudAccountSecureV2) (*CloudAccountSecureV2, error) | ||
GetCloudAccountSecureV2(ctx context.Context, accountID string) (*CloudAccountSecureV2, error) | ||
DeleteCloudAccountSecureV2(ctx context.Context, accountID string) error | ||
UpdateCloudAccountSecureV2(ctx context.Context, accountID string, cloudAccount *CloudAccountSecureV2) (*CloudAccountSecureV2, error) | ||
} | ||
|
||
func (client *Client) CreateCloudAccountSecureV2(ctx context.Context, cloudAccount *CloudAccountSecureV2) (*CloudAccountSecureV2, error) { | ||
// TODO: convert payload as per cloudauth API request object OR till API is updated return {}, nil | ||
payload, err := Marshal(cloudAccount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := client.requester.Request(ctx, http.MethodPost, client.cloudAccountsV2URL(), payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { | ||
err = client.ErrorFromResponse(response) | ||
return nil, err | ||
} | ||
|
||
// TODO: convert response as per return CloudAccountSecureV2 struct OR till API is updated return {}, nil | ||
return Unmarshal[*CloudAccountSecureV2](response.Body) | ||
} | ||
|
||
func (client *Client) GetCloudAccountSecureV2(ctx context.Context, accountID string) (*CloudAccountSecureV2, error) { | ||
response, err := client.requester.Request(ctx, http.MethodGet, client.cloudAccountV2URL(accountID), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK { | ||
return nil, client.ErrorFromResponse(response) | ||
} | ||
|
||
return Unmarshal[*CloudAccountSecureV2](response.Body) | ||
} | ||
|
||
func (client *Client) DeleteCloudAccountSecureV2(ctx context.Context, accountID string) error { | ||
response, err := client.requester.Request(ctx, http.MethodDelete, client.cloudAccountV2URL(accountID), nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusNoContent && response.StatusCode != http.StatusOK { | ||
return client.ErrorFromResponse(response) | ||
} | ||
return nil | ||
} | ||
|
||
func (client *Client) UpdateCloudAccountSecureV2(ctx context.Context, accountID string, cloudAccount *CloudAccountSecureV2) (*CloudAccountSecureV2, error) { | ||
payload, err := Marshal(cloudAccount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := client.requester.Request(ctx, http.MethodPut, client.cloudAccountV2URL(accountID), payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK { | ||
err = client.ErrorFromResponse(response) | ||
return nil, err | ||
} | ||
|
||
return Unmarshal[*CloudAccountSecureV2](response.Body) | ||
} | ||
|
||
func (client *Client) cloudAccountsV2URL() string { | ||
return fmt.Sprintf(cloudAccountsPathV2, client.config.url) | ||
} | ||
|
||
func (client *Client) cloudAccountV2URL(accountID string) string { | ||
return fmt.Sprintf(cloudAccountPathV2, client.config.url, accountID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters