Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _run_queries(self, queries: List[Query]) -> None:
"""Creates and runs queries with a maximum concurrency defined by query slots"""
QUERY_TASK_LIMIT = 250
while queries or self._running_queries:
if queries:
logger.debug(f"Starting a new loop, {len(queries)} queries queued")
self._fill_query_slots(queries)
query_tasks = self.get_running_query_tasks()[:QUERY_TASK_LIMIT]
logger.debug(f"Checking for results of {len(query_tasks)} query tasks")
for query_result in self._get_query_results(query_tasks):
self._handle_query_result(query_result)
time.sleep(0.5)
def get_lookml_models(self) -> List[JsonDict]:
"""Gets all models and explores from the LookmlModel endpoint.
Returns:
List[JsonDict]: JSON response containing LookML models and explores.
"""
logger.debug(f"Getting all models and explores from {self.base_url}")
url = utils.compose_url(self.api_url, path=["lookml_models"])
response = self.get(url=url, timeout=TIMEOUT_SEC)
try:
response.raise_for_status()
except requests.exceptions.HTTPError:
raise LookerApiError(
name="unable-to-get-lookml",
title="Couldn't retrieve models and explores.",
status=response.status_code,
detail="Unable to retrieve LookML details. Please try again.",
response=response,
)
return response.json()
def authenticate(self) -> None:
"""Logs in to Looker's API using a client ID/secret pair and an API version.
Args:
client_id: Looker API client ID.
client_secret: Looker API client secret.
api_version: Desired API version to use for requests.
"""
logger.debug("Authenticating Looker API credentials")
url = utils.compose_url(self.api_url, path=["login"])
body = {"client_id": self.client_id, "client_secret": self.client_secret}
# This should not use `self.post` or it will create a recursive loop
response = self.session.post(url=url, data=body, timeout=TIMEOUT_SEC)
try:
response.raise_for_status()
except requests.exceptions.HTTPError:
raise LookerApiError(
name="unable-to-authenticate",
title="Couldn't authenticate to the Looker API.",
status=response.status_code,
detail=(
f"Unable to authenticate with client ID '{self.client_id}'. "
"Check that your credentials are correct and try again."
),
def setup_temp_branch(self, project: str, original_branch: str) -> str:
name = "tmp_spectacles_" + time_hash()
logger.debug(
f"Branch '{name}' will be restored to branch '{original_branch}' in "
f"project '{project}'"
)
self.temp_branches.append(BranchState(project, original_branch, name))
return name
def reset_to_remote(self, project: str) -> None:
"""Reset a project development branch to the revision of the project that is on the remote.
Args:
project: Name of the Looker project to use.
"""
logger.debug("Resetting branch to remote.")
url = utils.compose_url(
self.api_url, path=["projects", project, "reset_to_remote"]
)
response = self.post(url=url, timeout=TIMEOUT_SEC)
try:
response.raise_for_status()
except requests.exceptions.HTTPError:
raise LookerApiError(
name="unable-to-reset-remote",
title="Couldn't checkout Git branch.",
status=response.status_code,
detail=(
"Unable to reset local Git branch"
"to match remote. Please try again."
),
response=response,