Statistics
| Branch: | Tag: | Revision:

root / kamaki / cli / commands / astakos_cli.py @ 17d86215

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 43ee6ae1 Stavros Sachtouris
from kamaki.clients.astakos import AstakosClient
36 36526b3c Stavros Sachtouris
from kamaki.cli.utils import print_dict
37 a00de254 Stavros Sachtouris
from kamaki.cli.commands import _command_init, errors
38 be99b6ad Stavros Sachtouris
from kamaki.cli.command_tree import CommandTree
39 33c52ea6 Stavros Sachtouris
from kamaki.cli.argument import ValueArgument
40 7493ccb6 Stavros Sachtouris
41 d486baec Stavros Sachtouris
astakos_cmds = CommandTree('astakos', 'Astakos API commands')
42 d486baec Stavros Sachtouris
_commands = [astakos_cmds]
43 234954d1 Stavros Sachtouris
44 234954d1 Stavros Sachtouris
45 5eae854d Stavros Sachtouris
class _astakos_init(_command_init):
46 36526b3c Stavros Sachtouris
47 a03ade9e Stavros Sachtouris
    @errors.generic.all
48 a03ade9e Stavros Sachtouris
    @errors.astakos.load
49 436bd910 Stavros Sachtouris
    def _run(self):
50 234954d1 Stavros Sachtouris
        token = self.config.get('astakos', 'token')\
51 234954d1 Stavros Sachtouris
            or self.config.get('global', 'token')
52 234954d1 Stavros Sachtouris
        base_url = self.config.get('astakos', 'url')\
53 234954d1 Stavros Sachtouris
            or self.config.get('global', 'url')
54 a7c7afc7 Stavros Sachtouris
        self.client = AstakosClient(base_url=base_url, token=token)
55 7493ccb6 Stavros Sachtouris
56 436bd910 Stavros Sachtouris
    def main(self):
57 436bd910 Stavros Sachtouris
        self._run
58 436bd910 Stavros Sachtouris
59 234954d1 Stavros Sachtouris
60 d486baec Stavros Sachtouris
@command(astakos_cmds)
61 7493ccb6 Stavros Sachtouris
class astakos_authenticate(_astakos_init):
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 a00de254 Stavros Sachtouris
    @errors.astakos.authenticate
72 436bd910 Stavros Sachtouris
    def _run(self, custom_token=None):
73 436bd910 Stavros Sachtouris
        super(self.__class__, self)._run()
74 a00de254 Stavros Sachtouris
        reply = self.client.authenticate(custom_token)
75 234954d1 Stavros Sachtouris
        print_dict(reply)
76 436bd910 Stavros Sachtouris
77 436bd910 Stavros Sachtouris
    def main(self, custom_token=None):
78 436bd910 Stavros Sachtouris
        self._run(custom_token)