external-resources-io 0.0.1.post1__tar.gz

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.
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: external-resources-io
3
+ Version: 0.0.1.post1
4
+ Summary: Util classes for AppSRE External Resources system
5
+ Author: Jordi Piriz
6
+ Author-email: jpiriz@redhat.com
7
+ Requires-Python: >=3.11,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: pydantic (>=2.5.3,<2.6.0)
12
+ Description-Content-Type: text/markdown
13
+
14
+ # External Resources IO
15
+
16
+ This is a WIP
17
+
18
+ Utility library to parse INPUT data from App-Interface into External Resource modules.
19
+
@@ -0,0 +1,5 @@
1
+ # External Resources IO
2
+
3
+ This is a WIP
4
+
5
+ Utility library to parse INPUT data from App-Interface into External Resource modules.
@@ -0,0 +1,77 @@
1
+ from pydantic import BaseModel
2
+ from typing import Optional
3
+ import json
4
+ import base64
5
+ from typing import TypeVar, Type, Any
6
+ from collections.abc import Mapping
7
+ import os
8
+
9
+ # EXAMPLE INPUT
10
+ # {
11
+ # "data": {
12
+ # "identifier": "test-external-resources-iam-role",
13
+ # "assume_role": {
14
+ # "aws": null,
15
+ # "service": [
16
+ # "ec2.amazonaws.com"
17
+ # ],
18
+ # "federated": null
19
+ # },
20
+ # "inline_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"ec2:DescribeVpcs\"],\"Resource\":[\"*\"]}]}",
21
+ # "output_resource_name": "test-external-resources",
22
+ # "region": "us-east-1"
23
+ # },
24
+ # "provision": {
25
+ # "provision_provider": "aws",
26
+ # "provisioner": "ter-int-dev",
27
+ # "provider": "aws-iam-role",
28
+ # "identifier": "test-external-resources-iam-role",
29
+ # "target_cluster": "app-sre-stage-01",
30
+ # "target_namespace": "test-jpiriz",
31
+ # "target_secret_name": "test-external-resources",
32
+ # "module_provision_data": {
33
+ # "tf_state_bucket": "test-external-resources-state",
34
+ # "tf_state_region": "us-east-1",
35
+ # "tf_state_dynamodb_table": "test-external-resources-lock",
36
+ # "tf_state_key": "aws/ter-int-dev/aws-iam-role/test-external-resources-iam-role/terraform.state"
37
+ # }
38
+ # }
39
+ # }
40
+
41
+
42
+ class TerraformProvisionOptions(BaseModel):
43
+ tf_state_bucket: str
44
+ tf_state_region: str
45
+ tf_state_dynamodb_table: str
46
+ tf_state_key: str
47
+
48
+
49
+ class AppInterfaceProvision(BaseModel):
50
+ provision_provider: str # aws
51
+ provisioner: str # ter-int-dev
52
+ provider: str # aws-iam-role
53
+ identifier: str
54
+ target_cluster: str
55
+ target_namespace: str
56
+ target_secret_name: Optional[str]
57
+ module_provision_data: TerraformProvisionOptions
58
+
59
+
60
+ T = TypeVar("T", bound=BaseModel)
61
+
62
+ def parse_model(model_class: Type[T], data: Mapping[str, Any]) -> T:
63
+ input = model_class.model_validate(data)
64
+ return input
65
+
66
+ def read_input_from_file(file_path: str = "/inputs/input.json") -> dict[str, Any]:
67
+ with open(file_path, "r") as f:
68
+ return json.loads(f.read())
69
+
70
+ def read_input_from_env_var(var: str = "INPUT") -> dict[str, Any]:
71
+ b64data = os.environ[var]
72
+ str_input = base64.b64decode(b64data.encode("utf-8")).decode("utf-8")
73
+ return json.loads(str_input)
74
+
75
+ def check_container_env() -> None:
76
+ if "INPUT" not in os.environ:
77
+ raise Exception("INPUT env var not present")
@@ -0,0 +1,24 @@
1
+ [tool.poetry]
2
+ name = "external-resources-io"
3
+ version = "0.0.1-1"
4
+ description = "Util classes for AppSRE External Resources system"
5
+ authors = ["Jordi Piriz <jpiriz@redhat.com>"]
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.11"
10
+ pydantic = "~2.5.3"
11
+
12
+
13
+ [tool.poetry.group.dev.dependencies]
14
+ pytest = "^7.4.4"
15
+
16
+ [build-system]
17
+ requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
18
+ build-backend = "poetry_dynamic_versioning.backend"
19
+
20
+ [tool.poetry-dynamic-versioning]
21
+ enable = false
22
+ vcs = "git"
23
+ format = "{base}-{distance}"
24
+ latest-tag= true