Skip to content

Commit

Permalink
Adjusted SCIM templates and added Resource Type Template
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryKodden committed Jan 12, 2023
1 parent d9413af commit 11cea33
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 10 deletions.
20 changes: 20 additions & 0 deletions server/api/scim.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from server.scim.group_template import find_groups_template, find_group_by_id_template
from server.scim.repo import all_scim_users_by_service, all_scim_groups_by_service
from server.scim.schema_template import SCIM_SCHEMA_CORE, schemas_template, schema_user_template, schema_group_template
from server.scim.resource_type_template import resource_type_template, resource_type_user_template, resource_type_group_template
from server.scim.sweep import perform_sweep
from server.scim.user_template import find_users_template, find_user_by_id_template, version_value

Expand Down Expand Up @@ -45,6 +46,25 @@ def schemas():
return schemas_template(), 200


@scim_api.route("/ResourceTypes/User", methods=["GET"], strict_slashes=False)
@json_endpoint
def resource_types_user():
return resource_type_user_template(), 200


@scim_api.route("/ResourceTypes/Group", methods=["GET"], strict_slashes=False)
@json_endpoint
def resource_types_group():
return resource_type_group_template(), 200


@scim_api.route("/ResourceTypes", methods=["GET"], strict_slashes=False)
@swag_from("../swagger/public/paths/get_resource_types.yml")
@json_endpoint
def resource_types():
return resource_type_template(), 200


@scim_api.route("/Users", methods=["GET"], strict_slashes=False)
@swag_from("../swagger/public/paths/get_users.yml")
@json_endpoint
Expand Down
2 changes: 1 addition & 1 deletion server/scim/group_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _meta_info(group: Union[Group, Collaboration]):
"created": date_time_format(group.created_at),
"lastModified": date_time_format(group.updated_at),
"version": version_value(group),
"location": f"{SCIM_URL_PREFIX}/Groups/{group.identifier}{EXTERNAL_ID_POST_FIX}"}
"location": f"/Groups/{group.identifier}{EXTERNAL_ID_POST_FIX}"}


def create_group_template(group: Union[Group, Collaboration], membership_scim_objects):
Expand Down
40 changes: 40 additions & 0 deletions server/scim/resource_type_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from server.scim.schema_template import SCIM_SCHEMA_CORE, SCIM_API_MESSAGES


def _resource_type(name):
return {
"description": f"Defined resource types for the {name} schema",
"endpoint": f"/{name}s",
"id": f"{name}",
"meta": {
"location": f"/ResourceTypes/{name}",
"resourceType": "ResourceType"
},
"name": f"{name}",
"schema": f"{SCIM_SCHEMA_CORE}:{name}",
"schemas": [
f"{SCIM_SCHEMA_CORE}:ResourceType"
]
}


def resource_type_user_template():
return _resource_type("User")


def resource_type_group_template():
return _resource_type("Group")


def resource_type_template():
resources = [resource_type_user_template(), resource_type_group_template()]

return {
"schemas": [
f"{SCIM_API_MESSAGES}:ListResponse"
],
"totalResults": len(resources),
"startIndex": 1,
"itemsPerPage": len(resources),
"Resources": resources
}
12 changes: 5 additions & 7 deletions server/scim/schema_template.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from server.scim import SCIM_URL_PREFIX

SCIM_SCHEMA_CORE = "urn:ietf:params:scim:schemas:core:2.0"
SCIM_API_MESSAGES = "urn:ietf:params:scim:api:messages:2.0"

Expand All @@ -12,7 +10,7 @@ def _schema(name, schema, attributes):
"id": schema,
"meta": {
"resourceType": "Schema",
"location": f"{SCIM_URL_PREFIX}/Schemas/{schema}"
"location": f"/Schemas/{schema}"
},
"name": name,
"Description": f"Defined attributes for the {name} schema",
Expand Down Expand Up @@ -199,14 +197,14 @@ def schema_group_template():


def schemas_template():
schemas = [schema_user_template(), schema_group_template()]
resources = [schema_user_template(), schema_group_template()]

return {
"schemas": [
f"{SCIM_API_MESSAGES}:ListResponse"
],
"totalResults": len(schemas),
"totalResults": len(resources),
"startIndex": 1,
"itemsPerPage": len(schemas),
"Resources": schemas
"itemsPerPage": len(resources),
"Resources": resources
}
4 changes: 2 additions & 2 deletions server/scim/user_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Union

from server.db.domain import User, Group, Collaboration
from server.scim import SCIM_URL_PREFIX, EXTERNAL_ID_POST_FIX
from server.scim import EXTERNAL_ID_POST_FIX
from server.scim.schema_template import SCIM_SCHEMA_CORE, SCIM_API_MESSAGES


Expand All @@ -29,7 +29,7 @@ def _meta_info(user: User):
"created": date_time_format(user.created_at),
"lastModified": date_time_format(user.updated_at),
"version": version_value(user),
"location": f"{SCIM_URL_PREFIX}/Users/{user.external_id}{EXTERNAL_ID_POST_FIX}"}
"location": f"/Users/{user.external_id}{EXTERNAL_ID_POST_FIX}"}


def create_user_template(user: User):
Expand Down
17 changes: 17 additions & 0 deletions server/swagger/public/paths/get_resource_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
summary: "Get Resource Types."
description: "Retrieves the SCIM Resource Types provided by SRAM."

tags:
- "SCIM Services"

consumes:
- "application/json"

produces:
- "application/json"

responses:
200:
description: All users
schema:
$ref: "/swagger/schemas/ScimResourceTypes.yml"
25 changes: 25 additions & 0 deletions server/swagger/public/schemas/ScimResourceTypes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
type: object
properties:
itemsPerPage:
type: number
description: "Number of item per page"
example: 15
startIndex:
type: number
description: "Zero-based start index of the result for pagination"
example: 0
totalResults:
type: number
description: "Total number of results"
example: 15
schemas:
type: array
description: "SCIM schema's"
items:
type: string
example: "urn:ietf:params:scim:api:messages:2.0:ListResponse"
Resources:
type: array
items:
type: object

0 comments on commit 11cea33

Please sign in to comment.