vaultmanager/modules/VaultManagerPolicies.py
def policies_push(self):
        """
        Push all policies from policies folder to Vault
        """
        self.logger.info("Pushing Policies to Vault")
        self.logger.debug("Push all policies")
        distant_policies = self.vault_client.policy_list()
        local_policies = []
        # Building local policies list
        for policy_file in glob.iglob(os.path.join(self.policies_folder,
                                                   "*/**/*.hcl"), recursive=True):

            prefix = os.path.relpath(policy_file, self.policies_folder)
            policy_name = prefix.replace("/", "_")
            self.logger.debug("Local policy %s - name: %s found"
                              % (policy_file, policy_name))
            with open(policy_file, 'r') as fd:
                local_policies.append(
                    {"name": policy_name.replace(".hcl", "_policy"),
                     "content": fd.read()})
        # Removing distant policies which doesn't exists locally
        for distant_policy in distant_policies:
            if distant_policy not in [pol["name"] for pol in local_policies]:
                self.logger.info("Removing distant policy " + distant_policy)
                self.vault_client.policy_delete(distant_policy)
        # Push local policies
        for policy in local_policies:
            self.vault_client.policy_set(policy_name=policy["name"],
                                         policy_content=policy["content"])
            if policy["name"] in distant_policies:
                self.logger.info("Policy %s has been updated" % policy["name"])
            else:
                self.logger.info("Policy %s has been created" % policy["name"])
        self.logger.info("Policies pushed to Vault")

        Push all policies from policies folder to Vault
        
Push all policies from policies folder to Vault
Push all policies from policies folder to Vault
def policies_push(self):
        self.logger.info("Pushing Policies to Vault")
        self.logger.debug("Push all policies")
        distant_policies = self.vault_client.policy_list()
        local_policies = []
        for policy_file in glob.iglob(os.path.join(self.policies_folder,
                                                   "*/**/*.hcl"), recursive=True):
            prefix = os.path.relpath(policy_file, self.policies_folder)
            policy_name = prefix.replace("/", "_")
            self.logger.debug("Local policy %s - name: %s found"
                              % (policy_file, policy_name))
            with open(policy_file, 'r') as fd:
                local_policies.append(
                    {"name": policy_name.replace(".hcl", "_policy"),
                     "content": fd.read()})
        for distant_policy in distant_policies:
            if distant_policy not in [pol["name"] for pol in local_policies]:
                self.logger.info("Removing distant policy " + distant_policy)
                self.vault_client.policy_delete(distant_policy)
        for policy in local_policies:
            self.vault_client.policy_set(policy_name=policy["name"],
                                         policy_content=policy["content"])
            if policy["name"] in distant_policies:
                self.logger.info("Policy %s has been updated" % policy["name"])
            else:
                self.logger.info("Policy %s has been created" % policy["name"])
        self.logger.info("Policies pushed to Vault")
def policies_push ( self ) : self . logger . info ( "Pushing Policies to Vault" ) self . logger . debug ( "Push all policies" ) distant_policies = self . vault_client . policy_list ( ) local_policies = [ ] for policy_file in glob . iglob ( os . path . join ( self . policies_folder , "*/**/*.hcl" ) , recursive = True ) : prefix = os . path . relpath ( policy_file , self . policies_folder ) policy_name = prefix . replace ( "/" , "_" ) self . logger . debug ( "Local policy %s - name: %s found" % ( policy_file , policy_name ) ) with open ( policy_file , 'r' ) as fd : local_policies . append ( { "name" : policy_name . replace ( ".hcl" , "_policy" ) , "content" : fd . read ( ) } ) for distant_policy in distant_policies : if distant_policy not in [ pol [ "name" ] for pol in local_policies ] : self . logger . info ( "Removing distant policy " + distant_policy ) self . vault_client . policy_delete ( distant_policy ) for policy in local_policies : self . vault_client . policy_set ( policy_name = policy [ "name" ] , policy_content = policy [ "content" ] ) if policy [ "name" ] in distant_policies : self . logger . info ( "Policy %s has been updated" % policy [ "name" ] ) else : self . logger . info ( "Policy %s has been created" % policy [ "name" ] ) self . logger . info ( "Policies pushed to Vault" )
Push all policies from policies folder to Vault
Push all policies from policies folder to Vault
"""
        Push all policies from policies folder to Vault
        """ # Building local policies list # Removing distant policies which doesn't exists locally # Push local policies
self