classifyawsetsjsonbyregion 0.1.0__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.
Files changed (26) hide show
  1. classifyawsetsjsonbyregion-0.1.0/LICENSE +21 -0
  2. classifyawsetsjsonbyregion-0.1.0/MANIFEST.in +2 -0
  3. classifyawsetsjsonbyregion-0.1.0/PKG-INFO +130 -0
  4. classifyawsetsjsonbyregion-0.1.0/README.md +75 -0
  5. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/__init__.py +5 -0
  6. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/analyzer.py +46 -0
  7. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/awsets.py +39 -0
  8. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/awsregion/__init__.py +1 -0
  9. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/awsregion/classifier.py +51 -0
  10. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/cli.py +17 -0
  11. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/config.py +11 -0
  12. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/csv.py +27 -0
  13. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/filepath.py +21 -0
  14. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion/py.typed +0 -0
  15. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/PKG-INFO +130 -0
  16. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/SOURCES.txt +25 -0
  17. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/dependency_links.txt +1 -0
  18. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/entry_points.txt +2 -0
  19. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/not-zip-safe +1 -0
  20. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/requires.txt +7 -0
  21. classifyawsetsjsonbyregion-0.1.0/classifyawsetsjsonbyregion.egg-info/top_level.txt +1 -0
  22. classifyawsetsjsonbyregion-0.1.0/docs/CONTRIBUTING.md +127 -0
  23. classifyawsetsjsonbyregion-0.1.0/pyproject.toml +221 -0
  24. classifyawsetsjsonbyregion-0.1.0/setup.cfg +21 -0
  25. classifyawsetsjsonbyregion-0.1.0/setup.py +5 -0
  26. classifyawsetsjsonbyregion-0.1.0/tests/test_cli.py +59 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Yukihiko Shinoda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include classifyawsetsjsonbyregion/py.typed
