Пример #1
0
 def handle(self, client, parser):
     auth = parser.add_argument_group('OAuth2.0 Options')
     auth.add_argument('--conf.client_id', metavar='TEXT')
     auth.add_argument('--conf.client_secret', metavar='TEXT')
     auth.add_argument('--conf.scope',
                       choices=['read', 'write'],
                       default='write')
     parsed = parser.parse_known_args()[0]
     kwargs = {
         'client_id': getattr(parsed, 'conf.client_id', None),
         'client_secret': getattr(parsed, 'conf.client_secret', None),
         'scope': getattr(parsed, 'conf.scope', None),
     }
     try:
         token = api.Api().get_oauth2_token(**kwargs)
     except Exception as e:
         add_authentication_arguments(parser, os.environ)
         parser.print_help()
         cprint(
             'Error retrieving an OAuth2.0 token ({}).'.format(e.__class__),
             'red')
     else:
         print('export TOWER_TOKEN={}'.format(token))
Пример #2
0
 def print_help(self, parser):
     add_authentication_arguments(parser, os.environ)
     parser.print_help()