@@ -53,14 +53,16 @@ class ChefAPI(object):
53
53
54
54
In order to use :class:`EncryptedDataBagItem` object it is necessary
55
55
to specify either a path to a file containing the Chef secret key and
56
- the Encrypted Databag version to be used (v1 by default)
56
+ the Encrypted Databag version to be used (v1 by default).
57
+ If both secret_file and secret_key are passed as argument, secret_key
58
+ will take precedence.
57
59
"""
58
60
59
61
ruby_value_re = re .compile (r'#\{([^}]+)\}' )
60
62
env_value_re = re .compile (r'ENV\[(.+)\]' )
61
63
ruby_string_re = re .compile (r'^\s*(["\'])(.*?)\1\s*$' )
62
64
63
- def __init__ (self , url , key , client , version = '0.10.8' , headers = {}, ssl_verify = True , secret_file = None , encryption_version = 1 ):
65
+ def __init__ (self , url , key , client , version = '0.10.8' , headers = {}, ssl_verify = True , secret_file = None , secret_key = None , encryption_version = 1 ):
64
66
self .url = url .rstrip ('/' )
65
67
self .parsed_url = six .moves .urllib .parse .urlparse (self .url )
66
68
if not isinstance (key , Key ):
@@ -78,11 +80,15 @@ def __init__(self, url, key, client, version='0.10.8', headers={}, ssl_verify=Tr
78
80
if not api_stack_value ():
79
81
self .set_default ()
80
82
self .encryption_key = None
83
+ # Read the secret key from the input file
81
84
if secret_file is not None :
82
85
self .secret_file = secret_file
83
86
if os .path .exists (self .secret_file ):
84
87
self .encryption_key = open (self .secret_file ).read ().strip ()
85
-
88
+ if secret_key is not None :
89
+ if encryption_key is not None :
90
+ log .debug ('Two encryption key found (file and parameter). The key passed as parameter will be used' )
91
+ self .encryption_key = secret_key
86
92
87
93
@classmethod
88
94
def from_config_file (cls , path ):
0 commit comments