def list_keychains()

in keyper/__init__.py [0:0]


    def list_keychains(*, domain: Optional[str] = None) -> List[str]:
        """Get the list of the current keychains.

        :param domain: The domain to list the keychains for. If left as None, all will be searched.
        """

        log.debug("Listing the current keychains")

        command = ["security", "list-keychains"]

        if domain is not None:
            if domain not in ["user", "system", "common", "dynamic"]:
                raise Exception("Invalid domain: " + domain)

            command += ["-d", domain]

        try:
            keychain_command_output = subprocess.run(
                command,
                universal_newlines=True,
                check=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            ).stdout
        except subprocess.CalledProcessError as ex:
            log.error("Failed to get keychains: %s", ex)
            raise

        # Cleanup the output format into a regular Python list of strings
        keychains = []
        for keychain in keychain_command_output.split("\n"):
            # Remove surrounding whitespace and then surrounding quotes
            current = keychain.strip()[1:-1]
            if not current:
                continue
            current = os.path.realpath(current)
            keychains.append(current)

        log.debug("Current keychains: %s", str(keychains))

        return keychains