def git_reset(tenant, env): """ Perform git reset in the specified tenant/environment folder. After this, updates the md5 file to reflect the new status. :type tenant: string :param tenant: The name of the tenant. :type env: string :param env: The name of the tenant. :rtype: None :return: the function doesn't have a return statement. """ _dir = utils.get_tenant_dir(tenant) _pipe = subprocess.PIPE subprocess.Popen( ['git', '-C', _dir, 'clean -xdf', env], stdout=_pipe, stderr=_pipe) subprocess.Popen( ['git', '-C', _dir, 'checkout', env], stdout=_pipe, stderr=_pipe) subprocess.Popen( ['git', '-C', _dir, 'reset --hard'], stdout=_pipe, stderr=_pipe) md5_store_folder = utils.get_md5_folder(tenant) md5_store_file = md5_store_folder + "/appflow-" + env + "-md5" utils.safe_remove(md5_store_file) utils.safe_remove(md5_store_file + "-new")
def decrypt(tenant, env): """ Decrypt the tenant/environment data :type tenant: string :param tenant: The name of the tenant. :type env: string :param env: The name of the tenant. :rtype: None :return: the function prints to screen the ansible output of the execution. """ target_folder = utils.get_tenant_env_dir(tenant, env) password_file = utils.get_vault_file(tenant, env) md5_store_folder = utils.get_md5_folder(tenant) md5_store_file = md5_store_folder + "/appflow-" + env + "-md5" utils.safe_remove(md5_store_file) flie_list = utils.get_file_list(target_folder) for file in flie_list: os.system('ansible-vault decrypt ' + file + ' --vault-password-file ' + password_file) utils.write_md5_sum(file, md5_store_file)
def setup_default_config(tenant, env): """ Deploy a default config file in ~/.appflow/config.yml :type tenant: string :param tenant: The name of the tenant. (ex: mrrobot) :type env: string :param env: The name of the tenant. :rtype: None :return: the function prints to screen the ansible output of the execution. """ file_name = os.getenv('HOME') + "/.appflow/config.yml" utils.safe_remove(file_name) conf = {'appflow': {'tenant': {'id': 'appflow-' + tenant, 'name': tenant, 'default_env': env}}} with open(file_name, 'w') as outfile: yaml.dump(conf, outfile, default_flow_style=False, indent=4)
def git_status(tenant, env): """ Return a status of modified files in the tenant/environment folder. this is tracked separately from git, because encryption/decryption of files will always override the git status method. :type tenant: string :param tenant: The name of the tenant. :type env: string :param env: The name of the tenant. :rtype: list :return: the function returns a list containing the different lines between the 2 md5 files. """ _dir = utils.get_tenant_dir(tenant) target_folder = _dir + env if not utils.check_string_in_file(target_folder + "/inventory", 'AES256'): md5_store_folder = utils.get_md5_folder(tenant) md5_store_file = md5_store_folder + "/appflow-" + env + "-md5" md5_store_file_new = md5_store_folder + "/appflow-" + env + "-md5-new" utils.safe_remove(md5_store_file_new) file_list = utils.get_file_list(target_folder) for file in file_list: utils.write_md5_sum(file, md5_store_file_new) diff = utils.diff_files(md5_store_file, md5_store_file_new) return diff # Files are encrypted, simply do a git diff _pipe = subprocess.PIPE out = subprocess.Popen(['git', '-C', _dir, 'diff-files', '--name-only', '-B', '-R', '-M', env], stdout=_pipe, stderr=_pipe) result = [] for line in iter(out.stdout): result.append(line.decode('utf-8')) return result