aws.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from __future__ import annotations
  10. from textwrap import dedent
  11. from materialize.checks.actions import Testdrive
  12. from materialize.checks.checks import Check, externally_idempotent
  13. @externally_idempotent(False)
  14. class AwsConnection(Check):
  15. def initialize(self) -> Testdrive:
  16. return Testdrive(
  17. dedent(
  18. """
  19. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  20. ALTER SYSTEM SET enable_connection_validation_syntax = true
  21. > CREATE CONNECTION aws_assume_role
  22. TO AWS (ASSUME ROLE ARN 'assume-role', ASSUME ROLE SESSION NAME 'session-name');
  23. > CREATE SECRET aws_secret_access_key as '...';
  24. > CREATE CONNECTION aws_credentials
  25. TO AWS (ACCESS KEY ID = 'access_key', SECRET ACCESS KEY = SECRET aws_secret_access_key);
  26. """
  27. )
  28. )
  29. def manipulate(self) -> list[Testdrive]:
  30. return [
  31. Testdrive(dedent(s))
  32. for s in [
  33. """
  34. > ALTER CONNECTION aws_assume_role SET (ASSUME ROLE ARN 'assume-role-2');
  35. """,
  36. """
  37. > ALTER CONNECTION aws_credentials SET (ACCESS KEY ID 'access_key_2');
  38. """,
  39. ]
  40. ]
  41. def validate(self) -> Testdrive:
  42. # We can't actually run `VALIDATE CONNECTION` here because we don't have
  43. # valid AWS credentials. So instead we settle for inspecting the system
  44. # catalog and ensuring it contains the altered values.
  45. return Testdrive(
  46. dedent(
  47. """
  48. > SELECT assume_role_arn FROM mz_internal.mz_aws_connections a
  49. JOIN mz_connections c ON a.id = c.id
  50. WHERE name = 'aws_assume_role'
  51. assume-role-2
  52. > SELECT access_key_id FROM mz_internal.mz_aws_connections a
  53. JOIN mz_connections c ON a.id = c.id
  54. WHERE name = 'aws_credentials'
  55. access_key_2
  56. """
  57. )
  58. )