devvault-xyltraz 1.0.0__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.
devvault/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ from .keys import get, keys
2
+
3
+
4
+ __version__ = "1.0.0"
5
+
6
+ __all__ = [
7
+ "get",
8
+ "keys",
9
+ ]
devvault/keys.py ADDED
@@ -0,0 +1,48 @@
1
+ from pathlib import Path
2
+
3
+
4
+ DEVVAULT_DIR = Path.home() / ".devvault"
5
+ ENV_FILE = DEVVAULT_DIR / ".env"
6
+
7
+
8
+ def _load_keys():
9
+ """Charge les clés depuis le coffre DevVault."""
10
+ if not ENV_FILE.exists():
11
+ return {}
12
+
13
+ result = {}
14
+
15
+ with ENV_FILE.open("r", encoding="utf-8") as file:
16
+ for line in file:
17
+ line = line.strip()
18
+
19
+ if not line or line.startswith("#") or "=" not in line:
20
+ continue
21
+
22
+ key, value = line.split("=", 1)
23
+ result[key.strip()] = value.strip()
24
+
25
+ return result
26
+
27
+
28
+ def get(name):
29
+ """Récupère une clé DevVault."""
30
+ keys = _load_keys()
31
+
32
+ if name not in keys:
33
+ raise KeyError(f"La clé '{name}' n'existe pas dans DevVault.")
34
+
35
+ return keys[name]
36
+
37
+
38
+ class Keys:
39
+ """Permet d'accéder aux clés avec keys.NOM_DE_LA_CLE."""
40
+
41
+ def __getattr__(self, name):
42
+ try:
43
+ return get(name)
44
+ except KeyError as error:
45
+ raise AttributeError(str(error)) from error
46
+
47
+
48
+ keys = Keys()
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.4
2
+ Name: devvault-xyltraz
3
+ Version: 1.0.0
4
+ Summary: A lightweight local environment variable manager for developers
5
+ Author: Xyltraz
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Xyltraz/DevVault
8
+ Project-URL: Repository, https://github.com/Xyltraz/DevVault
9
+ Keywords: env,environment,secrets,developer-tools,cli
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Utilities
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+
20
+ # DevVault
21
+
22
+ DevVault is a lightweight local environment variable manager for developers.
23
+
24
+ It provides:
25
+
26
+ - A command-line interface
27
+ - A Python API
28
+ - A central local `.env` vault
29
+ - Masked secret listing
30
+ - Simple secret management
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install devvault
@@ -0,0 +1,8 @@
1
+ main.py,sha256=t8AK1YQAVf6myir8gzmkWnKz8a-CRUT-4YdkRdl-TGw,3879
2
+ devvault/__init__.py,sha256=MYmnNI-Nx_aM1VhsQgMV6BBwC4sRmw91bLkQxU0rieI,97
3
+ devvault/keys.py,sha256=l7PXeqcnKH--ALs-f6P74zUrxdNZlyz8BdAFjjwAV_Q,1067
4
+ devvault_xyltraz-1.0.0.dist-info/METADATA,sha256=9RFoJwTdCYyoB9I0s97P1e-LtDnAcQbXVgaeAa7rDkg,1051
5
+ devvault_xyltraz-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ devvault_xyltraz-1.0.0.dist-info/entry_points.txt,sha256=8sVoqqeWAZPjk90QTuWzmqF_9naMIctufJeb8Prdatk,39
7
+ devvault_xyltraz-1.0.0.dist-info/top_level.txt,sha256=9J64qAeOk6UHLuVF9hyGFWg1Nyamc-NnLjJivmsBlcg,14
8
+ devvault_xyltraz-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ devvault = main:main
@@ -0,0 +1,2 @@
1
+ devvault
2
+ main
main.py ADDED
@@ -0,0 +1,153 @@
1
+ import sys
2
+ from pathlib import Path
3
+
4
+ from devvault.keys import get
5
+
6
+
7
+ DEVVAULT_DIR = Path.home() / ".devvault"
8
+ ENV_FILE = DEVVAULT_DIR / ".env"
9
+
10
+
11
+ def load_keys():
12
+ """Charge toutes les clés depuis le fichier .env."""
13
+ if not ENV_FILE.exists():
14
+ return {}
15
+
16
+ keys = {}
17
+
18
+ with ENV_FILE.open("r", encoding="utf-8") as file:
19
+ for line in file:
20
+ line = line.strip()
21
+
22
+ if not line or line.startswith("#") or "=" not in line:
23
+ continue
24
+
25
+ key, value = line.split("=", 1)
26
+ keys[key.strip()] = value.strip()
27
+
28
+ return keys
29
+
30
+
31
+ def set_key(name, value):
32
+ """Ajoute ou modifie une clé."""
33
+ DEVVAULT_DIR.mkdir(parents=True, exist_ok=True)
34
+
35
+ keys = load_keys()
36
+ keys[name] = value
37
+
38
+ with ENV_FILE.open("w", encoding="utf-8") as file:
39
+ for key, value in keys.items():
40
+ file.write(f"{key}={value}\n")
41
+
42
+
43
+ def delete_key(name):
44
+ """Supprime une clé."""
45
+ keys = load_keys()
46
+
47
+ if name not in keys:
48
+ raise KeyError(f"La clé '{name}' n'existe pas.")
49
+
50
+ del keys[name]
51
+
52
+ DEVVAULT_DIR.mkdir(parents=True, exist_ok=True)
53
+
54
+ with ENV_FILE.open("w", encoding="utf-8") as file:
55
+ for key, value in keys.items():
56
+ file.write(f"{key}={value}\n")
57
+
58
+
59
+ def mask_value(value):
60
+ """Masque une valeur sensible."""
61
+ if len(value) <= 4:
62
+ return "*" * len(value)
63
+
64
+ return value[:2] + "*" * (len(value) - 4) + value[-2:]
65
+
66
+
67
+ def show_keys():
68
+ """Affiche les clés sans révéler complètement leurs valeurs."""
69
+ keys = load_keys()
70
+
71
+ if not keys:
72
+ print("Aucune clé enregistrée.")
73
+ return
74
+
75
+ print("Clés enregistrées :")
76
+ print()
77
+
78
+ for key, value in keys.items():
79
+ print(f" {key} = {mask_value(value)}")
80
+
81
+
82
+ def show_help():
83
+ print("DevVault")
84
+ print()
85
+ print("Commandes :")
86
+ print(" set <clé> <valeur> Ajouter ou modifier une clé")
87
+ print(" get <clé> Récupérer une clé")
88
+ print(" list Afficher les clés")
89
+ print(" keys Afficher les clés")
90
+ print(" delete <clé> Supprimer une clé")
91
+ print(" help Afficher cette aide")
92
+ print()
93
+ print(f"Vault : {ENV_FILE}")
94
+
95
+
96
+ def main():
97
+ if len(sys.argv) < 2:
98
+ show_help()
99
+ return
100
+
101
+ command = sys.argv[1].lower()
102
+
103
+ if command == "set":
104
+ if len(sys.argv) < 4:
105
+ print("Erreur : arguments manquants.")
106
+ print("Usage : python main.py set <clé> <valeur>")
107
+ sys.exit(1)
108
+
109
+ name = sys.argv[2]
110
+ value = sys.argv[3]
111
+
112
+ set_key(name, value)
113
+ print(f"OK : clé '{name}' enregistrée.")
114
+
115
+ elif command == "get":
116
+ if len(sys.argv) < 3:
117
+ print("Erreur : clé manquante.")
118
+ print("Usage : python main.py get <clé>")
119
+ sys.exit(1)
120
+
121
+ try:
122
+ print(get(sys.argv[2]))
123
+ except KeyError as error:
124
+ print(f"Erreur : {error}")
125
+ sys.exit(1)
126
+
127
+ elif command in ("list", "keys"):
128
+ show_keys()
129
+
130
+ elif command == "delete":
131
+ if len(sys.argv) < 3:
132
+ print("Erreur : clé manquante.")
133
+ print("Usage : python main.py delete <clé>")
134
+ sys.exit(1)
135
+
136
+ try:
137
+ delete_key(sys.argv[2])
138
+ print(f"OK : clé '{sys.argv[2]}' supprimée.")
139
+ except KeyError as error:
140
+ print(f"Erreur : {error}")
141
+ sys.exit(1)
142
+
143
+ elif command == "help":
144
+ show_help()
145
+
146
+ else:
147
+ print(f"Erreur : commande inconnue : {command}")
148
+ print("Utilise 'python main.py help' pour voir les commandes.")
149
+ sys.exit(1)
150
+
151
+
152
+ if __name__ == "__main__":
153
+ main()