25
25
__logger = PlatformLogger ('wlsdeploy.tool.util' )
26
26
27
27
# substitution keys used in the templates
28
+ ADDITIONAL_SECRET_NAME = 'additionalSecretName'
29
+ ADDITIONAL_SECRETS = 'additionalSecrets'
28
30
CLUSTER_NAME = 'clusterName'
29
31
CLUSTERS = 'clusters'
30
32
DATABASE_CREDENTIALS = 'databaseCredentials'
36
38
DOMAIN_TYPE = 'domainType'
37
39
DOMAIN_UID = 'domainUid'
38
40
DS_URL = 'url'
41
+ HAS_ADDITIONAL_SECRETS = 'hasAdditionalSecrets'
39
42
HAS_CLUSTERS = 'hasClusters'
40
43
HAS_DATABASES = 'hasDatabases'
41
44
REPLICAS = 'replicas'
42
45
WEBLOGIC_CREDENTIALS_SECRET = 'webLogicCredentialsSecret'
43
46
44
47
45
- def create_additional_output (model , model_context , aliases , exception_type ):
48
+ def create_additional_output (model , model_context , aliases , credential_injector , exception_type ):
46
49
"""
47
50
Create and write additional output for the configured target type.
48
51
:param model: Model object, used to derive some values in the output
49
52
:param model_context: used to determine location and content for the output
50
53
:param aliases: used to derive secret names
54
+ :param credential_injector: used to identify secrets
51
55
:param exception_type: the type of exception to throw if needed
52
56
"""
53
57
54
58
# -output_dir argument was previously verified
55
59
output_dir = model_context .get_output_dir ()
56
60
57
61
# all current output types use this hash, and process a set of template files
58
- template_hash = _build_template_hash (model , model_context , aliases )
62
+ template_hash = _build_template_hash (model , model_context , aliases , credential_injector )
59
63
60
64
file_names = model_context .get_target_configuration ().get_additional_output_types ()
61
65
for file_name in file_names :
@@ -84,12 +88,13 @@ def _create_file(template_name, template_hash, model_context, output_dir, except
84
88
file_template_helper .create_file_from_file (template_path , template_hash , output_file , exception_type )
85
89
86
90
87
- def _build_template_hash (model , model_context , aliases ):
91
+ def _build_template_hash (model , model_context , aliases , credential_injector ):
88
92
"""
89
93
Create a dictionary of substitution values to apply to the templates.
90
94
:param model: Model object used to derive values
91
95
:param model_context: used to determine domain type
92
96
:param aliases: used to derive folder names
97
+ :param credential_injector: used to identify secrets
93
98
:return: the hash dictionary
94
99
"""
95
100
template_hash = dict ()
@@ -107,9 +112,13 @@ def _build_template_hash(model, model_context, aliases):
107
112
template_hash [DOMAIN_NAME ] = domain_uid
108
113
template_hash [DOMAIN_PREFIX ] = domain_uid
109
114
115
+ # secrets that should not be included in secrets section
116
+ declared_secrets = []
117
+
110
118
# admin credential
111
119
112
120
admin_secret = domain_uid + target_configuration_helper .WEBLOGIC_CREDENTIALS_SECRET_SUFFIX
121
+ declared_secrets .append (admin_secret )
113
122
template_hash [WEBLOGIC_CREDENTIALS_SECRET ] = admin_secret
114
123
115
124
# configuration / model
@@ -165,4 +174,26 @@ def _build_template_hash(model, model_context, aliases):
165
174
template_hash [DATABASES ] = databases
166
175
template_hash [HAS_DATABASES ] = len (databases ) != 0
167
176
177
+ # additional secrets - exclude admin
178
+
179
+ additional_secrets = []
180
+
181
+ # combine user/password properties to get a single list
182
+ secrets = []
183
+ for property_name in credential_injector .get_variable_cache ():
184
+ halves = property_name .split (':' , 1 )
185
+ name = halves [0 ]
186
+ if name not in secrets :
187
+ secrets .append (name )
188
+
189
+ for secret in secrets :
190
+ secrets_hash = dict ()
191
+ qualified_name = domain_uid + "-" + secret
192
+ if qualified_name not in declared_secrets :
193
+ secrets_hash [ADDITIONAL_SECRET_NAME ] = qualified_name
194
+ additional_secrets .append (secrets_hash )
195
+
196
+ template_hash [ADDITIONAL_SECRETS ] = additional_secrets
197
+ template_hash [HAS_ADDITIONAL_SECRETS ] = len (additional_secrets ) != 0
198
+
168
199
return template_hash
0 commit comments