Skip to content

Commit

Permalink
feat: more alias to atlas types (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn committed Oct 24, 2023
1 parent 4907ea7 commit c7d192c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 24 deletions.
18 changes: 12 additions & 6 deletions opsmngr/accesslist_api_keys.go
Expand Up @@ -22,6 +22,12 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

type (
AccessListAPIKey = atlas.AccessListAPIKey
AccessListAPIKeys = atlas.AccessListAPIKeys
AccessListAPIKeysReq = atlas.AccessListAPIKeysReq
)

const accessListAPIKeysPath = "api/public/v1.0/orgs/%s/apiKeys/%s/accessList" //nolint:gosec // This is a path

// AccessListAPIKeysServiceOp handles communication with the AccessList API keys related methods of the MongoDB Ops Manager API.
Expand All @@ -30,7 +36,7 @@ type AccessListAPIKeysServiceOp service
var _ atlas.AccessListAPIKeysService = &AccessListAPIKeysServiceOp{}

// List gets all AccessList API keys.
func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID string, listOptions *ListOptions) (*atlas.AccessListAPIKeys, *Response, error) {
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")
}
Expand All @@ -49,7 +55,7 @@ func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID s
return nil, nil, err
}

root := new(atlas.AccessListAPIKeys)
root := new(AccessListAPIKeys)
resp, err := s.Client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
Expand All @@ -63,7 +69,7 @@ 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) (*atlas.AccessListAPIKey, *Response, error) {
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")
}
Expand All @@ -81,7 +87,7 @@ func (s *AccessListAPIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID, i
return nil, nil, err
}

root := new(atlas.AccessListAPIKey)
root := new(AccessListAPIKey)
resp, err := s.Client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
Expand All @@ -91,7 +97,7 @@ 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 []*atlas.AccessListAPIKeysReq) (*atlas.AccessListAPIKeys, *Response, error) {
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")
}
Expand All @@ -109,7 +115,7 @@ func (s *AccessListAPIKeysServiceOp) Create(ctx context.Context, orgID, apiKeyID
return nil, nil, err
}

root := new(atlas.AccessListAPIKeys)
root := new(AccessListAPIKeys)
resp, err := s.Client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
Expand Down
18 changes: 12 additions & 6 deletions opsmngr/continuous_restore_jobs.go
Expand Up @@ -28,12 +28,18 @@ const continuousRestoreJobsPath = "api/public/v1.0/groups/%s/clusters/%s/restore
// of the MongoDB Ops Manager API.
type ContinuousRestoreJobsServiceOp service

type (
ContinuousJob = atlas.ContinuousJob
ContinuousJobs = atlas.ContinuousJobs
ContinuousJobRequest = atlas.ContinuousJobRequest
)

var _ atlas.ContinuousRestoreJobsService = &ContinuousRestoreJobsServiceOp{}

