Skip to content

Commit

Permalink
removed unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-armah committed Jul 18, 2024
1 parent 6fe5822 commit 7d3e515
Showing 1 changed file with 27 additions and 52 deletions.
79 changes: 27 additions & 52 deletions integration/clients/humanitec_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ async def get_all_environments(self, app) -> List[Dict[str, Any]]:

try:
if cached_environments := await self.cache.get(CACHE_KEYS.ENVIRONMENT):
if cached_environments := cached_environments.get(app["id"]):
if app_environments := cached_environments.get(app["id"]):
logger.info(
f"Retrieved {len(cached_environments)} environment for {app['id']} from cache"
f"Retrieved {len(app_environments)} environment for {app['id']} from cache"
)
return list(cached_environments.values())
return list(app_environments.values())

logger.info("Fetching environments from Humanitec")

Expand All @@ -104,13 +104,13 @@ async def get_all_environments(self, app) -> List[Dict[str, Any]]:
async def get_all_resources(self, app, env) -> List[Dict[str, Any]]:
try:
if cached_resources := await self.cache.get(CACHE_KEYS.RESOURCE):
if cached_resources := cached_resources.get(app["id"], {}).get(
env["id"], {}
if env_resources := cached_resources.get(app["id"], {}).get(
env["id"]
):
logger.info(
f"Retrieved {len(cached_resources)} resources from cache for app {app['id']} and env {env['id']}"
f"Retrieved {len(env_resources)} resources from cache for app {app['id']} and env {env['id']}"
)
return list(cached_resources.values())
return list(env_resources.values())

logger.info("Fetching resources from Humanitec")
endpoint = f"apps/{app['id']}/envs/{env['id']}/resources"
Expand Down Expand Up @@ -141,22 +141,28 @@ async def get_all_resources(self, app, env) -> List[Dict[str, Any]]:
async def get_dependency_graph(
self, app: Dict[str, Any], env: Dict[str, Any]
) -> List[Dict[str, Any]]:
if dependency_graph_id := env.get("last_deploy", {}).get("dependency_graph_id"):
endpoint = f"apps/{app['id']}/envs/{env['id']}/resources/graphs/{dependency_graph_id}"
humanitec_headers = self.get_humanitec_headers()
graph = await self.send_api_request(
"GET", endpoint, headers=humanitec_headers
)
nodes = graph["nodes"]
try:
if dependency_graph_id := env.get("last_deploy", {}).get("dependency_graph_id"):
endpoint = f"apps/{app['id']}/envs/{env['id']}/resources/graphs/{dependency_graph_id}"
humanitec_headers = self.get_humanitec_headers()
graph = await self.send_api_request(
"GET", endpoint, headers=humanitec_headers
)
nodes = graph["nodes"]
logger.info(
f"Received {len(nodes)} graph nodes for {env['id']} environment in {app['id']}"
)
return nodes

logger.info(
f"Received {len(nodes)} graph nodes for {env['id']} environment in {app['id']}"
f"No dependency graph found for {env['id']} environment in {app['id']}"
)
return nodes

logger.info(
f"No dependency graph found for {env['id']} environment in {app['id']}"
)
return []
return []
except Exception as e:
logger.error(
f"Failed to fetch dependency graphs for {env['id']} environment in {app['id']}: {str(e)}"
)
return []

async def get_resource_graph(
self, app: Dict[str, Any], env: Dict[str, Any], data: List[Dict[str, Any]]
Expand All @@ -168,37 +174,6 @@ async def get_resource_graph(
)
return graph

async def get_all_resource_graphs(
self, modules: List[Dict[str, Any]], app: Dict[str, Any], env: Dict[str, Any]
) -> List[Dict[str, Any]]:

try:

def get_resource_graph_request_body(modules):
return [
{
"id": module["res_id"],
"type": module["type"],
"resource": module["resource"],
}
for module in modules
]

data = get_resource_graph_request_body(modules)

graph_entities: List[Dict[str, Any]] = await self.get_resource_graph(
app, env, data
)
logger.info(
f"Received {len(graph_entities)} resource graph entities from app: {app['id']} and env: {env['id']} using data: {data}"
)
return graph_entities
except Exception as e:
logger.error(
f"Failed to fetch resource graphs from {env['id']} environment in {app['id']}: {str(e)}"
)
return []

def group_resources_by_type(
self, data: List[Dict[str, Any]]
) -> Dict[str, List[Dict[str, Any]]]:
Expand Down

0 comments on commit 7d3e515

Please sign in to comment.