runbooks 0.2.3__py3-none-any.whl → 0.6.1__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.
- conftest.py +26 -0
- jupyter-agent/.env.template +2 -0
- jupyter-agent/.gitattributes +35 -0
- jupyter-agent/README.md +16 -0
- jupyter-agent/app.py +256 -0
- jupyter-agent/cloudops-agent.png +0 -0
- jupyter-agent/ds-system-prompt.txt +154 -0
- jupyter-agent/jupyter-agent.png +0 -0
- jupyter-agent/llama3_template.jinja +123 -0
- jupyter-agent/requirements.txt +9 -0
- jupyter-agent/utils.py +409 -0
- runbooks/__init__.py +71 -3
- runbooks/__main__.py +13 -0
- runbooks/aws/ec2_describe_instances.py +1 -1
- runbooks/aws/ec2_run_instances.py +8 -2
- runbooks/aws/ec2_start_stop_instances.py +17 -4
- runbooks/aws/ec2_unused_volumes.py +5 -1
- runbooks/aws/s3_create_bucket.py +4 -2
- runbooks/aws/s3_list_objects.py +6 -1
- runbooks/aws/tagging_lambda_handler.py +13 -2
- runbooks/aws/tags.json +12 -0
- runbooks/base.py +353 -0
- runbooks/cfat/README.md +49 -0
- runbooks/cfat/__init__.py +74 -0
- runbooks/cfat/app.ts +644 -0
- runbooks/cfat/assessment/__init__.py +40 -0
- runbooks/cfat/assessment/asana-import.csv +39 -0
- runbooks/cfat/assessment/cfat-checks.csv +31 -0
- runbooks/cfat/assessment/cfat.txt +520 -0
- runbooks/cfat/assessment/collectors.py +200 -0
- runbooks/cfat/assessment/jira-import.csv +39 -0
- runbooks/cfat/assessment/runner.py +387 -0
- runbooks/cfat/assessment/validators.py +290 -0
- runbooks/cfat/cli.py +103 -0
- runbooks/cfat/docs/asana-import.csv +24 -0
- runbooks/cfat/docs/cfat-checks.csv +31 -0
- runbooks/cfat/docs/cfat.txt +335 -0
- runbooks/cfat/docs/checks-output.png +0 -0
- runbooks/cfat/docs/cloudshell-console-run.png +0 -0
- runbooks/cfat/docs/cloudshell-download.png +0 -0
- runbooks/cfat/docs/cloudshell-output.png +0 -0
- runbooks/cfat/docs/downloadfile.png +0 -0
- runbooks/cfat/docs/jira-import.csv +24 -0
- runbooks/cfat/docs/open-cloudshell.png +0 -0
- runbooks/cfat/docs/report-header.png +0 -0
- runbooks/cfat/models.py +1026 -0
- runbooks/cfat/package-lock.json +5116 -0
- runbooks/cfat/package.json +38 -0
- runbooks/cfat/report.py +496 -0
- runbooks/cfat/reporting/__init__.py +46 -0
- runbooks/cfat/reporting/exporters.py +337 -0
- runbooks/cfat/reporting/formatters.py +496 -0
- runbooks/cfat/reporting/templates.py +135 -0
- runbooks/cfat/run-assessment.sh +23 -0
- runbooks/cfat/runner.py +69 -0
- runbooks/cfat/src/actions/check-cloudtrail-existence.ts +43 -0
- runbooks/cfat/src/actions/check-config-existence.ts +37 -0
- runbooks/cfat/src/actions/check-control-tower.ts +37 -0
- runbooks/cfat/src/actions/check-ec2-existence.ts +46 -0
- runbooks/cfat/src/actions/check-iam-users.ts +50 -0
- runbooks/cfat/src/actions/check-legacy-cur.ts +30 -0
- runbooks/cfat/src/actions/check-org-cloudformation.ts +30 -0
- runbooks/cfat/src/actions/check-vpc-existence.ts +43 -0
- runbooks/cfat/src/actions/create-asanaimport.ts +14 -0
- runbooks/cfat/src/actions/create-backlog.ts +372 -0
- runbooks/cfat/src/actions/create-jiraimport.ts +15 -0
- runbooks/cfat/src/actions/create-report.ts +616 -0
- runbooks/cfat/src/actions/define-account-type.ts +51 -0
- runbooks/cfat/src/actions/get-enabled-org-policy-types.ts +40 -0
- runbooks/cfat/src/actions/get-enabled-org-services.ts +26 -0
- runbooks/cfat/src/actions/get-idc-info.ts +34 -0
- runbooks/cfat/src/actions/get-org-da-accounts.ts +34 -0
- runbooks/cfat/src/actions/get-org-details.ts +35 -0
- runbooks/cfat/src/actions/get-org-member-accounts.ts +44 -0
- runbooks/cfat/src/actions/get-org-ous.ts +35 -0
- runbooks/cfat/src/actions/get-regions.ts +22 -0
- runbooks/cfat/src/actions/zip-assessment.ts +27 -0
- runbooks/cfat/src/types/index.d.ts +147 -0
- runbooks/cfat/tests/__init__.py +141 -0
- runbooks/cfat/tests/test_cli.py +340 -0
- runbooks/cfat/tests/test_integration.py +290 -0
- runbooks/cfat/tests/test_models.py +505 -0
- runbooks/cfat/tests/test_reporting.py +354 -0
- runbooks/cfat/tsconfig.json +16 -0
- runbooks/cfat/webpack.config.cjs +27 -0
- runbooks/config.py +260 -0
- runbooks/finops/__init__.py +88 -0
- runbooks/finops/aws_client.py +245 -0
- runbooks/finops/cli.py +151 -0
- runbooks/finops/cost_processor.py +410 -0
- runbooks/finops/dashboard_runner.py +448 -0
- runbooks/finops/helpers.py +355 -0
- runbooks/finops/main.py +14 -0
- runbooks/finops/profile_processor.py +174 -0
- runbooks/finops/types.py +66 -0
- runbooks/finops/visualisations.py +80 -0
- runbooks/inventory/.gitignore +354 -0
- runbooks/inventory/ArgumentsClass.py +261 -0
- runbooks/inventory/Inventory_Modules.py +6130 -0
- runbooks/inventory/LandingZone/delete_lz.py +1075 -0
- runbooks/inventory/README.md +1320 -0
- runbooks/inventory/__init__.py +62 -0
- runbooks/inventory/account_class.py +532 -0
- runbooks/inventory/all_my_instances_wrapper.py +123 -0
- runbooks/inventory/aws_decorators.py +201 -0
- runbooks/inventory/cfn_move_stack_instances.py +1526 -0
- runbooks/inventory/check_cloudtrail_compliance.py +614 -0
- runbooks/inventory/check_controltower_readiness.py +1107 -0
- runbooks/inventory/check_landingzone_readiness.py +711 -0
- runbooks/inventory/cloudtrail.md +727 -0
- runbooks/inventory/collectors/__init__.py +20 -0
- runbooks/inventory/collectors/aws_compute.py +518 -0
- runbooks/inventory/collectors/aws_networking.py +275 -0
- runbooks/inventory/collectors/base.py +222 -0
- runbooks/inventory/core/__init__.py +19 -0
- runbooks/inventory/core/collector.py +303 -0
- runbooks/inventory/core/formatter.py +296 -0
- runbooks/inventory/delete_s3_buckets_objects.py +169 -0
- runbooks/inventory/discovery.md +81 -0
- runbooks/inventory/draw_org_structure.py +748 -0
- runbooks/inventory/ec2_vpc_utils.py +341 -0
- runbooks/inventory/find_cfn_drift_detection.py +272 -0
- runbooks/inventory/find_cfn_orphaned_stacks.py +719 -0
- runbooks/inventory/find_cfn_stackset_drift.py +733 -0
- runbooks/inventory/find_ec2_security_groups.py +669 -0
- runbooks/inventory/find_landingzone_versions.py +201 -0
- runbooks/inventory/find_vpc_flow_logs.py +1221 -0
- runbooks/inventory/inventory.sh +659 -0
- runbooks/inventory/list_cfn_stacks.py +558 -0
- runbooks/inventory/list_cfn_stackset_operation_results.py +252 -0
- runbooks/inventory/list_cfn_stackset_operations.py +734 -0
- runbooks/inventory/list_cfn_stacksets.py +453 -0
- runbooks/inventory/list_config_recorders_delivery_channels.py +681 -0
- runbooks/inventory/list_ds_directories.py +354 -0
- runbooks/inventory/list_ec2_availability_zones.py +286 -0
- runbooks/inventory/list_ec2_ebs_volumes.py +244 -0
- runbooks/inventory/list_ec2_instances.py +425 -0
- runbooks/inventory/list_ecs_clusters_and_tasks.py +562 -0
- runbooks/inventory/list_elbs_load_balancers.py +411 -0
- runbooks/inventory/list_enis_network_interfaces.py +526 -0
- runbooks/inventory/list_guardduty_detectors.py +568 -0
- runbooks/inventory/list_iam_policies.py +404 -0
- runbooks/inventory/list_iam_roles.py +518 -0
- runbooks/inventory/list_iam_saml_providers.py +359 -0
- runbooks/inventory/list_lambda_functions.py +882 -0
- runbooks/inventory/list_org_accounts.py +446 -0
- runbooks/inventory/list_org_accounts_users.py +354 -0
- runbooks/inventory/list_rds_db_instances.py +406 -0
- runbooks/inventory/list_route53_hosted_zones.py +318 -0
- runbooks/inventory/list_servicecatalog_provisioned_products.py +575 -0
- runbooks/inventory/list_sns_topics.py +360 -0
- runbooks/inventory/list_ssm_parameters.py +402 -0
- runbooks/inventory/list_vpc_subnets.py +433 -0
- runbooks/inventory/list_vpcs.py +422 -0
- runbooks/inventory/lockdown_cfn_stackset_role.py +224 -0
- runbooks/inventory/models/__init__.py +24 -0
- runbooks/inventory/models/account.py +192 -0
- runbooks/inventory/models/inventory.py +309 -0
- runbooks/inventory/models/resource.py +247 -0
- runbooks/inventory/recover_cfn_stack_ids.py +205 -0
- runbooks/inventory/requirements.txt +12 -0
- runbooks/inventory/run_on_multi_accounts.py +211 -0
- runbooks/inventory/tests/common_test_data.py +3661 -0
- runbooks/inventory/tests/common_test_functions.py +204 -0
- runbooks/inventory/tests/script_test_data.py +0 -0
- runbooks/inventory/tests/setup.py +24 -0
- runbooks/inventory/tests/src.py +18 -0
- runbooks/inventory/tests/test_cfn_describe_stacks.py +208 -0
- runbooks/inventory/tests/test_ec2_describe_instances.py +162 -0
- runbooks/inventory/tests/test_inventory_modules.py +55 -0
- runbooks/inventory/tests/test_lambda_list_functions.py +86 -0
- runbooks/inventory/tests/test_moto_integration_example.py +273 -0
- runbooks/inventory/tests/test_org_list_accounts.py +49 -0
- runbooks/inventory/update_aws_actions.py +173 -0
- runbooks/inventory/update_cfn_stacksets.py +1215 -0
- runbooks/inventory/update_cloudwatch_logs_retention_policy.py +294 -0
- runbooks/inventory/update_iam_roles_cross_accounts.py +478 -0
- runbooks/inventory/update_s3_public_access_block.py +539 -0
- runbooks/inventory/utils/__init__.py +23 -0
- runbooks/inventory/utils/aws_helpers.py +510 -0
- runbooks/inventory/utils/threading_utils.py +493 -0
- runbooks/inventory/utils/validation.py +682 -0
- runbooks/inventory/verify_ec2_security_groups.py +1430 -0
- runbooks/main.py +785 -0
- runbooks/organizations/__init__.py +12 -0
- runbooks/organizations/manager.py +374 -0
- runbooks/security_baseline/README.md +324 -0
- runbooks/security_baseline/checklist/alternate_contacts.py +8 -1
- runbooks/security_baseline/checklist/bucket_public_access.py +4 -1
- runbooks/security_baseline/checklist/cloudwatch_alarm_configuration.py +9 -2
- runbooks/security_baseline/checklist/guardduty_enabled.py +9 -2
- runbooks/security_baseline/checklist/multi_region_instance_usage.py +5 -1
- runbooks/security_baseline/checklist/root_access_key.py +6 -1
- runbooks/security_baseline/config-origin.json +1 -1
- runbooks/security_baseline/config.json +1 -1
- runbooks/security_baseline/permission.json +1 -1
- runbooks/security_baseline/report_generator.py +10 -2
- runbooks/security_baseline/report_template_en.html +8 -8
- runbooks/security_baseline/report_template_jp.html +8 -8
- runbooks/security_baseline/report_template_kr.html +13 -13
- runbooks/security_baseline/report_template_vn.html +8 -8
- runbooks/security_baseline/requirements.txt +7 -0
- runbooks/security_baseline/run_script.py +8 -2
- runbooks/security_baseline/security_baseline_tester.py +10 -2
- runbooks/security_baseline/utils/common.py +5 -1
- runbooks/utils/__init__.py +204 -0
- runbooks-0.6.1.dist-info/METADATA +373 -0
- runbooks-0.6.1.dist-info/RECORD +237 -0
- {runbooks-0.2.3.dist-info → runbooks-0.6.1.dist-info}/WHEEL +1 -1
- runbooks-0.6.1.dist-info/entry_points.txt +7 -0
- runbooks-0.6.1.dist-info/licenses/LICENSE +201 -0
- runbooks-0.6.1.dist-info/top_level.txt +3 -0
- runbooks/python101/calculator.py +0 -34
- runbooks/python101/config.py +0 -1
- runbooks/python101/exceptions.py +0 -16
- runbooks/python101/file_manager.py +0 -218
- runbooks/python101/toolkit.py +0 -153
- runbooks-0.2.3.dist-info/METADATA +0 -435
- runbooks-0.2.3.dist-info/RECORD +0 -61
- runbooks-0.2.3.dist-info/entry_points.txt +0 -3
- runbooks-0.2.3.dist-info/top_level.txt +0 -1
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright (c) 2025, Nhat-Thanh Nguyen <nnthanh101@gmail.com>
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
runbooks/python101/calculator.py
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
from typing import Union
|
2
|
-
|
3
|
-
from runbooks.python101.config import DEFAULT_CONFIG
|
4
|
-
from runbooks.python101.exceptions import CalculatorError
|
5
|
-
|
6
|
-
|
7
|
-
class Calculator:
|
8
|
-
"""Calculator class supporting arithmetic operations with configurable precision."""
|
9
|
-
|
10
|
-
def __init__(self, precision: int = DEFAULT_CONFIG["precision"]):
|
11
|
-
"""Initialize calculator with configurable precision."""
|
12
|
-
self.precision = precision
|
13
|
-
|
14
|
-
def _format_result(self, result: Union[int, float]) -> Union[int, float]:
|
15
|
-
"""Format result based on precision."""
|
16
|
-
return round(result, self.precision)
|
17
|
-
|
18
|
-
def add(self, x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
|
19
|
-
"""Adds two numbers."""
|
20
|
-
return self._format_result(x + y)
|
21
|
-
|
22
|
-
def subtract(self, x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
|
23
|
-
"""Subtracts second number from first."""
|
24
|
-
return self._format_result(x - y)
|
25
|
-
|
26
|
-
def multiply(self, x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
|
27
|
-
"""Multiplies two numbers."""
|
28
|
-
return self._format_result(x * y)
|
29
|
-
|
30
|
-
def divide(self, x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
|
31
|
-
"""Divides first number by second."""
|
32
|
-
if y == 0:
|
33
|
-
raise CalculatorError("Division by zero is not allowed.")
|
34
|
-
return self._format_result(x / y)
|
runbooks/python101/config.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
DEFAULT_CONFIG = {"precision": 2, "allow_negative": True, "debug": False, "log_file": "calculator.log"}
|
runbooks/python101/exceptions.py
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class CalculatorError(Exception):
|
2
|
-
"""Custom exception for errors in the Calculator."""
|
3
|
-
|
4
|
-
pass
|
5
|
-
|
6
|
-
|
7
|
-
class InvalidOperationError(CalculatorError):
|
8
|
-
"""Raised when an invalid operation is attempted."""
|
9
|
-
|
10
|
-
pass
|
11
|
-
|
12
|
-
|
13
|
-
class InputValidationError(CalculatorError):
|
14
|
-
"""Raised when input validation fails."""
|
15
|
-
|
16
|
-
pass
|
@@ -1,218 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
|
3
|
-
"""
|
4
|
-
Utilities to create a specified folder and an empty file inside it with safe error handling.
|
5
|
-
|
6
|
-
Author: Python Developer
|
7
|
-
Date: 2025-01-05
|
8
|
-
Version: 1.0.0
|
9
|
-
|
10
|
-
Usage:
|
11
|
-
file_manager.py <folder_name> <file_name>
|
12
|
-
"""
|
13
|
-
|
14
|
-
import os
|
15
|
-
import sys
|
16
|
-
from pathlib import Path
|
17
|
-
from typing import Union
|
18
|
-
|
19
|
-
|
20
|
-
## ==============================
|
21
|
-
## VALIDATION UTILITIES
|
22
|
-
## ==============================
|
23
|
-
def validate_input(value: Union[str, float, int]) -> float:
|
24
|
-
"""
|
25
|
-
Validates and converts input into a float.
|
26
|
-
|
27
|
-
Args:
|
28
|
-
value (Union[str, float, int]): The input value to validate and convert.
|
29
|
-
|
30
|
-
Returns:
|
31
|
-
float: The validated and converted float value.
|
32
|
-
|
33
|
-
Raises:
|
34
|
-
TypeError: If input type is unsupported.
|
35
|
-
ValueError: If input cannot be converted to float, or fails constraints.
|
36
|
-
"""
|
37
|
-
|
38
|
-
## ✅ Step 1.1: Input Type Validation
|
39
|
-
if not isinstance(value, (str, int, float)):
|
40
|
-
raise TypeError(f"Invalid type '{type(value).__name__}'. Expected str, int, or float.")
|
41
|
-
|
42
|
-
## ✅ Step 1.2: Handle Empty String
|
43
|
-
if isinstance(value, str) and not value.strip():
|
44
|
-
raise ValueError(f"Invalid input '{value}'. Input cannot be empty or whitespace-only.")
|
45
|
-
|
46
|
-
## ✅ Step 2: Convert Input to Float
|
47
|
-
try:
|
48
|
-
result = float(value) ## Attempt numeric conversion
|
49
|
-
except ValueError as e:
|
50
|
-
raise ValueError(f"Invalid input '{value}'. Must be a valid number.") from e
|
51
|
-
|
52
|
-
## ✅ Step 3: Return Validated Float
|
53
|
-
return result
|
54
|
-
|
55
|
-
|
56
|
-
def validate_folder_name(folder_name: str) -> None:
|
57
|
-
"""
|
58
|
-
Validates folder name for OS-specific constraints.
|
59
|
-
|
60
|
-
Args:
|
61
|
-
folder_name (str): The folder name to validate.
|
62
|
-
|
63
|
-
Raises:
|
64
|
-
ValueError: If the folder name violates naming constraints.
|
65
|
-
"""
|
66
|
-
if not folder_name:
|
67
|
-
raise ValueError("Folder name cannot be empty.")
|
68
|
-
|
69
|
-
if len(folder_name) > 255: # Max length in most file systems
|
70
|
-
raise ValueError("Folder name exceeds maximum length (255 characters).")
|
71
|
-
|
72
|
-
invalid_chars = '<>:"/\\|?*' # Reserved characters in Windows
|
73
|
-
if any(char in invalid_chars for char in folder_name):
|
74
|
-
raise ValueError(f"Folder name '{folder_name}' contains invalid characters.")
|
75
|
-
|
76
|
-
if folder_name in {"CON", "PRN", "AUX", "NUL"}: # Reserved Windows names
|
77
|
-
raise ValueError(f"Folder name '{folder_name}' is a reserved keyword.")
|
78
|
-
|
79
|
-
if folder_name.startswith(" ") or folder_name.endswith(" "):
|
80
|
-
raise ValueError("Folder name cannot start or end with spaces.")
|
81
|
-
|
82
|
-
|
83
|
-
def validate_file_name(file_name: str) -> None:
|
84
|
-
"""
|
85
|
-
Validates file name for OS-specific constraints.
|
86
|
-
|
87
|
-
Args:
|
88
|
-
file_name (str): The file name to validate.
|
89
|
-
|
90
|
-
Raises:
|
91
|
-
ValueError: If the file name violates naming constraints.
|
92
|
-
"""
|
93
|
-
if not file_name:
|
94
|
-
raise ValueError("File name cannot be empty.")
|
95
|
-
|
96
|
-
if len(file_name) > 255:
|
97
|
-
raise ValueError("File name exceeds maximum length (255 characters).")
|
98
|
-
|
99
|
-
invalid_chars = '<>:"/\\|?*'
|
100
|
-
if any(char in invalid_chars for char in file_name):
|
101
|
-
raise ValueError(f"File name '{file_name}' contains invalid characters.")
|
102
|
-
|
103
|
-
if file_name.startswith(" ") or file_name.endswith(" "):
|
104
|
-
raise ValueError("File name cannot start or end with spaces.")
|
105
|
-
|
106
|
-
if len(Path(file_name).suffix) == 0: # Ensure file has an extension
|
107
|
-
raise ValueError("File name must include a valid extension (e.g., '.txt').")
|
108
|
-
|
109
|
-
|
110
|
-
## ==============================
|
111
|
-
## FILE SYSTEM UTILITIES
|
112
|
-
## ==============================
|
113
|
-
def create_folder_and_file(folder_name: str, file_name: str) -> None:
|
114
|
-
"""
|
115
|
-
Create a folder and an empty file safely with robust error handling.
|
116
|
-
|
117
|
-
Args:
|
118
|
-
folder_name (str): Name of the folder to be created.
|
119
|
-
file_name (str): Name of the file to be created inside the folder.
|
120
|
-
|
121
|
-
Raises:
|
122
|
-
FileExistsError: If the folder already exists.
|
123
|
-
FileNotFoundError: If the folder path is invalid.
|
124
|
-
PermissionError: If there are insufficient permissions.
|
125
|
-
ValueError: If inputs are invalid.
|
126
|
-
"""
|
127
|
-
## ✅ Input Validation
|
128
|
-
validate_folder_name(folder_name)
|
129
|
-
validate_file_name(file_name)
|
130
|
-
|
131
|
-
## ✅ Create Path Object
|
132
|
-
folder_path = Path(folder_name)
|
133
|
-
file_path = folder_path / file_name
|
134
|
-
|
135
|
-
try:
|
136
|
-
## ✅ Create folder if it doesn't exist; same behavior as the POSIX `mkdir -p` command
|
137
|
-
folder_path.mkdir(parents=True, exist_ok=True) ## Safe parent directory creation
|
138
|
-
print(f"✅ Folder '{folder_name}' created successfully.")
|
139
|
-
|
140
|
-
## ✅ Create an empty file inside the folder
|
141
|
-
# os.chdir(folder_name) ## May Raise FileNotFoundError
|
142
|
-
# with open(file_name, 'a'):
|
143
|
-
# pass
|
144
|
-
if file_path.exists():
|
145
|
-
raise FileExistsError(f"File '{file_name}' already exists in '{folder_name}'.")
|
146
|
-
|
147
|
-
file_path.touch(exist_ok=False) ## Create an empty file; Fails safely if file exists
|
148
|
-
print(f"✅ File '{file_name}' created successfully inside '{folder_name}'.")
|
149
|
-
|
150
|
-
except FileExistsError as e:
|
151
|
-
raise FileExistsError(str(e)) # Re-raise exception without exiting
|
152
|
-
|
153
|
-
except PermissionError:
|
154
|
-
print("❌ Permission denied. Check your user permissions.")
|
155
|
-
sys.exit(1)
|
156
|
-
|
157
|
-
except Exception as e:
|
158
|
-
print(f"❌ Unexpected error: {e}")
|
159
|
-
sys.exit(1)
|
160
|
-
|
161
|
-
|
162
|
-
## ✅ Handle Arguments Dynamically for Terminal and Debugger Compatibility
|
163
|
-
def parse_arguments() -> tuple[str, str]:
|
164
|
-
"""
|
165
|
-
Parses and validates command-line arguments for both terminal and VSCode debugger compatibility.
|
166
|
-
|
167
|
-
Returns:
|
168
|
-
tuple[str, str]: A tuple containing folder_name and file_name.
|
169
|
-
|
170
|
-
Raises:
|
171
|
-
ValueError: If arguments are invalid or insufficient.
|
172
|
-
"""
|
173
|
-
import shlex # Safely split arguments with quotes (if present)
|
174
|
-
|
175
|
-
## ✅ Check Arguments Length
|
176
|
-
if len(sys.argv) < 2:
|
177
|
-
raise ValueError("Provide exactly 2 arguments: <folder_name> <file_name>")
|
178
|
-
|
179
|
-
## ✅ Handle Debugger Inputs (Single Combined Argument)
|
180
|
-
if len(sys.argv) == 2:
|
181
|
-
args = shlex.split(sys.argv[1]) # Split safely with quote handling
|
182
|
-
else:
|
183
|
-
args = sys.argv[1:] # Use normal command-line arguments
|
184
|
-
|
185
|
-
## ✅ Validate Number of Arguments
|
186
|
-
if len(args) != 2:
|
187
|
-
raise ValueError("❌ Invalid arguments. Provide exactly 2 arguments: <folder_name> <file_name>")
|
188
|
-
|
189
|
-
## ✅ Extract Folder and File Names
|
190
|
-
folder_name, file_name = args[0], args[1]
|
191
|
-
return folder_name, file_name
|
192
|
-
|
193
|
-
|
194
|
-
## ==============================
|
195
|
-
## MAIN FUNCTION
|
196
|
-
## ==============================
|
197
|
-
def main() -> None:
|
198
|
-
"""
|
199
|
-
Main entry point for the script.
|
200
|
-
"""
|
201
|
-
try:
|
202
|
-
## ✅ Handle Debugger Arguments (Optional for Debugging Tools)
|
203
|
-
folder_name, file_name = parse_arguments()
|
204
|
-
|
205
|
-
## ✅ Execute Function for Folder and File Creation
|
206
|
-
print(f"✅ Usage: file_manager.py '{folder_name}' '{file_name}'")
|
207
|
-
create_folder_and_file(folder_name, file_name)
|
208
|
-
except ValueError as e:
|
209
|
-
print(f"❌ Error: {e}")
|
210
|
-
sys.exit(1)
|
211
|
-
|
212
|
-
except Exception as e:
|
213
|
-
print(f"❌ Unexpected Error: {e}")
|
214
|
-
sys.exit(1)
|
215
|
-
|
216
|
-
|
217
|
-
if __name__ == "__main__":
|
218
|
-
main()
|
runbooks/python101/toolkit.py
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Toolkit Module: Implements basic arithmetic operations.
|
3
|
-
|
4
|
-
This module provides functions to perform addition, subtraction,
|
5
|
-
multiplication, and division with detailed input validation.
|
6
|
-
|
7
|
-
Features:
|
8
|
-
- Handles edge cases like NaN, Infinity, and division by zero.
|
9
|
-
- Supports logging for better traceability.
|
10
|
-
- Enforces type checks for input safety.
|
11
|
-
|
12
|
-
Author: Python Developer
|
13
|
-
"""
|
14
|
-
|
15
|
-
from typing import Union
|
16
|
-
|
17
|
-
from loguru import logger
|
18
|
-
|
19
|
-
# Define a type alias for supported numeric types
|
20
|
-
Number = Union[int, float]
|
21
|
-
|
22
|
-
# Configure loguru logger to simplify logs for testing
|
23
|
-
logger.remove()
|
24
|
-
logger.add(lambda msg: print(msg, end=""), format="{message}", level="DEBUG")
|
25
|
-
|
26
|
-
|
27
|
-
def _validate_inputs(a: Number, b: Number, allow_zero: bool = True) -> None:
|
28
|
-
"""
|
29
|
-
Validates numeric inputs and checks edge cases.
|
30
|
-
|
31
|
-
Args:
|
32
|
-
a (Number): The first input value.
|
33
|
-
b (Number): The second input value.
|
34
|
-
allow_zero (bool): Whether zero is allowed as a value for `b`. Default is True.
|
35
|
-
|
36
|
-
Raises:
|
37
|
-
TypeError: If inputs are not integers or floats.
|
38
|
-
ValueError: If inputs are NaN or Infinity.
|
39
|
-
ZeroDivisionError: If `b` is zero and `allow_zero` is False.
|
40
|
-
"""
|
41
|
-
# Type check
|
42
|
-
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):
|
43
|
-
raise TypeError(f"Inputs must be numbers. Received: {type(a)} and {type(b)}")
|
44
|
-
|
45
|
-
# Edge cases: NaN or Infinity
|
46
|
-
for value in [a, b]:
|
47
|
-
if value != value or value in [float("inf"), float("-inf")]:
|
48
|
-
raise ValueError(f"Invalid input {value}. Must be a finite number.")
|
49
|
-
|
50
|
-
# Zero Division Check
|
51
|
-
if not allow_zero and b == 0:
|
52
|
-
raise ZeroDivisionError("division by zero")
|
53
|
-
|
54
|
-
|
55
|
-
def add(a: Number, b: Number) -> float:
|
56
|
-
"""
|
57
|
-
Adds two numbers and returns the result.
|
58
|
-
|
59
|
-
Examples:
|
60
|
-
>>> add(4.0, 2.0)
|
61
|
-
6.0
|
62
|
-
>>> add(4, 2)
|
63
|
-
6.0
|
64
|
-
|
65
|
-
Args:
|
66
|
-
a (Number): The first number.
|
67
|
-
b (Number): The second number.
|
68
|
-
|
69
|
-
Returns:
|
70
|
-
float: The sum of `a` and `b`.
|
71
|
-
|
72
|
-
Raises:
|
73
|
-
TypeError: If inputs are not numbers.
|
74
|
-
"""
|
75
|
-
_validate_inputs(a, b)
|
76
|
-
logger.debug(f"Adding {a} + {b}")
|
77
|
-
return float(a + b)
|
78
|
-
|
79
|
-
|
80
|
-
def subtract(a: Number, b: Number) -> float:
|
81
|
-
"""
|
82
|
-
Subtracts the second number from the first.
|
83
|
-
|
84
|
-
Examples:
|
85
|
-
>>> subtract(4.0, 2.0)
|
86
|
-
2.0
|
87
|
-
>>> subtract(4, 2)
|
88
|
-
2.0
|
89
|
-
|
90
|
-
Args:
|
91
|
-
a (Number): The first number.
|
92
|
-
b (Number): The second number.
|
93
|
-
|
94
|
-
Returns:
|
95
|
-
float: The result of `a - b`.
|
96
|
-
|
97
|
-
Raises:
|
98
|
-
TypeError: If inputs are not numbers.
|
99
|
-
"""
|
100
|
-
_validate_inputs(a, b)
|
101
|
-
logger.debug(f"Subtracting {a} - {b}")
|
102
|
-
return float(a - b)
|
103
|
-
|
104
|
-
|
105
|
-
def multiply(a: Number, b: Number) -> float:
|
106
|
-
"""
|
107
|
-
Multiplies two numbers and returns the result.
|
108
|
-
|
109
|
-
Examples:
|
110
|
-
>>> multiply(4.0, 2.0)
|
111
|
-
8.0
|
112
|
-
>>> multiply(4, 2)
|
113
|
-
8.0
|
114
|
-
|
115
|
-
Args:
|
116
|
-
a (Number): The first number.
|
117
|
-
b (Number): The second number.
|
118
|
-
|
119
|
-
Returns:
|
120
|
-
float: The result of `a * b`.
|
121
|
-
|
122
|
-
Raises:
|
123
|
-
TypeError: If inputs are not numbers.
|
124
|
-
"""
|
125
|
-
_validate_inputs(a, b)
|
126
|
-
logger.debug(f"Multiplying {a} * {b}")
|
127
|
-
return float(a * b)
|
128
|
-
|
129
|
-
|
130
|
-
def divide(a: Number, b: Number) -> float:
|
131
|
-
"""
|
132
|
-
Divides the first number by the second.
|
133
|
-
|
134
|
-
Examples:
|
135
|
-
>>> divide(4.0, 2.0)
|
136
|
-
2.0
|
137
|
-
>>> divide(4, 2)
|
138
|
-
2.0
|
139
|
-
|
140
|
-
Args:
|
141
|
-
a (Number): The numerator.
|
142
|
-
b (Number): The denominator.
|
143
|
-
|
144
|
-
Returns:
|
145
|
-
float: The result of `a / b`.
|
146
|
-
|
147
|
-
Raises:
|
148
|
-
TypeError: If inputs are not numbers.
|
149
|
-
ZeroDivisionError: If `b` is zero.
|
150
|
-
"""
|
151
|
-
_validate_inputs(a, b, allow_zero=False)
|
152
|
-
logger.debug(f"Dividing {a} / {b}")
|
153
|
-
return float(a / b)
|