// List lists all continuous backup jobs in Atlas
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/restorejobs/get-all-restore-jobs-for-one-cluster/
func (s *ContinuousRestoreJobsServiceOp) List(ctx context.Context, groupID, clusterID string, opts *ListOptions) (*atlas.ContinuousJobs, *Response, error) {
func (s *ContinuousRestoreJobsServiceOp) List(ctx context.Context, groupID, clusterID string, opts *ListOptions) (*ContinuousJobs, *Response, error) {
if clusterID == "" {
return nil, nil, atlas.NewArgError("clusterID", "must be set")
}
Expand All @@ -53,7 +59,7 @@ func (s *ContinuousRestoreJobsServiceOp) List(ctx context.Context, groupID, clus
return nil, nil, err
}

root := new(atlas.ContinuousJobs)
root := new(ContinuousJobs)
resp, err := s.Client.Do(ctx, req, root)

return root, resp, err
Expand All @@ -62,7 +68,7 @@ func (s *ContinuousRestoreJobsServiceOp) List(ctx context.Context, groupID, clus
// Get gets a continuous backup job in Atlas
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/restorejobs/get-one-single-restore-job-for-one-cluster/
func (s *ContinuousRestoreJobsServiceOp) Get(ctx context.Context, groupID, clusterID, jobID string) (*atlas.ContinuousJob, *Response, error) {
func (s *ContinuousRestoreJobsServiceOp) Get(ctx context.Context, groupID, clusterID, jobID string) (*ContinuousJob, *Response, error) {
if clusterID == "" {
return nil, nil, atlas.NewArgError("clusterID", "must be set")
}
Expand All @@ -82,7 +88,7 @@ func (s *ContinuousRestoreJobsServiceOp) Get(ctx context.Context, groupID, clust
return nil, nil, err
}

root := new(atlas.ContinuousJob)
root := new(ContinuousJob)
resp, err := s.Client.Do(ctx, req, root)

return root, resp, err
Expand All @@ -91,7 +97,7 @@ func (s *ContinuousRestoreJobsServiceOp) Get(ctx context.Context, groupID, clust
// Create creates a continuous backup job in Atlas
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/restorejobs/create-one-restore-job-for-one-cluster/
func (s *ContinuousRestoreJobsServiceOp) Create(ctx context.Context, groupID, clusterID string, request *atlas.ContinuousJobRequest) (*atlas.ContinuousJobs, *Response, error) {
func (s *ContinuousRestoreJobsServiceOp) Create(ctx context.Context, groupID, clusterID string, request *ContinuousJobRequest) (*ContinuousJobs, *Response, error) {
if request == nil {
return nil, nil, atlas.NewArgError("request", "must be set")
}
Expand All @@ -110,7 +116,7 @@ func (s *ContinuousRestoreJobsServiceOp) Create(ctx context.Context, groupID, cl
return nil, nil, err
}

root := new(atlas.ContinuousJobs)
root := new(ContinuousJobs)
resp, err := s.Client.Do(ctx, req, root)

return root, resp, err
Expand Down
13 changes: 10 additions & 3 deletions opsmngr/measurements.go
Expand Up @@ -20,13 +20,20 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

type (
ProcessMeasurements = atlas.ProcessMeasurements
ProcessDiskMeasurements = atlas.ProcessDiskMeasurements
ProcessDatabaseMeasurements = atlas.ProcessDatabaseMeasurements
ProcessMeasurementListOptions = atlas.ProcessMeasurementListOptions
)

// MeasurementsService provides access to the measurement related functions in the Ops Manager API.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/measurements/
type MeasurementsService interface {
Host(context.Context, string, string, *atlas.ProcessMeasurementListOptions) (*atlas.ProcessMeasurements, *Response, error)
Disk(context.Context, string, string, string, *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDiskMeasurements, *Response, error)
Database(context.Context, string, string, string, *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDatabaseMeasurements, *Response, error)
Host(context.Context, string, string, *ProcessMeasurementListOptions) (*ProcessMeasurements, *Response, error)
Disk(context.Context, string, string, string, *ProcessMeasurementListOptions) (*ProcessDiskMeasurements, *Response, error)
Database(context.Context, string, string, string, *ProcessMeasurementListOptions) (*ProcessDatabaseMeasurements, *Response, error)
}

// MeasurementsServiceOp provides an implementation of the MeasurementsService interface.
Expand Down
2 changes: 1 addition & 1 deletion opsmngr/measurements_databases.go
Expand Up @@ -28,7 +28,7 @@ const hostDatabaseMeasurementsPath = "api/public/v1.0/groups/%s/hosts/%s/databas
// The Monitoring collects database measurements through the dbStats command.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/measures/get-database-measurements/
func (s *MeasurementsServiceOp) Database(ctx context.Context, groupID, hostID, databaseName string, opts *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDatabaseMeasurements, *Response, error) {
func (s *MeasurementsServiceOp) Database(ctx context.Context, groupID, hostID, databaseName string, opts *ProcessMeasurementListOptions) (*ProcessDatabaseMeasurements, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
}
Expand Down
2 changes: 1 addition & 1 deletion opsmngr/measurements_disks.go
Expand Up @@ -28,7 +28,7 @@ const hostDiskMeasurementsPath = "api/public/v1.0/groups/%s/hosts/%s/disks/%s/me
// You must run Ops Manager Automation to retrieve disk measurements.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/measures/get-disk-measurements/
func (s *MeasurementsServiceOp) Disk(ctx context.Context, groupID, hostID, diskName string, opts *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDiskMeasurements, *Response, error) {
func (s *MeasurementsServiceOp) Disk(ctx context.Context, groupID, hostID, diskName string, opts *ProcessMeasurementListOptions) (*ProcessDiskMeasurements, *Response, error) {
if groupID == "" {
return nil, nil, atlas.NewArgError("groupID", "must be set")
}
Expand Down
2 changes: 1 addition & 1 deletion opsmngr/measurements_hosts.go
Expand Up @@ -30,7 +30,7 @@ const (
// The Monitoring collects host measurements through the MongoDB serverStatus and dbStats commands.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/measures/get-host-process-system-measurements/
func (s *MeasurementsServiceOp) Host(ctx context.Context, projectID, hostID string, listOptions *atlas.ProcessMeasurementListOptions) (*atlas.ProcessMeasurements, *Response, error) {
func (s *MeasurementsServiceOp) Host(ctx context.Context, projectID, hostID string, listOptions *ProcessMeasurementListOptions) (*ProcessMeasurements, *Response, error) {
if projectID == "" {
return nil, nil, atlas.NewArgError("projectID", "must be set")
}
Expand Down
6 changes: 4 additions & 2 deletions opsmngr/opsmngr.go
Expand Up @@ -48,8 +48,10 @@ type (
Link = atlas.Link
APIKey = atlas.APIKey
APIKeyInput = atlas.APIKeyInput
AccessListAPIKeys = atlas.AccessListAPIKeys
AccessListAPIKeysReq = atlas.AccessListAPIKeysReq
Part = atlas.Part
Checkpoint = atlas.Checkpoint
Checkpoints = atlas.Checkpoints
SnapshotTimestamp = atlas.SnapshotTimestamp
)

type HTTPClient interface {
Expand Down
8 changes: 4 additions & 4 deletions opsmngr/organization_api_keys.go
Expand Up @@ -41,7 +41,7 @@ type APIKeysResponse struct {
// List all API-KEY in the organization associated to {ORG-ID}.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/api-keys/org/get-all-org-api-keys/
func (s *APIKeysServiceOp) List(ctx context.Context, orgID string, listOptions *ListOptions) ([]atlas.APIKey, *Response, error) {
func (s *APIKeysServiceOp) List(ctx context.Context, orgID string, listOptions *ListOptions) ([]APIKey, *Response, error) {
path := fmt.Sprintf(apiKeysOrgPath, orgID)

// Add query params from listOptions
Expand Down Expand Up @@ -71,7 +71,7 @@ func (s *APIKeysServiceOp) List(ctx context.Context, orgID string, listOptions *
// Get gets the APIKey specified to {API-KEY-ID} from the organization associated to {ORG-ID}.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/api-keys/org/get-one-org-api-key/
func (s *APIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID string) (*atlas.APIKey, *Response, error) {
func (s *APIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID string) (*APIKey, *Response, error) {
if apiKeyID == "" {
return nil, nil, atlas.NewArgError("name", "must be set")
}
Expand All @@ -97,7 +97,7 @@ func (s *APIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID string) (*at
// Create an API Key by the {ORG-ID}.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/api-keys/org/create-one-org-api-key/
func (s *APIKeysServiceOp) Create(ctx context.Context, orgID string, createRequest *atlas.APIKeyInput) (*atlas.APIKey, *Response, error) {
func (s *APIKeysServiceOp) Create(ctx context.Context, orgID string, createRequest *APIKeyInput) (*APIKey, *Response, error) {
if createRequest == nil {
return nil, nil, atlas.NewArgError("createRequest", "cannot be nil")
}
Expand All @@ -121,7 +121,7 @@ func (s *APIKeysServiceOp) Create(ctx context.Context, orgID string, createReque
// Update a API Key in the organization associated to {ORG-ID}.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/api-keys/org/update-one-org-api-key/
func (s *APIKeysServiceOp) Update(ctx context.Context, orgID, apiKeyID string, updateRequest *atlas.APIKeyInput) (*atlas.APIKey, *Response, error) {
func (s *APIKeysServiceOp) Update(ctx context.Context, orgID, apiKeyID string, updateRequest *APIKeyInput) (*APIKey, *Response, error) {
if updateRequest == nil {
return nil, nil, atlas.NewArgError("updateRequest", "cannot be nil")
}
Expand Down

0 comments on commit c7d192c

Please sign in to comment.