Skip to content

Commit

Permalink
feat (User Management): add query params search and include_settings …
Browse files Browse the repository at this point in the history
…to list_users operation (#246)

Signed-off-by: David Lim <David.Lim0305@ibm.com>
  • Loading branch information
PureMathematics authored Apr 28, 2023
1 parent 14decd5 commit 9393079
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 19 deletions.
36 changes: 32 additions & 4 deletions usermanagementv1/user_management_v1.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2022.
* (C) Copyright IBM Corp. 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.60.2-95dc7721-20221102-203229
* IBM OpenAPI SDK Code Generator Version: 3.70.0-7df966bf-20230419-195904
*/

// Package usermanagementv1 : Operations and models for the UserManagementV1 service
Expand All @@ -28,7 +28,6 @@ import (
"net/http"
"reflect"
"time"

"github.com/IBM/go-sdk-core/v5/core"
common "github.com/IBM/platform-services-go-sdk/common"
)
Expand Down Expand Up @@ -166,7 +165,8 @@ func (userManagement *UserManagementV1) DisableRetries() {
// role. If restricted view is enabled and user has the viewer, editor, or administrator role on the user management
// service, the API returns all users in the account. If unrestricted view is enabled and the user does not have these
// roles, the API returns only the current user. Users are returned in a paginated list with a default limit of 100
// users. You can iterate through all users by following the `next_url` field.
// users. You can iterate through all users by following the `next_url` field. Additional substring search fields are
// supported to filter the users.
func (userManagement *UserManagementV1) ListUsers(listUsersOptions *ListUsersOptions) (result *UserList, response *core.DetailedResponse, err error) {
return userManagement.ListUsersWithContext(context.Background(), listUsersOptions)
}
Expand Down Expand Up @@ -207,6 +207,12 @@ func (userManagement *UserManagementV1) ListUsersWithContext(ctx context.Context
if listUsersOptions.Limit != nil {
builder.AddQuery("limit", fmt.Sprint(*listUsersOptions.Limit))
}
if listUsersOptions.IncludeSettings != nil {
builder.AddQuery("include_settings", fmt.Sprint(*listUsersOptions.IncludeSettings))
}
if listUsersOptions.Search != nil {
builder.AddQuery("search", fmt.Sprint(*listUsersOptions.Search))
}
if listUsersOptions.Start != nil {
builder.AddQuery("_start", fmt.Sprint(*listUsersOptions.Start))
}
Expand Down Expand Up @@ -994,6 +1000,16 @@ type ListUsersOptions struct {
// The number of results to be returned.
Limit *int64 `json:"limit,omitempty"`

// The user settings to be returned. Set to true to view language, allowed IP address, and authentication settings.
IncludeSettings *bool `json:"include_settings,omitempty"`

// The desired search results to be returned. To view the list of users with the additional search filter, use the
// following query options: `firstname`, `lastname`, `email`, `state`, `substate`, `iam_id`, `realm`, and `userId`.
// HTML URL encoding for the search query and `:` must be used. For example, search=state%3AINVALID returns a list of
// invalid users. Multiple search queries can be combined to obtain `OR` results using `,` operator (not URL encoded).
// For example, search=state%3AINVALID,email%3Amail.test.ibm.com.
Search *string `json:"search,omitempty"`

// An optional token that indicates the beginning of the page of results to be returned. If omitted, the first page of
// results is returned. This value is obtained from the 'next_url' field of the operation response.
Start *string `json:"_start,omitempty"`
Expand Down Expand Up @@ -1024,6 +1040,18 @@ func (_options *ListUsersOptions) SetLimit(limit int64) *ListUsersOptions {
return _options
}

// SetIncludeSettings : Allow user to set IncludeSettings
func (_options *ListUsersOptions) SetIncludeSettings(includeSettings bool) *ListUsersOptions {
_options.IncludeSettings = core.BoolPtr(includeSettings)
return _options
}

// SetSearch : Allow user to set Search
func (_options *ListUsersOptions) SetSearch(search string) *ListUsersOptions {
_options.Search = core.StringPtr(search)
return _options
}

// SetStart : Allow user to set Start
func (_options *ListUsersOptions) SetStart(start string) *ListUsersOptions {
_options.Start = core.StringPtr(start)
Expand Down
10 changes: 5 additions & 5 deletions usermanagementv1/user_management_v1_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ package usermanagementv1_test
import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/usermanagementv1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
"time"
)

var _ = Describe(`UserManagementV1 Examples Tests`, func() {
Expand Down Expand Up @@ -192,14 +191,15 @@ var _ = Describe(`UserManagementV1 Examples Tests`, func() {
fmt.Println("\nListUsers() result:")
// begin-list_users
listUsersOptions := &usermanagementv1.ListUsersOptions{
AccountID: &accountID,
AccountID: &accountID,
IncludeSettings: core.BoolPtr(true),
Search: core.StringPtr("state:ACTIVE"),
}

pager, err := userManagementService.NewUsersPager(listUsersOptions)
if err != nil {
panic(err)
}

var allResults []usermanagementv1.UserProfile
for pager.HasNext() {
nextPage, err := pager.GetNext()
Expand Down
74 changes: 66 additions & 8 deletions usermanagementv1/user_management_v1_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ package usermanagementv1_test

import (
"fmt"
"log"
"os"
"time"

"github.com/IBM/go-sdk-core/v5/core"
common "github.com/IBM/platform-services-go-sdk/common"
"github.com/IBM/platform-services-go-sdk/usermanagementv1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"log"
"os"
"time"
)

/**
Expand Down Expand Up @@ -159,10 +158,9 @@ var _ = Describe(`UserManagementV1 Integration Tests`, func() {
It(`UpdateUserSettings(updateUserSettingsOptions *UpdateUserSettingsOptions)`, func() {

updateUserSettingsOptions := &usermanagementv1.UpdateUserSettingsOptions{
AccountID: &accountID,
IamID: &userID,
AllowedIPAddresses: core.StringPtr("32.96.110.50,172.16.254.1"),
SelfManage: core.BoolPtr(true),
AccountID: &accountID,
IamID: &userID,
SelfManage: core.BoolPtr(true),
}

response, err := userManagementService.UpdateUserSettings(updateUserSettingsOptions)
Expand Down Expand Up @@ -205,6 +203,66 @@ var _ = Describe(`UserManagementV1 Integration Tests`, func() {

fmt.Fprintf(GinkgoWriter, "Received a total of %d user profiles.\n", len(results))
})
It(`ListUsers(listUsersOptions *ListUsersOptions) using search`, func() {

results := []usermanagementv1.UserProfile{}
var moreResults bool = true
var pageStart *string = nil
for moreResults {
listUsersOptions := &usermanagementv1.ListUsersOptions{
AccountID: &accountID,
Search: core.StringPtr("state:ACTIVE"),
Start: pageStart,
}
result, response, err := userManagementService.ListUsers(listUsersOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(result).ToNot(BeNil())
// fmt.Fprintf(GinkgoWriter, "ListUsers() result:\n%s\n", common.ToJSON(result))

results = append(results, result.Resources...)

if result.NextURL != nil {
pageStart, err = core.GetQueryParam(result.NextURL, "_start")
Expect(err).To(BeNil())
} else {
moreResults = false
}
}

fmt.Fprintf(GinkgoWriter, "Received a total of %d user profiles.\n", len(results))
})
It(`ListUsers(listUsersOptions *ListUsersOptions) using include_settings`, func() {

results := []usermanagementv1.UserProfile{}
var moreResults bool = true
var pageStart *string = nil

for moreResults {
listUsersOptions := &usermanagementv1.ListUsersOptions{
AccountID: &accountID,
IncludeSettings: core.BoolPtr(true),
Limit: core.Int64Ptr(10),
Start: pageStart,
}
result, response, err := userManagementService.ListUsers(listUsersOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(result).ToNot(BeNil())
// fmt.Fprintf(GinkgoWriter, "ListUsers() result:\n%s\n", common.ToJSON(result))

results = append(results, result.Resources...)

if result.NextURL != nil {
pageStart, err = core.GetQueryParam(result.NextURL, "_start")
Expect(err).To(BeNil())
} else {
moreResults = false
}
}

fmt.Fprintf(GinkgoWriter, "Received a total of %d user profiles.\n", len(results))
})
It(`ListUsers(listUsersOptions *ListUsersOptions) using UsersPager`, func() {
listUsersOptions := &usermanagementv1.ListUsersOptions{
AccountID: &accountID,
Expand Down
2 changes: 1 addition & 1 deletion usermanagementv1/user_management_v1_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2021.
* (C) Copyright IBM Corp. 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
26 changes: 25 additions & 1 deletion usermanagementv1/user_management_v1_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2022.
* (C) Copyright IBM Corp. 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -174,6 +174,8 @@ var _ = Describe(`UserManagementV1`, func() {
Expect(req.URL.EscapedPath()).To(Equal(listUsersPath))
Expect(req.Method).To(Equal("GET"))
Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))}))
// TODO: Add check for include_settings query parameter
Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"}))
res.Header().Set("Content-type", "application/json")
Expand All @@ -193,6 +195,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := new(usermanagementv1.ListUsersOptions)
listUsersOptionsModel.AccountID = core.StringPtr("testString")
listUsersOptionsModel.Limit = core.Int64Ptr(int64(10))
listUsersOptionsModel.IncludeSettings = core.BoolPtr(true)
listUsersOptionsModel.Search = core.StringPtr("testString")
listUsersOptionsModel.Start = core.StringPtr("testString")
listUsersOptionsModel.UserID = core.StringPtr("testString")
listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
Expand Down Expand Up @@ -226,6 +230,8 @@ var _ = Describe(`UserManagementV1`, func() {
Expect(req.Method).To(Equal("GET"))

Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))}))
// TODO: Add check for include_settings query parameter
Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"}))
// Sleep a short time to support a timeout test
Expand All @@ -250,6 +256,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := new(usermanagementv1.ListUsersOptions)
listUsersOptionsModel.AccountID = core.StringPtr("testString")
listUsersOptionsModel.Limit = core.Int64Ptr(int64(10))
listUsersOptionsModel.IncludeSettings = core.BoolPtr(true)
listUsersOptionsModel.Search = core.StringPtr("testString")
listUsersOptionsModel.Start = core.StringPtr("testString")
listUsersOptionsModel.UserID = core.StringPtr("testString")
listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
Expand Down Expand Up @@ -289,6 +297,8 @@ var _ = Describe(`UserManagementV1`, func() {
Expect(req.Method).To(Equal("GET"))

Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))}))
// TODO: Add check for include_settings query parameter
Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"}))
// Set mock response
Expand All @@ -315,6 +325,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := new(usermanagementv1.ListUsersOptions)
listUsersOptionsModel.AccountID = core.StringPtr("testString")
listUsersOptionsModel.Limit = core.Int64Ptr(int64(10))
listUsersOptionsModel.IncludeSettings = core.BoolPtr(true)
listUsersOptionsModel.Search = core.StringPtr("testString")
listUsersOptionsModel.Start = core.StringPtr("testString")
listUsersOptionsModel.UserID = core.StringPtr("testString")
listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
Expand All @@ -338,6 +350,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := new(usermanagementv1.ListUsersOptions)
listUsersOptionsModel.AccountID = core.StringPtr("testString")
listUsersOptionsModel.Limit = core.Int64Ptr(int64(10))
listUsersOptionsModel.IncludeSettings = core.BoolPtr(true)
listUsersOptionsModel.Search = core.StringPtr("testString")
listUsersOptionsModel.Start = core.StringPtr("testString")
listUsersOptionsModel.UserID = core.StringPtr("testString")
listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
Expand Down Expand Up @@ -382,6 +396,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := new(usermanagementv1.ListUsersOptions)
listUsersOptionsModel.AccountID = core.StringPtr("testString")
listUsersOptionsModel.Limit = core.Int64Ptr(int64(10))
listUsersOptionsModel.IncludeSettings = core.BoolPtr(true)
listUsersOptionsModel.Search = core.StringPtr("testString")
listUsersOptionsModel.Start = core.StringPtr("testString")
listUsersOptionsModel.UserID = core.StringPtr("testString")
listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
Expand Down Expand Up @@ -457,6 +473,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := &usermanagementv1.ListUsersOptions{
AccountID: core.StringPtr("testString"),
Limit: core.Int64Ptr(int64(10)),
IncludeSettings: core.BoolPtr(true),
Search: core.StringPtr("testString"),
UserID: core.StringPtr("testString"),
}

Expand Down Expand Up @@ -484,6 +502,8 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := &usermanagementv1.ListUsersOptions{
AccountID: core.StringPtr("testString"),
Limit: core.Int64Ptr(int64(10)),
IncludeSettings: core.BoolPtr(true),
Search: core.StringPtr("testString"),
UserID: core.StringPtr("testString"),
}

Expand Down Expand Up @@ -1840,12 +1860,16 @@ var _ = Describe(`UserManagementV1`, func() {
listUsersOptionsModel := userManagementService.NewListUsersOptions(accountID)
listUsersOptionsModel.SetAccountID("testString")
listUsersOptionsModel.SetLimit(int64(10))
listUsersOptionsModel.SetIncludeSettings(true)
listUsersOptionsModel.SetSearch("testString")
listUsersOptionsModel.SetStart("testString")
listUsersOptionsModel.SetUserID("testString")
listUsersOptionsModel.SetHeaders(map[string]string{"foo": "bar"})
Expect(listUsersOptionsModel).ToNot(BeNil())
Expect(listUsersOptionsModel.AccountID).To(Equal(core.StringPtr("testString")))
Expect(listUsersOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10))))
Expect(listUsersOptionsModel.IncludeSettings).To(Equal(core.BoolPtr(true)))
Expect(listUsersOptionsModel.Search).To(Equal(core.StringPtr("testString")))
Expect(listUsersOptionsModel.Start).To(Equal(core.StringPtr("testString")))
Expect(listUsersOptionsModel.UserID).To(Equal(core.StringPtr("testString")))
Expect(listUsersOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
Expand Down

0 comments on commit 9393079

Please sign in to comment.