Debian Codegraph @

adjutantclient/osc/v1/signup.py

raw
1 # Copyright (c) 2016 Catalyst IT Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import json
16 import logging
17
18 from osc_lib.command import command
19 from osc_lib.i18n import _
20
21 from adjutantclient import client as adjutant_client
22
23
24 LOG = logging.getLogger(__name__)
25
26
27 class Signup(command.Command):
28 """Submits a sign-up request."""
29 auth_required = False
30
31 def get_parser(self, prog_name):
32 parser = super(Signup, self).get_parser(prog_name)
33
34 parser.add_argument(
35 '--user', metavar='<user>',
36 required=False,
37 help=_('Username for new account. '
38 'May not be required depending on API configuration.'),
39 default=None)
40 parser.add_argument(
41 'email', metavar='<email>',
42 help=_('New account email address.'))
43 parser.add_argument(
44 'project_name', metavar='<project_name>',
45 help=_('Name of the new project'))
46 parser.add_argument(
47 '--bypass-url', metavar='<bypass-url>', default=None,
48 help=_('Bypasss URL for unauthenticated access to the endpoint.'))
49 parser.add_argument(
50 '--setup-network', action='store_true',
51 help=_('Create a default network during project creation.'))
52
53 return parser
54
55 def take_action(self, parsed_args):
56 if not parsed_args.bypass_url:
57 # NOTE(amelia): Assumes that this is an already authenticated
58 # user wanting to access and submit a sign up (I.E. an admin)
59 self.app.client_manager._auth_required = True
60 self.app.client_manager.setup_auth()
61 client = self.app.client_manager.admin_logic
62 else:
63 client = adjutant_client.Client(1, parsed_args.bypass_url)
64
65 signup = client.signup.post(parsed_args.user, parsed_args.email,
66 parsed_args.project_name,
67 parsed_args.setup_network).json()
68 print(json.dumps(signup, indent=2))