qontract-reconcile 0.10.1rc1148__py3-none-any.whl → 0.10.1rc1150__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qontract-reconcile
3
- Version: 0.10.1rc1148
3
+ Version: 0.10.1rc1150
4
4
  Summary: Collection of tools to reconcile services with their desired state as defined in the app-interface DB.
5
5
  Home-page: https://github.com/app-sre/qontract-reconcile
6
6
  Author: Red Hat App-SRE Team
@@ -574,7 +574,7 @@ reconcile/test/test_terraform_vpc_peerings.py,sha256=bpjCjhmic07cw3XKSHf-2JvmLuW
574
574
  reconcile/test/test_terraform_vpc_peerings_build_desired_state.py,sha256=cHmr1_yhRgfdqlFX6TMw-aiKXebaRv0szl16M9YRJic,49988
575
575
  reconcile/test/test_three_way_diff_strategy.py,sha256=v3rNkQFNy5e1uyfeNSlNBA07fvrPGD0aXD91Lgv8oxc,4062
576
576
  reconcile/test/test_utils_jinja2.py,sha256=rKugJEPl0qFC9joenJBXyk2qe-9md31-4EdxvQ2h5cs,4058
577
- reconcile/test/test_vault_replication.py,sha256=auadux0xrZb82xh7gKXThCQMct5nhbvujR-6m8um0yE,17522
577
+ reconcile/test/test_vault_replication.py,sha256=WO18WnkXXQDqJ0FnSCl2HOiTfSY3LdRnKn_y6-Gre3w,17490
578
578
  reconcile/test/test_vault_utils.py,sha256=vbJnc89XAuE07qbTuWxHM5o9F6R9SO5aHXA38fwxT7A,1122
579
579
  reconcile/test/test_version_bump.py,sha256=q6-3Y1roriI6YWpFwaHOMN7emEP3yL33sh_0VdbmG7E,511
580
580
  reconcile/test/test_vpc_peerings_validator.py,sha256=dFSmjc_dMN2GqMbntCFpa7PUZmyYuQ9DKffh-T5wmxM,6639
@@ -838,7 +838,7 @@ tools/app_interface_metrics_exporter.py,sha256=zkwkxdAUAxjdc-pzx2_oJXG25fo0Fnyd5
838
838
  tools/app_interface_reporter.py,sha256=oZPib4HPq0aZ2Zui1QGJGk6qQdfpeihujGDBnSdKyGE,17627
839
839
  tools/glitchtip_access_reporter.py,sha256=oPBnk_YoDuljU3v0FaChzOwwnk4vap1xEE67QEjzdqs,2948
840
840
  tools/glitchtip_access_revalidation.py,sha256=8kbBJk04mkq28kWoRDDkfCGIF3GRg3pJrFAh1sW0dbk,2821
841
- tools/qontract_cli.py,sha256=OPfTSTyzhWrE1-s0Dl2L57aJ3soYpvAKKQmRlQnc6l0,139114
841
+ tools/qontract_cli.py,sha256=dGK3kA7DS9ld63k3i4k8pY65D8MeQCjalte22TDXEwU,140204
842
842
  tools/sd_app_sre_alert_report.py,sha256=e9vAdyenUz2f5c8-z-5WY0wv-SJ9aePKDH2r4IwB6pc,5063
843
843
  tools/template_validation.py,sha256=qpKYaTgk0GOPGa2Ct5_5sKdwIHtCAKIBGzsMPuJU5fw,3371
844
844
  tools/cli_commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -871,8 +871,8 @@ tools/test/test_qontract_cli.py,sha256=_D61RFGAN5x44CY1tYbouhlGXXABwYfxKSWSQx3Jr
871
871
  tools/test/test_saas_promotion_state.py,sha256=dy4kkSSAQ7bC0Xp2CociETGN-2aABEfL6FU5D9Jl00Y,6056
