Package: ucam-identitylib
Identity LibThis 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.UseInstallucam-identitylibusing pip:pip install ucam-identitylibThe module can then be used asidentitylib:fromidentitylib.identifiersimportIdentifieridentifier=Identifier.from_string('wgd23@v1.person.identifiers.cam.ac.uk')print(identifier)Developer quickstartThis project depends onpoetry&poe:pipx install poetrypipx inject poetry poethepoet[poetry_plugin]This project contains a dockerized testing environment which wrapstox.Tests can be run using thetoxpoe command:# Run all PyTest tests and Flake8 checks$poetrypoetox# Run PyTest and Flake8 and recreate test environments$poetrypoetox--recreate# Run just PyTest$poetrypoetox-epy3# Run a single test file within PyTest$poetrypoetox-epy3--tests/test_identifiers.py# Run a single test file within PyTest with verbose logging$poetrypoetox-epy3--tests/test_identifiers.py-vvvPulling latest specs from source repositoriesLocal copies of the OpenAPI specs used to generate the library should be pulled in to this repo
so the specific specs used in each build are under revision control. This can be done using the
provided poe command:$poetrypoepull-specs# If an access token required for https clones from gitlab repositories# then this can be specified using:$poetrypoepull-specs--token"ACCESS_TOKEN_HERE"# You may need to first set the $USER environment variable to match the GitLab account name.Generating the identitylibThe identitylib is generated during the docker build process. To create a local copy of the
identitylib distribution use the poe command:$poetrypoebuild-localThis will create a new folder/distin the current directory with the wheel and tar package for
identitylib.Interactive testingAn interactive testing environment is provided to smoke-test any changes to the identitylib against
staging or local instances of the APIs. Note that to test local instance you will need to set the
URL in the config file tohost.docker.internal:<PORT NUMBER>on linux.To set up the interactive testing environment, copy thescripts/api-loader-config.yaml.examplefile toscripts/api-loader-config.yamland populate with valid API key/secret pairs for any of
the APIs you wish to test.Run the interactive test environment against the latest test release (i.e. uploaded totest.pypi.org) of the library using the poe command:$poetrypoeinteractive-testTo run the interactive tests using a local copy ofidentitylibfrom thedistdirectory:$poetrypoeinteractive-test:local--sourcedist/ucam_identitylib-1.7.0-py3-none-any.whlwill build the interactive environment from a local wheel stored in thedistdirectory.Once the environment is active you can load up test instances and manipulate them using the python
interactive console. TheLOADERglobal variable contains a helper class which reads the config
file and generates clients based off it:# Docker build output...>>>config,client,inst=LOADER.load_card()>>>inst.v1beta1_cards_list()...# Output printed to the screenUse the builtinhelpcommand to view info on theLOADER, and the returnedapi_instobjects
that can be used to make requests.You can view the structure of the generatedidentitylibpackage using theget_module_structurefunction:>>>importidentitylib>>>frompprintimportpprint>>>pprint(get_module_structure(identitylib))...