Statistics
| Branch: | Tag: | Revision:

root / kamaki / cli / commands / astakos.py @ f724cd35

History | View | Annotate | Download (2.9 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 f724cd35 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 7493ccb6 Stavros Sachtouris
39 4018326d Stavros Sachtouris
user_cmds = CommandTree('user', 'Astakos API commands')
40 4018326d Stavros Sachtouris
_commands = [user_cmds]
41 234954d1 Stavros Sachtouris
42 234954d1 Stavros Sachtouris
43 4018326d Stavros Sachtouris
class _user_init(_command_init):
44 36526b3c Stavros Sachtouris
45 a03ade9e Stavros Sachtouris
    @errors.generic.all
46 4018326d Stavros Sachtouris
    @errors.user.load
47 436bd910 Stavros Sachtouris
    def _run(self):
48 f724cd35 Stavros Sachtouris
        #token = self.config.get('user', 'token')\
49 f724cd35 Stavros Sachtouris
        #    or self.config.get('global', 'token')
50 f724cd35 Stavros Sachtouris
        #base_url = self.config.get('global', 'url')
51 f724cd35 Stavros Sachtouris
        #self.client = AstakosClient(base_url=base_url, token=token)
52 f724cd35 Stavros Sachtouris
        self.client = self.auth_base
53 f47417e7 Stavros Sachtouris
        self._set_log_params()
54 c5b9380c Stavros Sachtouris
        self._update_max_threads()
55 7493ccb6 Stavros Sachtouris
56 436bd910 Stavros Sachtouris
    def main(self):
57 5fdccdec Stavros Sachtouris
        self._run()
58 436bd910 Stavros Sachtouris
59 234954d1 Stavros Sachtouris
60 4018326d Stavros Sachtouris
@command(user_cmds)
61 545c6c29 Stavros Sachtouris
class user_authenticate(_user_init, _optional_json):
62 0663d8d6 Stavros Sachtouris
    """Authenticate a user
63 0663d8d6 Stavros Sachtouris
    Get user information (e.g. unique account name) from token
64 0663d8d6 Stavros Sachtouris
    Token should be set in settings:
65 0663d8d6 Stavros Sachtouris
    *  check if a token is set    /config get token
66 0663d8d6 Stavros Sachtouris
    *  permanently set a token    /config set token <token>
67 0663d8d6 Stavros Sachtouris
    Token can also be provided as a parameter
68 0663d8d6 Stavros Sachtouris
    """
69 7493ccb6 Stavros Sachtouris
70 a03ade9e Stavros Sachtouris
    @errors.generic.all
71 4018326d Stavros Sachtouris
    @errors.user.authenticate
72 436bd910 Stavros Sachtouris
    def _run(self, custom_token=None):
73 436bd910 Stavros Sachtouris
        super(self.__class__, self)._run()
74 f724cd35 Stavros Sachtouris
        r = self.auth_base.authenticate(custom_token)
75 f724cd35 Stavros Sachtouris
        self._print([r], title=('uuid', 'name',), with_redundancy=True)
76 436bd910 Stavros Sachtouris
77 436bd910 Stavros Sachtouris
    def main(self, custom_token=None):
78 436bd910 Stavros Sachtouris
        self._run(custom_token)