Exemple #1
0
    def check(self) -> CheckResult:
        if detect_os() != OS.OS_X:
            return self.passed_with_warning(
                "Not checking docker gcloud configuration as it might require sudo"
            )

        docker_config_path = os.path.expanduser("~/.docker/config.json")
        if not file_exists(docker_config_path):
            return self.failed(f"{docker_config_path} does not exist")

        try:
            with open(docker_config_path, "rb") as docker_config_file:
                docker_config = json.load(docker_config_file)
        except IOError:
            logging.error(f"Exception reading {docker_config_path}",
                          exc_info=True)
            return self.failed(f"Failed to read {docker_config_path}")
        except JSONDecodeError:
            logging.error(f"Exception parsing {docker_config_path}",
                          exc_info=True)
            return self.failed(f"Failed to parse {docker_config_path}")

        if docker_config.get("credHelpers", {}).get("gcr.io") != "gcloud":
            return self.failed("docker gcloud auth not configured")

        return self.passed("docker gcloud auth configured")
Exemple #2
0
    def perform_query(self) -> bool:
        if not file_exists(self.file_path):
            logging.debug(f"File {self.file_path} does not exist")
            return False

        try:
            doc = ElementTree(file=self.file_path)
        except ParseError:
            logging.debug(f"Error parsing {self.file_path}", exc_info=True)
            return False

        query_result = doc.find(self.xpath_query)
        return self.validate_query_result(query_result)
Exemple #3
0
    def check(self) -> CheckResult:
        yarnrc_path = get_yarnrc_path()
        if not file_exists(yarnrc_path):
            return self.failed("~/.yarnrc.yml does not exist")

        try:
            with open(yarnrc_path, "rb") as yarnrc_file:
                yarnrc = yaml.safe_load(yarnrc_file)
        except YAMLError:
            logging.error(f"Exception reading {yarnrc_path}", exc_info=True)
            return self.failed("Failed to parse yarnrc")

        if not yarnrc_contains_scope(yarnrc, self.scope):
            return self.failed(
                f"Scope {self.scope.name} not configured in yarnrc")

        return self.passed(f"Scope {self.scope.name} configured in yarnrc")
Exemple #4
0
    def check(self) -> CheckResult:

        home = str(Path.home())
        possible_paths = [f"{home}/.op/config", f"{home}/.config/op/config"]

        for config_path in possible_paths:
            if file_exists(config_path):
                op_config = json.loads(open(config_path).read())
                account_json = op_config["accounts"]
                repo = next(
                    filter(
                        lambda op_contexts: op_contexts.get("shorthand") ==
                        self.context_name, account_json), None)
                if repo is None:
                    return self.failed(
                        f"{self.context_name} is not configured with OP CLI for the current user"
                    )

                return self.passed(
                    f"{self.context_name} is configured with OP CLI for the current user"
                )

        return self.failed(
            "No 1Password config appears to be present on this machine.")
Exemple #5
0
 def check(self) -> CheckResult:
     files_exist = all([file_exists(expanduser(file_path)) for file_path in self.file_paths])
     return self.verify(files_exist, self.pass_fail_message)