From 01db6d977f518d6a348a89549ca566c4aa780e79 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Tue, 1 Apr 2014 10:30:03 -0500 Subject: move read_blob_file_contents to utils Thinking ahead, a few other upcoming keystone features could benefit from reading contents from a file. Thus, moving the function from policy to utils. Change-Id: I713ab0e5a00c949ad996daf83b775a7c19044888 --- openstackclient/common/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'openstackclient/common/utils.py') diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index d7702a3f..bc9ed264 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -249,3 +249,13 @@ def get_password(stdin): raise exceptions.CommandError("Error reading password.") raise exceptions.CommandError("There was a request to be prompted for a" " password and a terminal was not detected.") + + +def read_blob_file_contents(blob_file): + try: + with open(blob_file) as file: + blob = file.read().strip() + return blob + except IOError: + msg = "Error occurred trying to read from file %s" + raise exceptions.CommandError(msg % blob_file) -- cgit v1.2.1