Skip to main content

A module containing helpers and shared code related to identity systems within UIS, University of Cambridge.

Project description

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.

Use

Install ucam-identitylib using pip:

pip install ucam-identitylib

The module can then be used as identitylib:

from identitylib.identifiers import Identifier

identifier = Identifier.from_string('wgd23@v1.person.identifiers.cam.ac.uk')
print(identifier)

Developer quickstart

This project depends on poetry & poe:

pipx install poetry
pipx inject poetry poethepoet[poetry_plugin]

This project contains a dockerized testing environment which wraps tox.

Tests can be run using the tox poe command:

# Run all PyTest tests and Flake8 checks
$ poetry poe tox

# Run PyTest and Flake8 and recreate test environments
$ poetry poe tox --recreate

# Run just PyTest
$ poetry poe tox -e py3

# Run a single test file within PyTest
$ poetry poe tox -e py3 -- tests/test_identifiers.py

# Run a single test file within PyTest with verbose logging
$ poetry poe tox -e py3 -- tests/test_identifiers.py -vvv

Pulling latest specs from source repositories

Local 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:

$ poetry poe pull-specs

# If an access token required for https clones from gitlab repositories
# then this can be specified using:
$ poetry poe pull-specs --token "ACCESS_TOKEN_HERE"

# You may need to first set the $USER environment variable to match the GitLab account name.

Generating the identitylib

The identitylib is generated during the docker build process. To create a local copy of the identitylib distribution use the poe command:

$ poetry poe build-local

This will create a new folder /dist in the current directory with the wheel and tar package for identitylib.

Interactive testing

An 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 to host.docker.internal:<PORT NUMBER> on linux.

To set up the interactive testing environment, copy the scripts/api-loader-config.yaml.example file to scripts/api-loader-config.yaml and 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 to test.pypi.org) of the library using the poe command:

$ poetry poe interactive-test

To run the interactive tests using a local copy of identitylib from the dist directory:

$ poetry poe interactive-test:local --source dist/ucam_identitylib-1.7.0-py3-none-any.whl

will build the interactive environment from a local wheel stored in the dist directory.

Once the environment is active you can load up test instances and manipulate them using the python interactive console. The LOADER global 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 screen

Use the builtin help command to view info on the LOADER, and the returned api_inst objects that can be used to make requests.

You can view the structure of the generated identitylib package using the get_module_structure function:

>>> import identitylib
>>> from pprint import pprint
>>> pprint(get_module_structure(identitylib))
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ucam_identitylib-3.3.0.tar.gz (227.3 kB view details)

Uploaded Source

Built Distribution

ucam_identitylib-3.3.0-py3-none-any.whl (714.5 kB view details)

Uploaded Python 3

File details

Details for the file ucam_identitylib-3.3.0.tar.gz.

File metadata

  • Download URL: ucam_identitylib-3.3.0.tar.gz
  • Upload date:
  • Size: 227.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for ucam_identitylib-3.3.0.tar.gz
Algorithm Hash digest
SHA256 854e601c6cd818d135ee895e4839a3c21f2a77e5dc97ef88029d8a7de902f7d3
MD5 e113310d53665394a8d40ab26a529e9e
BLAKE2b-256 c69cf05e688179a696978e9bbe771a7879bdb558cc6594878a1ce1da8daa1c52

See more details on using hashes here.

File details

Details for the file ucam_identitylib-3.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ucam_identitylib-3.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e103dd09f3cd688b18aa00f2e3245b4b50d67c422c0f5fb5d655a76fe605b17b
MD5 93fceaf2b3c20fd94395c12d9436895e
BLAKE2b-256 6833f366f0e64f000b4e920fad91b7d62e4592a9ce7d282cfe106ccdd3b29107

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page