API Reference

Public

cchdo.auth.dirs: appdirs.AppDirs

The preconfigured AppDirs instance which has the following read only properties:

  • user_data_dir

  • user_config_dir

  • user_cache_dir

  • site_data_dir

  • site_config_dir

  • user_log_dir

The actual values are platform dependent.

cchdo.auth.CONFIG_FILE: str

A string containing the path to the config file on the running platform.

example in the devcontainer (linux):

>>> from cchdo.auth import CONFIG_FILE
>>> CONFIG_FILE
'/home/vscode/.config/edu.ucsd.cchdo/config.cfg'
class cchdo.auth.CCHDOAuth(apikey: str | None = None)

AuthClass for use with the requests library

If the request URI is detected to be for the CCHDO api endpoint, it will automatically set the correct headers.

If the apikey is given as a string when initialized, it will use that as the key. When initialized with no arguments, will attempt to load the apikey with cchdo.auth.get_apikey().

>>> import requests
>>> from cchdo.auth import CCHDOAuth
>>> cruises = requests.get("https://cchdo.ucsd.edu/api/v1/cruise", auth=CCHDOAuth()).json()

It is highly recomended that the cchdo.auth.session.session object be used instead of manually including this auth class

cchdo.auth.get_apikey() str

Retrieves the apikey from the first source available

Checks the following in order:

  • The environment variable CCHDO_AUTH_API_KEY

  • The local config file, which has a platform dependent location

cchdo.auth.write_apikey(apikey: str) None

Write the apikey to the config file

This will create the config file and containing directories if needed.

Private

cchdo.auth._check_apikey(apikey: str) bool

check to see if the api key “looks” ok

It cannot validate without the secrets but the payload can be checked to see if it at least decodes

cchdo.auth._create_config_dir() None

Creates the user config dir using appdirs.user_config_dir

The actual location is system dependent and can be found by doing the following:

>>> from cchdo.auth import dirs
>>> dirs.user_config_dir
'/home/vscode/.config/edu.ucsd.cchdo'

The above being inside the devcontainer (linux) used for this project.

cchdo.auth._load_config() ConfigParser

Loads the config file into a ConfigParser object

cchdo.auth._migrate_uow_config() None

Migrates the old uow config file to the new appdirs defined location.

Will remove the old config file and attempt to removed the containing directory.

cchdo.auth._write_config(config: ConfigParser) None

Write the ConfigParser object to the config file.

Will create the file and containing directories if needed.