├── .gitignore ├── LICENSE ├── README.md ├── dockscribe ├── __init__.py ├── __main__.py ├── composeCraft │ ├── __init__.py │ ├── cli.py │ ├── server.py │ └── utils.py ├── config.py └── container │ ├── __init__.py │ ├── analyse.py │ ├── cli.py │ └── utils.py ├── gif.gif ├── img.png ├── pyproject.toml ├── requirements.txt └── setup.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .python-version 3 | build 4 | dist 5 | *.egg-info -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | Copyright [2024] [Lucas Sovre] 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockscribe 2 | 3 | This is a command line tool to produce a visual map of any docker infrastructure from cmd line. 4 | This tool require an account on composecraft.com to be used, it's open source for security reason. 5 | 6 | ![gif](gif.gif) 7 | 8 | # Get started 9 | 10 | ## Installation 11 | 12 | ```bash 13 | pip install dockscribe 14 | ``` 15 | 16 | ## Requirements 17 | 18 | While running the tool, you need to use a user that can call docker cmd like (without sudo): 19 | 20 | ```bash 21 | docker run --rm hello-world 22 | ``` 23 | 24 | [this doc](https://docs.docker.com/engine/install/linux-postinstall/) might help you learn how to use docker without sudo. 25 | 26 | 27 | ## Usage 28 | 29 | The first thing, is to log in to your composecraft.com account ; 30 | 31 | Note : You can also use it with your own instance by specifying `--url` 32 | (you will have to specify it for each CLI call) 33 | 34 | like : 35 | 36 | ```bash 37 | dockscribe --url https://composecraft.com login --password mypasword --email my_compose_craft_email 38 | ``` 39 | 40 | ```bash 41 | dockscribe login --password mypasword --email my_compose_craft_email 42 | ``` 43 | 44 | Then : 45 | 46 | ```bash 47 | dockscribe describe 48 | ``` 49 | 50 | ![img.png](img.png) 51 | 52 | This command will produce you a visual map of your current docker infrastructure. 53 | You can also view a compose file with : 54 | 55 | ```bash 56 | dockscribe describe --filename=./pathToDockerCompose.yaml 57 | ``` 58 | 59 | You can also directly analyse from an url : 60 | 61 | ```bash 62 | dockscribe describe --filename=https://yourdockercompose.com/yamlfile.yaml 63 | ``` 64 | 65 | In case of help, you can call any cmd with `--help` 66 | 67 | ```bash 68 | dockscribe --help 69 | ``` 70 | -------------------------------------------------------------------------------- /dockscribe/__init__.py: -------------------------------------------------------------------------------- 1 | from .__main__ import app -------------------------------------------------------------------------------- /dockscribe/__main__.py: -------------------------------------------------------------------------------- 1 | from typing import Annotated 2 | 3 | import typer 4 | from .composeCraft import app as compose_craft_app 5 | from .container import app as container_app 6 | from .config import config 7 | 8 | app = typer.Typer() 9 | 10 | 11 | @app.callback(invoke_without_command=True) 12 | def default(ctx: typer.Context, 13 | url:Annotated[str, typer.Option(help="The compose craft server url (usefull in case of self-hosting)")] = "https://composecraft.com"): 14 | if url is not None: 15 | config.update({"url": url}) 16 | # Only print help if no subcommand is invoked 17 | if ctx.invoked_subcommand is None: 18 | print(""" 19 | Dockscribe helps you understand and debug a docker stack. 20 | 21 | First you need to login to composecraft.com as it uses this website UI to show you the diagram. 22 | \t$ dockscribe login 23 | Then you can use: 24 | \t$ dockscribe describe 25 | 26 | If you need any more help, you can use: 27 | \t$ dockscribe --help 28 | """) 29 | 30 | @app.command() 31 | def github(): 32 | """ 33 | Get the project official GitHub 34 | """ 35 | print("The project github is under : https://github.com/LucasSovre/dockscribe") 36 | 37 | app.add_typer(compose_craft_app) 38 | app.add_typer(container_app) 39 | 40 | if __name__ == "__main__": 41 | app() -------------------------------------------------------------------------------- /dockscribe/composeCraft/__init__.py: -------------------------------------------------------------------------------- 1 | from .cli import app 2 | -------------------------------------------------------------------------------- /dockscribe/composeCraft/cli.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import threading 3 | 4 | import typer 5 | 6 | from .server import login_with_email_password 7 | from .utils import get_app_data_path 8 | from ..container.utils import exitIfBadToken, save_config 9 | 10 | app = typer.Typer() 11 | 12 | @app.command() 13 | def login( 14 | token:str=None, 15 | email:str=None, 16 | password:str=None, 17 | ) -> None: 18 | """ 19 | Login to composecraft.com 20 | """ 21 | if token : 22 | save_config(token) 23 | return 24 | if email or password : 25 | if not email or not password: 26 | sys.exit("When providing an email or password, you must provide both") 27 | try: 28 | save_config(login_with_email_password(email, password)) 29 | return 30 | except Exception as e: 31 | sys.exit(f"Failed to login to composecraft.com: {e}") 32 | try: 33 | from .server import run_server 34 | server_thread = threading.Thread(target=run_server, args=(5555,), daemon=True) 35 | server_thread.start() 36 | server_thread.join() 37 | except Exception : 38 | print("Your system does not support login through browser.\nYou can use the cmd : $ dockscribe login --token=YOUR_TOKEN") 39 | 40 | @app.command() 41 | def check_login(show_config:bool=False)->None: 42 | """ 43 | Check login status to composecraft.com 44 | """ 45 | if show_config : 46 | print(f"the config file is locateed under {get_app_data_path()+'/config.json'}") 47 | exitIfBadToken() 48 | print("The config is valid and you are logged in") 49 | 50 | if __name__ == "__main__": 51 | app() -------------------------------------------------------------------------------- /dockscribe/composeCraft/server.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import requests 4 | 5 | from ..config import config 6 | import threading 7 | from http.server import BaseHTTPRequestHandler, HTTPServer 8 | from urllib.parse import urlparse, parse_qs 9 | import webbrowser 10 | 11 | from .utils import get_app_data_path 12 | 13 | 14 | def open_browser(url): 15 | try: 16 | webbrowser.open(url) 17 | except Exception as e: 18 | print(f"Can't automatically open '{url}'") 19 | 20 | class ShutdownHTTPRequestHandler(BaseHTTPRequestHandler): 21 | def do_GET(self): 22 | query_params = parse_qs(urlparse(self.path).query) 23 | token = query_params.get("token", [None])[0] # Get the token value 24 | print(token) 25 | 26 | if token : 27 | # Respond with a simple message 28 | self.send_response(200) 29 | self.send_header("Content-type", "text/plain") 30 | self.send_header("Connection", "close") 31 | self.send_header("Access-Control-Allow-Origin", "*") 32 | self.end_headers() 33 | self.wfile.write(b"You are successfully logged in. You can close this page.") 34 | self.wfile.flush() 35 | 36 | config_path = get_app_data_path()+"/config.json" 37 | with open(config_path,"w+") as f: 38 | f.write(json.dumps({"token":token})) 39 | print(f"config file written to {config_path}") 40 | 41 | # Signal the server to shut down from a separate thread 42 | threading.Thread(target=self.server.shutdown).start() 43 | else: 44 | self.send_response(400) 45 | self.send_header("Content-type", "text/plain") 46 | self.send_header("Connection", "close") 47 | self.send_header("Access-Control-Allow-Origin", "*") 48 | self.end_headers() 49 | self.wfile.write(b"Token is missing.") 50 | self.wfile.flush() 51 | 52 | def run_server(port: int): 53 | """ 54 | Starts an HTTP server that shuts down after a GET request. 55 | """ 56 | try: 57 | server = HTTPServer(('localhost', port), ShutdownHTTPRequestHandler) 58 | print(f"Wait for login on {config['url']}/login/cli ...") 59 | open_browser(f"{config['url']}/login/cli") 60 | server.serve_forever() 61 | except KeyboardInterrupt: 62 | print("\nCmd interrupted by user.") 63 | finally: 64 | server.server_close() 65 | 66 | def login_with_email_password(email:str, password:str)->str|None: 67 | url = f"{config['url']}/api/auth/jwt" 68 | params = {"email": email, "password": password} 69 | response = requests.get(url, params=params) 70 | response.raise_for_status() # Raise an exception for HTTP errors (4xx/5xx) 71 | 72 | # Parse the JSON response to extract the token 73 | token = response.json().get("token") 74 | if token: 75 | return token 76 | else: 77 | raise Exception("Token not found in response.") -------------------------------------------------------------------------------- /dockscribe/composeCraft/utils.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import os 3 | from enum import Enum 4 | 5 | class OS(Enum): 6 | MACOS = 'macOS' 7 | WINDOWS = 'windows' 8 | LINUX = 'linux' 9 | 10 | def get_OS()->OS: 11 | os_name = platform.system() 12 | if "windo" in os_name.lower(): 13 | return OS.WINDOWS 14 | elif "dar" in os_name.lower(): 15 | return OS.MACOS 16 | return OS.LINUX 17 | 18 | 19 | def get_cache_path() -> str: 20 | os_type = get_OS() 21 | if os_type == OS.WINDOWS: 22 | # Use APPDATA for Windows 23 | cache_dir = os.getenv('LOCALAPPDATA', os.path.expanduser('~\\AppData\\Local')) 24 | elif os_type == OS.MACOS: 25 | # Use ~/Library/Caches for macOS 26 | cache_dir = os.path.expanduser('~/Library/Caches') 27 | else: 28 | # Use ~/.cache for Linux 29 | cache_dir = os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache')) 30 | dockscribe_dir = os.path.join(cache_dir, 'dockscribe') 31 | os.makedirs(dockscribe_dir, exist_ok=True) 32 | return dockscribe_dir 33 | 34 | 35 | def get_app_data_path() -> str: 36 | os_type = get_OS() 37 | if os_type == OS.WINDOWS: 38 | # Use APPDATA for Windows application data 39 | app_data_dir = os.getenv('LOCALAPPDATA', os.path.expanduser('~\\AppData\\Local')) 40 | elif os_type == OS.MACOS: 41 | # Use ~/Library/Application Support for macOS application data 42 | app_data_dir = os.path.expanduser('~/Library/Application Support') 43 | else: 44 | # Use ~/.local/share for Linux application data 45 | app_data_dir = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) 46 | 47 | dockscribe_dir = os.path.join(app_data_dir, 'dockscribe') 48 | os.makedirs(dockscribe_dir, exist_ok=True) 49 | return dockscribe_dir -------------------------------------------------------------------------------- /dockscribe/config.py: -------------------------------------------------------------------------------- 1 | config = { 2 | "url": "https://composecraft.com" 3 | } -------------------------------------------------------------------------------- /dockscribe/container/__init__.py: -------------------------------------------------------------------------------- 1 | from .cli import app -------------------------------------------------------------------------------- /dockscribe/container/analyse.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | import yaml 4 | 5 | import docker 6 | import requests 7 | from string import ascii_lowercase 8 | 9 | from .utils import clean_object 10 | 11 | 12 | def analyse_whole_machine(include_volumes:bool)->{}: 13 | client = docker.from_env() 14 | containers = client.containers.list(all=True) 15 | networks_lists = {} 16 | containers_lists = {} 17 | volumes_lists = {} 18 | for container in containers: 19 | #networks 20 | network_settings = container.attrs.get('NetworkSettings', {}) 21 | networks = network_settings.get('Networks', {}) 22 | for network_name in networks.keys(): 23 | networks_lists[network_name] = { 24 | 25 | } 26 | volumes_binded = [] 27 | #volumes 28 | if(include_volumes): 29 | volumes = container.attrs.get("Mounts", []) 30 | for volume in volumes: 31 | source = volume.get("Source", "") 32 | name = volume.get("Name", "") 33 | if not name: 34 | name = f"{source[source.rfind('/')+1:]}-{''.join(random.choice(ascii_lowercase) for _ in range(2))}" 35 | volumes_binded.append(name) 36 | volumes_lists[name] = { 37 | "type": volume.get("Type", ""), 38 | "source" : source, 39 | } 40 | #containers 41 | containers_lists[container.name] = { 42 | "image": container.image.attrs.get('RepoTags', '')[0], 43 | "running": container.image.attrs.get('State', {}).get('Running', False), 44 | "networks": list(networks), 45 | "volumes": volumes_binded 46 | } 47 | return { 48 | "containers": containers_lists, 49 | "networks": networks_lists, 50 | "volumes": volumes_lists, 51 | } 52 | 53 | def analyse_compose_file(uri:str)->{}: 54 | if "http" in uri : 55 | #distant file 56 | response = requests.get(uri, {"downloadformat": "yaml"}) 57 | data = yaml.safe_load(response.content) 58 | else : 59 | # local file 60 | with open(uri, "r") as f: 61 | data = yaml.safe_load(f) 62 | #remove envs and secrets 63 | result = clean_object(data,["secrets","environment"]) 64 | return result 65 | -------------------------------------------------------------------------------- /dockscribe/container/cli.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from typing import Annotated 3 | 4 | import requests 5 | import typer 6 | 7 | from ..config import config 8 | from .analyse import analyse_whole_machine, analyse_compose_file 9 | from .utils import exitIfBadToken, getTokenFromData 10 | 11 | app = typer.Typer() 12 | 13 | @app.command() 14 | def describe( 15 | filename: Annotated[str, typer.Option("--filename",'-f',help="Docker compose file to analyse (also works with a compose file url)")] = None, 16 | include_volumes:Annotated[bool, typer.Option(help="If the volumes are included in the analysis (no effect with --filename )")] = False 17 | )->None: 18 | """ 19 | Produce a composecraft visualMap of a container system. 20 | If you specify a file using --filename or -f ,it wll produce a view of the compose file. 21 | 22 | By default, it produces a view of the whole dockers in the system. 23 | 24 | For security reason the env and secrets are never uploaded to analyze. 25 | """ 26 | exitIfBadToken() 27 | if filename: 28 | print(f"describe {filename}") 29 | compose_file_content_cleaned = analyse_compose_file(filename) 30 | resp = requests.post(f"{config['url']}/api/compose", json=compose_file_content_cleaned, headers={"Authorization":getTokenFromData() }) 31 | if resp.status_code != 200: 32 | sys.exit("Failed to describe compose, there is a problem with the API.") 33 | else : 34 | print(f""" 35 | Complete analysis 🥳 ! 36 | 37 | You can view the compose file at : 38 | \t{config['url']}/dashboard/playground?id={resp.json()['id']} 39 | """) 40 | return 41 | print("describe whole container") 42 | data = analyse_whole_machine(include_volumes) 43 | resp = requests.post(f"{config['url']}/api/compose/machine", json=data, 44 | headers={"Authorization": getTokenFromData()}) 45 | if resp.status_code != 200: 46 | sys.exit("Failed to describe compose, there is a problem with the API.") 47 | else: 48 | print(f""" 49 | Complete analysis 🥳 ! 50 | 51 | You can view the compose file at : 52 | \t{config['url']}/dashboard/playground?id={resp.json()['id']} 53 | """) 54 | return -------------------------------------------------------------------------------- /dockscribe/container/utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | from ..config import config 4 | 5 | import requests 6 | 7 | from ..composeCraft.utils import get_app_data_path 8 | 9 | 10 | def clean_object(obj:dict, keys_to_remove:list): 11 | # Handle dictionaries 12 | if isinstance(obj, dict): 13 | # Create a new dictionary to avoid modifying the original 14 | cleaned_dict = {} 15 | for key, value in obj.items(): 16 | # Skip keys that should be removed 17 | if key not in keys_to_remove: 18 | # Recursively clean nested values 19 | cleaned_dict[key] = clean_object(value, keys_to_remove) 20 | return cleaned_dict 21 | 22 | # Handle lists 23 | elif isinstance(obj, list): 24 | # Recursively clean each item in the list 25 | return [clean_object(item, keys_to_remove) for item in obj] 26 | 27 | # For non-container types, return as-is 28 | return obj 29 | 30 | def getTokenFromData()->str: 31 | config_path = get_app_data_path() + "/config.json" 32 | with open(config_path, 'r') as file: 33 | data = json.load(file) 34 | return data.get("token") 35 | 36 | def verifyToken()->bool: 37 | resp = requests.post(f"{config['url']}/api/auth/jwt",json={ 38 | "token":getTokenFromData() 39 | }) 40 | return resp.ok 41 | 42 | def exitIfBadToken(): 43 | if not verifyToken(): 44 | print("The composecraft token has expired or is invalid.\n\nPlease login and try again. You can use : \n\t$ dockscribe login") 45 | sys.exit("Token invalid") 46 | 47 | def save_config(token:str)->None: 48 | config_path = get_app_data_path() + "/config.json" 49 | with open(config_path, "w+") as f: 50 | f.write(json.dumps({"token": token})) 51 | print(f"config file written to {config_path}") -------------------------------------------------------------------------------- /gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/composecraft/dockscribe/945520e8953813caa9539801e3f72c38e0cbd108/gif.gif -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/composecraft/dockscribe/945520e8953813caa9539801e3f72c38e0cbd108/img.png -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "dockscribe" 7 | version = "1.0.2" 8 | authors = [ 9 | {name = "Lucas Sovre", email = "lucas.sovre@entrecompetents.fr"}, 10 | ] 11 | description = "Turn any docker infrastructure in a visual map with composecraft.com" 12 | license = {file = "LICENSE"} 13 | readme = "README.md" 14 | requires-python = ">=3.9" 15 | dependencies = [ 16 | "typer", 17 | "docker", 18 | "requests", 19 | "pyyaml" 20 | ] 21 | 22 | [project.scripts] 23 | dockscribe = "dockscribe:app" 24 | 25 | [project.urls] 26 | "Homepage" = "https://github.com/LucasSovre/dockscribe" 27 | "Source" = "https://github.com/LucasSovre/dockscribe" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2024.8.30 2 | charset-normalizer==3.4.0 3 | click==8.1.7 4 | docker==7.1.0 5 | idna==3.10 6 | markdown-it-py==3.0.0 7 | mdurl==0.1.2 8 | Pygments==2.18.0 9 | requests==2.32.3 10 | rich==13.9.4 11 | shellingham==1.5.4 12 | typer==0.15.1 13 | typing_extensions==4.12.2 14 | urllib3==2.2.3 15 | PyYAML~=6.0.2 -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [options] 2 | packages = find: 3 | python_requires = >=3.9 4 | install_requires = 5 | typer 6 | docker 7 | requests 8 | pyyaml 9 | 10 | [options.entry_points] 11 | console_scripts = 12 | dockscribe = dockscribe:app --------------------------------------------------------------------------------