def test_tool_info_set(): tool_obj = ToolInfo(**FAKE_TOOL_INFO) # Unable to change name with pytest.raises(AttributeError): tool_obj.name = "new_name" with pytest.raises(ValueError): tool_obj.updated = "16062006" tool_obj.updated = datetime(2020, 3, 11, 11, 37) assert tool_obj.updated == datetime(2020, 3, 11, 11, 37)
def fetch_tags(self, tool: ToolInfo, update_cache: bool = False): """ Fetches available tags for single tool from quay.io HTTP API See: https://docs.quay.io/api/swagger/#!/repository/getRepo """ if not self.auth_url: self._set_auth_and_service_location() # In case name includes tag, separate it self.logger.info("fetch %s...", tool.name) tool_name, tool_tag = split_tool_tag(tool.name) # Use name without registry prefix e.g. quay.io # name_without_prefix = "/".join(tool_name.split("/")[-2:]) name_without_prefix = f"{self.cincan_namespace}/{tool_name}" endpoint = f"{self.registry_root}/api/v1/repository/{name_without_prefix}" params = { "includeTags": True, "includeStats": False } resp = None try: resp = self.session.get(endpoint, params=params) except requests.exceptions.ConnectionError as e: self.logger.error(e) if resp and resp.status_code == 200: resp_cont = resp.json() tags = resp_cont.get("tags") tag_names = tags.keys() if tag_names: available_versions = self.update_versions_from_manifest_by_tags(name_without_prefix, tag_names) else: self.logger.error(f"No tags found for tool {tool_name}.") return tool.versions = available_versions tool.updated = datetime.datetime.now() if update_cache: self.update_cache_by_tool(tool) else: self.logger.error(f"Failed to fetch tags for image {tool.name} - not updated") if resp: self._quay_api_error(resp) return