From 8410c1937b008da71e82d22e512edfdec938e541 Mon Sep 17 00:00:00 2001 From: leofigy Date: Fri, 18 Sep 2020 13:41:20 -0500 Subject: [PATCH] goclient update fix #292 #312 --- go.mod | 2 +- go.sum | 2 + .../atlas/mongodbatlas/database_users.go | 31 ++- .../atlas/mongodbatlas/ldap_configurations.go | 206 +++++++++++++++++ .../atlas/mongodbatlas/mongodbatlas.go | 4 + .../atlas/mongodbatlas/organizations.go | 7 +- .../atlas/mongodbatlas/performance_advisor.go | 209 ++++++++++++++++++ vendor/modules.txt | 2 +- 8 files changed, 457 insertions(+), 6 deletions(-) create mode 100644 vendor/go.mongodb.org/atlas/mongodbatlas/ldap_configurations.go create mode 100644 vendor/go.mongodb.org/atlas/mongodbatlas/performance_advisor.go diff --git a/go.mod b/go.mod index 131a5f3d50..4e2fe9da77 100644 --- a/go.mod +++ b/go.mod @@ -11,5 +11,5 @@ require ( github.com/spf13/cast v1.3.1 github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20200518153306-40099de47e37 github.com/terraform-providers/terraform-provider-google v1.20.1-0.20200518165017-1dd21651c496 - go.mongodb.org/atlas v0.4.1-0.20200903102338-049d0778b833 + go.mongodb.org/atlas v0.4.1-0.20200916170654-ac3833accfa2 ) diff --git a/go.sum b/go.sum index 6cff037725..fbc8e854b8 100644 --- a/go.sum +++ b/go.sum @@ -611,6 +611,8 @@ go.mongodb.org/atlas v0.4.1-0.20200820152733-8dc4a7c19a2b h1:AuAQZDrQLesdmz9mIPa go.mongodb.org/atlas v0.4.1-0.20200820152733-8dc4a7c19a2b/go.mod h1:QlKvZKT43+R6lhHlaTy2E7Q/3AoAljMI6v5apfqslIs= go.mongodb.org/atlas v0.4.1-0.20200903102338-049d0778b833 h1:gH8Ih2OacuB6qVitO+wI5EBKdbtM/YdbhJstiMR2Vfw= go.mongodb.org/atlas v0.4.1-0.20200903102338-049d0778b833/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs= +go.mongodb.org/atlas v0.4.1-0.20200916170654-ac3833accfa2 h1:qjEP4bC8yTi57jBYHtSSA8gzPN4vJl3XG23YBMXCgUg= +go.mongodb.org/atlas v0.4.1-0.20200916170654-ac3833accfa2/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/vendor/go.mongodb.org/atlas/mongodbatlas/database_users.go b/vendor/go.mongodb.org/atlas/mongodbatlas/database_users.go index c8a4dd1223..b97d7093cc 100644 --- a/vendor/go.mongodb.org/atlas/mongodbatlas/database_users.go +++ b/vendor/go.mongodb.org/atlas/mongodbatlas/database_users.go @@ -8,6 +8,16 @@ import ( const dbUsersBasePath = "groups/%s/databaseUsers" +var adminX509Type = map[string]struct{}{ + "MANAGED": {}, + "CUSTOMER": {}, +} + +var awsIAMType = map[string]struct{}{ + "USER": {}, + "ROLE": {}, +} + // DatabaseUsersService is an interface for interfacing with the Database Users // endpoints of the MongoDB Atlas API. // See more: https://docs.atlas.mongodb.com/reference/api/database-users/index.html @@ -48,6 +58,24 @@ type DatabaseUser struct { Username string `json:"username,omitempty"` } +// GetAuthDB determines the authentication database based on the type of user. +// LDAP, X509 and AWSIAM should all use $external. +// SCRAM-SHA should use admin +func (user *DatabaseUser) GetAuthDB() (name string) { + // base documentation https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/database_user + name = "admin" + _, isX509 := adminX509Type[user.X509Type] + _, isIAM := awsIAMType[user.AWSIAMType] + + isLDAP := len(user.LDAPAuthType) > 0 && user.LDAPAuthType != "NONE" + + if isX509 || isIAM || isLDAP { + name = "$external" + } + + return +} + // Scope if presents a database user only have access to the indicated resource // if none is given then it has access to all type Scope struct { @@ -158,7 +186,8 @@ func (s *DatabaseUsersServiceOp) Update(ctx context.Context, groupID, username s } basePath := fmt.Sprintf(dbUsersBasePath, groupID) - path := fmt.Sprintf("%s/admin/%s", basePath, username) + + path := fmt.Sprintf("%s/%s/%s", basePath, updateRequest.GetAuthDB(), username) req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, updateRequest) if err != nil { diff --git a/vendor/go.mongodb.org/atlas/mongodbatlas/ldap_configurations.go b/vendor/go.mongodb.org/atlas/mongodbatlas/ldap_configurations.go new file mode 100644 index 0000000000..12a3cadcda --- /dev/null +++ b/vendor/go.mongodb.org/atlas/mongodbatlas/ldap_configurations.go @@ -0,0 +1,206 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "net/http" +) + +const ( + ldapConfigurationPath = "groups/%s/userSecurity" + ldapConfigurationPathuserToDNMapping = ldapConfigurationPath + "/ldap/userToDNMapping" + ldapVerifyConfigurationPath = ldapConfigurationPath + "/ldap/verify" +) + +// LDAPConfigurationsService is an interface of the LDAP Configuration +// endpoints of the MongoDB Atlas API. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration/ +type LDAPConfigurationsService interface { + Verify(context.Context, string, *LDAP) (*LDAPConfiguration, *Response, error) + Get(context.Context, string) (*LDAPConfiguration, *Response, error) + GetStatus(context.Context, string, string) (*LDAPConfiguration, *Response, error) + Save(context.Context, string, *LDAPConfiguration) (*LDAPConfiguration, *Response, error) + Delete(context.Context, string) (*LDAPConfiguration, *Response, error) +} + +// LDAPConfigurationsServiceOp handles communication with the LDAP Configuration related methods of the MongoDB Atlas API +type LDAPConfigurationsServiceOp service + +var _ LDAPConfigurationsService = &LDAPConfigurationsServiceOp{} + +// LDAPConfiguration represents MongoDB LDAP Configuration. +type LDAPConfiguration struct { + RequestID string `json:"requestId,omitempty"` // Identifier for the Atlas project associated with the request to verify an LDAP over TLS/SSL configuration. + GroupID string `json:"groupId,omitempty"` // Unique identifier of the project that owns this alert configuration. + Request *LDAPRequest `json:"request,omitempty"` // Contains the details of the request to verify an LDAP over TLS/SSL configuration. + Status string `json:"status,omitempty"` // The current status of the LDAP over TLS/SSL configuration. + Validations []*LDAPValidation `json:"validations,omitempty"` // Array of validation messages related to the verification of the provided LDAP over TLS/SSL configuration details. + Links []*Link `json:"links,omitempty"` + LDAP *LDAP `json:"ldap,omitempty"` // Specifies the LDAP over TLS/SSL configuration details for an Atlas group. +} + +// LDAP specifies an LDAP configuration for a Atlas project. +type LDAP struct { + AuthenticationEnabled bool `json:"authenticationEnabled,omitempty"` // Specifies whether user authentication with LDAP is enabled. + AuthorizationEnabled bool `json:"authorizationEnabled,omitempty"` // The current status of the LDAP over TLS/SSL configuration. + Hostname string `json:"hostname,omitempty"` // The hostname or IP address of the LDAP server + Port int `json:"port,omitempty"` // The port to which the LDAP server listens for client connections. + BindUsername string `json:"bindUsername,omitempty"` // The user DN that Atlas uses to connect to the LDAP server. + UserToDNMapping []*UserToDNMapping `json:"userToDNMapping,omitempty"` // Maps an LDAP username for authentication to an LDAP Distinguished Name (DN). + BindPassword string `json:"bindPassword,omitempty"` // The password used to authenticate the bindUsername. + CaCertificate string `json:"caCertificate,omitempty"` // CA certificate used to verify the identify of the LDAP server. + AuthzQueryTemplate string `json:"authzQueryTemplate,omitempty"` // An LDAP query template that Atlas executes to obtain the LDAP groups to which the authenticated user belongs. +} + +// UserToDNMapping maps an LDAP username for authentication to an LDAP Distinguished Name (DN). Each document contains a match regular expression and either a substitution or ldapQuery template used to transform the LDAP username extracted from the regular expression +type UserToDNMapping struct { + Match string `json:"match,omitempty"` // A regular expression to match against a provided LDAP username. + Substitution string `json:"substitution,omitempty"` // An LDAP Distinguished Name (DN) formatting template that converts the LDAP name matched by the match regular expression into an LDAP Distinguished Name. + LDAPQuery string `json:"ldapQuery,omitempty"` // An LDAP query formatting template that inserts the LDAP name matched by the match regular expression into an LDAP query URI as specified by RFC 4515 and RFC 4516. +} + +// LDAPValidation contains an array of validation messages related to the verification of the provided LDAP over TLS/SSL configuration details. +type LDAPValidation struct { + Status string `json:"status,omitempty"` // The status of the validation. + ValidationType string `json:"validationType,omitempty"` // The type of the validation. +} + +// LDAPRequest contains the details of the request to verify an LDAP over TLS/SSL configuration. +type LDAPRequest struct { + Hostname string `json:"hostname,omitempty"` // The hostname or IP address of the LDAP server. + Port int `json:"port,omitempty"` // The port to which the LDAP server listens for client connections from Atlas. + BindUsername string `json:"bindUsername,omitempty"` // The user DN that Atlas uses to connect to the LDAP server. +} + +// Verify requests verification of an LDAP configuration. Use this endpoint to test your LDAP configuration details before saving them. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-request-verification/ +func (s *LDAPConfigurationsServiceOp) Verify(ctx context.Context, groupID string, configuration *LDAP) (*LDAPConfiguration, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if configuration == nil { + return nil, nil, NewArgError("configuration", "must be set") + } + + path := fmt.Sprintf(ldapVerifyConfigurationPath, groupID) + + req, err := s.Client.NewRequest(ctx, http.MethodPost, path, configuration) + if err != nil { + return nil, nil, err + } + + root := new(LDAPConfiguration) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetStatus retrieves the status of a request for verification of an LDAP configuration. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-verification-status/ +func (s *LDAPConfigurationsServiceOp) GetStatus(ctx context.Context, groupID, requestID string) (*LDAPConfiguration, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if requestID == "" { + return nil, nil, NewArgError("requestID", "must be set") + } + + basePath := fmt.Sprintf(ldapVerifyConfigurationPath, groupID) + path := fmt.Sprintf("%s/%s", basePath, requestID) + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(LDAPConfiguration) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// Save saves an LDAP configuration for a Atlas project. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-save/ +func (s *LDAPConfigurationsServiceOp) Save(ctx context.Context, groupID string, configuration *LDAPConfiguration) (*LDAPConfiguration, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if configuration == nil { + return nil, nil, NewArgError("configuration", "must be set") + } + + path := fmt.Sprintf(ldapConfigurationPath, groupID) + + req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, configuration) + if err != nil { + return nil, nil, err + } + + root := new(LDAPConfiguration) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// Get retrieves the current LDAP configuration for an Atlas project. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-get-current/ +func (s *LDAPConfigurationsServiceOp) Get(ctx context.Context, groupID string) (*LDAPConfiguration, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + path := fmt.Sprintf(ldapConfigurationPath, groupID) + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(LDAPConfiguration) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// Delete removes the current userToDNMapping from the LDAP configuration for an Atlas project. +// +// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-remove-usertodnmapping/ +func (s *LDAPConfigurationsServiceOp) Delete(ctx context.Context, groupID string) (*LDAPConfiguration, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + path := fmt.Sprintf(ldapConfigurationPathuserToDNMapping, groupID) + + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(LDAPConfiguration) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} diff --git a/vendor/go.mongodb.org/atlas/mongodbatlas/mongodbatlas.go b/vendor/go.mongodb.org/atlas/mongodbatlas/mongodbatlas.go index d2e81808bb..f89accd4c6 100644 --- a/vendor/go.mongodb.org/atlas/mongodbatlas/mongodbatlas.go +++ b/vendor/go.mongodb.org/atlas/mongodbatlas/mongodbatlas.go @@ -105,6 +105,8 @@ type Client struct { Search SearchService CustomAWSDNS AWSCustomDNSService Integrations IntegrationsService + LDAPConfigurations LDAPConfigurationsService + PerformanceAdvisor PerformanceAdvisorService onRequestCompleted RequestCompletionCallback } @@ -241,6 +243,8 @@ func NewClient(httpClient *http.Client) *Client { c.Search = &SearchServiceOp{Client: c} c.CustomAWSDNS = &AWSCustomDNSServiceOp{Client: c} c.Integrations = &IntegrationsServiceOp{Client: c} + c.LDAPConfigurations = &LDAPConfigurationsServiceOp{Client: c} + c.PerformanceAdvisor = &PerformanceAdvisorServiceOp{Client: c} return c } diff --git a/vendor/go.mongodb.org/atlas/mongodbatlas/organizations.go b/vendor/go.mongodb.org/atlas/mongodbatlas/organizations.go index eca4e96d43..910e52f41b 100644 --- a/vendor/go.mongodb.org/atlas/mongodbatlas/organizations.go +++ b/vendor/go.mongodb.org/atlas/mongodbatlas/organizations.go @@ -42,9 +42,10 @@ var _ OrganizationsService = &OrganizationsServiceOp{} // Organization represents the structure of an organization. type Organization struct { - ID string `json:"id,omitempty"` - Links []*Link `json:"links,omitempty"` - Name string `json:"name,omitempty"` + ID string `json:"id,omitempty"` + IsDeleted *bool `json:"isDeleted,omitempty"` + Links []*Link `json:"links,omitempty"` + Name string `json:"name,omitempty"` } // Organizations represents an array of organization diff --git a/vendor/go.mongodb.org/atlas/mongodbatlas/performance_advisor.go b/vendor/go.mongodb.org/atlas/mongodbatlas/performance_advisor.go new file mode 100644 index 0000000000..22e5ee9e4e --- /dev/null +++ b/vendor/go.mongodb.org/atlas/mongodbatlas/performance_advisor.go @@ -0,0 +1,209 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "net/http" +) + +const ( + performanceAdvisorPath = "groups/%s/processes/%s/performanceAdvisor" + performanceAdvisorNamespacesPath = performanceAdvisorPath + "/namespaces" + performanceAdvisorSlowQueryLogsPath = performanceAdvisorPath + "/slowQueryLogs" + performanceAdvisorSuggestedIndexesLogsPath = performanceAdvisorPath + "/suggestedIndexes" +) + +// PerformanceAdvisorService is an interface of the Performance Advisor +// endpoints of the MongoDB Atlas API. +// +// See more: https://docs.atlas.mongodb.com/reference/api/performance-advisor/ +type PerformanceAdvisorService interface { + GetNamespaces(context.Context, string, string, *NamespaceOptions) (*Namespaces, *Response, error) + GetSlowQueries(context.Context, string, string, *SlowQueryOptions) (*SlowQueries, *Response, error) + GetSuggestedIndexes(context.Context, string, string, *SuggestedIndexOptions) (*SuggestedIndexes, *Response, error) +} + +// PerformanceAdvisorServiceOp handles communication with the Performance Advisor related methods of the MongoDB Atlas API +type PerformanceAdvisorServiceOp service + +var _ PerformanceAdvisorService = &PerformanceAdvisorServiceOp{} + +// Namespace represents a Namespace. +type Namespace struct { + Namespace string `json:"namespace,omitempty"` // A namespace on the specified host. + Type string `json:"type,omitempty"` // The type of namespace. +} + +// Namespaces represents a list of Namespace. +type Namespaces struct { + Namespaces []*Namespace `json:"namespaces,omitempty"` +} + +// SlowQuery represents a slow query. +type SlowQuery struct { + Namespace string `json:"namespace,omitempty"` // The namespace in which the slow query ran. + Line string `json:"line,omitempty"` // The raw log line pertaining to the slow query. +} + +// SlowQueries represents a list of SlowQuery. +type SlowQueries struct { + SlowQuery []*SlowQuery `json:"slowQueries,omitempty"` // A list of documents with information about slow queries as detected by the Performance Advisor. +} + +// Shape represents a document with information about the query shapes that are served by the suggested indexes. +type Shape struct { + AvgMs float64 `json:"avgMs,omitempty"` // Average duration in milliseconds for the queries examined that match this shape. + Count int64 `json:"count,omitempty"` // Number of queries examined that match this shape. + ID string `json:"id,omitempty"` // Unique id for this shape. Exists only for the duration of the API request. + InefficiencyScore int64 `json:"inefficiencyScore,omitempty"` // Average number of documents read for every document returned by the query. + Namespace string `json:"namespace,omitempty"` // The namespace in which the slow query ran. + Operations []*Operation `json:"operations,omitempty"` // It represents documents with specific information and log lines for individual queries. +} + +// Operation represents a document with specific information and log lines for individual queries. +type Operation struct { + Raw string `json:"raw,omitempty"` // Raw log line produced by the query. + Stats Stats `json:"stats,omitempty"` // Query statistics. + Predicates []map[string]map[string]string `json:"predicates,omitempty"` // Documents containing the search criteria used by the query. +} + +// Stats represents query statistics. +type Stats struct { + MS float64 `json:"ms,omitempty"` // Duration in milliseconds of the query. + NReturned int64 `json:"nReturned,omitempty"` // Number of results returned by the query. + NScanned int64 `json:"nScanned,omitempty"` // Number of documents read by the query. + TS int64 `json:"ts,omitempty"` // Query timestamp, in seconds since epoch. +} + +// SuggestedIndex represents a suggested index. +type SuggestedIndex struct { + ID string `json:"id,omitempty"` // Unique id for this suggested index. + Impact []string `json:"impact,omitempty"` // List of unique identifiers which correspond the query shapes in this response which pertain to this suggested index. + Namespace string `json:"namespace,omitempty"` // Namespace of the suggested index. + Weight float64 `json:"weight,omitempty"` // Estimated percentage performance improvement that the suggested index would provide. + Index []map[string]int `json:"index,omitempty"` // Array of documents that specifies a key in the index and its sort order, ascending or descending. +} + +// SuggestedIndexes represents an array of suggested indexes. +type SuggestedIndexes struct { + SuggestedIndexes []*SuggestedIndex `json:"suggestedIndexes,omitempty"` // Documents with information about the indexes suggested by the Performance Advisor. + Shapes []*Shape `json:"shapes,omitempty"` // Documents with information about the query shapes that are served by the suggested indexes. + +} + +// SlowQueryOptions contains the request query parameters for the API request. +type SlowQueryOptions struct { + Namespaces string `url:"namespaces,omitempty"` // Namespaces from which to retrieve slow query logs. A namespace consists of the database and collection resource separated by a ., such as .. + NLogs int64 `url:"nLogs,omitempty"` // Maximum number of log lines to return. Defaults to 20000. + NamespaceOptions +} + +// NamespaceOptions contains the request query parameters for the API request. +type NamespaceOptions struct { + Since int64 `url:"since,omitempty"` // Point in time, specified as milliseconds since the Unix Epoch, from which you want to receive results. + Duration int64 `url:"duration,omitempty"` // Length of time from the since parameter, in milliseconds, for which you want to receive results. +} + +// SuggestedIndexOptions contains the request query parameters for the API request. +type SuggestedIndexOptions struct { + Namespaces string `url:"namespaces,omitempty"` // Namespaces from which to retrieve slow query logs. A namespace consists of the database and collection resource separated by a ., such as .. + NIndexes int64 `url:"nIndexes,omitempty"` // Maximum number of indexes to suggest. Defaults to unlimited. + NExamples int64 `url:"NExamples,omitempty"` // Maximum number of examples queries to provide that will be improved by a suggested index. Defaults to 5. + NamespaceOptions +} + +// GetNamespaces retrieves the namespaces for collections experiencing slow queries for a specified host. +// +// See more: https://docs.atlas.mongodb.com/reference/api/pa-namespaces-get-all/ +func (s *PerformanceAdvisorServiceOp) GetNamespaces(ctx context.Context, groupID, processName string, opts *NamespaceOptions) (*Namespaces, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if processName == "" { + return nil, nil, NewArgError("processName", "must be set") + } + + path := fmt.Sprintf(performanceAdvisorNamespacesPath, groupID, processName) + path, err := setListOptions(path, opts) + 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(Namespaces) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetSlowQueries gets log lines for slow queries as determined by the Performance Advisor. +// +// See more: https://docs.atlas.mongodb.com/reference/api/pa-get-slow-query-logs/ +func (s *PerformanceAdvisorServiceOp) GetSlowQueries(ctx context.Context, groupID, processName string, opts *SlowQueryOptions) (*SlowQueries, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if processName == "" { + return nil, nil, NewArgError("processName", "must be set") + } + + path := fmt.Sprintf(performanceAdvisorSlowQueryLogsPath, groupID, processName) + path, err := setListOptions(path, opts) + 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(SlowQueries) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetSuggestedIndexes gets suggested indexes as determined by the Performance Advisor. +// +// See more: https://docs.atlas.mongodb.com/reference/api/pa-suggested-indexes-get-all/ +func (s *PerformanceAdvisorServiceOp) GetSuggestedIndexes(ctx context.Context, groupID, processName string, opts *SuggestedIndexOptions) (*SuggestedIndexes, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if processName == "" { + return nil, nil, NewArgError("processName", "must be set") + } + + path := fmt.Sprintf(performanceAdvisorSuggestedIndexesLogsPath, groupID, processName) + path, err := setListOptions(path, opts) + 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(SuggestedIndexes) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0854d85391..c2abd22f2c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -476,7 +476,7 @@ github.com/zclconf/go-cty/cty/msgpack github.com/zclconf/go-cty/cty/set # github.com/zclconf/go-cty-yaml v1.0.1 github.com/zclconf/go-cty-yaml -# go.mongodb.org/atlas v0.4.1-0.20200903102338-049d0778b833 +# go.mongodb.org/atlas v0.4.1-0.20200916170654-ac3833accfa2 ## explicit go.mongodb.org/atlas/mongodbatlas # go.opencensus.io v0.22.3