keyserver: add generate key function
The superuser API, initdb, and tests will all need this functionality.
This commit is contained in:
parent
23a8a29654
commit
d19eb16b45
4 changed files with 35 additions and 24 deletions
15
initdb.py
15
initdb.py
|
@ -157,20 +157,18 @@ def __create_subtree(with_storage, repo, structure, creator_username, parent, ta
|
|||
|
||||
|
||||
def __generate_service_key(kid, name, user, timestamp, approval_type, expiration=None,
|
||||
metadata=None):
|
||||
private_key = RSA.generate(1024)
|
||||
jwk = RSAKey(key=private_key.publickey()).serialize()
|
||||
metadata=None, service='sample_service'):
|
||||
_, key = model.service_keys.generate_service_key(service, expiration, kid=kid,
|
||||
name=name, metadata=metadata)
|
||||
|
||||
metadata = metadata or {}
|
||||
model.service_keys.create_service_key(name, kid, 'sample_service', jwk, metadata, expiration)
|
||||
if approval_type is not None:
|
||||
model.service_keys.approve_service_key(kid, user, approval_type,
|
||||
model.service_keys.approve_service_key(key.kid, user, approval_type,
|
||||
notes='The **test** apporval')
|
||||
|
||||
key_metadata = {
|
||||
'kid': kid,
|
||||
'preshared': True,
|
||||
'service': 'sample_service',
|
||||
'service': service,
|
||||
'name': name,
|
||||
'expiration_date': expiration,
|
||||
'auto_approved': True
|
||||
|
@ -664,6 +662,9 @@ def populate_database(minimal=False, with_storage=False):
|
|||
__generate_service_key('kid4', 'autorotatingkey', new_user_1, six_ago,
|
||||
ServiceKeyApprovalType.KEY_ROTATION, today + timedelta(1),
|
||||
dict(rotation_ttl=timedelta(hours=12).total_seconds()))
|
||||
__generate_service_key('kid5', 'key for another service', new_user_1, today,
|
||||
ServiceKeyApprovalType.SUPERUSER, today + timedelta(14),
|
||||
service='different_sample_service')
|
||||
|
||||
model.log.log_action('org_create_team', org.username, performer=new_user_1,
|
||||
timestamp=week_ago, metadata={'team': 'readers'})
|
||||
|
|
Reference in a new issue