872
872
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
873
873
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
874
- qontract_reconcile-0.10.1rc1148.dist-info/METADATA,sha256=D-ZIpS5GYoipyMcDl5QuXJTq3n-DsESc0GbyvYDrNjM,2213
875
- qontract_reconcile-0.10.1rc1148.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
876
- qontract_reconcile-0.10.1rc1148.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
877
- qontract_reconcile-0.10.1rc1148.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
878
- qontract_reconcile-0.10.1rc1148.dist-info/RECORD,,
874
+ qontract_reconcile-0.10.1rc1150.dist-info/METADATA,sha256=C_3wTc7F0vF9ai1ABtWqBjJCpW4gunMjA7cYGBSr5xU,2213
875
+ qontract_reconcile-0.10.1rc1150.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
876
+ qontract_reconcile-0.10.1rc1150.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
877
+ qontract_reconcile-0.10.1rc1150.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
878
+ qontract_reconcile-0.10.1rc1150.dist-info/RECORD,,
@@ -504,20 +504,19 @@ def test_get_policy_secret_list(mocker):
504
504
  vault_client.list_all.side_effect = [
505
505
  ["policy/path/1/secret1", "policy/path/1/secret2"],
506
506
  ["policy/path/2/secret1", "policy/path/2/secret2"],
507
- ["my-policy/path_to_it/3/secret1"],
508
507
  ]
509
508
 
510
509
  assert set(
511
510
  integ.get_policy_secret_list(
512
511
  vault_client,
513
- ["policy/path/1/*", "policy/path/2/*", "policy/path/3/secret1"],
512
+ ["policy/path/1/*", "policy/path/2/*", "policy/p-a_th/3/secret1_1-1"],
514
513
  )
515
514
  ) == {
516
515
  "policy/path/1/secret1",
517
516
  "policy/path/1/secret2",
518
517
  "policy/path/2/secret1",
519
518
  "policy/path/2/secret2",
520
- "policy/path/3/secret1",
519
+ "policy/p-a_th/3/secret1_1-1",
521
520
  }
522
521
 
523
522
 
tools/qontract_cli.py CHANGED
@@ -7,6 +7,7 @@ import logging
7
7
  import os
8
8
  import re
9
9
  import sys
10
+ import textwrap
10
11
  from collections import defaultdict
