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 contains a dockerized testing environment which wraps tox.

Tests can be run using the ./test.sh command:

# Run all PyTest tests and Flake8 checks
$ ./test.sh

# Run PyTest and Flake8 and recreate test environments
$ ./test.sh --recreate

# 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

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

$ ./pull-specs.sh

# If an access token required for https clones from gitlab repositories
# then this can be specified using:
$ ./pull-specs.sh --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 build script:

$ ./build-local.sh

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 using the provided script:

$ ./interactive-tests.sh

Additional arguments can be passed to the docker build and docker run commands by setting the variables ITEST_BUILD_ARGS and ITEST_RUN_ARGS, e.g.:

$ ITEST_BUILD_ARGS="--build-arg install_from=dist/ucam_identitylib-1.7.0-py3-none-any.whl" ./interactive-tests.sh

will build the interactive environment from a local wheel stored in the dist directory. By default the latest version avaiable in the test.pypi.org/simple index is installed into the environment.

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.v1_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.

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-2.0.2.tar.gz (339.6 kB view details)

Uploaded Source

Built Distribution

ucam_identitylib-2.0.2-py3-none-any.whl (891.3 kB view details)

Uploaded Python 3

File details

Details for the file ucam-identitylib-2.0.2.tar.gz.

File metadata

  • Download URL: ucam-identitylib-2.0.2.tar.gz
  • Upload date:
  • Size: 339.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for ucam-identitylib-2.0.2.tar.gz
Algorithm Hash digest
SHA256 46fafd6984b334c1611b20aa25a7e9c999b898d363a6d4511fa469c4497cd64e
MD5 d3403a9927cd9b83dc88380d6a0c284a
BLAKE2b-256 65df23845c532838ccd334177e4933978199df96eedbaa867f44a1c3c50a25e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ucam_identitylib-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92d96e7793d1ab5eadcd32248a20a5da9ad441447ab011652572829920739451
MD5 03c9f38c88374afa24740d0ae41ca781
BLAKE2b-256 e7e641ef2ebf5d4e2dc3403b5c142055916bb0ea03180300e2114441215effc6

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