From 8f60d502e3185f73ef3418157c673cbe68fca9ac Mon Sep 17 00:00:00 2001 From: "Jose A. Rivera" Date: Sat, 3 Jun 2017 15:02:09 -0500 Subject: oc_secret: allow use of force for secret type Signed-off-by: Jose A. Rivera --- roles/lib_openshift/library/oc_secret.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'roles/lib_openshift/library') diff --git a/roles/lib_openshift/library/oc_secret.py b/roles/lib_openshift/library/oc_secret.py index 02257500f..db6e682d0 100644 --- a/roles/lib_openshift/library/oc_secret.py +++ b/roles/lib_openshift/library/oc_secret.py @@ -1613,7 +1613,7 @@ class OCSecret(OpenShiftCLI): '''delete a secret by name''' return self._delete('secrets', self.name) - def create(self, files=None, contents=None): + def create(self, files=None, contents=None, force=False): '''Create a secret ''' if not files: files = Utils.create_tmp_files_from_contents(contents) @@ -1622,6 +1622,8 @@ class OCSecret(OpenShiftCLI): cmd = ['secrets', 'new', self.name] if self.type is not None: cmd.append("--type=%s" % (self.type)) + if force: + cmd.append('--confirm') cmd.extend(secrets) results = self.openshift_cmd(cmd) @@ -1634,7 +1636,7 @@ class OCSecret(OpenShiftCLI): This receives a list of file names and converts it into a secret. The secret is then written to disk and passed into the `oc replace` command. ''' - secret = self.prep_secret(files) + secret = self.prep_secret(files, force) if secret['returncode'] != 0: return secret @@ -1646,7 +1648,7 @@ class OCSecret(OpenShiftCLI): return self._replace(sfile_path, force=force) - def prep_secret(self, files=None, contents=None): + def prep_secret(self, files=None, contents=None, force=False): ''' return what the secret would look like if created This is accomplished by passing -ojson. This will most likely change in the future ''' @@ -1657,6 +1659,8 @@ class OCSecret(OpenShiftCLI): cmd = ['-ojson', 'secrets', 'new', self.name] if self.type is not None: cmd.extend(["--type=%s" % (self.type)]) + if force: + cmd.append('--confirm') cmd.extend(secrets) return self.openshift_cmd(cmd, output=True) @@ -1719,7 +1723,7 @@ class OCSecret(OpenShiftCLI): return {'changed': True, 'msg': 'Would have performed a create.'} - api_rval = ocsecret.create(files, params['contents']) + api_rval = ocsecret.create(files, params['contents'], force=params['force']) # Remove files if files and params['delete_after']: @@ -1736,7 +1740,7 @@ class OCSecret(OpenShiftCLI): ######## # Update ######## - secret = ocsecret.prep_secret(params['files'], params['contents']) + secret = ocsecret.prep_secret(params['files'], params['contents'], force=params['force']) if secret['returncode'] != 0: return {'failed': True, 'msg': secret} -- cgit v1.2.3