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

(feature) bulk get groups #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@awssolutions/cdf-assetlibrary-client",
"comment": "Added \"bulkGetGroups\" to groups service",
"type": "none"
}
],
"packageName": "@awssolutions/cdf-assetlibrary-client"
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ Feature: Group lifecycle
When I delete assetlibrary group template "TEST-groups-groupTemplate001"
Then it fails with a 409
And published assetlibrary group template "TEST-groups-groupTemplate001" exists

Scenario: Retrieving a list of groups in bulk
Given my authorization is
| / | * |
When I get bulk groups "/TEST-groups-group001,/TEST-groups-group002"
Then result contains groups "/test-groups-group001,/test-groups-group002"

Scenario: Teardown device artifacts
Given my authorization is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ When('I get group {string}', async function (groupPath: string) {
}
});

When('I get bulk groups {string}', async function (paths: string) {
try {
const groupPaths: string[] = paths.split(",");
this['members'] = await groupService.bulkGetGroups(groupPaths, false, getAdditionalHeaders(this));
} catch (err) {
this[RESPONSE_STATUS] = err.status;
}
});

When(
'I detatch group {string} from group {string} via {string}',
async function (thisGroup: string, otherGroup: string, relation: string) {
Expand Down Expand Up @@ -363,3 +372,18 @@ Then('group contains device {string}', async function (deviceId: string) {
Then('response should fail with {int}', async function (status: number) {
expect(this[RESPONSE_STATUS]).eq(status);
});

Then('result contains groups {string}', async function (paths: string) {
let found = false;
const groupPaths: string[] = paths.split(",");
(<GroupResourceList>this['members']).results.forEach((group) => {
if (groupPaths.indexOf(group.groupPath) > -1) {
// found
found = true;
} else {
// not found
found = false;
}
});
expect(found).eq(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,43 @@ export class GroupsApigwService extends GroupsServiceBase implements GroupsServi
throw createError(err.response.status, err.response.text);
});
}

/**
* Gets the group details in bulk for the given group paths.
* @param groupPaths List of group paths to get details for
* @param includeGroups Optional flag to include the groups in the response.
* @param additionalHeaders Optional additional headers to send with the request.
* @returns Group details for the given group paths.
* @throws Error if the groupPaths is not an array.
*
*/
async bulkGetGroups(
groupPaths: string[],
includeGroups?:boolean,
additionalHeaders?:RequestHeaders,
): Promise<GroupResourceList> {
ow(groupPaths, 'groupPaths', ow.array.nonEmpty);
let url = `${this.baseUrl}${super.bulkGroupsRelativeUrl()}`;
const qs = QSHelper.getQueryString({includeGroups});
let query = "";
groupPaths.forEach(gp => {
query += gp + ",";
});
query = query.substring(0, query.length - 1);
if (qs) {
url += `?${qs}&groupPaths=${query}`;
} else {
url += `?groupPaths=${query}`;
}
return await request
.get(url)
.set(this.buildHeaders(additionalHeaders))
.use(await signClientRequest())
.then((res) => {
return res.body;
})
.catch((err) => {
throw createError(err.response.status, err.response.text);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,34 @@ export class GroupsLambdaService extends GroupsServiceBase implements GroupsServ
const res = await this.lambdaInvoker.invoke(this.functionName, event);
return res.body;
}

/**
* Gets the group details in bulk for the given group paths.
* @param groupPaths List of group paths to get details for
* @param includeGroups Optional flag to include the groups in the response.
* @param additionalHeaders Optional additional headers to send with the request.
* @returns Group details for the given group paths.
* @throws Error if the groupPaths is not an array.
*
*/
async bulkGetGroups(
groupPaths: string[],
includeGroups?:boolean,
additionalHeaders?:RequestHeaders,
): Promise<GroupResourceList> {
ow(groupPaths, 'groupPaths', ow.array.nonEmpty);
let query = "";
groupPaths.forEach(gp => {
query += gp + ",";
});
query = query.substring(0, query.length - 1);
const event = new LambdaApiGatewayEventBuilder()
.setMethod('GET')
.setPath(super.bulkGroupsRelativeUrl())
.setQueryStringParameters({groupPaths: query, includeGroups: `${includeGroups}`})
.setHeaders(super.buildHeaders(additionalHeaders));

const res = await this.lambdaInvoker.invoke(this.functionName, event);
return res.body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ export interface GroupsService {
sort?: string,
additionalHeaders?: RequestHeaders
): Promise<DeviceResourceList>;

/**
* Provide a list of groups based on the supplied group paths.
* @param groupPaths List of group paths to return
* @param includeGroups Flag to indicate whether the group details need to be fetched
* @param additionalHeaders additional headers to pass along with the request.
*/
bulkGetGroups(
groupPaths: string[],
includeGroups?:boolean,
additionalHeaders?:RequestHeaders,
): Promise<GroupResourceList>;
}

@injectable()
Expand Down
Loading