~suligap/canonical-identity-provider/charm-talisker

« back to all changes in this revision

Viewing changes to templates/settings.py.j2

  • Committer: Tarmac
  • Author(s): Daniel Manrique
  • Date: 2016-05-17 20:31:09 UTC
  • mfrom: (73.1.1 sso-charm-try-crypto)
  • Revision ID: tarmac-20160517203109-rf8432gty01trhyy
[r=facundo] Handle possible absence of one of the two cryptography modules in settings.

 This accounts for a short transition period while we move over to   python-cryptography.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
{% endif %}
47
47
COMBINE = {{ combine }}
48
48
{% if crypto_sso_privkey %}
 
49
_crypto_sso_raw = base64.b64decode("{{ crypto_sso_privkey }}")
 
50
# Try/except is temporary while we transition to devportal.macaroons.crypto,
 
51
# once that's deployed we can remove the except and Crypto and RSA.
 
52
# crypto from identityprovider imported first because we prefer that if both
 
53
# are available.
 
54
try:
 
55
    # importing this here because it should happen in the project's context,
 
56
    # not in the charm's one
 
57
    from identityprovider import crypto
 
58
    CRYPTO_SSO_PRIVKEY = crypto.parse_private_key(_crypto_sso_raw)
 
59
except ImportError:
 
60
    from Crypto.PublicKey import RSA
 
61
    CRYPTO_SSO_PRIVKEY = RSA.importKey(_crypto_sso_raw)
49
62
# importing this here because it should happen in the project's context, not in the charm's one
50
 
from identityprovider import crypto
51
 
_crypto_sso_raw = base64.b64decode("{{ crypto_sso_privkey }}")
52
 
CRYPTO_SSO_PRIVKEY = crypto.parse_private_key(_crypto_sso_raw)
53
63
{% endif %}
54
64
DATABASES['default']['USER'] = os.getenv('DB_USER', "{{ db_user }}")
55
65
DATABASES['default']['PASSWORD'] = os.getenv('DB_PASSWORD', "{{ db_password }}")