Skip to content

Commit

Permalink
Added GET /group/{groupName}
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jul 4, 2024
1 parent 4ba45ad commit e488036
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import software.amazon.awssdk.services.cognitoidentityprovider.model.CreateGroupRequest;
import software.amazon.awssdk.services.cognitoidentityprovider.model.CreateGroupResponse;
import software.amazon.awssdk.services.cognitoidentityprovider.model.DeleteGroupRequest;
import software.amazon.awssdk.services.cognitoidentityprovider.model.GetGroupRequest;
import software.amazon.awssdk.services.cognitoidentityprovider.model.GetGroupResponse;
import software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserRequest;
import software.amazon.awssdk.services.cognitoidentityprovider.model.GetUserResponse;
import software.amazon.awssdk.services.cognitoidentityprovider.model.ListGroupsRequest;
Expand Down Expand Up @@ -205,6 +207,18 @@ public GetUserResponse getUser(final AuthenticationResultType token) {
return this.cognitoProvider.getUser(req);
}

/**
* Get Group.
*
* @param groupName {@link String}.
* @return {@link GetGroupResponse}
*/
public GetGroupResponse getGroup(final String groupName) {
GetGroupRequest req = GetGroupRequest.builder().userPoolId(this.userPoolId).groupName(groupName
).build();
return this.cognitoProvider.getGroup(req);
}

/**
* Get User.
*
Expand Down
31 changes: 31 additions & 0 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4260,6 +4260,32 @@
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
"200":
description: 200 OK
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
$ref: '#/components/schemas/GetGroupResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9620,6 +9646,11 @@
description: List of groups
items:
$ref: '#/components/schemas/Group'
GetGroupResponse:
type: object
properties:
group:
$ref: '#/components/schemas/Group'
GetUserResponse:
type: object
properties:
Expand Down
31 changes: 31 additions & 0 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4260,6 +4260,32 @@
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
"200":
description: 200 OK
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
$ref: '#/components/schemas/GetGroupResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9620,6 +9646,11 @@
description: List of groups
items:
$ref: '#/components/schemas/Group'
GetGroupResponse:
type: object
properties:
group:
$ref: '#/components/schemas/Group'
GetUserResponse:
type: object
properties:
Expand Down
31 changes: 31 additions & 0 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4260,6 +4260,32 @@
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
"200":
description: 200 OK
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
$ref: '#/components/schemas/GetGroupResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9620,6 +9646,11 @@
description: List of groups
items:
$ref: '#/components/schemas/Group'
GetGroupResponse:
type: object
properties:
group:
$ref: '#/components/schemas/Group'
GetUserResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,32 @@ Resources:
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
'200':
description: "200 OK"
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
"$ref": "#/components/schemas/GetGroupResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9706,6 +9732,11 @@ Resources:
description: "List of groups"
items:
$ref: "#/components/schemas/Group"
GetGroupResponse:
type: object
properties:
group:
$ref: "#/components/schemas/Group"
GetUserResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,32 @@ Resources:
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
'200':
description: "200 OK"
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
"$ref": "#/components/schemas/GetGroupResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9706,6 +9732,11 @@ Resources:
description: "List of groups"
items:
$ref: "#/components/schemas/Group"
GetGroupResponse:
type: object
properties:
group:
$ref: "#/components/schemas/Group"
GetUserResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,32 @@ Resources:
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/groups/{groupName}:
get:
operationId: GetGroup
description: Returns a user group
summary: Get a user group
parameters:
- $ref: '#/components/parameters/groupNamePath'
tags:
- User Management
responses:
'200':
description: "200 OK"
headers:
Access-Control-Allow-Origin:
$ref: '#/components/headers/AccessControlAllowOrigin'
Access-Control-Allow-Methods:
$ref: '#/components/headers/AccessControlAllowMethods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/AccessControlAllowHeaders'
content:
application/json:
schema:
"$ref": "#/components/schemas/GetGroupResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
delete:
operationId: DeleteGroup
summary: Delete Group
Expand Down Expand Up @@ -9706,6 +9732,11 @@ Resources:
description: "List of groups"
items:
$ref: "#/components/schemas/Group"
GetGroupResponse:
type: object
properties:
group:
$ref: "#/components/schemas/Group"
GetUserResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.formkiq.aws.services.lambda.ApiPermission;
import com.formkiq.aws.services.lambda.ApiRequestHandlerResponse;
import com.formkiq.module.lambdaservices.AwsServiceCache;
import com.formkiq.stacks.api.transformers.GroupsResponseToMap;
import software.amazon.awssdk.services.cognitoidentityprovider.model.GetGroupResponse;

import java.util.Map;
import java.util.Optional;
Expand All @@ -45,6 +47,22 @@ public class GroupRequestHandler implements ApiGatewayRequestHandler, ApiGateway
/** {@link GroupRequestHandler} URL. */
public static final String URL = "/groups/{groupName}";

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger,
final ApiGatewayRequestEvent event, final ApiAuthorization authorization,
final AwsServiceCache awsservice) throws Exception {

CognitoIdentityProviderService service =
awsservice.getExtension(CognitoIdentityProviderService.class);

String groupName = event.getPathParameters().get("groupName");
GetGroupResponse response = service.getGroup(groupName);

Map<String, Object> group = new GroupsResponseToMap().apply(response.group());
ApiMapResponse resp = new ApiMapResponse(Map.of("group", group));
return new ApiRequestHandlerResponse(SC_OK, resp);
}

@Override
public Optional<Boolean> isAuthorized(final AwsServiceCache awsServiceCache, final String method,
final ApiGatewayRequestEvent event, final ApiAuthorization authorization) {
Expand Down

0 comments on commit e488036

Please sign in to comment.