root / kamaki / cli / commands / astakos.py @ ca5b9261
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 | 8cec3671 | Stavros Sachtouris | from kamaki.clients.astakos import AstakosClient |
36 | b4f69041 | Stavros Sachtouris | from kamaki.cli.commands import ( |
37 | b4f69041 | Stavros Sachtouris | _command_init, errors, _optional_json, addLogSettings) |
38 | be99b6ad | Stavros Sachtouris | from kamaki.cli.command_tree import CommandTree |
39 | 8cec3671 | Stavros Sachtouris | from kamaki.cli.errors import CLIBaseUrlError |
40 | f5c28bfa | Stavros Sachtouris | from kamaki.cli.utils import print_dict |
41 | 7493ccb6 | Stavros Sachtouris | |
42 | 4018326d | Stavros Sachtouris | user_cmds = CommandTree('user', 'Astakos API commands') |
43 | 4018326d | Stavros Sachtouris | _commands = [user_cmds] |
44 | 234954d1 | Stavros Sachtouris | |
45 | 234954d1 | Stavros Sachtouris | |
46 | 4018326d | Stavros Sachtouris | class _user_init(_command_init): |
47 | 36526b3c | Stavros Sachtouris | |
48 | a03ade9e | Stavros Sachtouris | @errors.generic.all
|
49 | 4018326d | Stavros Sachtouris | @errors.user.load
|
50 | b4f69041 | Stavros Sachtouris | @addLogSettings
|
51 | 436bd910 | Stavros Sachtouris | def _run(self): |
52 | b4f69041 | Stavros Sachtouris | if getattr(self, 'cloud', False): |
53 | b4f69041 | Stavros Sachtouris | base_url = self._custom_url('astakos') |
54 | b4f69041 | Stavros Sachtouris | if base_url:
|
55 | b4f69041 | Stavros Sachtouris | token = self._custom_token('astakos')\ |
56 | b4f69041 | Stavros Sachtouris | or self.config.get_remote(self.cloud, 'token') |
57 | b4f69041 | Stavros Sachtouris | self.client = AstakosClient(base_url=base_url, token=token)
|
58 | b4f69041 | Stavros Sachtouris | return
|
59 | b4f69041 | Stavros Sachtouris | else:
|
60 | b4f69041 | Stavros Sachtouris | self.cloud = 'default' |
61 | 8cec3671 | Stavros Sachtouris | if getattr(self, 'auth_base', False): |
62 | 8cec3671 | Stavros Sachtouris | self.client = self.auth_base |
63 | b4f69041 | Stavros Sachtouris | return
|
64 | b4f69041 | Stavros Sachtouris | raise CLIBaseUrlError(service='astakos') |
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 | ca5b9261 | Stavros Sachtouris | * check if a token is set /config get remote.default.token
|
76 | ca5b9261 | Stavros Sachtouris | * permanently set a token /config set remote.default.token <token>
|
77 | 0663d8d6 | Stavros Sachtouris | Token can also be provided as a parameter
|
78 | ca5b9261 | Stavros Sachtouris | (In case of another named cloud remote, use its name instead of default)
|
79 | 0663d8d6 | Stavros Sachtouris | """
|
80 | 7493ccb6 | Stavros Sachtouris | |
81 | f5c28bfa | Stavros Sachtouris | @staticmethod
|
82 | f5c28bfa | Stavros Sachtouris | def _print_access(r): |
83 | f5c28bfa | Stavros Sachtouris | print_dict(r['access'])
|
84 | f5c28bfa | Stavros Sachtouris | |
85 | a03ade9e | Stavros Sachtouris | @errors.generic.all
|
86 | 4018326d | Stavros Sachtouris | @errors.user.authenticate
|
87 | 436bd910 | Stavros Sachtouris | def _run(self, custom_token=None): |
88 | 436bd910 | Stavros Sachtouris | super(self.__class__, self)._run() |
89 | 8cec3671 | Stavros Sachtouris | r = self.client.authenticate(custom_token)
|
90 | f5c28bfa | Stavros Sachtouris | self._print(r, self._print_access) |
91 | 436bd910 | Stavros Sachtouris | |
92 | 436bd910 | Stavros Sachtouris | def main(self, custom_token=None): |
93 | 436bd910 | Stavros Sachtouris | self._run(custom_token) |