コード例 #1
0
    def handle(self, *args, **options):
        config_manager = Config.objects.db_manager(DEFAULT_DB_ALIAS)

        if options.get('json'):
            print(json.dumps(get_auth_config(config_manager)))
            return

        auth_url, auth_user, auth_key = None, '', ''

        agent_file = options.get('idm_agent_file')
        if agent_file:
            auth_url, auth_user, auth_key = read_agent_file(agent_file)
            set_auth_config(config_manager, auth_url, auth_user, auth_key)
            return

        auth_url = options.get('idm_url')
        if auth_url is None:
            existing_url = config_manager.get_config('external_auth_url')
            auth_url = prompt_for_external_auth_url(existing_url)
        if auth_url == 'none':
            auth_url = ''
        if auth_url:
            if not is_valid_auth_url(auth_url):
                raise InvalidURLError(
                    "Please enter a valid http or https URL.")
            auth_user = options.get('idm_user')
            auth_key = options.get('idm_key')
            if not auth_user:
                auth_user = read_input("Username for IDM API access: ")
            if not auth_key:
                auth_key = read_input("Private key for IDM API access: ")

        set_auth_config(config_manager, auth_url, auth_user, auth_key)
コード例 #2
0
def prompt_for_external_auth_url(existing_url):
    if existing_url == '':
        existing_url = 'none'
    new_url = read_input(
        "URL to external IDM server [default={}]: ".format(existing_url))
    if new_url == '':
        new_url = existing_url
    return new_url
コード例 #3
0
ファイル: configauth.py プロジェクト: zeronewb/maas
def _get_or_prompt(options, option, message, replace_none=False):
    """Return a config option either from command line or interactive input."""
    config = options.get(option)
    if not config:
        config = read_input(message)
    if replace_none and config == 'none':
        config = ''
    return config
コード例 #4
0
def _pick_service(services):
    print('Please select which service to register this MAAS as:\n')
    services_list = sorted(
        (service['name'], service['pending']) for service in services.values())
    for idx, (name, pending) in enumerate(services_list, 1):
        print(' {:3} - {} {}'.format(idx, name,
                                     '(pending)' if pending else ''))
    print()
    idx = read_input('Select service index: ')
    try:
        service_name = services_list[int(idx) - 1][0]
    except (ValueError, IndexError):
        raise CommandError('Invalid index')
    return services[service_name]