Statistics
| Branch: | Tag: | Revision:

root / kamaki / cli / commands / astakos.py @ 54b6be76

History | View | Annotate | Download (3.4 kB)

1 7493ccb6 Stavros Sachtouris
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 7493ccb6 Stavros Sachtouris
#
3 7493ccb6 Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 7493ccb6 Stavros Sachtouris
# without modification, are permitted provided that the following
5 7493ccb6 Stavros Sachtouris
# conditions are met:
6 7493ccb6 Stavros Sachtouris
#
7 7493ccb6 Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 7493ccb6 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 7493ccb6 Stavros Sachtouris
#      disclaimer.
10 7493ccb6 Stavros Sachtouris
#
11 7493ccb6 Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 7493ccb6 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 7493ccb6 Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 7493ccb6 Stavros Sachtouris
#      provided with the distribution.
15 7493ccb6 Stavros Sachtouris
#
16 7493ccb6 Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 7493ccb6 Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 7493ccb6 Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 7493ccb6 Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 7493ccb6 Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 7493ccb6 Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 7493ccb6 Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 7493ccb6 Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 7493ccb6 Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 7493ccb6 Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 7493ccb6 Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 7493ccb6 Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 7493ccb6 Stavros Sachtouris
#
29 7493ccb6 Stavros Sachtouris
# The views and conclusions contained in the software and
30 7493ccb6 Stavros Sachtouris
# documentation are those of the authors and should not be
31 7493ccb6 Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 7493ccb6 Stavros Sachtouris
# or implied, of GRNET S.A.command
33 7493ccb6 Stavros Sachtouris
34 c2be5c96 Stavros Sachtouris
from kamaki.cli import command
35 54b6be76 Stavros Sachtouris
from kamaki.clients.astakos import AstakosClient
36 545c6c29 Stavros Sachtouris
from kamaki.cli.commands import _command_init, errors, _optional_json
37 be99b6ad Stavros Sachtouris
from kamaki.cli.command_tree import CommandTree
38 54b6be76 Stavros Sachtouris
from kamaki.cli.errors import CLIBaseUrlError
39 7493ccb6 Stavros Sachtouris
40 4018326d Stavros Sachtouris
user_cmds = CommandTree('user', 'Astakos API commands')
41 4018326d Stavros Sachtouris
_commands = [user_cmds]
42 234954d1 Stavros Sachtouris
43 234954d1 Stavros Sachtouris
44 4018326d Stavros Sachtouris
class _user_init(_command_init):
45 36526b3c Stavros Sachtouris
46 a03ade9e Stavros Sachtouris
    @errors.generic.all
47 4018326d Stavros Sachtouris
    @errors.user.load
48 436bd910 Stavros Sachtouris
    def _run(self):
49 f724cd35 Stavros Sachtouris
        #token = self.config.get('user', 'token')\
50 f724cd35 Stavros Sachtouris
        #    or self.config.get('global', 'token')
51 f724cd35 Stavros Sachtouris
        #base_url = self.config.get('global', 'url')
52 f724cd35 Stavros Sachtouris
        #self.client = AstakosClient(base_url=base_url, token=token)
53 54b6be76 Stavros Sachtouris
        if getattr(self, 'auth_base', False):
54 54b6be76 Stavros Sachtouris
            self.client = self.auth_base
55 54b6be76 Stavros Sachtouris
        else:
56 54b6be76 Stavros Sachtouris
            token = self.config.get('astakos', 'token')\
57 54b6be76 Stavros Sachtouris
                or self.config.get('global', 'token')
58 54b6be76 Stavros Sachtouris
            base_url = self.config.get('astakos', 'url')
59 54b6be76 Stavros Sachtouris
            if not base_url:
60 54b6be76 Stavros Sachtouris
                raise CLIBaseUrlError(service='astakos')
61 54b6be76 Stavros Sachtouris
            self.client = AstakosClient(base_url=base_url, token=token)
62 54b6be76 Stavros Sachtouris
63 f47417e7 Stavros Sachtouris
        self._set_log_params()
64 c5b9380c Stavros Sachtouris
        self._update_max_threads()
65 7493ccb6 Stavros Sachtouris
66 436bd910 Stavros Sachtouris
    def main(self):
67 5fdccdec Stavros Sachtouris
        self._run()
68 436bd910 Stavros Sachtouris
69 234954d1 Stavros Sachtouris
70 4018326d Stavros Sachtouris
@command(user_cmds)
71 545c6c29 Stavros Sachtouris
class user_authenticate(_user_init, _optional_json):
72 0663d8d6 Stavros Sachtouris
    """Authenticate a user
73 0663d8d6 Stavros Sachtouris
    Get user information (e.g. unique account name) from token
74 0663d8d6 Stavros Sachtouris
    Token should be set in settings:
75 0663d8d6 Stavros Sachtouris
    *  check if a token is set    /config get token
76 0663d8d6 Stavros Sachtouris
    *  permanently set a token    /config set token <token>
77 0663d8d6 Stavros Sachtouris
    Token can also be provided as a parameter
78 0663d8d6 Stavros Sachtouris
    """
79 7493ccb6 Stavros Sachtouris
80 a03ade9e Stavros Sachtouris
    @errors.generic.all
81 4018326d Stavros Sachtouris
    @errors.user.authenticate
82 436bd910 Stavros Sachtouris
    def _run(self, custom_token=None):
83 436bd910 Stavros Sachtouris
        super(self.__class__, self)._run()
84 54b6be76 Stavros Sachtouris
        r = self.client.authenticate(custom_token)
85 f724cd35 Stavros Sachtouris
        self._print([r], title=('uuid', 'name',), with_redundancy=True)
86 436bd910 Stavros Sachtouris
87 436bd910 Stavros Sachtouris
    def main(self, custom_token=None):
88 436bd910 Stavros Sachtouris
        self._run(custom_token)