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

ID-663 Admin delete resource endpoint. #1113

Open
wants to merge 2 commits into
base: develop
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
32 changes: 32 additions & 0 deletions src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,38 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorReport'
/api/admin/v1/resources/{resourceTypeName}/{resourceId}:
delete:
tags:
- Admin
summary: Delete a resource
operationId: adminDeleteResource
parameters:
- name: resourceTypeName
in: path
description: Type of resource
required: true
schema:
type: string
- name: resourceId
in: path
description: Id of resource
required: true
schema:
type: string
responses:
204:
description: Resource successfully deleted
content: {}
403:
description: You do not have admin privileges
content: {}
500:
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorReport'
/api/admin/v1/resources/{resourceTypeName}/{resourceId}/policies:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,46 +119,59 @@ trait AdminRoutes extends SecurityDirectives with SamRequestContextDirectives wi
}

def adminResourcesRoutes(user: SamUser, samRequestContext: SamRequestContext): server.Route =
pathPrefix("resources" / Segment / Segment / "policies") { case (resourceTypeName, resourceId) =>
withNonAdminResourceType(ResourceTypeName(resourceTypeName)) { resourceType =>
val resource = FullyQualifiedResourceId(resourceType.name, ResourceId(resourceId))
pathEndOrSingleSlash {
get {
requireAdminResourceAction(adminReadPolicies, resourceType, user, samRequestContext) {
complete {
resourceService
.listResourcePolicies(resource, samRequestContext)
.map(response => OK -> response.toSet)
}
pathPrefix("resources" / Segment / Segment) { case (resourceTypeName, resourceId) =>
pathEndOrSingleSlash {
asWorkbenchAdmin(user) {
delete {
complete {
resourceService
.deleteResource(FullyQualifiedResourceId(ResourceTypeName(resourceTypeName), ResourceId(resourceId)), samRequestContext)
.map(_ => NoContent)
}
}
} ~
pathPrefix(Segment / "memberEmails" / Segment) { case (policyName, userEmail) =>
val policyId = FullyQualifiedPolicyId(resource, AccessPolicyName(policyName))
}
} ~
pathPrefix("policies") {
withNonAdminResourceType(ResourceTypeName(resourceTypeName)) { resourceType =>
val resource = FullyQualifiedResourceId(resourceType.name, ResourceId(resourceId))
pathEndOrSingleSlash {
withSubject(WorkbenchEmail(userEmail), samRequestContext) { subject =>
put {
requireAdminResourceAction(adminAddMember, resourceType, user, samRequestContext) {
complete {
resourceService
.addSubjectToPolicy(policyId, subject, samRequestContext)
.as(NoContent)
}
get {
requireAdminResourceAction(adminReadPolicies, resourceType, user, samRequestContext) {
complete {
resourceService
.listResourcePolicies(resource, samRequestContext)
.map(response => OK -> response.toSet)
}
} ~
delete {
requireAdminResourceAction(adminRemoveMember, resourceType, user, samRequestContext) {
complete {
resourceService
.removeSubjectFromPolicy(policyId, subject, samRequestContext)
.as(NoContent)
}
}
} ~
pathPrefix(Segment / "memberEmails" / Segment) { case (policyName, userEmail) =>
val policyId = FullyQualifiedPolicyId(resource, AccessPolicyName(policyName))
pathEndOrSingleSlash {
withSubject(WorkbenchEmail(userEmail), samRequestContext) { subject =>
put {
requireAdminResourceAction(adminAddMember, resourceType, user, samRequestContext) {
complete {
resourceService
.addSubjectToPolicy(policyId, subject, samRequestContext)
.as(NoContent)
}
}
} ~
delete {
requireAdminResourceAction(adminRemoveMember, resourceType, user, samRequestContext) {
complete {
resourceService
.removeSubjectFromPolicy(policyId, subject, samRequestContext)
.as(NoContent)
}
}
}
}
}
}
}
}
}
}
Copy link
Contributor Author

@Ghost-in-a-Jar Ghost-in-a-Jar Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was just a PathPrefix("resources" / Segment / Segment / "policies") here before and now we have a new PathPrefix("resources" / Segment / Segment) delete endpoint. The old one is now nested in the PathPrefix("resources" / Segment / Segment) block.

}
}

def adminResourceTypesRoutes(user: SamUser, samRequestContext: SamRequestContext): server.Route =
Expand Down