How to use the keyper.__init__.Keychain._create_keychain function in keyper

To help you get started, we’ve selected a few keyper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / keyper / keyper / __init__.py View on Github external
def create_temporary() -> 'Keychain':
        """Create a new temporary keychain."""

        keychain_name = str(uuid.uuid4()) + ".keychain"
        keychain_path = os.path.join(tempfile.gettempdir(), keychain_name)
        keychain_password = ''.join(secrets.choice(_PASSWORD_ALPHABET) for _ in range(50))

        if os.path.exists(keychain_path):
            raise Exception("Cannot create temporary keychain. Path already exists: " + keychain_path)

        keychain = Keychain(keychain_path, keychain_password, is_temporary=True)

        # We have a reference, but now we need to create the keychain with the
        # system.
        Keychain._create_keychain(keychain_path, keychain_password)

        log.info("Created temporary keychain: %s", keychain_path)

        return keychain