summaryrefslogtreecommitdiff
path: root/functionaltests/cli/v1/behaviors/secret_behaviors.py
diff options
context:
space:
mode:
Diffstat (limited to 'functionaltests/cli/v1/behaviors/secret_behaviors.py')
-rw-r--r--functionaltests/cli/v1/behaviors/secret_behaviors.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/functionaltests/cli/v1/behaviors/secret_behaviors.py b/functionaltests/cli/v1/behaviors/secret_behaviors.py
index 5ea5e9a..9522871 100644
--- a/functionaltests/cli/v1/behaviors/secret_behaviors.py
+++ b/functionaltests/cli/v1/behaviors/secret_behaviors.py
@@ -79,6 +79,31 @@ class SecretBehaviors(base_behaviors.BaseBehaviors):
self.secret_hrefs_to_delete.append(secret_href)
return secret_href
+ def store_secret_file(self, filename="/tmp/storesecret", store_argv=[]):
+ """Store (aka create) a secret from file
+
+ The store_argv parameter allows additional command line parameters for
+ the store operation to be specified. This can be used to specify -a for
+ algorithm as an example.
+
+ :param payload The payload to use when storing the secret
+ :param store_argv The store command line parameters
+
+ :return: the href to the newly created secret
+ """
+ argv = ['secret', 'store']
+ self.add_auth_and_endpoint(argv)
+ argv.extend(['--file', filename])
+ argv.extend(store_argv)
+
+ stdout, stderr = self.issue_barbican_command(argv)
+
+ secret_data = self._prettytable_to_dict(stdout)
+
+ secret_href = secret_data['Secret href']
+ self.secret_hrefs_to_delete.append(secret_href)
+ return secret_href
+
def get_secret(self, secret_href):
"""Get a secret
@@ -126,6 +151,25 @@ class SecretBehaviors(base_behaviors.BaseBehaviors):
return secret
+ def get_secret_file(self, secret_href, filename='/tmp/getsecret'):
+ """Get a secret and store in a file
+
+ :param: the href to a secret
+ :param filename: name of file to store secret in
+ :return string representing the file name.
+ """
+ argv = ['secret', 'get']
+ self.add_auth_and_endpoint(argv)
+ argv.extend([secret_href])
+ argv.extend(['--file', filename])
+
+ stdout, stderr = self.issue_barbican_command(argv)
+
+ if '4xx Client error: Not Found' in stderr:
+ return {}
+
+ return filename
+
def list_secrets(self):
"""List secrets
@@ -146,3 +190,26 @@ class SecretBehaviors(base_behaviors.BaseBehaviors):
secrets_to_delete = list(self.secret_hrefs_to_delete)
for href in secrets_to_delete:
self.delete_secret(href)
+
+ def read_secret_test_file(self, filename='/tmp/getsecret'):
+ """Read payload from file used in testing
+
+ :param filename: name of file to write
+ :return contents of the file
+ """
+ with open(filename, "r") as myfile:
+ data = myfile.read()
+ return data
+
+ def write_secret_test_file(self, filename='/tmp/storesecret',
+ payload="Payload for testing"):
+ """Write payload to file for use in testing
+
+ :param filename: name of file to write
+ :param payload: data to store
+ :return
+ """
+ myfile = open(filename, "wb")
+ myfile.write(payload)
+ myfile.close()
+ return