11
12
  from datetime import (
12
13
  UTC,
@@ -1372,53 +1373,70 @@ def aws_creds(ctx, account_name):
1372
1373
 
1373
1374
 
1374
1375
  @root.command()
1375
- @click.argument("account_name")
1376
- @click.argument("bucket")
1377
- @click.argument("src")
1378
- @click.argument("dest")
1379
- @click.argument("region", required=False, default="us-east-1")
1376
+ @click.option(
1377
+ "--account-uid",
1378
+ help="account UID of the account that owns the bucket",
1379
+ required=True,
1380
+ )
1381
+ @click.option(
1382
+ "--source-bucket",
1383
+ help="aws bucket where the source statefile is stored",
1384
+ required=True,
1385
+ )
1386
+ @click.option(
1387
+ "--source-object-path",
1388
+ help="path in the bucket where the statefile is stored",
1389
+ required=True,
1390
+ )
1391
+ @click.option(
1392
+ "--rename",
1393
+ help="optionally rename the destination repo, otherwise keep the same name for the new location",
1394
+ )
1395
+ @click.option("--region", help="AWS region")
1380
1396
  @click.option(
1381
1397
  "--force/--no-force",
1382
1398
  help="Force the copy even if a statefile already exists at the destination",
1383
1399
  default=False,
1384
1400
  )
1385
1401
  @click.pass_context
1386
- def copy_tfstate(ctx, account_name, bucket, src, dest, region, force):
1387
- """copy a manually managed terraform state file to the correct location expected by
1388
- the terraform-repo integration.
1389
-
1390
- SRC should include the full filename including the extension
1391
-
1392
- DEST should include the filename without extension.
1393
- """
1402
+ def copy_tfstate(
1403
+ ctx, source_bucket, source_object_path, account_uid, rename, region, force
1404
+ ):
1394
1405
  settings = queries.get_app_interface_settings()
1395
1406
  secret_reader = SecretReader(settings=settings)
1396
- accounts = queries.get_aws_accounts(name=account_name, terraform_state=True)
1407
+ accounts = queries.get_aws_accounts(uid=account_uid, terraform_state=True)
1397
1408
  if not accounts:
1398
- print(f"{account_name} not found.")
1409
+ print(f"{account_uid} not found in App-Interface.")
1399
1410
  sys.exit(1)
1400
1411
  account = accounts[0]
1401
1412
 
1402
- state_key = [
1413
+ # terraform repo stores its statefiles within a "folder" in AWS S3 which is defined in App-Interface
1414
+ dest_folder = [
1403
1415
  i
1404
1416
  for i in account["terraformState"]["integrations"]
1405
1417
  if i["integration"] == "terraform-repo"
1406
1418
  ]
1407
- if len(state_key) == 0:
1419
+ if not dest_folder:
1408
1420
  logging.error(
1409
- "terraform-repo is missing a section in this account's '/dependencies/terraform-state-1.yml' file, please add one using the docs in https://gitlab.cee.redhat.com/service/app-interface/-/blob/master/docs/terraform-repo/sop/migrating-existing-state.md?ref_type=heads and then try again"
1421
+ "terraform-repo is missing a section in this account's '/dependencies/terraform-state-1.yml' file, please add one using the docs in https://gitlab.cee.redhat.com/service/app-interface/-/blob/master/docs/terraform-repo/getting-started.md?ref_type=heads#step-1-setup-aws-account and then try again"
1410
1422
  )
1411
1423
  return
1412
1424
 
1413
- dest_key = f"{state_key[0]['key']}/{dest}-tf-repo.tfstate"
1425
+ dest_filename = ""
1426
+ if rename:
1427
+ dest_filename = rename.removesuffix(".tfstate")
1428
+ else:
1429
+ dest_filename = source_object_path.removesuffix(".tfstate")
1430
+
1431
+ dest_key = f"{dest_folder[0]['key']}/{dest_filename}-tf-repo.tfstate"
1414
1432
  dest_bucket = account["terraformState"]["bucket"]
1415
1433
 
1416
1434
  with AWSApi(1, accounts, settings, secret_reader) as aws:
1417
- session = aws.get_session(account_name)
1435
+ session = aws.get_session(account["name"])
1418
1436
  s3_client = aws.get_session_client(session, "s3", region)
1419
1437
  copy_source = {
1420
- "Bucket": bucket,
1421
- "Key": src,
1438
+ "Bucket": source_bucket,
1439
+ "Key": source_object_path,
1422
1440
  }
1423
1441
 
1424
1442
  dest_pretty_path = f"s3://{dest_bucket}/{dest_key}"
@@ -1438,10 +1456,25 @@ def copy_tfstate(ctx, account_name, bucket, src, dest, region, force):
1438
1456
  )
1439
1457
  return
1440
1458
 
1441
- prompt_text = f"Are you sure you want to copy 's3://{bucket}/{src}' to '{dest_pretty_path}'?"
1459
+ prompt_text = f"Are you sure you want to copy 's3://{source_bucket}/{source_object_path}' to '{dest_pretty_path}'?"
1442
1460
  if click.confirm(prompt_text):
1443
1461
  s3_client.copy(copy_source, dest_bucket, dest_key)
1444
- logging.info("successfully copied the statefile to the new location")
1462
+ print(
1463
+ textwrap.dedent(f"""
1464
+ Nicely done! Your tfstate file has been migrated. Now you can create a repo definition in App-Interface like so:
1465
+
1466
+ ---
1467
+ $schema: /aws/terraform-repo-1.yml
1468
+
1469
+ account:
1470
+ $ref: {account["path"]}
1471
+
1472
+ name: {dest_filename}
1473
+ repository: <FILL_IN>
1474
+ projectPath: <FILL_IN>
1475
+ tfVersion: <FILL_IN>
1476
+ ref: <FILL_IN>""")
1477
+ )
1445
1478
 
1446
1479
 
1447
1480
  @get.command(short_help='obtain "rosa create cluster" command by cluster name')