This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/boot.py

76 lines
2 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2016-04-27 18:39:01 +00:00
from datetime import datetime, timedelta
from urlparse import urlunparse
2016-04-27 18:39:01 +00:00
import json
2016-04-27 18:39:01 +00:00
from jwkest.jwk import RSAKey
from jinja2 import Template
2016-04-27 18:39:01 +00:00
import release
from app import app
2016-04-27 18:39:01 +00:00
from data.database import ServiceKeyApprovalType
from data.model.release import set_region_release
2016-04-27 18:39:01 +00:00
from data.model.service_keys import generate_service_key, approve_service_key
from util.config.database import sync_database_with_config
2016-04-27 18:39:01 +00:00
def create_quay_service_key(seconds_until_expiration):
expiration = timedelta(seconds=seconds_until_expiration)
private_key, service_key = generate_service_key('quay', datetime.now()+expiration)
approve_service_key(service_key.kid, None, ServiceKeyApprovalType.SUPERUSER)
private_key_file = {
'KeyID': service_key.kid,
'PrivateKey': {
'N': int(private_key._n),
'E': int(private_key._e),
'D': int(private_key._d),
'Primes': [int(private_key._p), int(private_key._q)],
'Precomputed': {
'Dp': None,
'Dq': None,
'Quinv': None,
'CRTValues': []
}
}
}
with open('/conf/quay.jwk', mode='w') as f:
f.truncate(0)
f.write(json.dumps(private_key_file))
def create_jwtproxy_conf():
audience = urlunparse((
app.config.get('PREFERRED_URL_SCHEME'),
app.config.get('SERVER_HOSTNAME'), '', '', '', ''))
registry = audience + '/keys'
with open("/conf/jwtproxy_conf.yaml.jnj") as f:
template = Template(f.read())
rendered = template.render(
audience=audience,
registry=registry
)
with open('/conf/jwtproxy_conf.yaml', 'w') as f:
f.write(rendered)
def main():
create_jwtproxy_conf()
if app.config.get('SETUP_COMPLETE', False):
sync_database_with_config(app.config)
2016-04-27 18:39:01 +00:00
create_quay_service_key(app.config.get('QUAY_SERVICE_KEY_EXPIRATION', 500))
# Record deploy
if release.REGION and release.GIT_HEAD:
set_region_release(release.SERVICE, release.REGION, release.GIT_HEAD)
if __name__ == '__main__':
main()