rasenmaeher_api.db
Gino based database abstraction
Submodules
Package Contents
Classes
DB config dataclass, functools etc used to avoid import-time side-effects |
|
People, pk is UUID and comes from basemodel |
|
Give a person a role |
|
Enrollments, pk is UUID and comes from basemodel |
|
Enrollment pools aka links, pk is UUID and comes from basemodel |
|
Enrollment states |
|
Store tokens we should see used only once |
|
Track the login codes that can be exchanged for session JWTs |
Functions
Set bind from config and return |
|
|
Create schemas and tables, normally one should use migration manager |
Attributes
- class DBConfig[source]
DB config dataclass, functools etc used to avoid import-time side-effects
- password: starlette.datastructures.Secret
- async init_db()[source]
Create schemas and tables, normally one should use migration manager
- Return type:
None
- class Person[source]
Bases:
rasenmaeher_api.db.base.ORMBaseModel
People, pk is UUID and comes from basemodel
NOTE: at some point we want to stop keeping track of people in our own db and only use keycloack as the store for actual users. In any case we need a nice pythonic abstraction layer so implement any queries you need to add as helpers here.
- property productapidata: libpvarki.schemas.product.UserCRUDRequest
Return a model that is usable with the product integration APIs
- Return type:
libpvarki.schemas.product.UserCRUDRequest
- property privkeyfile: pathlib.Path
Path to the private key
- Return type:
- property pfxfile: pathlib.Path
Return a PKCS12 PFX file
- Return type:
- property certfile: pathlib.Path
Path to the public cert
- Return type:
- property csrfile: pathlib.Path
Path to the CSR file
- Return type:
- property pubkeyfile: pathlib.Path
Path to the public key
- Return type:
- __tablename__ = 'users'
- callsign
- certspath
- extra
- revoke_reason
- async classmethod by_pk_or_callsign(inval, allow_deleted=False)[source]
Get person by pk or by callsign
- async classmethod create_with_cert(callsign, extra=None)[source]
Create the cert etc and save the person
- async revoke(reason)[source]
Revokes the cert with given reason and makes user deleted see validate_reason for info on reasons
- Parameters:
reason (rasenmaeher_api.cfssl.private.ReasonTypes)
- Return type:
- async classmethod by_role(role)[source]
List people that have given role, if role is None list all people
- async classmethod by_mtlsjwt_payload(payload, allow_deleted=False)[source]
Get by MTLSorJWTMiddleWare payload
- Parameters:
payload (rasenmaeher_api.web.api.middleware.datatypes.MTLSorJWTPayload)
allow_deleted (bool)
- Return type:
Self
- get_cert_pfx()[source]
Read the cert and private key from under certspath and return the PFX container
- Return type:
- async assign_role(role)[source]
Assign a role, return true if role was created, false if it already existed
- class Role[source]
Bases:
rasenmaeher_api.db.base.DBModel
Give a person a role
- __tablename__ = 'roles'
- __table_args__
- pk
- created
- updated
- user
- role
- _idx
- class Enrollment[source]
Bases:
rasenmaeher_api.db.base.ORMBaseModel
Enrollments, pk is UUID and comes from basemodel
- __tablename__ = 'enrollments'
- approvecode
- callsign
- decided_on
- decided_by
- person
- pool
- state
- extra
- async classmethod by_pk_or_callsign(inval)[source]
Get enrollment by pk or by callsign
- Parameters:
- Return type:
- async approve(approver)[source]
Creates the person record, their certs etc
- Parameters:
approver (rasenmaeher_api.db.people.Person)
- Return type:
- async reject(decider)[source]
Reject
- Parameters:
decider (rasenmaeher_api.db.people.Person)
- Return type:
None
- async classmethod list(by_pool=None)[source]
List enrollments, optionally by pool (enrollment deletion is not allowed, they can only be rejected)
- Parameters:
by_pool (Optional[EnrollmentPool])
- Return type:
AsyncGenerator[Enrollment, None]
- async classmethod by_callsign(callsign)[source]
Get by callsign
- Parameters:
callsign (str)
- Return type:
Self
- async classmethod by_approvecode(code)[source]
Get by approvecode
- Parameters:
code (str)
- Return type:
Self
- async classmethod _generate_unused_code()[source]
Internal helper to generate a code that is free NOTE: This MUST ONLY be used inside a transaction for nothing is guaranteed
- Return type:
- async classmethod create_for_callsign(callsign, pool=None, extra=None)[source]
Create a new one with random code for the callsign
- Parameters:
callsign (str)
pool (Optional[EnrollmentPool])
extra (Optional[Dict[str, Any]])
- Return type:
Self
- class EnrollmentPool[source]
Bases:
rasenmaeher_api.db.base.ORMBaseModel
Enrollment pools aka links, pk is UUID and comes from basemodel
- __tablename__ = 'enrollmentpools'
- owner
- active
- extra
- invitecode
- async classmethod by_pk_or_invitecode(inval, allow_deleted=False)[source]
Get pool by pk or by invitecode
- Parameters:
- Return type:
- async create_enrollment(callsign)[source]
Create enrollment from this pool
- Parameters:
callsign (str)
- Return type:
- async set_active(state)[source]
Set active and return refreshed object
- Parameters:
state (bool)
- Return type:
Self
- async classmethod list(by_owner=None, include_deleted=False)[source]
List pools, optionally by owner or including deleted pools
- Parameters:
by_owner (Optional[rasenmaeher_api.db.people.Person])
include_deleted (bool)
- Return type:
AsyncGenerator[EnrollmentPool, None]
- async classmethod _generate_unused_code()[source]
Internal helper to generate a code that is free NOTE: This MUST ONLY be used inside a transaction for nothing is guaranteed
- Return type:
- async classmethod create_for_owner(person, extra=None)[source]
Creates one for given owner
- Parameters:
person (rasenmaeher_api.db.people.Person)
extra (Optional[Dict[str, Any]])
- Return type:
Self
- class EnrollmentState[source]
Bases:
enum.IntEnum
Enrollment states
- PENDING = 0
- APPROVED = 1
- REJECTED = 2
- class SeenToken[source]
Bases:
rasenmaeher_api.db.base.ORMBaseModel
Store tokens we should see used only once
- __tablename__ = 'seentokens'
- token
- auditmeta
- class LoginCode[source]
Bases:
rasenmaeher_api.db.base.ORMBaseModel
Track the login codes that can be exchanged for session JWTs
- __tablename__ = 'logincodes'
- code
- auditmeta
- used_on
- claims
- async classmethod use_code(code, auditmeta=None)[source]
Exchange the code for JWT, if it was already used raise error that is also 403, return JWT with the claims