Commit 436bd910 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Propagate changes to config_cli

parent a00de254
......@@ -44,13 +44,16 @@ _commands = [astakos_cmds]
class _astakos_init(_command_init):
@errors.astakos.init
def main(self):
def _run(self):
token = self.config.get('astakos', 'token')\
or self.config.get('global', 'token')
base_url = self.config.get('astakos', 'url')\
or self.config.get('global', 'url')
self.client = AstakosClient(base_url=base_url, token=token)
def main(self):
self._run
@command(astakos_cmds)
class astakos_authenticate(_astakos_init):
......@@ -63,7 +66,10 @@ class astakos_authenticate(_astakos_init):
"""
@errors.astakos.authenticate
def main(self, custom_token=None):
super(self.__class__, self).main()
def _run(self, custom_token=None):
super(self.__class__, self)._run()
reply = self.client.authenticate(custom_token)
print_dict(reply)
def main(self, custom_token=None):
self._run(custom_token)
......@@ -33,7 +33,7 @@
from kamaki.cli import command
from kamaki.cli.argument import FlagArgument
from kamaki.cli.commands import _command_init
from kamaki.cli.commands import _command_init, errors
from kamaki.cli.command_tree import CommandTree
config_cmds = CommandTree('config', 'Configuration commands')
......@@ -59,27 +59,34 @@ class config_list(_command_init):
A: Default options remain if not explicitly replaced or deleted
"""
def main(self):
@errors.generic.all
def _run(self):
for section in sorted(self.config.sections()):
items = self.config.items(section)
for key, val in sorted(items):
print('%s.%s = %s' % (section, key, val))
def main(self):
self._run()
@command(config_cmds)
class config_get(_command_init):
"""Show a configuration option
"""
"""Show a configuration option"""
__doc__ += about_options
def main(self, option):
@errors.generic.all
def _run(self, option):
section, sep, key = option.rpartition('.')
section = section or 'global'
value = self.config.get(section, key)
if value:
print(value)
def main(self, option):
self._run(option)
@command(config_cmds)
class config_set(_command_init):
......@@ -87,13 +94,17 @@ class config_set(_command_init):
__doc__ += about_options
def main(self, option, value):
@errors.generic.all
def _run(self, option, value):
section, sep, key = option.rpartition('.')
section = section or 'global'
self.config.set(section, key, value)
self.config.write()
self.config.reload()
def main(self, option, value):
self._run(option, value)
@command(config_cmds)
class config_delete(_command_init):
......@@ -104,13 +115,17 @@ class config_delete(_command_init):
arguments = dict(
default=FlagArgument(
'Remove default value as well (persists until end of sesion)',
'Remove default value as well (persists until end of session)',
'--default')
)
def main(self, option):
@errors.generic.all
def _run(self, option):
section, sep, key = option.rpartition('.')
section = section or 'global'
self.config.remove_option(section, key, self['default'])
self.config.write()
self.config.reload()
def main(self, option):
self._run(option)
......@@ -82,7 +82,7 @@ class astakos(object):
if not getattr(client, 'base_url', False):
raise CLIError('Missing astakos server URL',
importance=3,
details=['Please check if astakos.url is set correctly',
details=['Check if astakos.url is set correctly',
'To get astakos url: /config get astakos.url',
'To set astakos url: /config set astakos.url <URL>'])
return r
......@@ -90,15 +90,16 @@ class astakos(object):
@classmethod
def authenticate(this, foo):
@generic.all
def _raise(self, *args, **kwargs):
try:
return foo(self, *args, **kwargs)
r = foo(self, *args, **kwargs)
except ClientError as ce:
if ce.status == 401:
token = kwargs.get('custom_token', 0) or self.client.token
raiseCLIError(ce,
'Authorization failed for token %s' % token if token\
else 'No token provided',
details=this._token_details)
details=[] if token else this._token_details)
self._raise = foo
return r
return _raise
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment