qontract-reconcile 0.10.2.dev51__py3-none-any.whl → 0.10.2.dev52__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qontract-reconcile might be problematic. Click here for more details.

tools/qontract_cli.py CHANGED
@@ -20,7 +20,7 @@ from operator import itemgetter
20
20
  from pathlib import Path
21
21
  from statistics import median
22
22
  from textwrap import dedent
23
- from typing import Any
23
+ from typing import TYPE_CHECKING, Any, cast
24
24
 
25
25
  import boto3
26
26
  import click
@@ -186,6 +186,11 @@ from tools.sre_checkpoints import (
186
186
  get_latest_sre_checkpoints,
187
187
  )
188
188
 
189
+ if TYPE_CHECKING:
190
+ from mypy_boto3_s3.type_defs import CopySourceTypeDef
191
+ else:
192
+ CopySourceTypeDef = object
193
+
189
194
 
190
195
  def output(function: Callable) -> Callable:
191
196
  function = click.option(
@@ -1011,6 +1016,7 @@ def clusters_network(ctx: click.Context, name: str) -> None:
1011
1016
  ]
1012
1017
  with AWSApi(1, [account], settings=settings, init_users=False) as aws_api:
1013
1018
  vpc_id, _, _, _ = aws_api.get_cluster_vpc_details(account)
1019
+ assert vpc_id
1014
1020
  cluster["vpc_id"] = vpc_id
1015
1021
  egress_ips = aws_api.get_cluster_nat_gateways_egress_ips(account, vpc_id)
1016
1022
  cluster["egress_ips"] = ", ".join(sorted(egress_ips))
@@ -1459,10 +1465,13 @@ def copy_tfstate(
1459
1465
  with AWSApi(1, accounts, settings, secret_reader) as aws:
1460
1466
  session = aws.get_session(account["name"])
1461
1467
  s3_client = aws.get_session_client(session, "s3", region)
1462
- copy_source = {
1463
- "Bucket": source_bucket,
1464
- "Key": source_object_path,
1465
- }
1468
+ copy_source = cast(
1469
+ CopySourceTypeDef,
1470
+ {
1471
+ "Bucket": source_bucket,
1472
+ "Key": source_object_path,
1473
+ },
1474
+ )
1466
1475
 
1467
1476
  dest_pretty_path = f"s3://{dest_bucket}/{dest_key}"
1468
1477
  # check if dest already exists
@@ -1881,23 +1890,23 @@ def rds_recommendations(ctx: click.Context) -> None:
1881
1890
  with AWSApi(1, [account], settings=settings, init_users=False) as aws:
1882
1891
  try:
1883
1892
  data = aws.describe_rds_recommendations(account_name, region)
1884
- recommendations = data.get("DBRecommendations", [])
1893
+ db_recommendations = data.get("DBRecommendations", [])
1885
1894
  except Exception as e:
1886
1895
  logging.error(f"Error describing RDS recommendations: {e}")
1887
1896
  continue
1888
1897
 
1889
1898
  # Add field ResourceName infered from ResourceArn
1890
1899
  recommendations = [
1891
- {**rec, "ResourceName": rec["ResourceArn"].split(":")[-1]}
1892
- for rec in recommendations
1900
+ {
1901
+ **rec,
1902
+ "ResourceName": rec["ResourceArn"].split(":")[-1],
1903
+ # The Description field has \n that are causing issues with the markdown table
1904
+ "Description": rec["Description"].replace("\n", " "),
1905
+ }
1906
+ for rec in db_recommendations
1893
1907
  if rec.get("Status") not in IGNORED_STATUSES
1894
1908
  and rec.get("Severity") not in IGNORED_SEVERITIES
1895
1909
  ]
1896
- # The Description field has \n that are causing issues with the markdown table
1897
- recommendations = [
1898
- {**rec, "Description": rec["Description"].replace("\n", " ")}
1899
- for rec in recommendations
1900
- ]
1901
1910
  # If we have no recommendations to show, skip
1902
1911
  if not recommendations:
1903
1912
  continue
@@ -2263,7 +2272,7 @@ def app_interface_review_queue(ctx: click.Context) -> None:
2263
2272
  }:
2264
2273
  continue
2265
2274
 
2266
- labels = mr.attributes.get("labels")
2275
+ labels = mr.attributes.get("labels") or []
2267
2276
  if glhk.is_good_to_merge(labels):
2268
2277
  continue
2269
2278
  if "stale" in labels:
@@ -2358,7 +2367,7 @@ def app_interface_open_selfserviceable_mr_queue(ctx: click.Context) -> None:
2358
2367
  continue
2359
2368
 
2360
2369
  # skip stale or non self serviceable MRs
2361
- labels = mr.attributes.get("labels")
2370
+ labels = mr.attributes.get("labels", [])
2362
2371
  if "stale" in labels:
2363
2372
  continue
2364
2373
  if SELF_SERVICEABLE not in labels and SAAS_FILE_UPDATE not in labels:
@@ -2447,7 +2456,7 @@ def app_interface_merge_history(ctx: click.Context) -> None:
2447
2456
  "id": f"[{mr.iid}]({mr.web_url})",
2448
2457
  "title": mr.title,
2449
2458
  "merged_at": mr.merged_at,
2450
- "labels": ", ".join(mr.attributes.get("labels")),
2459
+ "labels": ", ".join(mr.attributes.get("labels", [])),
2451
2460
  }
2452
2461
  merge_queue_data.append(item)
2453
2462
 
@@ -4587,7 +4596,7 @@ def log_group_usage(ctx: click.Context, aws_account: str) -> None:
4587
4596
  settings = queries.get_app_interface_settings()
4588
4597
  secret_reader = SecretReader(settings=settings)
4589
4598
  columns = ["log_group", "stored_bytes", "retention_days"]
4590
- results: list[dict[str, str]] = []
4599
+ results: list[dict[str, str | int]] = []
4591
4600
 
4592
4601
  with AWSApi(1, [account], settings, secret_reader) as aws:
4593
4602
  session = aws.get_session(account["name"])
@@ -1,13 +0,0 @@
1
- def get_or_init(d, k, v):
2
- """Gets (or initiates) a value in a dictionary key
3
-
4
- Args:
5
- d (dict): dictionary to work
6
- k (hashable): key to use
7
- v (value): value to initiate if key doesn't exist
8
-
9
- Returns:
10
- [type]: [description]
11
- """
12
- d.setdefault(k, v)
13
- return d[k]