Facade for the OpenAlchemy package database
Project description
Database
The database has a facade exposes a series of functions that enable services to personalize responses.
Tables
Specs
Stores information about the specs for a user. The following access patterns are expected:
- count the number of models for a user,
- create or update a spec record for a user,
- get the latest version of a spec for a user,
- list all specs for a user,
- delete a particular spec for a user,
- list all versions of a spec for a user and
- delete all specs for a user.
Count Models for a User
Counts the number of models a user has defined.
Input:
sub
: unique identifier for the user.
Output:
- The sum of the latest
model_count
for each spec for the user.
Algorithm:
- filter by the
sub
andupdated_at_id
to start withlatest#
and - sum over the
model_count
of each record.
Create or Update a Spec
Input:
sub
,id
: unique identifier for the spec,version
: the version of the spec,model_count
: the number of models in the spec,title
(optional): the title of the spec anddescription
(optional): the description of the spec.
Output:
Algorithm:
- calculate
updated_at
based on he current EPOCH time using https://docs.python.org/3/library/time.html#time.time and convert to an integer represented as a string, - calculate the value for
updated_at_id
by joining a zero paddedupdated_at
to 20 characters andid
with a#
and forid_updated_at
by joiningid
andupdated_at
with a#
, - save the item to the database,
- create another item but use
latest
forupdated_at
when generatingupdated_at_id
andid_updated_at
Get Latest Spec Version
Retrieve the latest version of a spec.
Input:
sub
andid
.
Output:
- The latest
version
of the spec.
Algorithm:
- Retrieve the item using the
sub
partition key andupdated_at_id
sort key equal tolatest#<id>
and - return the version of the item.
List Specs
Returns information about all the available specs for a user.
Input:
sub
.
Output:
- A list of dictionaries with the
id
,updated_at
,version
,model_count
andtitle
anddescription
if they are defined.
Algorithm:
- filter items using the
sub
partition key andupdated_at_id
starting withlatest#
and - convert the items to dictionaries.
Delete Spec
Delete a particular spec for a user.
Input:
sub
andid
.
Output:
Algorithm:
- query the
id_updated_at_index
local secondary index by filtering forsub
andid_updated_at
starting with<id>#
and - delete all returned items.
List Spec Versions
Returns information about all the available versions of a spec for a user.
Input:
sub
andid
.
Output:
- A list of dictionaries with the
id
,updated_at
,version
,model_count
andtitle
anddescription
if they are defined.
Algorithm:
- query the
id_updated_at_index
local secondary index by filtering forsub
andid_updated_at
starting with<id>#
, - filter out any items where
updated_at_id
starts withlatest#
and - convert the items to dictionaries.
Delete All Specs for a User
Input:
sub
.
Output:
Algorithm:
- Delete all entries for
sub
.
Spec Properties
sub
: A string that is the partition key of the table.id
: A string.updated_at
: A string.version
: A string.title
: An optional string.description
: An optional string.model_count
A number.updated_at_id
: A string that is the sort key of the table.id_updated_at
: A string that is the sort key of theidUpdatedAt
local secondary index of the table.
Credentials
Stores credentials for a user. The following access patterns are expected:
- list available credentials for a user,
- create or update credentials for a user,
- retrieve particular credentials for a user,
- check that a public and secret key combination exists and retrieve the
sub
for it, - delete particular credentials for a user and
- delete all credentials for a user.
List Credentials
List all available credentials for a user.
Input:
sub
.
Output:
- list of dictionaries with the
id
,public_key
andsalt
keys.
Algorithm:
- use the
sub
partition key to retrieve all credentials for the user and - map the items to a dictionary.
Create or Update Credentials
Create or update credentials for a user.
Input:
sub
: unique identifier for the user,id
: unique identifier for the credentials,public_key
: public identifier for the credentials,secret_key_hash
: a hash of the secret key for the credentials that is safe to store,salt
: a random value used to generate the credentials.
Output:
Algorithm:
- create and store an item based on the input.
Retrieve Credentials
If the credential with the id exists, return it. Otherwise, return None
.
Input:
sub
: unique identifier for the user andid
: unique identifier for the credential.
Output:
id
,public_key
,salt
.
Algorithm:
- Use the
sub
partition key andid
sort key to check whether an entry exists, - if an entry exists, return the
public_key
andsalt
and - return
None
.
Retrieve User
Check that the public key exists and retrieve the user and salt for it.
Input:
public_key
.
Output:
sub
,salt
andsecret_key_hash
.
Algorithm:
- check whether an entry exists using the
public_key
partition key for thepublicKey
global secondary index - if it does not exist, return
None
and - retrieve and return the
sub
,salt
andsecret_key_hash
.
Delete a Credential for a User
Input:
sub
andid
.
Output:
Algorithm:
- Delete all entries for
sub
andid
.
Delete All Credentials for a User
Input:
sub
.
Output:
Algorithm:
- Delete all entries for
sub
.
Credentials Properties
sub
: A string that is the partition key of the table.id
: A string that is the sort key of the table.public_key
: A string that is the partition key of thepublicKey
global secondary index.secret_key_hash
: Bytes.salt
: Bytes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for open-alchemy.package-database-1.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3975a7197097cc63ec5416ed2869221c4f1a9c33a940ff1d4ab5a0502eeffb4c |
|
MD5 | 4926bc1ba6650b9dad4a94e13c17e84b |
|
BLAKE2b-256 | 1ac39dca3530a180a9c96b56827eacd828db1ef9c03f94fea6742ca16f0d5870 |
Hashes for open_alchemy.package_database-1.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2084013f35ceecb88d0d80c45b8de83850b64691b2efa4e74f40eba54cb1d5e8 |
|
MD5 | 35d88b08687d25ae9ef8ebb5da035072 |
|
BLAKE2b-256 | c09b0668cded214c2c3098d1085cce3d0ceb1e329841f64b481446892d4cfab1 |