FAQ
| This is a
LIVE
service |
Changelog
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Identity Lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Information Services
DevOps
Identity and Access Management
Identity Lib
Commits
aed4b8db
Commit
aed4b8db
authored
3 years ago
by
Monty Dawson
Browse files
Options
Downloads
Patches
Plain Diff
Use a dict to describe identifier aliases and add a readme
parent
47847468
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Abstract identifiers code into identity lib
Pipeline
#99519
passed with warnings
3 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+25
-0
25 additions, 0 deletions
README.md
identitylib/identifiers.py
+56
-54
56 additions, 54 deletions
identitylib/identifiers.py
with
81 additions
and
54 deletions
README.md
0 → 100644
+
25
−
0
View file @
aed4b8db
# Identity Lib
This Python package contains shared code related to Identity systems within UIS. It's primary
purpose is to encourage code-reuse and to allow for client systems to make use of the same
data structures and logic that is contained within our emergent identity APIs.
## Developer quickstart
This project contains a dockerized testing environment which wraps
[
tox
](
https://tox.readthedocs.io/en/latest/
)
.
Tests can be run using the
`./test.sh`
command:
```
bash
# Run all PyTest tests and Flake8 checks
$
./test.sh
# Run just PyTest
$
./test.sh
-e
py3
# Run a single test file within PyTest
$
./test.sh
-e
py3
--
tests/test_identifiers.py
# Run a single test file within PyTest with verbose logging
$
./test.sh
-e
py3
--
tests/test_identifiers.py
-vvv
```
This diff is collapsed.
Click to expand it.
identitylib/identifiers.py
+
56
−
54
View file @
aed4b8db
from
typing
import
Optional
,
List
,
Callable
from
typing
import
Optional
,
List
,
Callable
,
Dict
from
collections
import
namedtuple
from
dataclasses
import
dataclass
from
functools
import
lru_cache
...
...
@@ -13,7 +13,9 @@ class IdentifierScheme:
identifier
:
str
# the actual string which identifiers this scheme
common_name
:
str
# a common name for this identifier (e.g. CRSid or USN)
aliases
:
List
[
str
]
# a list of equivalent schemes
# a dict of aliases - each value being a previous representation of this identifier
# keyed on a brief description of that alias
aliases
:
Dict
[
str
,
str
]
value_parser
:
Optional
[
Callable
]
=
None
# a parser for the value of an id with this scheme
def
__str__
(
self
):
...
...
@@ -38,44 +40,44 @@ class IdentifierSchemes:
CRSID
=
IdentifierScheme
(
'
v1.person.identifiers.cam.ac.uk
'
,
'
CRSid
'
,
[
'
person.crs.identifiers.uis.cam.ac.uk
'
,
'
person.v1.crs.identifiers.cam.ac.uk
'
]
{
'
deprecated
'
:
'
person.crs.identifiers.uis.cam.ac.uk
'
,
'
deprecated-versioned
'
:
'
person.v1.crs.identifiers.cam.ac.uk
'
,
}
)
USN
=
IdentifierScheme
(
'
person.v1.student-records.university.identifiers.cam.ac.uk
'
,
'
USN
'
,
[
'
person.camsis.identifiers.admin.cam.ac.uk
'
,
'
person.v1.ust.identifiers.cam.ac.uk
'
]
{
'
deprecated
'
:
'
person.camsis.identifiers.admin.cam.ac.uk
'
,
'
deprecated-versioned
'
:
'
person.v1.ust.identifiers.cam.ac.uk
'
,
}
)
STAFF_NUMBER
=
IdentifierScheme
(
'
person.v1.human-resources.university.identifiers.cam.ac.uk
'
,
'
Staff Number
'
,
[
'
person.
v1.uhr
.identifiers.cam.ac.uk
'
,
'
person.
chris
.identifiers.
admin.
cam.ac.uk
'
]
{
'
deprecated
'
:
'
person.
chris
.identifiers.
admin.
cam.ac.uk
'
,
'
deprecated-versioned
'
:
'
person.
v1.uhr
.identifiers.cam.ac.uk
'
,
}
)
BOARD_OF_GRADUATE_STUDIES
=
IdentifierScheme
(
'
person.v1.board-of-graduate-studies.university.identifiers.cam.ac.uk
'
,
'
Board of Graduate Studies Identifier
'
,
[
'
person.bgs.identifiers.admin.cam.ac.uk
'
]
{
'
deprecated
'
:
'
person.bgs.identifiers.admin.cam.ac.uk
'
,
}
)
LEGACY_CARDHOLDER
=
IdentifierScheme
(
'
person.v1.legacy-card.university.identifiers.cam.ac.uk
'
,
'
Legacy cardholder Identifier
'
,
[
'
person.bgs.identifiers.admin.cam.ac.uk
'
]
{
'
deprecated
'
:
'
person.bgs.identifiers.admin.cam.ac.uk
'
,
}
)
"""
...
...
@@ -86,25 +88,25 @@ class IdentifierSchemes:
STUDENT_INSTITUTION
=
IdentifierScheme
(
'
institution.v1.student-records.university.identifiers.cam.ac.uk
'
,
'
Student Institution
'
,
[
'
institution.v1.ust.identifiers.cam.ac.uk
'
]
{
'
deprecated
'
:
'
institution.v1.ust.identifiers.cam.ac.uk
'
,
}
)
HR_INSTITUTION
=
IdentifierScheme
(
'
institution.v1.human-resources.university.identifiers.cam.ac.uk
'
,
'
Human Resources Institution
'
,
[
'
institution.v1.uhr.identifiers.cam.ac.uk
'
]
{
'
deprecated
'
:
'
institution.v1.uhr.identifiers.cam.ac.uk
'
,
}
)
LEGACY_CARD_INSTITUTION
=
IdentifierScheme
(
'
institution.v1.legacy-card.university.identifiers.cam.ac.uk
'
,
'
Legacy Card Institution
'
,
[
'
inst.legacy_card.identifiers.admin.cam.ac.uk
'
]
{
'
deprecated
'
:
'
inst.legacy_card.identifiers.admin.cam.ac.uk
'
,
}
)
"""
...
...
@@ -115,25 +117,25 @@ class IdentifierSchemes:
STUDENT_ACADEMIC_PLAN
=
IdentifierScheme
(
'
academic-plan.v1.student-records.university.identifiers.cam.ac.uk
'
,
'
Student Academic Plan
'
,
[
'
academicPlan.v1.ust.identifiers.cam.ac.uk
'
]
{
'
deprecated
'
:
'
academicPlan.v1.ust.identifiers.cam.ac.uk
'
,
}
)
CARD
=
IdentifierScheme
(
'
card.v1.card.university.identifiers.cam.ac.uk
'
,
'
Card Identifier
'
,
[
'
card.card.identifiers.uis.cam.ac.uk
'
]
{
'
deprecated
'
:
'
card.card.identifiers.uis.cam.ac.uk
'
,
}
)
MIFARE_ID
=
IdentifierScheme
(
'
mifare-identifier.v1.card.university.identifiers.cam.ac.uk
'
,
'
Mifare Identifier
'
,
[
'
mifare_id.card.identifiers.uis.cam.ac.uk
'
]
,
{
'
deprecated
'
:
'
mifare_id.card.identifiers.uis.cam.ac.uk
'
,
}
,
value_parser
=
(
lambda
v
:
v
.
lstrip
(
'
0
'
)
or
'
0
'
# fallback to '0' to avoid stripping '000' to ''
)
...
...
@@ -142,41 +144,41 @@ class IdentifierSchemes:
MIFARE_NUMBER
=
IdentifierScheme
(
'
mifare-number.v1.card.university.identifiers.cam.ac.uk
'
,
'
Mifare Number
'
,
[
'
mifare_number.card.identifiers.uis.cam.ac.uk
'
]
{
'
deprecated
'
:
'
mifare_number.card.identifiers.uis.cam.ac.uk
'
,
}
)
BARCODE
=
IdentifierScheme
(
'
barcode.v1.card.university.identifiers.cam.ac.uk
'
,
'
Card Barcode
'
,
[
'
barcode.identifiers.lib.cam.ac.uk
'
]
{
'
deprecated
'
:
'
barcode.identifiers.lib.cam.ac.uk
'
,
}
)
CARD_LOGO
=
IdentifierScheme
(
'
card-logo.v1.card.university.identifiers.cam.ac.uk
'
,
'
Card Logo Identifier
'
,
[
'
card_logo.card.identifiers.uis.cam.ac.uk
'
]
{
'
deprecated
'
:
'
card_logo.card.identifiers.uis.cam.ac.uk
'
,
}
)
PHOTO
=
IdentifierScheme
(
'
photo.v1.photo.university.identifiers.cam.ac.uk
'
,
'
Photo Identifier
'
,
[
'
photo_id.photo.identifiers.uis.cam.ac.uk
'
]
{
'
deprecated
'
:
'
photo_id.photo.identifiers.uis.cam.ac.uk
'
,
}
)
LEGACY_CARD
=
IdentifierScheme
(
'
card.v1.legacy-card.university.identifiers.cam.ac.uk
'
,
'
Legacy Card Identifier
'
,
[
'
card.legacy_card.identifiers.admin.cam.ac.uk
'
]
{
'
deprecated
'
:
'
card.legacy_card.identifiers.admin.cam.ac.uk
'
,
}
)
@staticmethod
...
...
@@ -203,7 +205,7 @@ class IdentifierSchemes:
matching_scheme
=
next
((
scheme
for
scheme
in
IdentifierSchemes
.
get_registered_schemes
()
if
(
scheme
.
identifier
==
identifier_scheme
or
find_by_alias
and
identifier_scheme
in
scheme
.
aliases
find_by_alias
and
identifier_scheme
in
scheme
.
aliases
.
values
()
)
),
None
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment