Revision 17d86215 kamaki/cli/commands/astakos_cli.py

b/kamaki/cli/commands/astakos_cli.py
33 33

  
34 34
from kamaki.cli import command
35 35
from kamaki.clients.astakos import AstakosClient
36
<<<<<<< HEAD
37
from kamaki.cli.utils import print_dict, print_items
38
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
39
from kamaki.cli.commands import _command_init
40
=======
41 36
from kamaki.cli.utils import print_dict
42 37
from kamaki.cli.commands import _command_init, errors
43
>>>>>>> develop
44 38
from kamaki.cli.command_tree import CommandTree
45 39
from kamaki.cli.argument import ValueArgument
46 40

  
......
65 59

  
66 60
@command(astakos_cmds)
67 61
class astakos_authenticate(_astakos_init):
68
<<<<<<< HEAD
69
    """Authenticate a user, show user information"""
70

  
71
    def main(self, token=None):
72
        super(self.__class__, self).main()
73
        try:
74
            reply = self.client.authenticate(token)
75
        except Exception as err:
76
            raiseCLIError(err)
77
        print_dict(reply)
78

  
79

  
80
@command(astakos_cmds)
81
class astakos_admin_userinfo(_astakos_init):
82
    """Get user info, provided you have admin privileges"""
83

  
84
    def __init__(self, arguments={}):
85
        super(self.__class__, self).__init__(arguments)
86
        self.arguments['email'] = ValueArgument('target user email', '--email')
87
        self.arguments['username'] = ValueArgument('target username',
88
            '--username')
89

  
90
    def main(self, admin_token=None):
91
        super(self.__class__, self).main()
92
        email = self.get_argument('email')
93
        username = self.get_argument('username')
94
        try:
95
            if email and username:
96
                raise CLISyntaxError(
97
                    'Arguments %s and %s are mutually exclusive' % (
98
                        self.arguments['email'].parsed_name,
99
                        self.arguments['username'].parsed_name
100
                        ), importance=1)
101
            elif email:
102
                reply = self.client.get_user_by_email(email,
103
                    admin=True,
104
                    token=admin_token)
105
            elif username:
106
                reply = self.client.get_user_by_username(username,
107
                    admin=True,
108
                    token=admin_token)
109
            else:
110
                raise CLISyntaxError(
111
                    'Exactly one of %s or %s is obligatory' % (
112
                        self.arguments['email'].parsed_name,
113
                        self.arguments['username'].parsed_name
114
                        ), importance=1)
115
        except Exception as err:
116
            raiseCLIError(err)
117
        print_dict(reply)
118

  
119

  
120
@command(astakos_cmds)
121
class astakos_service_userinfo(_astakos_init):
122
    """Get user info with service token"""
123

  
124
    def __init__(self, arguments={}):
125
        super(self.__class__, self).__init__(arguments)
126
        self.arguments['email'] = ValueArgument('target user email', '--email')
127
        self.arguments['username'] = ValueArgument('target username',
128
            '--username')
129

  
130
    def main(self, service_token=None):
131
        super(self.__class__, self).main()
132
        email = self.get_argument('email')
133
        username = self.get_argument('username')
134
        try:
135
            if email and username:
136
                raise CLISyntaxError(
137
                    'Arguments %s and %s are mutually exclusive' % (
138
                        self.arguments['email'].parsed_name,
139
                        self.arguments['username'].parsed_name
140
                        ), importance=1)
141
            elif email:
142
                reply = self.client.get_user_by_email(email,
143
                    token=service_token)
144
            elif username:
145
                reply = self.client.get_user_by_username(username,
146
                    token=service_token)
147
            else:
148
                raise CLISyntaxError(
149
                    'Exactly one of %s or %s is obligatory' % (
150
                        self.arguments['email'].parsed_name,
151
                        self.arguments['username'].parsed_name
152
                        ), importance=1)
153
        except Exception as err:
154
            raiseCLIError(err)
155
        print_dict(reply)
156

  
157

  
158
@command(astakos_cmds)
159
class astakos_service_list(_astakos_init):
160
    """List cloud services associated with astakos"""
161

  
162
    def main(self, token=None):
163
        super(self.__class__, self).main()
164
        reply = self.client.list_services(token)
165
        print_items(reply)
166
=======
167 62
    """Authenticate a user
168 63
    Get user information (e.g. unique account name) from token
169 64
    Token should be set in settings:
......
181 76

  
182 77
    def main(self, custom_token=None):
183 78
        self._run(custom_token)
184
>>>>>>> develop

Also available in: Unified diff