Skip to content
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

feat: add pagination to listing x509 users #294

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mongodbatlas/x509_authentication_database_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const x509CustomerAuthDBUserPath = "api/atlas/v1.0/groups/%s/userSecurity"
// See more: https://docs.atlas.mongodb.com/reference/api/x509-configuration/
type X509AuthDBUsersService interface {
CreateUserCertificate(context.Context, string, string, int) (*UserCertificate, *Response, error)
GetUserCertificates(context.Context, string, string) ([]UserCertificate, *Response, error)
GetUserCertificates(context.Context, string, string, *ListOptions) ([]UserCertificate, *Response, error)
SaveConfiguration(context.Context, string, *CustomerX509) (*CustomerX509, *Response, error)
GetCurrentX509Conf(context.Context, string) (*CustomerX509, *Response, error)
DisableCustomerX509(context.Context, string) (*Response, error)
Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *X509AuthDBUsersServiceOp) CreateUserCertificate(ctx context.Context, gr
// GetUserCertificates gets a list of all Atlas-managed, unexpired certificates for a user.
//
// See more: https://docs.atlas.mongodb.com/reference/api/x509-configuration-get-certificates/
func (s *X509AuthDBUsersServiceOp) GetUserCertificates(ctx context.Context, groupID, username string) ([]UserCertificate, *Response, error) {
func (s *X509AuthDBUsersServiceOp) GetUserCertificates(ctx context.Context, groupID, username string, listOptions *ListOptions) ([]UserCertificate, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupID", "must be set")
}
Expand All @@ -120,6 +120,10 @@ func (s *X509AuthDBUsersServiceOp) GetUserCertificates(ctx context.Context, grou
}

path := fmt.Sprintf(x509AuthDBUsersPath, groupID, username)
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 {
Expand Down
9 changes: 1 addition & 8 deletions mongodbatlas/x509_authentication_database_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestX509AuthDBUsers_CreateUserCertificate(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

groupID := "1"
username := "username_test"
monthsUntilExpiration := 4

Expand Down Expand Up @@ -72,7 +71,6 @@ func TestX509AuthDBUsers_GetUserCertificates(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

groupID := "1"
username := "username_test"

mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/databaseUsers/%s/certs", groupID, username), func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -104,7 +102,7 @@ func TestX509AuthDBUsers_GetUserCertificates(t *testing.T) {
}`)
})

x509AuthDBUserCertificates, _, err := client.X509AuthDBUsers.GetUserCertificates(ctx, groupID, username)
x509AuthDBUserCertificates, _, err := client.X509AuthDBUsers.GetUserCertificates(ctx, groupID, username, nil)
if err != nil {
t.Errorf("X509AuthDBUsers.GetUserCertificates returned error: %v", err)
}
Expand Down Expand Up @@ -135,7 +133,6 @@ func TestX509AuthDBUsers_SaveConfiguration(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

groupID := "1"
customerX509Req := &CustomerX509{
Cas: "-BEGIN CERTIFICATE--MIIFCTCCAvGgAwIBAgIIb--END CERTIFICATE---BEGIN PRIVATE KEY--MIIJQgIBADANBgkqhkiG==--END PRIVATE KEY--",
}
Expand Down Expand Up @@ -179,8 +176,6 @@ func TestX509AuthDBUsers_GetCurrentX509Conf(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

groupID := "1"

mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/userSecurity", groupID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
Expand Down Expand Up @@ -209,8 +204,6 @@ func TestX509AuthDBUsers_DisableCustomerX509(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

groupID := "1"

mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/userSecurity/customerX509", groupID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
})
Expand Down