reverse-diagrams 1.3.3__py3-none-any.whl → 1.3.5__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.
src/utils/progress.py ADDED
@@ -0,0 +1,257 @@
1
+ """Progress tracking utilities with rich console output."""
2
+ import logging
3
+ from typing import List, Optional, Any, Iterator
4
+ from contextlib import contextmanager
5
+
6
+ from rich.console import Console
7
+ from rich.progress import (
8
+ Progress,
9
+ SpinnerColumn,
10
+ TextColumn,
11
+ BarColumn,
12
+ TimeElapsedColumn,
13
+ TaskID
14
+ )
15
+ from rich.panel import Panel
16
+ from rich.text import Text
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ class ProgressTracker:
22
+ """Enhanced progress tracking with rich console output."""
23
+
24
+ def __init__(self, console: Optional[Console] = None):
25
+ """
26
+ Initialize progress tracker.
27
+
28
+ Args:
29
+ console: Rich console instance (optional)
30
+ """
31
+ self.console = console or Console()
32
+ self.progress = Progress(
33
+ SpinnerColumn(),
34
+ TextColumn("[progress.description]{task.description}"),
35
+ BarColumn(),
36
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
37
+ TimeElapsedColumn(),
38
+ console=self.console,
39
+ transient=False
40
+ )
41
+ self._active_tasks: List[TaskID] = []
42
+
43
+ @contextmanager
44
+ def track_operation(self, description: str, total: Optional[int] = None):
45
+ """
46
+ Context manager for tracking a single operation.
47
+
48
+ Args:
49
+ description: Operation description
50
+ total: Total number of items (optional for indeterminate progress)
51
+
52
+ Yields:
53
+ Task ID for updating progress
54
+ """
55
+ with self.progress:
56
+ task_id = self.progress.add_task(
57
+ f"[cyan]{description}",
58
+ total=total
59
+ )
60
+ self._active_tasks.append(task_id)
61
+
62
+ try:
63
+ yield task_id
64
+ finally:
65
+ if task_id in self._active_tasks:
66
+ self._active_tasks.remove(task_id)
67
+
68
+ def update_progress(self, task_id: TaskID, advance: int = 1, description: Optional[str] = None):
69
+ """
70
+ Update progress for a task.
71
+
72
+ Args:
73
+ task_id: Task identifier
74
+ advance: Number of items to advance
75
+ description: Updated description (optional)
76
+ """
77
+ kwargs = {"advance": advance}
78
+ if description:
79
+ kwargs["description"] = f"[cyan]{description}"
80
+
81
+ self.progress.update(task_id, **kwargs)
82
+
83
+ def complete_task(self, task_id: TaskID, description: Optional[str] = None):
84
+ """
85
+ Mark a task as completed.
86
+
87
+ Args:
88
+ task_id: Task identifier
89
+ description: Completion message (optional)
90
+ """
91
+ if description:
92
+ self.progress.update(task_id, description=f"[green]✓ {description}")
93
+ else:
94
+ current_desc = self.progress.tasks[task_id].description
95
+ self.progress.update(task_id, description=f"[green]✓ {current_desc}")
96
+
97
+ def track_aws_operations(self, operations: List[str]) -> Iterator[TaskID]:
98
+ """
99
+ Track multiple AWS operations with progress bars.
100
+
101
+ Args:
102
+ operations: List of operation descriptions
103
+
104
+ Yields:
105
+ Task IDs for each operation
106
+ """
107
+ with self.progress:
108
+ task_ids = []
109
+
110
+ # Create tasks for all operations
111
+ for operation in operations:
112
+ task_id = self.progress.add_task(
113
+ f"[cyan]{operation}",
114
+ total=None # Indeterminate progress
115
+ )
116
+ task_ids.append(task_id)
117
+
118
+ # Yield task IDs for updating
119
+ for task_id in task_ids:
120
+ yield task_id
121
+
122
+ def show_summary(self, title: str, items: List[str], color: str = "blue"):
123
+ """
124
+ Display a summary panel with items.
125
+
126
+ Args:
127
+ title: Panel title
128
+ items: List of items to display
129
+ color: Panel border color
130
+ """
131
+ if not items:
132
+ content = Text("No items to display", style="italic")
133
+ else:
134
+ content = Text("\n".join(f"• {item}" for item in items))
135
+
136
+ panel = Panel(
137
+ content,
138
+ title=f"[bold {color}]{title}[/bold {color}]",
139
+ border_style=color,
140
+ padding=(1, 2)
141
+ )
142
+
143
+ self.console.print(panel)
144
+
145
+ def show_error(self, message: str, details: Optional[str] = None):
146
+ """
147
+ Display an error message with optional details.
148
+
149
+ Args:
150
+ message: Error message
151
+ details: Additional error details (optional)
152
+ """
153
+ content = Text(message, style="bold red")
154
+ if details:
155
+ content.append("\n\n")
156
+ content.append(details, style="red")
157
+
158
+ panel = Panel(
159
+ content,
160
+ title="[bold red]❌ Error[/bold red]",
161
+ border_style="red",
162
+ padding=(1, 2)
163
+ )
164
+
165
+ self.console.print(panel)
166
+
167
+ def show_success(self, message: str, details: Optional[str] = None):
168
+ """
169
+ Display a success message with optional details.
170
+
171
+ Args:
172
+ message: Success message
173
+ details: Additional details (optional)
174
+ """
175
+ content = Text(message, style="bold green")
176
+ if details:
177
+ content.append("\n\n")
178
+ content.append(details, style="green")
179
+
180
+ panel = Panel(
181
+ content,
182
+ title="[bold green]✅ Success[/bold green]",
183
+ border_style="green",
184
+ padding=(1, 2)
185
+ )
186
+
187
+ self.console.print(panel)
188
+
189
+ def show_warning(self, message: str, details: Optional[str] = None):
190
+ """
191
+ Display a warning message with optional details.
192
+
193
+ Args:
194
+ message: Warning message
195
+ details: Additional details (optional)
196
+ """
197
+ content = Text(message, style="bold yellow")
198
+ if details:
199
+ content.append("\n\n")
200
+ content.append(details, style="yellow")
201
+
202
+ panel = Panel(
203
+ content,
204
+ title="[bold yellow]⚠️ Warning[/bold yellow]",
205
+ border_style="yellow",
206
+ padding=(1, 2)
207
+ )
208
+
209
+ self.console.print(panel)
210
+
211
+
212
+ # Global progress tracker instance
213
+ _progress_tracker: Optional[ProgressTracker] = None
214
+
215
+
216
+ def get_progress_tracker() -> ProgressTracker:
217
+ """Get or create global progress tracker instance."""
218
+ global _progress_tracker
219
+ if _progress_tracker is None:
220
+ _progress_tracker = ProgressTracker()
221
+ return _progress_tracker
222
+
223
+
224
+ def track_items(items: List[Any], description: str = "Processing items") -> Iterator[Any]:
225
+ """
226
+ Track progress while iterating over items.
227
+
228
+ Args:
229
+ items: List of items to process
230
+ description: Progress description
231
+
232
+ Yields:
233
+ Items from the list with progress tracking
234
+ """
235
+ tracker = get_progress_tracker()
236
+
237
+ with tracker.track_operation(description, total=len(items)) as task_id:
238
+ for item in items:
239
+ yield item
240
+ tracker.update_progress(task_id)
241
+
242
+
243
+ @contextmanager
244
+ def track_operation(description: str, total: Optional[int] = None):
245
+ """
246
+ Context manager for tracking operations with global progress tracker.
247
+
248
+ Args:
249
+ description: Operation description
250
+ total: Total number of items (optional)
251
+
252
+ Yields:
253
+ Task ID for updating progress
254
+ """
255
+ tracker = get_progress_tracker()
256
+ with tracker.track_operation(description, total) as task_id:
257
+ yield task_id
src/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  """Set version file."""
2
- __version__ = "1.3.3"
2
+ __version__ = "1.3.5"
@@ -1,247 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: reverse_diagrams
3
- Version: 1.3.3
4
- Summary: Continuous Documentation Tool - Documentation as Code Tool - This package create reverse diagrams based on your current state in your cloud environment using diagrams library
5
- Project-URL: Homepage, https://github.com/velez94/reverse_diagrams
6
- Project-URL: Bug Tracker, https://github.com/velez94/reverse_diagrams/issues
7
- Author-email: Alejandro Velez <avelez@labvel.io>
8
- License: Copyright [2024] [Alejandro Velez]
9
-
10
- Licensed under the Apache License, Version 2.0 (the "License");
11
- you may not use this file except in compliance with the License.
12
- You may obtain a copy of the License at
13
-
14
- http://www.apache.org/licenses/LICENSE-2.0
15
-
16
- Unless required by applicable law or agreed to in writing, software
17
- distributed under the License is distributed on an "AS IS" BASIS,
18
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- See the License for the specific language governing permissions and
20
- limitations under the License.
21
- License-File: LICENSE
22
- Classifier: Operating System :: OS Independent
23
- Classifier: Programming Language :: Python :: 3
24
- Requires-Python: >=3.8
25
- Requires-Dist: argcomplete>=3.4.0
26
- Requires-Dist: boto3>=1.26.44
27
- Requires-Dist: colorama>=0.4.4
28
- Requires-Dist: diagrams>=0.23.4
29
- Requires-Dist: emoji>=2.2.0
30
- Requires-Dist: inquirer>=3.1.4
31
- Requires-Dist: rich>=13.7.0
32
- Description-Content-Type: text/markdown
33
-
34
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
35
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
36
- **Table of Contents**
37
-
38
- - [Reverse Diagrams](#reverse-diagrams)
39
- - [Requirement](#requirement)
40
- - [Install](#install)
41
- - [Use](#use)
42
- - [Subcommands](#subcommands)
43
- - [watch](#watch)
44
- - [Service supported](#service-supported)
45
- - [AWS Organizations](#aws-organizations)
46
- - [Identity and Access Manager Center (SSO)](#identity-and-access-manager-center-sso)
47
- - [Additional Commands](#additional-commands)
48
- - [watch](#watch-1)
49
- - [Options](#options)
50
- - [Combine the options](#combine-the-options)
51
- - [Extras](#extras)
52
- - [Enable autocomplete](#enable-autocomplete)
53
-
54
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
55
-
56
- # Reverse Diagrams
57
-
58
- > Continuous Documentation Tool - Documentation as Code Tool
59
-
60
- This package create diagrams and help to audit your services from your shell.
61
-
62
- ![Complete demo](docs/images/complete_demo.gif)
63
- # Requirement
64
-
65
- AWS programmatic access using AWS CLI. [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
66
-
67
-
68
- # Install
69
-
70
- `pip install reverse-diagrams`
71
-
72
- # Use
73
-
74
- The following are the available options
75
-
76
- ```commandline
77
- $ reverse_diagrams -h
78
- usage: reverse_diagrams [-h] [-p PROFILE] [-od OUTPUT_DIR_PATH] [-r REGION] [-o] [-i] [-a] [-v] [-d] {watch} ...
79
-
80
- Create architecture diagram, inspect and audit your AWS services from your current state.
81
-
82
- options:
83
- -h, --help show this help message and exit
84
- -p PROFILE, --profile PROFILE
85
- AWS cli profile for AWS Apis
86
- -od OUTPUT_DIR_PATH, --output_dir_path OUTPUT_DIR_PATH
87
- Name of folder to save the diagrams python code files
88
- -r REGION, --region REGION
89
- AWS region
90
- -o, --graph_organization
91
- Set if you want to create graph for your organization
92
- -i, --graph_identity Set if you want to create graph for your IAM Center
93
- -a, --auto_create Create Automatically diagrams
94
- -v, --version Show version
95
- -d, --debug Debug Mode
96
-
97
- Commands:
98
- Command and functionalities
99
-
100
- {watch} reverse_diagrams Commands
101
- watch Create pretty console viewexample: reverse_diagrams watch -wi diagrams/json/account_assignments.json
102
-
103
- Thanks for using reverse_diagrams!
104
-
105
- ```
106
- For example:
107
-
108
- ```commandline
109
- reverse_diagrams -p labvel-master -o -i -r us-east-1
110
-
111
- ❇️ Describe Organization
112
- ❇️ Getting Organization Info
113
- ❇️ Listing Organizational Units
114
- ❇️ Getting the Account list info
115
- ℹ️ There are 11 Accounts in your organization
116
- ℹ️ The accounts are stored in diagrams/json/organizations.json
117
- ❇️ Creating diagrams in diagrams/code
118
- ❇️ Getting Identity store instance info
119
- ❇️ List groups
120
- ℹ️ There are 10 Groups in your Identity Store
121
- ❇️ Get groups and Users info
122
- Getting groups members... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:07
123
- Getting account assignments ... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:05:23
124
- Create user and groups assignments ... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
125
- ❇️ Getting account assignments, users and groups
126
- ℹ️ The accounts are stored in diagrams/json/account_assignments.json
127
- ℹ️ The accounts are stored in diagrams/json/groups.json
128
- ❇️ Creating diagrams in diagrams/code
129
-
130
- ```
131
- Then run `python3 graph_org.py` to create a png screenshot (`organizations-state.png`) for your current state.
132
-
133
- > Both files are saved into the current directory.
134
-
135
- ```commandline
136
- $ reverse_diagrams -p labvel-master -o -r us-east-2
137
- Date: 2022-12-17 22:44:07.623260
138
- ❇️ Getting Organization Info
139
- ❇️ The Organizational Units list
140
- ❇️ Getting the Account list info
141
- Run -> python3 graph_org.py
142
-
143
-
144
- $ python3 graph_org.py
145
- $ ls
146
- graph_org.py
147
- organizations-state.png
148
- ```
149
- For example:
150
-
151
- ![Organizations Diagram](./docs/images/organizations-state-copy.png)
152
-
153
- Now you can edit `graph_org.py` file or add to your repositories for keeping the documentation update.
154
- ## Subcommands
155
-
156
- ### watch
157
-
158
- Watch the result in console with a beautiful print style.
159
- ```commandline
160
- reverse_diagrams watch -h
161
- usage: reverse_diagrams watch [-h] [-wo WATCH_GRAPH_ORGANIZATION] [-wi WATCH_GRAPH_IDENTITY] [-wa WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS]
162
-
163
- Create view of diagrams in console based on kind of diagram and json file.
164
-
165
- options:
166
- -h, --help show this help message and exit
167
-
168
- Create view of diagrams in console based on kind of diagram and json file.:
169
- -wo WATCH_GRAPH_ORGANIZATION, --watch_graph_organization WATCH_GRAPH_ORGANIZATION
170
- Set if you want to see graph for your organization structure summary. For example: reverse_diagrams watch watch -wi diagrams/json/organizations.json
171
- -wi WATCH_GRAPH_IDENTITY, --watch_graph_identity WATCH_GRAPH_IDENTITY
172
- Set if you want to see graph for your groups and users. For example: reverse_diagrams watch watch -wi diagrams/json/groups.json
173
- -wa WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS, --watch_graph_accounts_assignments WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS
174
- Set if you want to see graph for your IAM Center- Accounts assignments. For example: reverse_diagrams watch watch -wi
175
- diagrams/json/account_assignments.json.jso
176
- ```
177
-
178
- # Service supported
179
-
180
- ## AWS Organizations
181
-
182
- ```commandline
183
- reverse_diagrams -p my-profile -o -r us-east-2
184
- ```
185
- ## Identity and Access Manager Center (SSO)
186
-
187
- ```commandline
188
- reverse_diagrams -p my-profile -i -r us-east-2
189
- ```
190
- # Additional Commands
191
-
192
- ## watch
193
- You can watch the configuration and summary in your shell based on json files generated previously.
194
-
195
- ### Options
196
-
197
- ```commandline
198
- $ reverse_diagrams watch -h
199
- usage: reverse_diagrams watch [-h] [-wo WATCH_GRAPH_ORGANIZATION] [-wi WATCH_GRAPH_IDENTITY] [-wa WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS]
200
-
201
- Create view of diagrams in console based on kind of diagram and json file.
202
-
203
- options:
204
- -h, --help show this help message and exit
205
-
206
- Create view of diagrams in console based on kind of diagram and json file.:
207
- -wo WATCH_GRAPH_ORGANIZATION, --watch_graph_organization WATCH_GRAPH_ORGANIZATION
208
- Set if you want to see graph for your organization structure summary. For example: reverse_diagrams watch watch -wo diagrams/json/organizations.json
209
- -wi WATCH_GRAPH_IDENTITY, --watch_graph_identity WATCH_GRAPH_IDENTITY
210
- Set if you want to see graph for your groups and users. For example: reverse_diagrams watch watch -wi diagrams/json/groups.json
211
- -wa WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS, --watch_graph_accounts_assignments WATCH_GRAPH_ACCOUNTS_ASSIGNMENTS
212
- Set if you want to see graph for your IAM Center- Accounts assignments. For example: reverse_diagrams watch watch -wa diagrams/json/account_assignments.json
213
-
214
- ```
215
-
216
- For example, to watch account assignments:
217
-
218
- ![view Acoount assigments](docs/images/show_console_view.gif)
219
-
220
- ### Combine the options
221
-
222
- ```commandline
223
- reverse_diagrams -p my-profile -o -i -r us-east-2
224
- ```
225
-
226
- ## Extras
227
- ### Enable autocomplete
228
- Argcomplete provides easy, extensible command line tab completion of arguments for your Python application.
229
-
230
- It makes two assumptions:
231
-
232
- * You’re using bash or zsh as your shell
233
-
234
- * You’re using argparse to manage your command line arguments/options
235
-
236
- Argcomplete is particularly useful if your program has lots of options or subparsers, and if your program can dynamically suggest completions for your argument/option values (for example, if the user is browsing resources over the network).
237
- Run:
238
- ```bash
239
- activate-global-python-argcomplete
240
- ```
241
- and to make sure that bash knows about this script, you use
242
- ```bash
243
-
244
- echo 'eval "$(register-python-argcomplete reverse_diagrams)"' >> ~/.bashrc
245
- source ~/.bashrc
246
-
247
- ```
@@ -1,21 +0,0 @@
1
- src/__init__.py,sha256=lOE8TAJF_WdxgxEBxVz9t8dC3s3t2c21VWYPrzfznkE,17
2
- src/reverse_diagrams.py,sha256=dVkz429-8MtDAfQFxVhchuuVrH8D-IcYyTBgRnw65cA,4208
3
- src/version.py,sha256=LtDJf1PMjrnorTQJTEoRmRf7HBHvjEaHQmMzO7fguPo,48
4
- src/aws/__init__.py,sha256=lOE8TAJF_WdxgxEBxVz9t8dC3s3t2c21VWYPrzfznkE,17
5
- src/aws/describe_identity_store.py,sha256=PJYpAXsqCeVMPfv72Q2nTuolXMnG4dah_HRuyu0hIkY,15450
6
- src/aws/describe_organization.py,sha256=6154J-jnGGql_uzr5DCeSNsNEiMblkOPNq5qF1UAjEw,14268
7
- src/aws/describe_sso.py,sha256=z65RnoxJDVSMPB1TRJAxi8S8-DllwmaxxXaZ4uicSzU,4915
8
- src/banner/__init__.py,sha256=lOE8TAJF_WdxgxEBxVz9t8dC3s3t2c21VWYPrzfznkE,17
9
- src/banner/banner.py,sha256=XREWjVLp1-PHVdfBSoADgw0LvRpYU5u7NPaUraL9Els,3893
10
- src/dgms/__init__.py,sha256=lOE8TAJF_WdxgxEBxVz9t8dC3s3t2c21VWYPrzfznkE,17
11
- src/dgms/graph_mapper.py,sha256=xutxzxLCIGSBfHCAF-BnWXN21bjzusA43ZhKtXUir2E,7714
12
- src/dgms/graph_template.py,sha256=IOEmTk9A0xqEhtdNnaFrVDJlBF0ggW0WpxosW4nbcQo,1217
13
- src/reports/__init__.py,sha256=lOE8TAJF_WdxgxEBxVz9t8dC3s3t2c21VWYPrzfznkE,17
14
- src/reports/console_view.py,sha256=1_ET53Bn_vKlLmqr0Sih5szP5kNFCQRH4A8tXJgip2Y,5832
15
- src/reports/save_results.py,sha256=g-UphsQ_tfDhvNH3QNV7j68TWWvy44vbbjaNyn4KWhU,719
16
- src/reports/tes.py,sha256=c6TdxhAedfHjPrqaRw0nucdCEQOM9xKsgw35IOIDdYs,17691
17
- reverse_diagrams-1.3.3.dist-info/METADATA,sha256=cwkUxQkCkzZkhxGZCtK1Y4DTMAb1r93GAslbpxSi1DQ,9624
18
- reverse_diagrams-1.3.3.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
19
- reverse_diagrams-1.3.3.dist-info/entry_points.txt,sha256=VZNkrc7qUDbddTCH3pGd83EhUT3PHTx9MzpAk6bb6qc,63
20
- reverse_diagrams-1.3.3.dist-info/licenses/LICENSE,sha256=o6nDaQ7M9xbR0L7HSJ3A-1JbBPoZro_zhVPO4-M5CAQ,571
21
- reverse_diagrams-1.3.3.dist-info/RECORD,,