Skip to content

Commit

Permalink
update lint
Browse files Browse the repository at this point in the history
  • Loading branch information
botranvan committed Jun 21, 2024
1 parent 26a7396 commit 419ae47
Show file tree
Hide file tree
Showing 36 changed files with 468 additions and 468 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

func main() {
client, err := gobizfly.NewClient(
gobizfly.WithAPIUrl(host),
gobizfly.WithAPIURL(host),
)
if err != nil {
log.Fatal(err)
Expand Down
26 changes: 13 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
AppCredentialAuthType = "application_credential"
appCredentialAuthType = "application_credential"
accountName = "bizfly_account"
authServiceName = "auth"
autoScalingServiceName = "auto_scaling"
Expand Down Expand Up @@ -85,8 +85,8 @@ type Client struct {
// Option set Client specific attributes
type Option func(c *Client) error

// WithAPIUrl sets the API url option for Bizfly client.
func WithAPIUrl(u string) Option {
// WithAPIURL sets the API url option for Bizfly client.
func WithAPIURL(u string) Option {
return func(c *Client) error {
var err error
c.apiURL, err = url.Parse(u)
Expand Down Expand Up @@ -119,7 +119,7 @@ func WithRegionName(region string) Option {
}
}

func WithProjectId(id string) Option {
func WithProjectID(id string) Option {
return func(c *Client) error {
c.projectID = id
return nil
Expand All @@ -140,7 +140,7 @@ func NewClient(options ...Option) (*Client, error) {
userAgent: ua,
}

err := WithAPIUrl(defaultAPIURL)(c)
err := WithAPIURL(defaultAPIURL)(c)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -168,29 +168,29 @@ func NewClient(options ...Option) (*Client, error) {
return c, nil
}

func (c *Client) GetServiceUrl(serviceName string) string {
func (c *Client) GetServiceURL(serviceName string) string {
// If service name is auth, return auth url without checking catalog
if serviceName == authServiceName {
// create a copy of apiURL
apiURL := *c.apiURL
// if apiUrl doesn't end with /api, append it
// if apiURL doesn't end with /api, append it
if !strings.HasSuffix(apiURL.Path, "/api") {
apiURL.Path = path.Join(c.apiURL.Path, "/api")
}
return apiURL.String()
}
for _, service := range c.services {
if service.CanonicalName == serviceName && service.Region == c.regionName {
return service.ServiceUrl
return service.ServiceURL
}
}
return defaultAPIURL
}

// NewRequest creates an API request.
func (c *Client) NewRequest(ctx context.Context, method, serviceName string, urlStr string, body interface{}) (*http.Request, error) {
serviceUrl := c.GetServiceUrl(serviceName)
url := serviceUrl + urlStr
serviceURL := c.GetServiceURL(serviceName)
url := serviceURL + urlStr
buf := new(bytes.Buffer)
if body != nil {
if err := json.NewEncoder(buf).Encode(body); err != nil {
Expand All @@ -205,7 +205,7 @@ func (c *Client) NewRequest(ctx context.Context, method, serviceName string, url
req.Header.Add("Content-Type", mediaType)
req.Header.Add("Accept", mediaType)
req.Header.Add("User-Agent", c.userAgent)
req.Header.Add("X-Project-Id", c.projectID)
req.Header.Add("X-Project-ID", c.projectID)
req.Header.Add("Authorization", "Basic "+c.basicAuth)

if c.authType == "" {
Expand All @@ -217,8 +217,8 @@ func (c *Client) NewRequest(ctx context.Context, method, serviceName string, url
}

req.Header.Add("X-Auth-Type", c.authType)
if c.authType == AppCredentialAuthType {
req.Header.Add("X-App-Credential-Id", c.appCredID)
if c.authType == appCredentialAuthType {
req.Header.Add("X-App-Credential-ID", c.appCredID)
req.Header.Add("X-App-Credential-Secret", c.appCredSecret)
}
return req, nil
Expand Down
26 changes: 13 additions & 13 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,76 @@ func setup() {

var err error
testRegion := "HaNoi"
client, err = NewClient(WithAPIUrl(serverTest.URL), WithRegionName(testRegion))
client, err = NewClient(WithAPIURL(serverTest.URL), WithRegionName(testRegion))
services := []*Service{
{Name: "Cloud Server",
CanonicalName: serverServiceName,
ServiceUrl: serverTest.URL + "/iaas-cloud/api",
ServiceURL: serverTest.URL + "/iaas-cloud/api",
Region: testRegion},
{
Name: "Load Balancer",
CanonicalName: loadBalancerServiceName,
ServiceUrl: serverTest.URL + "/api/loadbalancers",
ServiceURL: serverTest.URL + "/api/loadbalancers",
Region: testRegion,
},
{
Name: "CloudWatcher",
CanonicalName: cloudwatcherServiceName,
ServiceUrl: serverTest.URL + "/api/alert",
ServiceURL: serverTest.URL + "/api/alert",
Region: testRegion,
},
{
Name: "Auto Scaling",
CanonicalName: autoScalingServiceName,
ServiceUrl: serverTest.URL + "/api/auto-scaling",
ServiceURL: serverTest.URL + "/api/auto-scaling",
Region: testRegion,
},
{
Name: "Accounts",
CanonicalName: accountName,
ServiceUrl: serverTest.URL + "/api/account",
ServiceURL: serverTest.URL + "/api/account",
Region: testRegion,
},
{
Name: "Auth",
CanonicalName: authServiceName,
ServiceUrl: serverTest.URL + "/api",
ServiceURL: serverTest.URL + "/api",
Region: testRegion,
},
{
Name: "Kubernetes",
CanonicalName: kubernetesServiceName,
ServiceUrl: serverTest.URL + "/api/kubernetes-engine",
ServiceURL: serverTest.URL + "/api/kubernetes-engine",
Region: testRegion,
},
{
Name: "Container Registry",
CanonicalName: containerRegistryName,
ServiceUrl: serverTest.URL + "/api/container-registry",
ServiceURL: serverTest.URL + "/api/container-registry",
Region: testRegion,
},
{
Name: "CDN",
CanonicalName: cdnName,
ServiceUrl: serverTest.URL + "/api/cdn",
ServiceURL: serverTest.URL + "/api/cdn",
Region: testRegion,
},
{
Name: "DNS",
CanonicalName: dnsName,
ServiceUrl: serverTest.URL + "/api/dns",
ServiceURL: serverTest.URL + "/api/dns",
Region: testRegion,
},
{
Name: "Cloud Backup",
CanonicalName: cloudBackupServiceName,
ServiceUrl: serverTest.URL + "/api/cloud-backup",
ServiceURL: serverTest.URL + "/api/cloud-backup",
Region: testRegion,
},
{
Name: "Database",
CanonicalName: databaseServiceName,
ServiceUrl: serverTest.URL + "/api/cloud-database",
ServiceURL: serverTest.URL + "/api/cloud-database",
Region: testRegion,
},
}
Expand Down
78 changes: 39 additions & 39 deletions cloud_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@ type CloudBackupService interface {

ListTenantRecoveryPoints(ctx context.Context) ([]*CloudBackupMachineRecoveryPoint, error)
DeleteMultipleRecoveryPoints(ctx context.Context, payload CloudBackupDeleteMultipleRecoveryPointPayload) error
ListDirectoryRecoveryPoints(ctx context.Context, machineId string, directoryId string) ([]*CloudBackupMachineRecoveryPoint, error)
RecoveryPointAction(ctx context.Context, recoveryPointId string, payload *CloudBackupRecoveryPointActionPayload) (*CloudBackupMachineRecoveryPoint, error)
ListMachineRecoveryPoints(ctx context.Context, machineId string) ([]*CloudBackupExtendedRecoveryPoint, error)
GetRecoveryPoint(ctx context.Context, recoveryPointId string) (*CloudBackupMachineRecoveryPoint, error)
DeleteRecoveryPoint(ctx context.Context, recoveryPointId string) error
ListRecoveryPointItems(ctx context.Context, recoveryPointId string) ([]*CloudBackupRecoveryPointItem, error)
RestoreRecoveryPoint(ctx context.Context, recoveryPointId string, payload *CloudBackupRestoreRecoveryPointPayload) error
ListDirectoryRecoveryPoints(ctx context.Context, machineID string, directoryID string) ([]*CloudBackupMachineRecoveryPoint, error)
RecoveryPointAction(ctx context.Context, recoveryPointID string, payload *CloudBackupRecoveryPointActionPayload) (*CloudBackupMachineRecoveryPoint, error)
ListMachineRecoveryPoints(ctx context.Context, machineID string) ([]*CloudBackupExtendedRecoveryPoint, error)
GetRecoveryPoint(ctx context.Context, recoveryPointID string) (*CloudBackupMachineRecoveryPoint, error)
DeleteRecoveryPoint(ctx context.Context, recoveryPointID string) error
ListRecoveryPointItems(ctx context.Context, recoveryPointID string) ([]*CloudBackupRecoveryPointItem, error)
RestoreRecoveryPoint(ctx context.Context, recoveryPointID string, payload *CloudBackupRestoreRecoveryPointPayload) error

ListStorageVaults(ctx context.Context) ([]*CloudBackupStorageVault, error)
GetStorageVault(ctx context.Context, vaultId string) (*CloudBackupStorageVault, error)
GetStorageVault(ctx context.Context, vaultID string) (*CloudBackupStorageVault, error)
CreateStorageVault(ctx context.Context, payload *CloudBackupCreateStorageVaultPayload) (*CloudBackupStorageVault, error)

ListTenantMachines(ctx context.Context, listOption *CloudBackupListMachineParams) ([]*CloudBackupMachine, error)
CreateMachine(ctx context.Context, payload *CloudBackupCreateMachinePayload) (*CloudBackupExtendedMachine, error)
GetMachine(ctx context.Context, machineId string) (*CloudBackupMachine, error)
PatchMachine(ctx context.Context, machineId string, payload *CloudBackupPatchMachinePayload) (*CloudBackupMachine, error)
DeleteMachine(ctx context.Context, machineId string, payload *CloudBackupDeleteMachinePayload) error
ActionMachine(ctx context.Context, machineId string, payload *CloudBackupActionMachinePayload) error
ResetMachineSecretKey(ctx context.Context, machineId string) (*CloudBackupExtendedMachine, error)

ActionDirectory(ctx context.Context, machineId string, payload *CloudBackupStateDirectoryAction) error
ListMachineBackupDirectories(ctx context.Context, machineId string) ([]*CloudBackupDirectory, error)
CreateBackupDirectory(ctx context.Context, machineId string, payload *CloudBackupCreateDirectoryPayload) (*CloudBackupDirectory, error)
GetBackupDirectory(ctx context.Context, machineId string, directoryId string) (*CloudBackupDirectory, error)
PatchBackupDirectory(ctx context.Context, machineId string, directoryId string, payload *CloudBackupPatchDirectoryPayload) (*CloudBackupDirectory, error)
DeleteBackupDirectory(ctx context.Context, machineId string, directoryId string, payload *CloudBackupDeleteDirectoryPayload) error
GetMachine(ctx context.Context, machineID string) (*CloudBackupMachine, error)
PatchMachine(ctx context.Context, machineID string, payload *CloudBackupPatchMachinePayload) (*CloudBackupMachine, error)
DeleteMachine(ctx context.Context, machineID string, payload *CloudBackupDeleteMachinePayload) error
ActionMachine(ctx context.Context, machineID string, payload *CloudBackupActionMachinePayload) error
ResetMachineSecretKey(ctx context.Context, machineID string) (*CloudBackupExtendedMachine, error)

ActionDirectory(ctx context.Context, machineID string, payload *CloudBackupStateDirectoryAction) error
ListMachineBackupDirectories(ctx context.Context, machineID string) ([]*CloudBackupDirectory, error)
CreateBackupDirectory(ctx context.Context, machineID string, payload *CloudBackupCreateDirectoryPayload) (*CloudBackupDirectory, error)
GetBackupDirectory(ctx context.Context, machineID string, directoryID string) (*CloudBackupDirectory, error)
PatchBackupDirectory(ctx context.Context, machineID string, directoryID string, payload *CloudBackupPatchDirectoryPayload) (*CloudBackupDirectory, error)
DeleteBackupDirectory(ctx context.Context, machineID string, directoryID string, payload *CloudBackupDeleteDirectoryPayload) error
ListTenantDirectories(ctx context.Context) ([]*CloudBackupDirectory, error)
ActionBackupDirectory(ctx context.Context, machineId string, directoryId string, payload *CloudBackupActionDirectoryPayload) error
DeleteMultipleDirectories(ctx context.Context, machineId string, payload *CloudBackupDeleteMultipleDirectoriesPayload) error
ActionMultipleDirectories(ctx context.Context, machineId string, payload *CloudBackupActionMultipleDirectoriesPayload) error
ActionBackupDirectory(ctx context.Context, machineID string, directoryID string, payload *CloudBackupActionDirectoryPayload) error
DeleteMultipleDirectories(ctx context.Context, machineID string, payload *CloudBackupDeleteMultipleDirectoriesPayload) error
ActionMultipleDirectories(ctx context.Context, machineID string, payload *CloudBackupActionMultipleDirectoriesPayload) error

ListTenantPolicies(ctx context.Context) ([]*CloudBackupPolicy, error)
CreatePolicy(ctx context.Context, payload *CloudBackupCreatePolicyPayload) (*CloudBackupPolicy, error)
GetBackupDirectoryPolicy(ctx context.Context, machineId string, directoryId string) (*CloudBackupPolicy, error)
GetPolicy(ctx context.Context, policyId string) (*CloudBackupPolicy, error)
PatchPolicy(ctx context.Context, policyId string, payload *CloudBackupPatchPolicyPayload) (*CloudBackupPolicy, error)
DeletePolicy(ctx context.Context, policyId string) error
ListAppliedPolicyDirectories(ctx context.Context, policyId string) ([]*CloudBackupDirectory, error)
ActionPolicyDirectory(ctx context.Context, policyId string, payload *CloudBackupActionPolicyDirectoryPayload) error
GetBackupDirectoryPolicy(ctx context.Context, machineID string, directoryID string) (*CloudBackupPolicy, error)
GetPolicy(ctx context.Context, policyID string) (*CloudBackupPolicy, error)
PatchPolicy(ctx context.Context, policyID string, payload *CloudBackupPatchPolicyPayload) (*CloudBackupPolicy, error)
DeletePolicy(ctx context.Context, policyID string) error
ListAppliedPolicyDirectories(ctx context.Context, policyID string) ([]*CloudBackupDirectory, error)
ActionPolicyDirectory(ctx context.Context, policyID string, payload *CloudBackupActionPolicyDirectoryPayload) error
}

func (cb *cloudBackupService) dashboardPath() string {
Expand All @@ -73,12 +73,12 @@ func (cb *cloudBackupService) itemMachinePath(id string) string {
return strings.Join([]string{cb.machinesPath(), id}, "/")
}

func (cb *cloudBackupService) machineDirectoryPath(machineId string, directoryId string) string {
return strings.Join([]string{cb.machinesPath(), machineId, "directories", directoryId}, "/")
func (cb *cloudBackupService) machineDirectoryPath(machineID string, directoryID string) string {
return strings.Join([]string{cb.machinesPath(), machineID, "directories", directoryID}, "/")
}

func (cb *cloudBackupService) machineDirectoryRecoveryPointPath(machineId string, directoryId string) string {
return strings.Join([]string{cb.machineDirectoryPath(machineId, directoryId), "recovery-points"}, "/")
func (cb *cloudBackupService) machineDirectoryRecoveryPointPath(machineID string, directoryID string) string {
return strings.Join([]string{cb.machineDirectoryPath(machineID, directoryID), "recovery-points"}, "/")
}

func (cb *cloudBackupService) activityPath() string {
Expand All @@ -93,22 +93,22 @@ func (cb *cloudBackupService) policyPath() string {
return strings.Join([]string{cb.dashboardPath(), "policies"}, "/")
}

func (cb *cloudBackupService) itemPolicyPath(policyId string) string {
return strings.Join([]string{cb.policyPath(), policyId}, "/")
func (cb *cloudBackupService) itemPolicyPath(policyID string) string {
return strings.Join([]string{cb.policyPath(), policyID}, "/")
}

func (cb *cloudBackupService) recoveryPointPath() string {
return strings.Join([]string{cb.dashboardPath(), "recovery-points"}, "/")
}

func (cb *cloudBackupService) itemRecoveryPointPath(recoveryPointId string) string {
return strings.Join([]string{cb.recoveryPointPath(), recoveryPointId}, "/")
func (cb *cloudBackupService) itemRecoveryPointPath(recoveryPointID string) string {
return strings.Join([]string{cb.recoveryPointPath(), recoveryPointID}, "/")
}

func (cb *cloudBackupService) storageVaultsPath() string {
return strings.Join([]string{cb.dashboardPath(), "storage-vaults"}, "/")
}

func (cb *cloudBackupService) itemStorageVaultPath(storageVaultId string) string {
return strings.Join([]string{cb.storageVaultsPath(), storageVaultId}, "/")
func (cb *cloudBackupService) itemStorageVaultPath(storageVaultID string) string {
return strings.Join([]string{cb.storageVaultsPath(), storageVaultID}, "/")
}
12 changes: 6 additions & 6 deletions cloud_backup_activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
// CloudBackupActivity represents a Cloud Backup Activity data.
type CloudBackupActivity struct {
Action string `json:"action"`
BackupDirectoryId string `json:"backup_directory_id"`
BackupDirectoryID string `json:"backup_directory_id"`
CreatedAt string `json:"created_at"`
Id string `json:"id"`
ID string `json:"id"`
Extra string `json:"extra,omitempty"`
MachineId string `json:"machine_id"`
MachineID string `json:"machine_id"`
Message string `json:"message"`
PolicyId string `json:"policy_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
Reason string `json:"reason,omitempty"`
RecoveryPoint string `json:"recovery_point,omitempty"`
Status string `json:"status"`
TenantId string `json:"tenant_id"`
TenantID string `json:"tenant_id"`
UpdatedAt string `json:"updated_at"`
UserId string `json:"user_id"`
UserID string `json:"user_id"`
}

// CloudBackupListActivities - List Cloud Backup Activities
Expand Down
2 changes: 1 addition & 1 deletion cloud_backup_activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func TestListActivities(t *testing.T) {
activities, err := client.CloudBackup.CloudBackupListActivities(ctx)
require.NoError(t, err)
require.Equal(t, 2, len(activities))
assert.Equal(t, activities[0].BackupDirectoryId, "326bf60e-7065-478a-b4b2-9d59cf8b63aa")
assert.Equal(t, activities[0].BackupDirectoryID, "326bf60e-7065-478a-b4b2-9d59cf8b63aa")
}
Loading

0 comments on commit 419ae47

Please sign in to comment.