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
This commit is contained in:
parent
ee22070473
commit
01db6d977f
@ -249,3 +249,13 @@ def get_password(stdin):
|
|||||||
raise exceptions.CommandError("Error reading password.")
|
raise exceptions.CommandError("Error reading password.")
|
||||||
raise exceptions.CommandError("There was a request to be prompted for a"
|
raise exceptions.CommandError("There was a request to be prompted for a"
|
||||||
" password and a terminal was not detected.")
|
" 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)
|
||||||
|
@ -48,7 +48,7 @@ class CreatePolicy(show.ShowOne):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
blob = _read_blob_file_contents(parsed_args.blob_file)
|
blob = utils.read_blob_file_contents(parsed_args.blob_file)
|
||||||
|
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
policy = identity_client.policies.create(
|
policy = identity_client.policies.create(
|
||||||
@ -138,7 +138,7 @@ class SetPolicy(command.Command):
|
|||||||
blob = None
|
blob = None
|
||||||
|
|
||||||
if parsed_args.blob_file:
|
if parsed_args.blob_file:
|
||||||
blob = _read_blob_file_contents(parsed_args.blob_file)
|
blob = utils.read_blob_file_contents(parsed_args.blob_file)
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if blob:
|
if blob:
|
||||||
@ -174,9 +174,3 @@ class ShowPolicy(show.ShowOne):
|
|||||||
parsed_args.policy)
|
parsed_args.policy)
|
||||||
|
|
||||||
return zip(*sorted(six.iteritems(policy._info)))
|
return zip(*sorted(six.iteritems(policy._info)))
|
||||||
|
|
||||||
|
|
||||||
def _read_blob_file_contents(blob_file):
|
|
||||||
with open(blob_file) as file:
|
|
||||||
blob = file.read().strip()
|
|
||||||
return blob
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user