-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDP-57848: Implement events resource in the atlas go client #72
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,166 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const eventsPathProjects = "groups/%s/events" | ||
const eventsPathOrganization = "orgs/%s/events" | ||
|
||
// EventsService is an interface for interfacing with the Events | ||
// endpoints of the MongoDB Atlas API. | ||
// See more: https://docs.atlas.mongodb.com/reference/api/events/ | ||
type EventsService interface { | ||
ListOrganizationEvents(context.Context, string, *EventListOptions) (*EventResponse, *Response, error) | ||
GetOrganizationEvent(context.Context, string, string) (*Event, *Response, error) | ||
ListProjectEvents(context.Context, string, *ListOptions) (*EventResponse, *Response, error) | ||
GetProjectEvent(context.Context, string, string) (*Event, *Response, error) | ||
} | ||
|
||
// EventsServiceOp handles communication with the Event related methods | ||
// of the MongoDB Atlas API | ||
type EventsServiceOp struct { | ||
Client RequestDoer | ||
} | ||
|
||
var _ EventsService = &EventsServiceOp{} | ||
|
||
// Event represents an event of the MongoDB Atlas API | ||
type Event struct { | ||
AlertID string `json:"alertId"` | ||
AlertConfigID string `json:"alertConfigId"` | ||
APIKeyID string `json:"apiKeyId,omitempty"` | ||
Collection string `json:"collection,omitempty"` | ||
Created string `json:"created"` | ||
CurrentValue *CurrentValue `json:"currentValue,omitempty"` | ||
Database string `json:"database,omitempty"` | ||
EventTypeName string `json:"eventTypeName"` | ||
GroupID string `json:"groupId,omitempty"` | ||
Hostname string `json:"hostname"` | ||
ID string `json:"id"` | ||
InvoiceID string `json:"invoiceId,omitempty"` | ||
IsGlobalAdmin bool `json:"isGlobalAdmin,omitempty"` | ||
Links []*Link `json:"links"` | ||
MetricName string `json:"metricName,omitempty"` | ||
OpType string `json:"opType,omitempty"` | ||
OrgID string `json:"orgId,omitempty"` | ||
PaymentID string `json:"paymentId,omitempty"` | ||
Port int `json:"Port,omitempty"` | ||
PublicKey string `json:"publicKey,omitempty"` | ||
RemoteAddress string `json:"remoteAddress,omitempty"` | ||
ReplicaSetName string `json:"replicaSetName,omitempty"` | ||
ShardName string `json:"shardName,omitempty"` | ||
TargetPublicKey string `json:"targetPublicKey,omitempty"` | ||
TargetUsername string `json:"targetUsername,omitempty"` | ||
TeamID string `json:"teamId,omitempty"` | ||
UserID string `json:"userId,omitempty"` | ||
Username string `json:"username,omitempty"` | ||
WhitelistEntry string `json:"whitelistEntry,omitempty"` | ||
} | ||
|
||
// EventResponse is the response from the EventsService.List. | ||
type EventResponse struct { | ||
Links []*Link `json:"links,omitempty"` | ||
Results []*Event `json:"results,omitempty"` | ||
TotalCount int `json:"totalCount,omitempty"` | ||
} | ||
|
||
// EventListOptions specifies the optional parameters to the Event List methods. | ||
type EventListOptions struct { | ||
ListOptions | ||
EventType string `url:"eventType,omitempty"` | ||
MinDate string `url:"minDate,omitempty"` | ||
MaxDate string `url:"maxDate,omitempty"` | ||
} | ||
|
||
// ListOrganizationEvents lists all events in the organization associated to {ORG-ID}. | ||
// See more: https://docs.atlas.mongodb.com/reference/api/events-orgs-get-all/ | ||
func (s *EventsServiceOp) ListOrganizationEvents(ctx context.Context, orgID string, listOptions *EventListOptions) (*EventResponse, *Response, error) { | ||
path := fmt.Sprintf(eventsPathOrganization, orgID) | ||
|
||
//Add query params from listOptions | ||
path, err := setListOptions(path, listOptions) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(EventResponse) | ||
resp, err := s.Client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return root, resp, nil | ||
} | ||
|
||
// GetOrganizationEvent gets the alert specified to {EVENT-ID} from the organization associated to {ORG-ID}. | ||
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/events/get-one-event-for-org/ | ||
func (s *EventsServiceOp) GetOrganizationEvent(ctx context.Context, orgID string, eventID string) (*Event, *Response, error) { | ||
basePath := fmt.Sprintf(eventsPathOrganization, orgID) | ||
path := fmt.Sprintf("%s/%s", basePath, eventID) | ||
|
||
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(Event) | ||
resp, err := s.Client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return root, resp, err | ||
} | ||
|
||
// ListOrganizationEvents lists all events in the project associated to {PROJECT-ID}. | ||
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/events/get-all-events-for-project/ | ||
func (s *EventsServiceOp) ListProjectEvents(ctx context.Context, projectID string, listOptions *ListOptions) (*EventResponse, *Response, error) { | ||
path := fmt.Sprintf(eventsPathProjects, projectID) | ||
|
||
//Add query params from listOptions | ||
path, err := setListOptions(path, listOptions) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(EventResponse) | ||
resp, err := s.Client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return root, resp, nil | ||
} | ||
|
||
// GetOrganizationEvent gets the alert specified to {EVENT-ID} from the project associated to {PROJECT-ID}. | ||
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/events/get-one-event-for-project/ | ||
func (s *EventsServiceOp) GetProjectEvent(ctx context.Context, projectID string, eventID string) (*Event, *Response, error) { | ||
basePath := fmt.Sprintf(eventsPathProjects, projectID) | ||
path := fmt.Sprintf("%s/%s", basePath, eventID) | ||
|
||
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(Event) | ||
resp, err := s.Client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return root, resp, err | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