Skip to content

Commit 01db6d9

Browse files
author
Steve Martinelli
committed
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
1 parent ee22070 commit 01db6d9

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎openstackclient/common/utils.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,13 @@ def get_password(stdin):
249249
raise exceptions.CommandError("Error reading password.")
250250
raise exceptions.CommandError("There was a request to be prompted for a"
251251
" password and a terminal was not detected.")
252+
253+
254+
def read_blob_file_contents(blob_file):
255+
try:
256+
with open(blob_file) as file:
257+
blob = file.read().strip()
258+
return blob
259+
except IOError:
260+
msg = "Error occurred trying to read from file %s"
261+
raise exceptions.CommandError(msg % blob_file)

‎openstackclient/identity/v3/policy.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_parser(self, prog_name):
4848

4949
def take_action(self, parsed_args):
5050
self.log.debug('take_action(%s)' % parsed_args)
51-
blob = _read_blob_file_contents(parsed_args.blob_file)
51+
blob = utils.read_blob_file_contents(parsed_args.blob_file)
5252

5353
identity_client = self.app.client_manager.identity
5454
policy = identity_client.policies.create(
@@ -138,7 +138,7 @@ def take_action(self, parsed_args):
138138
blob = None
139139

140140
if parsed_args.blob_file:
141-
blob = _read_blob_file_contents(parsed_args.blob_file)
141+
blob = utils.read_blob_file_contents(parsed_args.blob_file)
142142

143143
kwargs = {}
144144
if blob:
@@ -174,9 +174,3 @@ def take_action(self, parsed_args):
174174
parsed_args.policy)
175175

176176
return zip(*sorted(six.iteritems(policy._info)))
177-
178-
179-
def _read_blob_file_contents(blob_file):
180-
with open(blob_file) as file:
181-
blob = file.read().strip()
182-
return blob

0 commit comments

Comments
 (0)