|
17 | 17 | import base64
|
18 | 18 | import json
|
19 | 19 | import os
|
20 |
| -import OpenSSL |
21 |
| -import random |
22 | 20 | from argparse import ArgumentParser
|
23 | 21 |
|
24 | 22 | import yaml
|
25 | 23 |
|
26 | 24 | import config_helper
|
| 25 | +import property_generator |
27 | 26 | import schema_values_common
|
28 |
| -from password import GeneratePassword |
29 | 27 |
|
30 | 28 | _PROG_HELP = """
|
31 | 29 | Modifies the configuration parameter files in a directory
|
@@ -98,12 +96,11 @@ def expand(values_dict, schema, app_uid=''):
|
98 | 96 | # thus is eligible for auto-generation.
|
99 | 97 | if v is None:
|
100 | 98 | if prop.password:
|
101 |
| - v = generate_password(prop.password) |
| 99 | + v = property_generator.generate_password(prop.password) |
102 | 100 | elif prop.application_uid:
|
103 | 101 | v = app_uid or ''
|
104 |
| - generate_properties_for_appuid(prop, app_uid, generated) |
105 | 102 | elif prop.tls_certificate:
|
106 |
| - v = generate_tls_certificate() |
| 103 | + v = property_generator.generate_tls_certificate() |
107 | 104 | elif prop.xtype == config_helper.XTYPE_ISTIO_ENABLED:
|
108 | 105 | # For backward compatibility.
|
109 | 106 | v = False
|
@@ -132,6 +129,8 @@ def expand(values_dict, schema, app_uid=''):
|
132 | 129 | raise InvalidProperty(
|
133 | 130 | 'Invalid value for TLS_CERTIFICATE property {}: {}'.format(k, v))
|
134 | 131 | generate_properties_for_tls_certificate(prop, v, generated)
|
| 132 | + elif prop.application_uid: |
| 133 | + generate_properties_for_appuid(prop, v, generated) |
135 | 134 |
|
136 | 135 | if v is not None:
|
137 | 136 | result[k] = v
|
@@ -247,37 +246,6 @@ def generate_properties_for_string(prop, value, result):
|
247 | 246 | result[prop.string.base64_encoded] = base64.b64encode(value)
|
248 | 247 |
|
249 | 248 |
|
250 |
| -def generate_password(config): |
251 |
| - pw = GeneratePassword(config.length, config.include_symbols) |
252 |
| - if config.base64: |
253 |
| - pw = base64.b64encode(pw) |
254 |
| - return pw |
255 |
| - |
256 |
| - |
257 |
| -def generate_tls_certificate(): |
258 |
| - cert_seconds_to_expiry = 60 * 60 * 24 * 365 # one year |
259 |
| - |
260 |
| - key = OpenSSL.crypto.PKey() |
261 |
| - key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048) |
262 |
| - |
263 |
| - cert = OpenSSL.crypto.X509() |
264 |
| - cert.get_subject().OU = 'GCP Marketplace K8s App Tools' |
265 |
| - cert.get_subject().CN = 'Temporary Certificate' |
266 |
| - cert.gmtime_adj_notBefore(0) |
267 |
| - cert.gmtime_adj_notAfter(cert_seconds_to_expiry) |
268 |
| - cert.set_serial_number(random.getrandbits(64)) |
269 |
| - cert.set_issuer(cert.get_subject()) |
270 |
| - cert.set_pubkey(key) |
271 |
| - cert.sign(key, 'sha256') |
272 |
| - |
273 |
| - return json.dumps({ |
274 |
| - 'private_key': |
275 |
| - OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key), |
276 |
| - 'certificate': |
277 |
| - OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert) |
278 |
| - }) |
279 |
| - |
280 |
| - |
281 | 249 | def generate_properties_for_tls_certificate(prop, value, result):
|
282 | 250 | certificate = json.loads(value)
|
283 | 251 | if prop.tls_certificate.base64_encoded_private_key:
|
|
0 commit comments