2
+ recursive-include docs *
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: classifyawsetsjsonbyregion
3
+ Version: 0.1.0
4
+ Summary: Classifies AWSets JSON by region.
5
+ Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
6
+ Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2023 Yukihiko Shinoda
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: homepage, https://github.com/yukihiko-shinoda/classify-awsets-json-by-region
30
+ Project-URL: repository, https://github.com/yukihiko-shinoda/classify-awsets-json-by-region
31
+ Keywords: classifyawsetsjsonbyregion,classify-awsets-json-by-region,awsets,aws
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Intended Audience :: Information Technology
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Natural Language :: English
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.7
41
+ Classifier: Programming Language :: Python :: 3.8
42
+ Classifier: Programming Language :: Python :: 3.9
43
+ Classifier: Programming Language :: Python :: 3.10
44
+ Classifier: Programming Language :: Python :: 3.11
45
+ Classifier: Topic :: Scientific/Engineering
46
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
47
+ Classifier: Topic :: Security
48
+ Classifier: Topic :: Text Processing
49
+ Classifier: Topic :: Text Processing :: Filters
50
+ Classifier: Typing :: Typed
51
+ Requires-Python: >=3.7
52
+ Description-Content-Type: text/markdown
53
+ Provides-Extra: test
54
+ License-File: LICENSE
55
+
56
+ # Classify AWSets JSON by Region
57
+
58
+ [![Test](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/actions?query=workflow%3ATest)
59
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/test_coverage)
60
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/maintainability)
61
+ [![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/classify-awsets-json-by-region)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region)
62
+ [![Python versions](https://img.shields.io/pypi/pyversions/classifyawsetsjsonbyregion.svg)](https://pypi.org/project/classifyawsetsjsonbyregion)
63
+ [![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fclassify-awsets-json-by-region)](http://twitter.com/share?text=Classify%20AWSets%20JSON%20by%20Region&url=https://pypi.org/project/classifyawsetsjsonbyregion/&hashtags=python)
64
+
65
+ Classifies AWSets JSON by AWS region.
66
+
67
+ ## Advantage
68
+
69
+ - Output the list of AWS resources as CSV files classified by AWS region
70
+ - Enable filter to exclude AWS resources not in question
71
+
72
+ ### Output the list of AWS resources as CSV files classified by AWS region
73
+
74
+ You can check the states of AWS resources by AWS region. It's also useful to compare the states of AWS resources between AWS regions by using text diff tools like [Visual Studio Code].
75
+
76
+ ### Enable filter to exclude AWS resources not in question
77
+
78
+ You can exclude AWS resources not in question by using `config.yml`. It's useful to reduce the number of AWS resources to be checked, such like the one AWS created by default. You can focus on AWS resources in question.
79
+
80
+ ## Quickstart
81
+
82
+ 1.\
83
+ Install `classifyawsetsjsonbyregion` with pip:
84
+
85
+ ```console
86
+ pip install classifyawsetsjsonbyregion
87
+ ```
88
+
89
+ 2.\
90
+ Create following directories:
91
+
92
+ - `input`
93
+ - `output`
94
+ - `intermediate`
95
+
96
+ 3.\
97
+ Put AWSets JSON files in it and rename it as `awsets.json`:
98
+
99
+ ```plaintext
100
+ your_working_directory/
101
+ +---input/
102
+ +---awsets.json
103
+ +---intermediate/
104
+ +---output/
105
+ ```
106
+
107
+ 4.\
108
+ Run `classify-awsets-json-by-region`:
109
+
110
+ ```console
111
+ classify-awsets-json-by-region
112
+ ```
113
+
114
+ <!-- markdownlint-disable no-trailing-punctuation -->
115
+ ## How do I...
116
+ <!-- markdownlint-enable no-trailing-punctuation -->
117
+
118
+ <!-- markdownlint-disable no-trailing-punctuation -->
119
+ ### Use intermediate directory for?
120
+ <!-- markdownlint-enable no-trailing-punctuation -->
121
+
122
+ This directory is for intermediate files. These files are useful for debugging. The contents of these files are the classifying result of AWSets JSON before filtering AWS resources. Note that the file for excluded AWS regions is not created.
123
+
124
+ ## Credits
125
+
126
+ This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.
127
+
128
+ [Cookiecutter]: https://github.com/audreyr/cookiecutter
129
+ [Visual Studio Code]: https://code.visualstudio.com/
130
+ [yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
@@ -0,0 +1,75 @@
1
+ # Classify AWSets JSON by Region
2
+
3
+ [![Test](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/actions?query=workflow%3ATest)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/test_coverage)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/maintainability)
6
+ [![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/classify-awsets-json-by-region)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region)
7
+ [![Python versions](https://img.shields.io/pypi/pyversions/classifyawsetsjsonbyregion.svg)](https://pypi.org/project/classifyawsetsjsonbyregion)
8
+ [![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fclassify-awsets-json-by-region)](http://twitter.com/share?text=Classify%20AWSets%20JSON%20by%20Region&url=https://pypi.org/project/classifyawsetsjsonbyregion/&hashtags=python)
9
+
10
+ Classifies AWSets JSON by AWS region.
11
+
12
+ ## Advantage
13
+
14
+ - Output the list of AWS resources as CSV files classified by AWS region
15
+ - Enable filter to exclude AWS resources not in question
16
+
17
+ ### Output the list of AWS resources as CSV files classified by AWS region
18
+
19
+ You can check the states of AWS resources by AWS region. It's also useful to compare the states of AWS resources between AWS regions by using text diff tools like [Visual Studio Code].
20
+
21
+ ### Enable filter to exclude AWS resources not in question
22
+
23
+ You can exclude AWS resources not in question by using `config.yml`. It's useful to reduce the number of AWS resources to be checked, such like the one AWS created by default. You can focus on AWS resources in question.
24
+
25
+ ## Quickstart
26
+
27
+ 1.\
28
+ Install `classifyawsetsjsonbyregion` with pip:
29
+
30
+ ```console
31
+ pip install classifyawsetsjsonbyregion
32
+ ```
33
+
34
+ 2.\
35
+ Create following directories:
36
+
37
+ - `input`
38
+ - `output`
39
+ - `intermediate`
40
+
41
+ 3.\
42
+ Put AWSets JSON files in it and rename it as `awsets.json`:
43
+
44
+ ```plaintext
45
+ your_working_directory/
46
+ +---input/
47
+ +---awsets.json
48
+ +---intermediate/
49
+ +---output/
50
+ ```
51
+
52
+ 4.\
53
+ Run `classify-awsets-json-by-region`:
54
+
55
+ ```console
56
+ classify-awsets-json-by-region
57
+ ```
58
+
59
+ <!-- markdownlint-disable no-trailing-punctuation -->
60
+ ## How do I...
61
+ <!-- markdownlint-enable no-trailing-punctuation -->
62
+
63
+ <!-- markdownlint-disable no-trailing-punctuation -->
64
+ ### Use intermediate directory for?
65
+ <!-- markdownlint-enable no-trailing-punctuation -->
66
+
67
+ This directory is for intermediate files. These files are useful for debugging. The contents of these files are the classifying result of AWSets JSON before filtering AWS resources. Note that the file for excluded AWS regions is not created.
68
+
69
+ ## Credits
70
+
71
+ This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.
72
+
73
+ [Cookiecutter]: https://github.com/audreyr/cookiecutter
74
+ [Visual Studio Code]: https://code.visualstudio.com/
75
+ [yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
@@ -0,0 +1,5 @@
1
+ """Top-level package for Classify AWSets JSON by Region."""
2
+
3
+ __author__ = """Yukihiko Shinoda"""
4
+ __email__ = "yuk.hik.future@gmail.com"
5
+ __version__ = "0.1.0"
@@ -0,0 +1,46 @@
1
+ """Analyze AWSets JSON."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ from typing import Any
6
+
7
+ from classifyawsetsjsonbyregion.awsets import Awset, AwsetFilter
8
+ from classifyawsetsjsonbyregion.awsregion.classifier import Classifier
9
+ from classifyawsetsjsonbyregion.config import Config
10
+ from classifyawsetsjsonbyregion.csv import OutputCsv
11
+ from classifyawsetsjsonbyregion.filepath import FilePathCreator
12
+
13
+ CONFIG: Config = Config()
14
+
15
+
16
+ class AwsetsJsonAnalyzer:
17
+ """To analyze AWSets JSON."""
18
+
19
+ UTF8 = "utf-8"
20
+
21
+ def __init__(self) -> None:
22
+ CONFIG.load("config.yml")
23
+ self.file_path_creator = FilePathCreator()
24
+ self.classifier = Classifier(CONFIG.region_exclude)
25
+ self.awset_filter = AwsetFilter(CONFIG.ignore_pattern)
26
+
27
+ def analyze(self) -> None:
28
+ awsets = json.loads(self.file_path_creator.path_resources_json.read_text(encoding=self.UTF8))
29
+ awsets = [awset for awset in awsets if awset["Region"] not in CONFIG.region_exclude]
30
+ self.file_path_creator.file_awsets_other_regions.write_text(json.dumps(awsets, indent=2), encoding=self.UTF8)
31
+ for region_name, awsets_in_region in self.classifier.classify_by_region(awsets).items():
32
+ self.analyze_each_region(region_name, awsets_in_region)
33
+
34
+ def analyze_each_region(self, region_name: str, awsets: list[Awset]) -> None:
35
+ """Analyzes AWSets in each region."""
36
+ sorted_awsets = sorted(awsets, key=lambda x: (x["Type"], x["Name"], x["Tags"]))
37
+ path_json = self.file_path_creator.create_path_json_per_region(region_name)
38
+ path_json.write_text(json.dumps(sorted_awsets, indent=2), encoding=self.UTF8)
39
+ output_csv = OutputCsv(self.file_path_creator.create_path_csv_per_region(region_name))
40
+ with output_csv.writer() as writer:
41
+ # Reason: Return values are None. pylint: disable=expression-not-assigned
42
+ [writer.writerow(self.to_row(awset)) for awset in sorted_awsets if self.awset_filter.is_passed(awset)]
43
+
44
+ @staticmethod
45
+ def to_row(awset: Awset) -> list[Any]:
46
+ return [awset["Type"], awset["Name"], awset["Tags"]]
@@ -0,0 +1,39 @@
1
+ """Model of AWSets."""
2
+ from __future__ import annotations
3
+
4
+ import re
5
+ import sys
6
+
7
+ if sys.version_info >= (3, 8):
8
+ from typing import TypedDict
9
+ else:
10
+ from typing_extensions import TypedDict # pragma: no cover
11
+
12
+
13
+ class Awset(TypedDict):
14
+ Region: str
15
+ Type: str
16
+ Name: str
17
+ Tags: dict[str, str]
18
+
19
+
20
+ class AwsetFilter:
21
+ """To filter AWSets data for specific investigation purpose."""
22
+
23
+ def __init__(self, dict_ignore_pattern: dict[str, list[str]]) -> None:
24
+ self.dict_ignore_pattern = dict_ignore_pattern
25
+
26
+ def is_passed(self, awset: Awset) -> bool:
27
+ """Filter AWSets data.
28
+
29
+ Args:
30
+ awset: AWSets data of target resource
31
+ Returns:
32
+ True: Target resource should be filtered
33
+ False: Target resource should not be filtered
34
+ """
35
+ list_ignore_pattern = self.dict_ignore_pattern.get(awset["Type"])
36
+ if not list_ignore_pattern:
37
+ return True
38
+ regex = "|".join(list_ignore_pattern)
39
+ return not re.search(regex, awset["Name"])
@@ -0,0 +1,51 @@
1
+ """Classifies AWSets into each regions."""
2
+ from __future__ import annotations
3
+
4
+ from typing import TYPE_CHECKING
5
+
6
+ if TYPE_CHECKING:
7
+ from classifyawsetsjsonbyregion.awsets import Awset
8
+
9
+
10
+ REGIONS = {
11
+ "us-east-1": "US East (N. Virginia)",
12
+ "us-east-2": "US East (Ohio)",
13
+ "us-west-1": "US West (N. California)",
14
+ "us-west-2": "US West (Oregon)",
15
+ "ap-south-1": "Asia Pacific (Mumbai)",
16
+ "ap-northeast-3": "Asia Pacific (Osaka)",
17
+ "ap-northeast-2": "Asia Pacific (Seoul)",
18
+ "ap-southeast-1": "Asia Pacific (Singapore)",
19
+ "ap-southeast-2": "Asia Pacific (Sydney)",
20
+ "ap-northeast-1": "Asia Pacific (Tokyo)",
21
+ "ca-central-1": "Canada (Central)",
22
+ "eu-central-1": "Europe (Frankfurt)",
23
+ "eu-west-1": "Europe (Ireland)",
24
+ "eu-west-2": "Europe (London)",
25
+ "eu-west-3": "Europe (Paris)",
26
+ "eu-north-1": "Europe (Stockholm)",
27
+ "sa-east-1": "South America (São Paulo)",
28
+ "aws-global": "global",
29
+ }
30
+
31
+
32
+ def create_classified_awsets_empty(regions_exclude: list[str]) -> dict[str, list[Awset]]:
33
+ classified_awsets_empty: dict[str, list[Awset]] = {}
34
+ for region_name in REGIONS:
35
+ if region_name in regions_exclude:
36
+ continue
37
+ classified_awsets_empty[region_name] = []
38
+ return classified_awsets_empty
39
+
40
+
41
+ class Classifier:
42
+ """To report in each region."""
43
+
44
+ def __init__(self, region_exclude: list[str]) -> None:
45
+ self.classified_awsets = create_classified_awsets_empty(region_exclude)
46
+
47
+ def classify_by_region(self, awsets: list[Awset]) -> dict[str, list[Awset]]:
48
+ for awset in awsets:
49
+ region = awset["Region"]
50
+ self.classified_awsets[region].append(awset)
51
+ return self.classified_awsets
@@ -0,0 +1,17 @@
1
+ """Console script for classifyawsetsjsonbyregion."""
2
+ import sys
3
+
4
+ import click
5
+
6
+ from classifyawsetsjsonbyregion.analyzer import AwsetsJsonAnalyzer
7
+
8
+
9
+ @click.command()
10
+ def main() -> int:
11
+ """Console script for classifyawsetsjsonbyregion."""
12
+ AwsetsJsonAnalyzer().analyze()
13
+ return 0
14
+
15
+
16
+ if __name__ == "__main__":
17
+ sys.exit(main()) # pragma: no cover
@@ -0,0 +1,11 @@
1
+ """Configurations."""
2
+ from dataclasses import dataclass
3
+ from typing import Dict, List
4
+
5
+ from yamldataclassconfig import YamlDataClassConfig
6
+
7
+
8
+ @dataclass
9
+ class Config(YamlDataClassConfig):
10
+ region_exclude: List[str] = None # type: ignore[assignment]
11
+ ignore_pattern: Dict[str, List[str]] = None # type: ignore[assignment]
@@ -0,0 +1,27 @@
1
+ """Json to CSV."""
2
+ from contextlib import contextmanager, suppress
3
+ import csv
4
+ from pathlib import Path
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from collections.abc import Generator
9
+
10
+ import _csv
11
+
12
+ # Reason: For type hinting.
13
+ standard_csv_writer = _csv._writer # noqa: SLF001 pylint: disable=protected-access,no-member
14
+
15
+
16
+ class OutputCsv:
17
+ """To output AWSets data into CSV."""
18
+
19
+ def __init__(self, path_csv: Path) -> None:
20
+ self.path_csv = path_csv
21
+ with suppress(FileNotFoundError):
22
+ self.path_csv.unlink()
23
+
24
+ @contextmanager
25
+ def writer(self) -> "Generator[standard_csv_writer, None, None]":
26
+ with self.path_csv.open("w", newline="") as csv_file_pointer:
27
+ yield csv.writer(csv_file_pointer, delimiter=" ", quotechar="|", quoting=csv.QUOTE_MINIMAL)
@@ -0,0 +1,21 @@
1
+ """JSON per each regions."""
2
+ from pathlib import Path
3
+
4
+
5
+ class FilePathCreator:
6
+ """To aggregate path to file."""
7
+
8
+ DIRECTORY_INPUT = Path("input")
9
+ DIRECTORY_INTERMEDIATE = Path("intermediate")
10
+ DIRECTORY_OUTPUT = Path("output")
11
+
12
+ def __init__(self) -> None:
13
+ self.path_resources_json = self.DIRECTORY_INPUT / "awsets.json"
14
+ output_file_name = f"{self.path_resources_json.stem}-other-regions.json"
15
+ self.file_awsets_other_regions = self.DIRECTORY_INTERMEDIATE / output_file_name
16
+
17
+ def create_path_json_per_region(self, regions_name: str) -> Path:
18
+ return self.DIRECTORY_INTERMEDIATE / f"{self.file_awsets_other_regions.stem}-{regions_name}.json"
19
+
20
+ def create_path_csv_per_region(self, region_name: str) -> Path:
21
+ return self.DIRECTORY_OUTPUT / f"{self.file_awsets_other_regions.stem}-{region_name}.csv"
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: classifyawsetsjsonbyregion
3
+ Version: 0.1.0
4
+ Summary: Classifies AWSets JSON by region.
5
+ Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
6
+ Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2023 Yukihiko Shinoda
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: homepage, https://github.com/yukihiko-shinoda/classify-awsets-json-by-region
30
+ Project-URL: repository, https://github.com/yukihiko-shinoda/classify-awsets-json-by-region
31
+ Keywords: classifyawsetsjsonbyregion,classify-awsets-json-by-region,awsets,aws
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Intended Audience :: Information Technology
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Natural Language :: English
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.7
41
+ Classifier: Programming Language :: Python :: 3.8
42
+ Classifier: Programming Language :: Python :: 3.9
43
+ Classifier: Programming Language :: Python :: 3.10
44
+ Classifier: Programming Language :: Python :: 3.11
45
+ Classifier: Topic :: Scientific/Engineering
46
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
47
+ Classifier: Topic :: Security
48
+ Classifier: Topic :: Text Processing
49
+ Classifier: Topic :: Text Processing :: Filters
50
+ Classifier: Typing :: Typed
51
+ Requires-Python: >=3.7
52
+ Description-Content-Type: text/markdown
53
+ Provides-Extra: test
54
+ License-File: LICENSE
55
+
56
+ # Classify AWSets JSON by Region
57
+
58
+ [![Test](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/actions?query=workflow%3ATest)
59
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/test_coverage)
60
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d3006b43fedc1ffd5db7/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region/maintainability)
61
+ [![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/classify-awsets-json-by-region)](https://codeclimate.com/github/yukihiko-shinoda/classify-awsets-json-by-region)
62
+ [![Python versions](https://img.shields.io/pypi/pyversions/classifyawsetsjsonbyregion.svg)](https://pypi.org/project/classifyawsetsjsonbyregion)
63
+ [![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fclassify-awsets-json-by-region)](http://twitter.com/share?text=Classify%20AWSets%20JSON%20by%20Region&url=https://pypi.org/project/classifyawsetsjsonbyregion/&hashtags=python)
64
+
65
+ Classifies AWSets JSON by AWS region.
66
+
67
+ ## Advantage
68
+
69
+ - Output the list of AWS resources as CSV files classified by AWS region
70
+ - Enable filter to exclude AWS resources not in question
71
+
72
+ ### Output the list of AWS resources as CSV files classified by AWS region
73
+
74
+ You can check the states of AWS resources by AWS region. It's also useful to compare the states of AWS resources between AWS regions by using text diff tools like [Visual Studio Code].
75
+
76
+ ### Enable filter to exclude AWS resources not in question
77
+
78
+ You can exclude AWS resources not in question by using `config.yml`. It's useful to reduce the number of AWS resources to be checked, such like the one AWS created by default. You can focus on AWS resources in question.
79
+
80
+ ## Quickstart
81
+
82
+ 1.\
83
+ Install `classifyawsetsjsonbyregion` with pip:
84
+
85
+ ```console
86
+ pip install classifyawsetsjsonbyregion
87
+ ```
88
+
89
+ 2.\
90
+ Create following directories:
91
+
92
+ - `input`
93
+ - `output`
94
+ - `intermediate`
95
+
96
+ 3.\
97
+ Put AWSets JSON files in it and rename it as `awsets.json`:
98
+
99
+ ```plaintext
100
+ your_working_directory/
101
+ +---input/
102
+ +---awsets.json
103
+ +---intermediate/
104
+ +---output/
105
+ ```
106
+
107
+ 4.\
108
+ Run `classify-awsets-json-by-region`:
109
+
110
+ ```console
111
+ classify-awsets-json-by-region
112
+ ```
113
+
114
+ <!-- markdownlint-disable no-trailing-punctuation -->
115
+ ## How do I...
116
+ <!-- markdownlint-enable no-trailing-punctuation -->
117
+
118
+ <!-- markdownlint-disable no-trailing-punctuation -->
119
+ ### Use intermediate directory for?
120
+ <!-- markdownlint-enable no-trailing-punctuation -->
121
+
122
+ This directory is for intermediate files. These files are useful for debugging. The contents of these files are the classifying result of AWSets JSON before filtering AWS resources. Note that the file for excluded AWS regions is not created.
123
+
124
+ ## Credits
125
+
126
+ This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.
127
+
128
+ [Cookiecutter]: https://github.com/audreyr/cookiecutter
129
+ [Visual Studio Code]: https://code.visualstudio.com/
130
+ [yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
@@ -0,0 +1,25 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.cfg
6
+ setup.py
7
+ classifyawsetsjsonbyregion/__init__.py
8
+ classifyawsetsjsonbyregion/analyzer.py
9
+ classifyawsetsjsonbyregion/awsets.py
10
+ classifyawsetsjsonbyregion/cli.py
11
+ classifyawsetsjsonbyregion/config.py
12
+ classifyawsetsjsonbyregion/csv.py
13
+ classifyawsetsjsonbyregion/filepath.py
14
+ classifyawsetsjsonbyregion/py.typed
15
+ classifyawsetsjsonbyregion.egg-info/PKG-INFO
16
+ classifyawsetsjsonbyregion.egg-info/SOURCES.txt
17
+ classifyawsetsjsonbyregion.egg-info/dependency_links.txt
18
+ classifyawsetsjsonbyregion.egg-info/entry_points.txt
19
+ classifyawsetsjsonbyregion.egg-info/not-zip-safe
20
+ classifyawsetsjsonbyregion.egg-info/requires.txt
21
+ classifyawsetsjsonbyregion.egg-info/top_level.txt
22
+ classifyawsetsjsonbyregion/awsregion/__init__.py
23
+ classifyawsetsjsonbyregion/awsregion/classifier.py
24
+ docs/CONTRIBUTING.md
25
+ tests/test_cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ classify-awsets-json-by-region = classifyawsetsjsonbyregion.cli:main
@@ -0,0 +1,7 @@
1
+ click>=7.0
2
+ yamldataclassconfig
3
+
4
+ [:python_version <= "3.7"]
5
+ typing-extensions
6
+
7
+ [test]
@@ -0,0 +1 @@
1
+ classifyawsetsjsonbyregion
@@ -0,0 +1,127 @@
1
+ # Contributing
2
+
3
+ Contributions are welcome, and they are greatly appreciated! Every little bit
4
+ helps, and credit will always be given.
5
+
6
+ You can contribute in many ways:
7
+
8
+ ## Types of Contributions
9
+
10
+ ### Report Bugs
11
+
12
+ Report bugs at [GitHub Issues].
13
+
14
+ If you are reporting a bug, please include:
15
+
16
+ - Your operating system name and version.
17
+ - Any details about your local setup that might be helpful in troubleshooting.
18
+ - Detailed steps to reproduce the bug.
19
+
20
+ ### Fix Bugs
21
+
22
+ Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
23
+ wanted" is open to whoever wants to implement it.
24
+
25
+ ### Implement Features
26
+
27
+ Look through the GitHub issues for features. Anything tagged with "enhancement"
28
+ and "help wanted" is open to whoever wants to implement it.
29
+
30
+ ### Write Documentation
31
+
32
+ Classify AWSets JSON by Region could always use more documentation, whether as part of the
33
+ official Classify AWSets JSON by Region docs, in docstrings, or even on the web in blog posts,
34
+ articles, and such.
35
+
36
+ ### Submit Feedback
37
+
38
+ The best way to send feedback is to file an issue at [GitHub Issues].
39
+
40
+ If you are proposing a feature:
41
+
42
+ - Explain in detail how it would work.
43
+ - Keep the scope as narrow as possible, to make it easier to implement.
44
+ - Remember that this is a volunteer-driven project, and that contributions
45
+ are welcome :)
46
+
47
+ <!-- markdownlint-disable no-trailing-punctuation -->
48
+ ## Get Started!
49
+ <!-- markdownlint-enaable no-trailing-punctuation -->
50
+
51
+ Ready to contribute? Here's how to set up `Classify AWSets JSON by Region` for local development.
52
+
53
+ 1. Fork the `classify-awsets-json-by-region` repo on GitHub.
54
+ 2. Clone your fork locally:
55
+
56
+ ```console
57
+ git clone git@github.com:your_name_here/classify-awsets-json-by-region.git
58
+ ```
59
+
60
+ 3. Install your local copy into a virtualenv. Assuming you have Pipenv installed, this is how you set up your fork for local development:
61
+
62
+ ```console
63
+ pipenv install --dev
64
+ ```
65
+
66
+ 4. Create a branch for local development:
67
+
68
+ ```console
69
+ git checkout -b name-of-your-bugfix-or-feature
70
+ ```
71
+
72
+ Now you can make your changes locally.
73
+
74
+ 5. When you're done making changes,
75
+ check that your changes pass isort, flake8, black,
76
+ and the tests, including testing oldest Python version:
77
+
78
+ ```console
79
+ pipenv run inv style --check
80
+ pipenv run pytest
81
+ pipenv install --python 3.7
82
+ pipenv run pytest
83
+ ```
84
+
85
+ 6. Commit your changes and push your branch to GitHub:
86
+
87
+ ```console
88
+ git add .
89
+ git commit -m "Your detailed description of your changes."
90
+ git push origin name-of-your-bugfix-or-feature
91
+ ```
92
+
93
+ 7. Submit a pull request through the GitHub website.
94
+
95
+ ## Pull Request Guidelines
96
+
97
+ Before you submit a pull request, check that it meets these guidelines:
98
+
99
+ 1. The pull request should include tests.
100
+ 2. If the pull request adds functionality, the docs should be updated. Put
101
+ your new functionality into a function with a docstring, and add the
102
+ feature to the list in README.md.
103
+
104
+ ## Tips
105
+
106
+ To run a subset of tests:
107
+
108
+ ```console
109
+ pipenv run pytest tests.test_classifyawsetsjsonbyregion
110
+
111
+ ```
112
+
113
+ ## Deploying
114
+
115
+ A reminder for the maintainers on how to deploy.
116
+ Make sure all your changes are committed.
117
+ Then run:
118
+
119
+ ```console
120
+ bump2version patch # possible: major / minor / patch
121
+ git push
122
+ git push --tags
123
+ ```
124
+
125
+ Travis will then deploy to PyPI if tests pass.
126
+
127
+ [GitHub Issues]: https://github.com/yukihiko-shinoda/classify-awsets-json-by-region/issues
@@ -0,0 +1,221 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "classifyawsetsjsonbyregion"
7
+ version = "0.1.0"
8
+ description = "Classifies AWSets JSON by region."
9
+ readme = "README.md"
10
+ requires-python = ">=3.7"
11
+ license = {file = "LICENSE"}
12
+ keywords = [
13
+ "classifyawsetsjsonbyregion",
14
+ "classify-awsets-json-by-region",
15
+ "awsets",
16
+ "aws",
17
+ ]
18
+ authors = [
19
+ {name = "Yukihiko Shinoda", email = "yuk.hik.future@gmail.com"},
20
+ ]
21
+ maintainers = [
22
+ {name = "Yukihiko Shinoda", email = "yuk.hik.future@gmail.com"},
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 4 - Beta",
26
+ "Intended Audience :: Developers",
27
+ "Intended Audience :: Information Technology",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Natural Language :: English",
30
+ "Operating System :: OS Independent",
31
+ "Programming Language :: Python",
32
+ "Programming Language :: Python :: 3",
33
+ "Programming Language :: Python :: 3.7",
34
+ "Programming Language :: Python :: 3.8",
35
+ "Programming Language :: Python :: 3.9",
36
+ "Programming Language :: Python :: 3.10",
37
+ "Programming Language :: Python :: 3.11",
38
+ "Topic :: Scientific/Engineering",
39
+ "Topic :: Scientific/Engineering :: Information Analysis",
40
+ "Topic :: Security",
41
+ "Topic :: Text Processing",
42
+ "Topic :: Text Processing :: Filters",
43
+ "Typing :: Typed",
44
+ ]
45
+ dependencies = [
46
+ "click>=7.0",
47
+ 'typing-extensions; python_version <= "3.7"',
48
+ "yamldataclassconfig",
49
+ ]
50
+
51
+ [project.optional-dependencies]
52
+ test = []
53
+
54
+ [project.urls]
55
+ homepage = "https://github.com/yukihiko-shinoda/classify-awsets-json-by-region"
56
+ # documentation = "https://readthedocs.org"
57
+ repository = "https://github.com/yukihiko-shinoda/classify-awsets-json-by-region"
58
+ # changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md"
59
+
60
+ [project.entry-points.console_scripts]
61
+ classify-awsets-json-by-region = "classifyawsetsjsonbyregion.cli:main"
62
+
63
+ [tool.setuptools]
64
+ zip-safe = false
65
+
66
+ [tool.setuptools.packages.find]
67
+ where = ["."]
68
+ include = ["classifyawsetsjsonbyregion", "classifyawsetsjsonbyregion.*"]
69
+
70
+ [tool.bandit.assert_used]
71
+ skips = [
72
+ "*_test.py",
73
+ "*/test_*.py",
74
+ ]
75
+
76
+ # @see https://black.readthedocs.io/en/stable/pyproject_toml.html#configuration-format
77
+ [tool.black]
78
+ line-length = 119
79
+
80
+ [tool.coverage.report]
81
+ exclude_lines = [
82
+ "pragma: no cover",
83
+ # Assume `if TYPE_CHECKING: ... else: ...` block is covered · Issue #831 · nedbat/coveragepy
84
+ # https://github.com/nedbat/coveragepy/issues/831#issuecomment-517778185
85
+ "if TYPE_CHECKING:",
86
+ # Pylint will detect instead:
87
+ # - abstract-method / W0223 - Pylint 2.17.0-dev0 documentation
88
+ # https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/abstract-method.html
89
+ "raise NotImplementedError",
90
+ ]
91
+
92
+ [tool.docformatter]
93
+ recursive = true
94
+ wrap-descriptions = 119
95
+ wrap-summaries = 119
96
+
97
+ [tool.isort]
98
+ # see:
99
+ # - Using Black with other tools - Black 23.1.0 documentation
100
+ # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#custom-configuration
101
+ multi_line_output = 3
102
+ include_trailing_comma = true
103
+ force_grid_wrap = 0
104
+ use_parentheses = true
105
+ ensure_newline_before_comments = true
106
+ line_length = 119
107
+ # For compatibility with PyLint and Hacking, Google also supports,
108
+ # Black doesn't have any opinions
109
+ # see:
110
+ # - https://pycqa.github.io/isort/docs/configuration/profiles.html
111
+ # - https://qiita.com/kaityo256/items/5b0b55d105ef2366cb0c
112
+ # - https://www.xn--ebkc7kqd.com/entry/hacking-isort
113
+ force_sort_within_sections = true
114
+ lexicographical = true
115
+ # Google supports, Black doesn't have any opinions
116
+ # see: https://pycqa.github.io/isort/docs/configuration/profiles.html
117
+ order_by_type = false
118
+
119
+ [tool.mypy]
120
+ strict = true
121
+
122
+ [tool.pydocstyle]
123
+ # To add Google convention
124
+ # see:
125
+ # - Error Codes — pydocstyle 6.1.1 documentation
126
+ # http://www.pydocstyle.org/en/stable/error_codes.html#default-conventions
127
+ add_select = ["D212", "D214", "D410", "D411", "D415", "D416", "D417"]
128
+ # D400: First line may ends with ":" for expression.
129
+ # D402: First line may ends with function signature for expression.
130
+ # D415: First line may ends with ":" for expression.
131
+ # D101: Docstring may be missed in public class since docstring-min-length is set.
132
+ # D102: Docstring may be missed in public method since docstring-min-length is set.
133
+ # D103: Docstring may be missed in public function since docstring-min-length is set.
134
+ # D105: Docstring may be missed in magic method since docstring-min-length is set.
135
+ # D105: Docstring may be missed in public nested class since docstring-min-length is set.
136
+ # D107: Docstring may be missed in __init__ method since docstring-min-length is set.
137
+ add_ignore = ["D400", "D401", "D402", "D415", "D101", "D102", "D103", "D105", "D106", "D107"]
138
+
139
+ [tool.pylint.basic]
140
+ docstring-min-length = "7"
141
+
142
+ [tool.pylint.format]
143
+ max-line-length = 119
144
+
145
+ [tool.pylint.options]
146
+ # Since this rule against single responsibility principle.
147
+ # @see https://stackoverflow.com/questions/28722314/why-does-pylint-want-2-public-methods-per-class/40258006#40258006
148
+ min-public-methods = "1"
149
+
150
+ [tool.pytest.ini_options]
151
+ markers = [
152
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
153
+ ]
154
+
155
+ [tool.ruff]
156
+ line-length = 119
157
+ select = [
158
+ "F", # Pyflakes
159
+ "E", # pycodestyle
160
+ "W", # pycodestyle
161
+ "C90", # mccabe
162
+ # "I", # isort
163
+ "N", # pep8-naming
164
+ # "D", # pydocstyle
165
+ "UP", # pyupgrade
166
+ "YTT", # flake8-2020
167
+ "ANN", # flake8-annotations
168
+ "S", # flake8-bandit
169
+ "BLE", # flake8-blind-except
170
+ "FBT", # flake8-boolean-trap
171
+ "B", # flake8-bugbear
172
+ "A", # flake8-builtins
173
+ "COM", # flake8-commas
174
+ "C4", # flake8-comprehensions
175
+ "DTZ", # flake8-datetimez
176
+ "T10", # flake8-debugger
177
+ "DJ", # flake8-django
178
+ "EM", # flake8-errmsg
179
+ "EXE", # flake8-executable
180
+ "ISC", # flake8-implicit-str-concat
181
+ "ICN", # flake8-import-conventions
182
+ "G", # flake8-logging-format
183
+ "INP", # flake8-no-pep420
184
+ "PIE", # flake8-pie
185
+ "T20", # flake8-print
186
+ "PYI", # flake8-pyi
187
+ "PT", # flake8-pytest-style
188
+ "Q", # flake8-quotes
189
+ "RSE", # flake8-raise
190
+ "RET", # flake8-return
191
+ "SLF", # flake8-self
192
+ "SIM", # flake8-simplify
193
+ "TID", # flake8-tidy-imports
194
+ "TCH", # flake8-type-checking
195
+ "ARG", # flake8-unused-arguments
196
+ "PTH", # flake8-use-pathlib
197
+ "ERA", # eradicate
198
+ "PD", # pandas-vet
199
+ "PGH", # pygrep-hooks
200
+ "PL", # Pylint
201
+ "TRY", # tryceratops
202
+ "NPY", # NumPy-specific rules
203
+ "RUF", # Ruff-specific rules
204
+ ]
205
+ ignore = [
206
+ "UP032", # [*] Use f-string instead of `format` call
207
+ "ANN101", # Missing type annotation for `self` in method
208
+ "ANN401", # Dynamically typed expressions (typing.Any) are disallowed, These warnings are disabled by default
209
+ ]
210
+ fixable = [
211
+ "COM812", # Trailing comma missing
212
+ "PT001", # Use `@pytest.fixture()` over `@pytest.fixture`
213
+ "PT006", # Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`
214
+ "SIM108", # Use ternary operator `extra_context = {} if extra_context is None else request.param` instead of `if`-`else`-block
215
+ "UP015", # Unnecessary open mode parameters
216
+ "UP037", # Remove quotes from type annotation
217
+ ]
218
+ target-version = "py37"
219
+
220
+ [tool.ruff.per-file-ignores]
221
+ "tests/*" = ["S101"]
@@ -0,0 +1,21 @@
1
+ [flake8]
2
+ max-line-length = 119
3
+ extend-ignore =
4
+ E203,
5
+ H301,
6
+ H601
7
+ statistics = True
8
+ show_source = True
9
+ exclude =
10
+ .venv,
11
+ docs
12
+
13
+ [radon]
14
+ cc_min = B
15
+ show_complexity = True
16
+ show_mi = True
17
+
18
+ [egg_info]
19
+ tag_build =
20
+ tag_date = 0
21
+
@@ -0,0 +1,5 @@
1
+ """The setup script."""
2
+
3
+ from setuptools import setup # type: ignore[import]
4
+
5
+ setup()
@@ -0,0 +1,59 @@
1
+ """Tests for `classifyawsetsjsonbyregion` package."""
2
+ from __future__ import annotations
3
+
4
+ from pathlib import Path
5
+
6
+ from click.testing import CliRunner
7
+
8
+ from classifyawsetsjsonbyregion import cli
9
+
10
+
11
+ def test_command_line_interface(configured_cli_runner: CliRunner) -> None:
12
+ """Tests the CLI.
13
+
14
+ Checks that:
15
+ - the CLI returns empty output
16
+ - the CLI returns 0 exit code
17
+ - the CLI creates the expected number of files
18
+ - the CLI creates the expected files
19
+ - the CLI creates the expected files with the expected content
20
+ """
21
+ expected = {
22
+ "awsets-other-regions-ap-northeast-2.csv": "athena/datacatalog AwsDataCatalog {}\n",
23
+ "awsets-other-regions-ap-northeast-3.csv": "athena/datacatalog AwsDataCatalog {}\n",
24
+ "awsets-other-regions-ap-south-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
25
+ "awsets-other-regions-ap-southeast-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
26
+ "awsets-other-regions-ap-southeast-2.csv": "athena/datacatalog AwsDataCatalog {}\n",
27
+ "awsets-other-regions-aws-global.csv": "",
28
+ "awsets-other-regions-ca-central-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
29
+ "awsets-other-regions-eu-central-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
30
+ "awsets-other-regions-eu-north-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
31
+ "awsets-other-regions-eu-west-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
32
+ "awsets-other-regions-eu-west-2.csv": "athena/datacatalog AwsDataCatalog {}\n",
33
+ "awsets-other-regions-eu-west-3.csv": "athena/datacatalog AwsDataCatalog {}\n",
34
+ "awsets-other-regions-sa-east-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
35
+ "awsets-other-regions-us-east-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
36
+ "awsets-other-regions-us-east-2.csv": "athena/datacatalog AwsDataCatalog {}\n",
37
+ "awsets-other-regions-us-west-1.csv": "athena/datacatalog AwsDataCatalog {}\n",
38
+ "awsets-other-regions-us-west-2.csv": "athena/datacatalog AwsDataCatalog {}\n",
39
+ }
40
+ result = configured_cli_runner.invoke(cli.main)
41
+ # Reason: Check that output is empty.
42
+ assert result.output == "" # noqa: PLC1901
43
+ assert result.exit_code == 0
44
+ list_output_file = list((Path.cwd() / "output").iterdir())
45
+ assert_output_files(expected, list_output_file)
46
+
47
+
48
+ def assert_output_files(expected: dict[str, str], list_output_file: list[Path]) -> None:
49
+ assert len(list_output_file) == len(expected)
50
+ for output_file, (expected_file_name, expected_json) in zip(sorted(list_output_file), expected.items()):
51
+ assert output_file.name == expected_file_name
52
+ assert output_file.read_text() == expected_json
53
+
54
+
55
+ def test_help() -> None:
56
+ runner = CliRunner()
57
+ help_result = runner.invoke(cli.main, ["--help"])
58
+ assert help_result.exit_code == 0
59
+ assert "--help Show this message and exit." in help_result.output