Revision dc897a7e kamaki/cli/__init__.py

b/kamaki/cli/__init__.py
41 41
from kamaki.cli.utils import print_dict, red, magenta, yellow
42 42
from kamaki.cli.errors import CLIError, CLICmdSpecError
43 43
from kamaki.cli import logger
44
from kamaki.clients.astakos import AstakosClient as AuthCachedClient
45
from kamaki.clients import ClientError
44 46

  
45 47
_help = False
46 48
_debug = False
......
285 287
    for term in ('url', 'token'):
286 288
        try:
287 289
            auth_args[term] = _cnf.get_cloud(cloud, term)
288
        except KeyError:
290
        except KeyError or IndexError:
289 291
            auth_args[term] = ''
290 292
        if not auth_args[term]:
291 293
            raise CLIError(
......
296 298
                    '  kamaki config set cloud.%s.%s <%s>' % (
297 299
                        cloud, term, term.upper())])
298 300

  
299
    from kamaki.clients.astakos import AstakosClient as AuthCachedClient
300 301
    try:
301
        return AuthCachedClient(auth_args['url'], auth_args['token']), cloud
302
        auth_base = None
303
        for token in reversed(auth_args['token'].split()):
304
            try:
305
                if auth_base:
306
                    auth_base.authenticate(token)
307
                else:
308
                    auth_base = AuthCachedClient(
309
                        auth_args['url'], auth_args['token'])
310
                    auth_base.authenticate(token)
311
            except ClientError as ce:
312
                if ce.status in (401, ):
313
                    kloger.warning(
314
                        'WARNING: Failed to authorize token %s' % token)
315
                else:
316
                    raise
317
        return auth_base, cloud
302 318
    except AssertionError as ae:
303 319
        kloger.warning('WARNING: Failed to load authenticator [%s]' % ae)
304 320
        return None, cloud

Also available in: Unified diff