Skip to content

Commit a26b876

Browse files
authored
[WR-175] change search access request signature (#77)
* changes multiple filter array arguments to be a single filters object
1 parent d276971 commit a26b876

File tree

6 files changed

+33
-105
lines changed

6 files changed

+33
-105
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ API_URL=https://dev.e3db.com
55
CLIENT_REGISTRATION_TOKEN=<existing_client_token_here>
66
ID_REALM_NAME=<existing_realm_name_here>
77
ID_APP_NAME=account
8-
TEST_TOZID_GROUP_ID=<existing_group_id_here>
8+
TEST_TOZID_GROUP_ID=<existing_group_id_that_has_access_policy_here>

__tests__/identity.test.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ describe('Tozny identity client', () => {
173173
)
174174

175175
// search for requests this client made!
176-
const searchByRequestorIDsParams = [identity.storage.config.clientId]
177-
176+
const filters = {
177+
requestorIds: [identity.storage.config.clientId],
178+
}
178179
// NOTE: fails due to "Group must have only 1 access policy" but we have none
179180
// create in 'Manage Realm' via UI to setup policy record
180181
const searchResults = await ops.searchAccessRequests(
181182
realmConfig,
182183
identity,
183-
searchByRequestorIDsParams,
184-
null, // searchByGroupIDsParams
184+
filters,
185185
0, // next token
186186
10 // limit
187187
)
@@ -258,11 +258,8 @@ describe('Tozny identity client', () => {
258258
accessRequestId: createdAccessRequest.id,
259259
comment: 'COMMENT',
260260
}
261-
await ops.approveAccessRequests(
262-
realmConfig,
263-
identity,
264-
realmName,
265-
[approval]
266-
)
261+
await ops.approveAccessRequests(realmConfig, identity, realmName, [
262+
approval,
263+
])
267264
})
268265
})

__tests__/utils/operations.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,20 +1276,12 @@ module.exports = {
12761276
)
12771277
return JSON.parse(result)
12781278
},
1279-
async searchAccessRequests(
1280-
config,
1281-
user,
1282-
searchByRequestorIDsParams,
1283-
searchByGroupIDsParams,
1284-
nextToken,
1285-
limit
1286-
) {
1279+
async searchAccessRequests(config, user, filters, nextToken, limit) {
12871280
const result = await runInEnvironment(
12881281
async function (
12891282
realmJSON,
12901283
userJSON,
1291-
searchByRequestorIDsParamsJSON,
1292-
searchByGroupIDsParamsJSON,
1284+
filtersJSON,
12931285
nextTokenJson,
12941286
limitJSON
12951287
) {
@@ -1302,18 +1294,12 @@ module.exports = {
13021294
)
13031295
const user = realm.fromObject(userJSON)
13041296
return user
1305-
.searchAccessRequests(
1306-
searchByRequestorIDsParamsJSON,
1307-
searchByGroupIDsParamsJSON,
1308-
nextTokenJson,
1309-
limitJSON
1310-
)
1297+
.searchAccessRequests(filtersJSON, nextTokenJson, limitJSON)
13111298
.then(JSON.stringify)
13121299
},
13131300
JSON.stringify(config),
13141301
user.stringify(),
1315-
searchByRequestorIDsParams,
1316-
searchByGroupIDsParams,
1302+
filters,
13171303
nextToken,
13181304
limit
13191305
)

lib/identity/client.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,30 +1183,30 @@ class Client extends PartialClient {
11831183
* searchAccessRequests allows for searching for all access requests associated or authorizable
11841184
* by the searcher, allowing for filtering based off group id to access or requestor id
11851185
*
1186-
* @param {Object} accessRequestSearchRequest
1186+
* @param {Object} filters Information about filters by which to search access requests.
1187+
* @param {string[]} [filters.groupIds] List of ids of which group the access request is for
1188+
* @param {string[]} [filters.requestorIds] List of ids of who created the access request
1189+
* @param {number} [nextToken] Pagination token of the search results
1190+
* @param {number} [limit] Maximum number of responses per search page. Defaults to 1000.
11871191
*
11881192
* @return {Object} Access requests matching the search filter
11891193
*/
1190-
async searchAccessRequests(
1191-
filterByRequestorIDs = [],
1192-
filterByGroupIDs = [],
1193-
nextToken = 0,
1194-
limit = 1000
1195-
) {
1196-
const requestParams = new AccessRequestSearchRequest(
1197-
filterByRequestorIDs,
1198-
filterByGroupIDs,
1199-
nextToken,
1200-
limit
1201-
)
1194+
async searchAccessRequests(filters = {}, nextToken = 0, limit = 1000) {
12021195
let response = await this.storage.authenticator.tsv1Fetch(
12031196
`${this.storage.config.apiUrl}/v1/identity/pam/access_requests/search`,
12041197
{
12051198
method: 'POST',
12061199
headers: {
12071200
'Content-Type': 'application/json',
12081201
},
1209-
body: requestParams.stringify(),
1202+
body: JSON.stringify({
1203+
access_request_search_filters: {
1204+
group_ids: filters.groupIds,
1205+
requestor_ids: filters.requestorIds,
1206+
},
1207+
next_token: nextToken,
1208+
limit,
1209+
}),
12101210
}
12111211
)
12121212
await checkStatus(response)
@@ -1256,13 +1256,13 @@ class Client extends PartialClient {
12561256
}
12571257

12581258
/**
1259-
* approveAccessRequests approves one or more access requests
1260-
*
1261-
* @param {string} realmName - name of realm
1262-
* @param {Array} approvals - an array of objects with the access request id and comment
1263-
*
1264-
* @return {Object} The updated access requests
1265-
*/
1259+
* approveAccessRequests approves one or more access requests
1260+
*
1261+
* @param {string} realmName - name of realm
1262+
* @param {Array} approvals - an array of objects with the access request id and comment
1263+
*
1264+
* @return {Object} The updated access requests
1265+
*/
12661266
async approveAccessRequests(realmName, approvals) {
12671267
const request = new AccessRequestApprovalsRequest(realmName, approvals)
12681268
let response = await this.storage.authenticator.tsv1Fetch(

types/accessRequestSearchRequest.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

types/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const GroupMembership = require('./groupMembership')
3636
const Capabilities = require('./capabilities')
3737
const GroupMember = require('./groupMember')
3838
const AccessRequest = require('./accessRequest')
39-
const AccessRequestSearchRequest = require('./accessRequestSearchRequest')
4039
const AccessRequestSearchResponse = require('./accessRequestSearchResponse')
4140
const AccessRequestApprovalsRequest = require('./accessRequestApprovalsRequest')
4241
const AccessRequestApprovalsResponse = require('./accessRequestApprovalsResponse')
@@ -80,7 +79,6 @@ module.exports = {
8079
Capabilities,
8180
GroupMember,
8281
AccessRequest,
83-
AccessRequestSearchRequest,
8482
AccessRequestSearchResponse,
8583
AccessRequestApprovalsRequest,
8684
AccessRequestApprovalsResponse,

0 commit comments

Comments
 (0)