Skip to content

Commit

Permalink
CLOUDP-252326: Replace Atlas Link and Error structs (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
husniMDB authored Jun 20, 2024
1 parent 7164107 commit 5b0c153
Show file tree
Hide file tree
Showing 57 changed files with 418 additions and 387 deletions.
22 changes: 11 additions & 11 deletions opsmngr/accesslist_api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ var _ atlas.AccessListAPIKeysService = &AccessListAPIKeysServiceOp{}
// List gets all AccessList API keys.
func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID string, listOptions *ListOptions) (*AccessListAPIKeys, *Response, error) {
if orgID == "" {
return nil, nil, atlas.NewArgError("orgID", "must be set")
return nil, nil, NewArgError("orgID", "must be set")
}
if apiKeyID == "" {
return nil, nil, atlas.NewArgError("apiKeyID", "must be set")
return nil, nil, NewArgError("apiKeyID", "must be set")
}

path := fmt.Sprintf(accessListAPIKeysPath, orgID, apiKeyID)
Expand Down Expand Up @@ -71,13 +71,13 @@ func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID s
// Get retrieve information on a single API Key access list entry using the unique identifier for the API Key and desired permitted address.
func (s *AccessListAPIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID, ipAddress string) (*AccessListAPIKey, *Response, error) {
if orgID == "" {
return nil, nil, atlas.NewArgError("orgID", "must be set")
return nil, nil, NewArgError("orgID", "must be set")
}
if apiKeyID == "" {
return nil, nil, atlas.NewArgError("apiKeyID", "must be set")
return nil, nil, NewArgError("apiKeyID", "must be set")
}
if ipAddress == "" {
return nil, nil, atlas.NewArgError("ipAddress", "must be set")
return nil, nil, NewArgError("ipAddress", "must be set")
}

path := fmt.Sprintf(accessListAPIKeysPath+"/%s", orgID, apiKeyID, ipAddress)
Expand All @@ -99,13 +99,13 @@ func (s *AccessListAPIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID, i
// Create one or more new access list entries for the specified API Key.
func (s *AccessListAPIKeysServiceOp) Create(ctx context.Context, orgID, apiKeyID string, createRequest []*AccessListAPIKeysReq) (*AccessListAPIKeys, *Response, error) {
if orgID == "" {
return nil, nil, atlas.NewArgError("orgID", "must be set")
return nil, nil, NewArgError("orgID", "must be set")
}
if apiKeyID == "" {
return nil, nil, atlas.NewArgError("apiKeyID", "must be set")
return nil, nil, NewArgError("apiKeyID", "must be set")
}
if createRequest == nil {
return nil, nil, atlas.NewArgError("createRequest", "cannot be nil")
return nil, nil, NewArgError("createRequest", "cannot be nil")
}

path := fmt.Sprintf(accessListAPIKeysPath, orgID, apiKeyID)
Expand All @@ -127,13 +127,13 @@ func (s *AccessListAPIKeysServiceOp) Create(ctx context.Context, orgID, apiKeyID
// Delete deletes the AccessList API keys.
func (s *AccessListAPIKeysServiceOp) Delete(ctx context.Context, orgID, apiKeyID, ipAddress string) (*Response, error) {
if orgID == "" {
return nil, atlas.NewArgError("orgID", "must be set")
return nil, NewArgError("orgID", "must be set")
}
if apiKeyID == "" {
return nil, atlas.NewArgError("apiKeyID", "must be set")
return nil, NewArgError("apiKeyID", "must be set")
}
if ipAddress == "" {
return nil, atlas.NewArgError("ipAddress", "must be set")
return nil, NewArgError("ipAddress", "must be set")
}

path := fmt.Sprintf(accessListAPIKeysPath+"/%s", orgID, apiKeyID, ipAddress)
Expand Down
30 changes: 14 additions & 16 deletions opsmngr/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand Down Expand Up @@ -60,19 +58,19 @@ type Agent struct {

// Agents is a paginated collection of Agent.
type Agents struct {
Links []*atlas.Link `json:"links"`
Results []*Agent `json:"results"`
TotalCount int `json:"totalCount"`
Links []*Link `json:"links"`
Results []*Agent `json:"results"`
TotalCount int `json:"totalCount"`
}

// SoftwareVersions is a set of software components and their expected current and minimum versions.
type SoftwareVersions struct {
AutomationVersion string `json:"automationVersion"`
AutomationMinimumVersion string `json:"automationMinimumVersion"`
BiConnectorVersion string `json:"biConnectorVersion"`
BiConnectorMinimumVersion string `json:"biConnectorMinimumVersion"`
Links []*atlas.Link `json:"links"`
MongoDBToolsVersion string `json:"mongoDbToolsVersion"`
AutomationVersion string `json:"automationVersion"`
AutomationMinimumVersion string `json:"automationMinimumVersion"`
BiConnectorVersion string `json:"biConnectorVersion"`
BiConnectorMinimumVersion string `json:"biConnectorMinimumVersion"`
Links []*Link `json:"links"`
MongoDBToolsVersion string `json:"mongoDbToolsVersion"`
}

// AgentVersions is a set of available agents and agent versions for a project.
Expand All @@ -82,7 +80,7 @@ type AgentVersions struct {
IsAnyAgentNotManaged bool `json:"isAnyAgentNotManaged"`
IsAnyAgentVersionDeprecated bool `json:"isAnyAgentVersionDeprecated"`
IsAnyAgentVersionOld bool `json:"isAnyAgentVersionOld"`
Links []*atlas.Link `json:"links"`
Links []*Link `json:"links"`
MinimumAgentVersionDetected string `json:"minimumAgentVersionDetected"`
MinimumVersion string `json:"minimumVersion"`
}
Expand Down Expand Up @@ -112,7 +110,7 @@ type AgentVersion struct {
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agents-get-all/
func (s *AgentsServiceOp) ListAgentLinks(ctx context.Context, groupID string) (*Agents, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
path := fmt.Sprintf(agentsBasePath, groupID)

Expand All @@ -135,10 +133,10 @@ func (s *AgentsServiceOp) ListAgentLinks(ctx context.Context, groupID string) (*
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agents-get-by-type/
func (s *AgentsServiceOp) ListAgentsByType(ctx context.Context, groupID, agentType string, listOptions *ListOptions) (*Agents, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if agentType == "" {
return nil, nil, atlas.NewArgError("agentType", "must be set")
return nil, nil, NewArgError("agentType", "must be set")
}
basePath := fmt.Sprintf(agentsBasePath, groupID)
path, err := setQueryParams(fmt.Sprintf("%s/%s", basePath, agentType), listOptions)
Expand Down Expand Up @@ -183,7 +181,7 @@ func (s *AgentsServiceOp) GlobalVersions(ctx context.Context) (*SoftwareVersions
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agents/get-agent-versions-per-project/
func (s *AgentsServiceOp) ProjectVersions(ctx context.Context, groupID string) (*AgentVersions, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
basePath := fmt.Sprintf(agentsBasePath, groupID)
path := fmt.Sprintf("%s/versions", basePath)
Expand Down
10 changes: 4 additions & 6 deletions opsmngr/agents_api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand Down Expand Up @@ -47,7 +45,7 @@ type AgentAPIKeysRequest struct {
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agentapikeys/create-one-agent-api-key/
func (s *AgentsServiceOp) CreateAgentAPIKey(ctx context.Context, projectID string, agent *AgentAPIKeysRequest) (*AgentAPIKey, *Response, error) {
if projectID == "" {
return nil, nil, atlas.NewArgError("projectID", "must be set")
return nil, nil, NewArgError("projectID", "must be set")
}
path := fmt.Sprintf(agentAPIKeysBasePath, projectID)

Expand All @@ -70,7 +68,7 @@ func (s *AgentsServiceOp) CreateAgentAPIKey(ctx context.Context, projectID strin
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agentapikeys/get-all-agent-api-keys-for-project/
func (s *AgentsServiceOp) ListAgentAPIKeys(ctx context.Context, projectID string) ([]*AgentAPIKey, *Response, error) {
if projectID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
path := fmt.Sprintf(agentAPIKeysBasePath, projectID)

Expand All @@ -94,10 +92,10 @@ func (s *AgentsServiceOp) ListAgentAPIKeys(ctx context.Context, projectID string
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/agentapikeys/delete-one-agent-api-key/
func (s *AgentsServiceOp) DeleteAgentAPIKey(ctx context.Context, projectID, agentAPIKey string) (*Response, error) {
if projectID == "" {
return nil, atlas.NewArgError("projectID", "must be set")
return nil, NewArgError("projectID", "must be set")
}
if agentAPIKey == "" {
return nil, atlas.NewArgError("agentAPIKey", "must be set")
return nil, NewArgError("agentAPIKey", "must be set")
}
basePath := fmt.Sprintf(agentAPIKeysBasePath, projectID)
path := fmt.Sprintf("%s/%s", basePath, agentAPIKey)
Expand Down
9 changes: 4 additions & 5 deletions opsmngr/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

"github.com/go-test/deep"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

func TestAgentsServiceOp_ListAgentLinks(t *testing.T) {
Expand Down Expand Up @@ -67,7 +66,7 @@ func TestAgentsServiceOp_ListAgentLinks(t *testing.T) {
}

expected := &Agents{
Links: []*atlas.Link{
Links: []*Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5e66185d917b220fbd8bb4d1/agents",
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestAgentsServiceOp_ListAgentsByType(t *testing.T) {
}

expected := &Agents{
Links: []*atlas.Link{},
Links: []*Link{},
Results: []*Agent{
{
TypeName: "MONITORING",
Expand Down Expand Up @@ -191,7 +190,7 @@ func TestAgentsServiceOp_GlobalVersions(t *testing.T) {
BiConnectorVersion: "2.3.4",
BiConnectorMinimumVersion: "2.3.1",
MongoDBToolsVersion: "100.0.1",
Links: []*atlas.Link{
Links: []*Link{
{
Rel: "self",
Href: "http://mms:9080/api/public/v1.0/softwareComponents/versions",
Expand Down Expand Up @@ -246,7 +245,7 @@ func TestAgentsServiceOp_ProjectVersions(t *testing.T) {
IsAnyAgentNotManaged: false,
IsAnyAgentVersionDeprecated: false,
IsAnyAgentVersionOld: false,
Links: []*atlas.Link{
Links: []*Link{
{
Href: "http://mms:9080/api/public/v1.0/groups/5e66185d917b220fbd8bb4d1/agents/current",
Rel: "self",
Expand Down
28 changes: 14 additions & 14 deletions opsmngr/alert_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ type (
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-create-config/
func (s *AlertConfigurationsServiceOp) Create(ctx context.Context, groupID string, createReq *AlertConfiguration) (*AlertConfiguration, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if createReq == nil {
return nil, nil, atlas.NewArgError("createReq", "cannot be nil")
return nil, nil, NewArgError("createReq", "cannot be nil")
}

path := fmt.Sprintf(alertConfigurationPath, groupID)
Expand All @@ -69,10 +69,10 @@ func (s *AlertConfigurationsServiceOp) Create(ctx context.Context, groupID strin
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-enable-disable-config/
func (s *AlertConfigurationsServiceOp) EnableAnAlertConfig(ctx context.Context, groupID, alertConfigID string, enabled *bool) (*AlertConfiguration, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if alertConfigID == "" {
return nil, nil, atlas.NewArgError("alertConfigID", "must be set")
return nil, nil, NewArgError("alertConfigID", "must be set")
}

basePath := fmt.Sprintf(alertConfigurationPath, groupID)
Expand All @@ -97,10 +97,10 @@ func (s *AlertConfigurationsServiceOp) EnableAnAlertConfig(ctx context.Context,
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-get-config/
func (s *AlertConfigurationsServiceOp) GetAnAlertConfig(ctx context.Context, groupID, alertConfigID string) (*AlertConfiguration, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if alertConfigID == "" {
return nil, nil, atlas.NewArgError("alertConfigID", "must be set")
return nil, nil, NewArgError("alertConfigID", "must be set")
}

basePath := fmt.Sprintf(alertConfigurationPath, groupID)
Expand All @@ -125,10 +125,10 @@ func (s *AlertConfigurationsServiceOp) GetAnAlertConfig(ctx context.Context, gro
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-get-open-alerts/
func (s *AlertConfigurationsServiceOp) GetOpenAlertsConfig(ctx context.Context, groupID, alertConfigID string) ([]AlertConfiguration, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if alertConfigID == "" {
return nil, nil, atlas.NewArgError("alertConfigID", "must be set")
return nil, nil, NewArgError("alertConfigID", "must be set")
}

basePath := fmt.Sprintf(alertConfigurationPath, groupID)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (s *AlertConfigurationsServiceOp) GetOpenAlertsConfig(ctx context.Context,
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-get-all-configs/
func (s *AlertConfigurationsServiceOp) List(ctx context.Context, groupID string, listOptions *ListOptions) ([]AlertConfiguration, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}

path := fmt.Sprintf(alertConfigurationPath, groupID)
Expand Down Expand Up @@ -190,13 +190,13 @@ func (s *AlertConfigurationsServiceOp) List(ctx context.Context, groupID string,
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-update-config/
func (s *AlertConfigurationsServiceOp) Update(ctx context.Context, groupID, alertConfigID string, updateReq *AlertConfiguration) (*AlertConfiguration, *Response, error) {
if updateReq == nil {
return nil, nil, atlas.NewArgError("updateRequest", "cannot be nil")
return nil, nil, NewArgError("updateRequest", "cannot be nil")
}
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if alertConfigID == "" {
return nil, nil, atlas.NewArgError("alertConfigID", "must be set")
return nil, nil, NewArgError("alertConfigID", "must be set")
}

basePath := fmt.Sprintf(alertConfigurationPath, groupID)
Expand All @@ -221,10 +221,10 @@ func (s *AlertConfigurationsServiceOp) Update(ctx context.Context, groupID, aler
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alert-configurations-delete-config/
func (s *AlertConfigurationsServiceOp) Delete(ctx context.Context, groupID, alertConfigID string) (*Response, error) {
if groupID == "" {
return nil, atlas.NewArgError("groupID", "must be set")
return nil, NewArgError("groupID", "must be set")
}
if alertConfigID == "" {
return nil, atlas.NewArgError("alertConfigID", "must be set")
return nil, NewArgError("alertConfigID", "must be set")
}

basePath := fmt.Sprintf(alertConfigurationPath, groupID)
Expand Down
12 changes: 6 additions & 6 deletions opsmngr/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type (
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alerts-get-alert/
func (s *AlertsServiceOp) Get(ctx context.Context, groupID, alertID string) (*Alert, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
if alertID == "" {
return nil, nil, atlas.NewArgError("alertID", "must be set")
return nil, nil, NewArgError("alertID", "must be set")
}

basePath := fmt.Sprintf(alertPath, groupID)
Expand All @@ -69,7 +69,7 @@ func (s *AlertsServiceOp) Get(ctx context.Context, groupID, alertID string) (*Al
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alerts-get-all-alerts/
func (s *AlertsServiceOp) List(ctx context.Context, groupID string, listOptions *AlertsListOptions) (*AlertsResponse, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}

path := fmt.Sprintf(alertPath, groupID)
Expand Down Expand Up @@ -103,15 +103,15 @@ func (s *AlertsServiceOp) List(ctx context.Context, groupID string, listOptions
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/alerts-acknowledge-alert/
func (s *AlertsServiceOp) Acknowledge(ctx context.Context, groupID, alertID string, params *AcknowledgeRequest) (*Alert, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}

if alertID == "" {
return nil, nil, atlas.NewArgError("alertID", "must be set")
return nil, nil, NewArgError("alertID", "must be set")
}

if params == nil {
return nil, nil, atlas.NewArgError("params", "must be set")
return nil, nil, NewArgError("params", "must be set")
}

basePath := fmt.Sprintf(alertPath, groupID)
Expand Down
4 changes: 1 addition & 3 deletions opsmngr/automation_agent_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

// UpdateAgentVersion updates the MongoDB Agent and tools to the latest versions available at the time of the request.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/automation-config/#update-agend-versions-example
func (s *AutomationServiceOp) UpdateAgentVersion(ctx context.Context, groupID string) (*AutomationConfigAgent, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}

basePath := fmt.Sprintf(automationConfigBasePath, groupID)
Expand Down
4 changes: 2 additions & 2 deletions opsmngr/automation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/automation-config/#get-the-automation-configuration
func (s *AutomationServiceOp) GetConfig(ctx context.Context, groupID string) (*AutomationConfig, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
return nil, nil, NewArgError("groupID", "must be set")
}
basePath := fmt.Sprintf(automationConfigBasePath, groupID)

Expand All @@ -52,7 +52,7 @@ func (s *AutomationServiceOp) GetConfig(ctx context.Context, groupID string) (*A
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/automation-config/#update-the-automation-configuration
func (s *AutomationServiceOp) UpdateConfig(ctx context.Context, groupID string, updateRequest *AutomationConfig) (*Response, error) {
if groupID == "" {
return nil, atlas.NewArgError("groupID", "must be set")
return nil, NewArgError("groupID", "must be set")
}
basePath := fmt.Sprintf(automationConfigBasePath, groupID)

Expand Down
Loading

0 comments on commit 5b0c153

Please sign in to comment.