2015-10-26 23:06:05 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-04-27 18:39:01 +00:00
|
|
|
from datetime import datetime, timedelta
|
2016-04-21 16:40:16 +00:00
|
|
|
from urlparse import urlunparse
|
2016-04-27 18:39:01 +00:00
|
|
|
import json
|
2016-04-21 16:40:16 +00:00
|
|
|
|
2016-04-27 18:39:01 +00:00
|
|
|
from jwkest.jwk import RSAKey
|
2016-04-21 16:40:16 +00:00
|
|
|
from jinja2 import Template
|
2016-04-27 18:39:01 +00:00
|
|
|
import release
|
2015-10-26 23:06:05 +00:00
|
|
|
|
|
|
|
from app import app
|
2016-04-27 18:39:01 +00:00
|
|
|
from data.database import ServiceKeyApprovalType
|
2015-10-26 23:06:05 +00:00
|
|
|
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
|
2015-10-26 23:06:05 +00:00
|
|
|
from util.config.database import sync_database_with_config
|
2016-04-27 19:37:48 +00:00
|
|
|
from util.generatepresharedkey import generate_key
|
2015-10-26 23:06:05 +00:00
|
|
|
|
|
|
|
|
2016-04-28 14:04:04 +00:00
|
|
|
def create_quay_service_key():
|
2016-04-27 19:37:48 +00:00
|
|
|
quay_key, key_id = generate_key(None, 'quay', 'quay')
|
2016-04-27 18:39:01 +00:00
|
|
|
|
2016-04-27 19:37:48 +00:00
|
|
|
with open('/conf/quay.pem', mode='w') as f:
|
2016-04-27 18:39:01 +00:00
|
|
|
f.truncate(0)
|
2016-04-27 19:37:48 +00:00
|
|
|
f.write(quay_key.exportKey())
|
2016-04-27 18:39:01 +00:00
|
|
|
|
2016-04-27 19:37:48 +00:00
|
|
|
return key_id
|
2016-04-27 18:39:01 +00:00
|
|
|
|
2016-04-27 19:37:48 +00:00
|
|
|
|
|
|
|
def create_jwtproxy_conf(quay_key_id):
|
2016-04-28 19:29:21 +00:00
|
|
|
audience = app.config.get('JWTPROXY_AUDIENCE')
|
2016-04-21 16:40:16 +00:00
|
|
|
registry = audience + '/keys'
|
|
|
|
|
|
|
|
with open("/conf/jwtproxy_conf.yaml.jnj") as f:
|
|
|
|
template = Template(f.read())
|
|
|
|
rendered = template.render(
|
|
|
|
audience=audience,
|
2016-04-27 19:37:48 +00:00
|
|
|
registry=registry,
|
|
|
|
key_id=quay_key_id
|
2016-04-21 16:40:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with open('/conf/jwtproxy_conf.yaml', 'w') as f:
|
|
|
|
f.write(rendered)
|
|
|
|
|
|
|
|
|
2015-10-26 23:06:05 +00:00
|
|
|
def main():
|
|
|
|
if app.config.get('SETUP_COMPLETE', False):
|
|
|
|
sync_database_with_config(app.config)
|
2016-04-28 14:04:04 +00:00
|
|
|
quay_key_id = create_quay_service_key()
|
2016-04-27 19:37:48 +00:00
|
|
|
create_jwtproxy_conf(quay_key_id)
|
2015-10-26 23:06:05 +00:00
|
|
|
|
|
|
|
# Record deploy
|
|
|
|
if release.REGION and release.GIT_HEAD:
|
|
|
|
set_region_release(release.SERVICE, release.REGION, release.GIT_HEAD)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|