def save_new_agent_creation_token(): assert os.path.exists(LOCAL_CONFIG_FILE) config = ConfigParser() config.read(LOCAL_CONFIG_FILE) rng = SystemRandom() agent_token = "".join([rng.choice(string.ascii_letters + string.digits) for _ in range(25)]) config.set('faraday_server', 'agent_token', agent_token) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile) faraday.server.config.faraday_server.agent_token = agent_token
def save_new_agent_creation_token_secret(): assert LOCAL_CONFIG_FILE.exists() config = ConfigParser() config.read(LOCAL_CONFIG_FILE) registration_secret = pyotp.random_base32() config.set('faraday_server', 'agent_registration_secret', registration_secret) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile) faraday.server.config.faraday_server.agent_registration_secret = registration_secret
def save_new_secret_key(app): if not os.path.exists(LOCAL_CONFIG_FILE): copy_default_config_to_local() config = ConfigParser() config.read(LOCAL_CONFIG_FILE) rng = SystemRandom() secret_key = "".join([rng.choice(string.ascii_letters + string.digits) for _ in range(25)]) app.config['SECRET_KEY'] = secret_key try: config.set('faraday_server', 'secret_key', secret_key) except NoSectionError: config.add_section('faraday_server') config.set('faraday_server', 'secret_key', secret_key) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile)
def setup_storage_path(): default_path = join(CONST_FARADAY_HOME_PATH, 'storage') if not os.path.exists(default_path): logger.info('Creating directory {0}'.format(default_path)) os.mkdir(default_path) config = ConfigParser() config.read(faraday.server.config.LOCAL_CONFIG_FILE) try: config.add_section('storage') config.set('storage', 'path', default_path) except DuplicateSectionError: logger.info('Duplicate section storage. skipping.') with open(faraday.server.config.LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile) return default_path
def setup_storage_path(): default_path = CONST_FARADAY_HOME_PATH / 'storage' if not default_path.exists(): logger.info(f'Creating directory {default_path}') default_path.mkdir() config = ConfigParser() config.read(faraday.server.config.LOCAL_CONFIG_FILE) try: config.add_section('storage') config.set('storage', 'path', str(default_path)) except DuplicateSectionError: logger.info('Duplicate section storage. skipping.') with faraday.server.config.LOCAL_CONFIG_FILE.open('w') as configfile: config.write(configfile) return default_path
def _save_config(self, config, username, password, database_name, hostname): """ This step saves database configuration to server.ini """ print(f'Saving database credentials file in {LOCAL_CONFIG_FILE}') conn_string = 'postgresql+psycopg2://{username}:{password}@{server}/{database_name}'.format( username=username, password=password, server=hostname, database_name=database_name) config.set('database', 'connection_string', conn_string) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile) return conn_string