def get_user_input(env): """Ask for username, secret (api_key or password) and endpoint_url.""" defaults = config.get_settings_from_client(env.client) # Ask for username username = env.input('Username', default=defaults['username']) # Ask for 'secret' which can be api_key or their password secret = env.getpass('API Key or Password', default=defaults['api_key']) # Ask for which endpoint they want to use endpoint_type = env.input('Endpoint (public|private|custom)', default='public') endpoint_type = endpoint_type.lower() if endpoint_type == 'custom': endpoint_url = env.input('Endpoint URL', default=defaults['endpoint_url']) elif endpoint_type == 'private': endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT else: endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT # Ask for timeout timeout = env.input('Timeout', default=defaults['timeout'] or 0) return username, secret, endpoint_url, timeout
def get_user_input(env): """Ask for username, secret (api_key or password) and endpoint_url.""" defaults = config.get_settings_from_client(env.client) # Ask for username username = env.input('Username', default=defaults['username']) # Ask for 'secret' which can be api_key or their password secret = env.getpass('API Key or Password', default=defaults['api_key']) # Ask for which endpoint they want to use endpoint_type = env.input( 'Endpoint (public|private|custom)', default='public') endpoint_type = endpoint_type.lower() if endpoint_type is None: endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT if endpoint_type == 'public': endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT elif endpoint_type == 'private': endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT elif endpoint_type == 'custom': endpoint_url = env.input('Endpoint URL', default=defaults['endpoint_url']) # Ask for timeout timeout = env.input('Timeout', default=defaults['timeout'] or 0) return username, secret, endpoint_url, timeout
def get_user_input(env): """Ask for username, secret (api_key or password) and endpoint_url.""" defaults = config.get_settings_from_client(env.client) timeout = defaults['timeout'] # Ask for username for _ in range(3): username = (env.input('Username [%s]: ' % defaults['username']) or defaults['username']) if username: break else: raise exceptions.CLIAbort('Aborted after 3 attempts') # Ask for 'secret' which can be api_key or their password for _ in range(3): secret = (env.getpass('API Key or Password [%s]: ' % defaults['api_key']) or defaults['api_key']) if secret: break else: raise exceptions.CLIAbort('Aborted after 3 attempts') # Ask for which endpoint they want to use for _ in range(3): endpoint_type = env.input( 'Endpoint (public|private|custom): ') endpoint_type = endpoint_type.lower() if not endpoint_type: endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT break if endpoint_type == 'public': endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT break elif endpoint_type == 'private': endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT break elif endpoint_type == 'custom': endpoint_url = env.input( 'Endpoint URL [%s]: ' % defaults['endpoint_url'] ) or defaults['endpoint_url'] break else: raise exceptions.CLIAbort('Aborted after 3 attempts') return username, secret, endpoint_url, timeout
def get_user_input(env): """Ask for username, secret (api_key or password) and endpoint_url.""" defaults = config.get_settings_from_client(env.client) timeout = defaults['timeout'] # Ask for username for _ in range(3): username = (env.input('Username [%s]: ' % defaults['username']) or defaults['username']) if username: break else: raise exceptions.CLIAbort('Aborted after 3 attempts') # Ask for 'secret' which can be api_key or their password for _ in range(3): secret = (env.getpass( 'API Key or Password [%s]: ' % defaults['api_key']) or defaults['api_key']) if secret: break else: raise exceptions.CLIAbort('Aborted after 3 attempts') # Ask for which endpoint they want to use for _ in range(3): endpoint_type = env.input('Endpoint (public|private|custom): ') endpoint_type = endpoint_type.lower() if not endpoint_type: endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT break if endpoint_type == 'public': endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT break elif endpoint_type == 'private': endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT break elif endpoint_type == 'custom': endpoint_url = env.input( 'Endpoint URL [%s]: ' % defaults['endpoint_url']) or defaults['endpoint_url'] break else: raise exceptions.CLIAbort('Aborted after 3 attempts') return username, secret, endpoint_url, timeout
def cli(env): """Show current configuration.""" settings = config.get_settings_from_client(env.client) return config.config_table(settings)
def cli(env, auth): """Setup the ~/.softlayer file with username and apikey. [Auth Types] ibmid: Requires your cloud.ibm.com username and password, and generates a classic infrastructure API key. cloud_key: A 32 character API key. Username will be 'apikey' classic_key: A 64 character API key used in the Softlayer/Classic Infrastructure systems. sso: For users with @ibm.com email addresses. """ username = None api_key = None timeout = 0 defaults = config.get_settings_from_client(env.client) endpoint_url = get_endpoint_url(env, defaults.get('endpoint_url', 'public')) # Get ths username and API key if auth == 'ibmid': username, api_key = ibmid_login(env) elif auth == 'cloud_key': username = '******' secret = env.getpass('Classic Infrastructue API Key', default=defaults['api_key']) new_client = SoftLayer.Client(username=username, api_key=secret, endpoint_url=endpoint_url, timeout=timeout) api_key = get_api_key(new_client, username, secret) elif auth == 'sso': username, api_key = sso_login(env) else: username = env.input('Classic Infrastructue Username', default=defaults['username']) secret = env.getpass('Classic Infrastructue API Key', default=defaults['api_key']) new_client = SoftLayer.Client(username=username, api_key=secret, endpoint_url=endpoint_url, timeout=timeout) api_key = get_api_key(new_client, username, secret) # Ask for timeout, convert to float, then to int timeout = int(float(env.input('Timeout', default=defaults['timeout'] or 0))) path = '~/.softlayer' if env.config_file: path = env.config_file config_path = os.path.expanduser(path) env.out( env.fmt( config.config_table({ 'username': username, 'api_key': api_key, 'endpoint_url': endpoint_url, 'timeout': timeout }))) if not formatting.confirm( 'Are you sure you want to write settings to "%s"?' % config_path, default=True): raise exceptions.CLIAbort('Aborted.') # Persist the config file. Read the target config file in before # setting the values to avoid clobbering settings parsed_config = configparser.RawConfigParser() parsed_config.read(config_path) try: parsed_config.add_section('softlayer') except configparser.DuplicateSectionError: pass parsed_config.set('softlayer', 'username', username) parsed_config.set('softlayer', 'api_key', api_key) parsed_config.set('softlayer', 'endpoint_url', endpoint_url) parsed_config.set('softlayer', 'timeout', timeout) config_fd = os.fdopen( os.open(config_path, (os.O_WRONLY | os.O_CREAT | os.O_TRUNC), 0o600), 'w') try: parsed_config.write(config_fd) finally: config_fd.close() env.fout("Configuration Updated Successfully")