@@ -71,6 +71,9 @@ def providers():
7171@cfy .options .secret_update_if_exists
7272@cfy .options .visibility (mutually_exclusive_required = False )
7373@cfy .options .hidden_value
74+ @cfy .options .secret_schema
75+ @cfy .options .secret_flag_dict
76+ @cfy .options .secret_flag_list
7477@cfy .options .tenant_name (required = False , resource_name_for_help = 'secret' )
7578@cfy .options .common_options
7679@cfy .assert_manager_active ()
@@ -81,6 +84,9 @@ def create(key,
8184 secret_file ,
8285 update_if_exists ,
8386 hidden_value ,
87+ secret_schema ,
88+ secret_flag_dict ,
89+ secret_flag_list ,
8490 visibility ,
8591 tenant_name ,
8692 logger ,
@@ -91,16 +97,42 @@ def create(key,
9197 """
9298 utils .explicit_tenant_name_message (tenant_name , logger )
9399 validate_visibility (visibility )
94- secret_string = _get_secret_string (secret_file , secret_string )
95- if not secret_string :
100+ value = _get_secret_string (secret_file , secret_string )
101+ if not value :
96102 raise CloudifyCliError ('Failed to create secret key. '
97103 'Missing option '
98104 '--secret-string or secret-file.' )
105+
106+ if secret_schema :
107+ try :
108+ secret_schema = json .loads (secret_schema )
109+ except json .decoder .JSONDecodeError as e :
110+ raise CloudifyCliError (
111+ f'Error decoding JSON schema "{ secret_schema } ": { e } ' )
112+ if not isinstance (secret_schema , dict ) or \
113+ not secret_schema .get ('type' ):
114+ raise CloudifyCliError (
115+ 'Invalid JSON schema. Expected a dict with a "type" key' )
116+
117+ if secret_flag_dict :
118+ secret_schema = {"type" : "object" }
119+ if secret_flag_list :
120+ secret_schema = {"type" : "array" }
121+
122+ if secret_schema :
123+ try :
124+ value = json .loads (value )
125+ except json .decoder .JSONDecodeError :
126+ raise CloudifyCliError (
127+ f'Error decoding secret value: \' { value } \' is not of '
128+ f'type \' { secret_schema .get ("type" )} \' ' )
129+
99130 client .secrets .create (key ,
100- secret_string ,
131+ value ,
101132 update_if_exists ,
102133 hidden_value ,
103- visibility )
134+ visibility ,
135+ secret_schema )
104136
105137 logger .info ('Secret `{0}` created' .format (key ))
106138
0 commit comments