def register(config, group_id=None): """ Do registration using basic auth """ username = config.get(APP_NAME, 'username') password = config.get(APP_NAME, 'password') if (( username == "" and password == "" and config.get(APP_NAME, 'authmethod') == 'BASIC') and not config.get(APP_NAME, 'auto_config')): # Get input from user print "Please enter your Red Hat Customer Portal Credentials" sys.stdout.write('User Name: ') username = raw_input().strip() password = getpass.getpass() sys.stdout.write("Would you like to save these credentials? (y/n) ") save = raw_input().strip() config.set(APP_NAME, 'username', username) config.set(APP_NAME, 'password', password) logger.debug("savestr: %s", save) if save.lower() == "y" or save.lower() == "yes": logger.debug("writing user/pass to config file") cmd = ("/bin/sed -e 's/^username.*=.*$/username="******"/' " + "-e 's/^password.*=.*$/password="******"/' " + constants.default_conf_file) status = DataCollector().run_command_get_output(cmd, nolog=True) config_file = open(constants.default_conf_file, 'w') config_file.write(status['output']) config_file.flush() pconn = InsightsConnection(config) return pconn.register(group_id)
def register(config, group_id=None): """ Do registration using basic auth """ username = config.get(APP_NAME, 'username') password = config.get(APP_NAME, 'password') if (((username == "") and (password == "") and (config.get(APP_NAME, 'authmethod') == 'BASIC')) and not (config.get(APP_NAME, 'auto_config'))): # Get input from user print "Please enter your Red Hat Customer Portal Credentials" sys.stdout.write('User Name: ') username = raw_input().strip() password = getpass.getpass() sys.stdout.write("Would you like to save these credentials? (y/n) ") save = raw_input().strip() config.set(APP_NAME, 'username', username) config.set(APP_NAME, 'password', password) logger.debug("savestr: %s", save) if save.lower() == "y" or save.lower() == "yes": logger.debug("writing user/pass to config file") cmd = ("/bin/sed -e 's/^username.*=.*$/username="******"/' " + "-e 's/^password.*=.*$/password="******"/' " + constants.default_conf_file) status = DataCollector().run_command_get_output(cmd, nolog=True) config_file = open(constants.default_conf_file, 'w') config_file.write(status['output']) config_file.flush() pconn = InsightsConnection(config) return pconn.register(group_id)
def register(): """ Do registration using basic auth """ username = InsightsClient.config.get(APP_NAME, 'username') password = InsightsClient.config.get(APP_NAME, 'password') authmethod = InsightsClient.config.get(APP_NAME, 'authmethod') # TODO validate this is boolean somewhere in config load auto_config = InsightsClient.config.getboolean(APP_NAME, 'auto_config') if not username and not password and not auto_config and authmethod == 'BASIC': print 'Please enter your Red Hat Customer Portal Credentials' sys.stdout.write('Username: '******'Would you like to save these credentials? (y/n) ') save = raw_input().strip() InsightsClient.config.set(APP_NAME, 'username', username) InsightsClient.config.set(APP_NAME, 'password', password) logger.debug('savestr: %s', save) if save.lower() == 'y' or save.lower() == 'yes': logger.debug('Writing user/pass to config') cmd = ('/bin/sed -e \'s/^username.*=.*$/username='******'/\' ' + '-e \'s/^password.*=.*$/password='******'/\' ' + constants.default_conf_file) status = DataCollector().run_command_get_output(cmd, nolog=True) with open(constants.default_conf_file, 'w') as config_file: config_file.write(status['output']) config_file.flush() pconn = InsightsConnection() return pconn.register()
def register(): """ Do registration using basic auth """ username = InsightsClient.config.get(APP_NAME, 'username') password = InsightsClient.config.get(APP_NAME, 'password') authmethod = InsightsClient.config.get(APP_NAME, 'authmethod') # TODO validate this is boolean somewhere in config load auto_config = InsightsClient.config.getboolean(APP_NAME, 'auto_config') if not username and not password and not auto_config and authmethod == 'BASIC': print 'Please enter your Red Hat Customer Portal Credentials' sys.stdout.write('Username: '******'Would you like to save these credentials? (y/n) ') save = raw_input().strip() InsightsClient.config.set(APP_NAME, 'username', username) InsightsClient.config.set(APP_NAME, 'password', password) logger.debug('savestr: %s', save) if save.lower() == 'y' or save.lower() == 'yes': logger.debug('Writing user/pass to config') modify_config_file({'username': username, 'password': password}) pconn = InsightsConnection() return pconn.register()