hashenv 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hashenv-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: hashenv
3
+ Version: 0.1.0
4
+ Summary: CLI tool for managing environment tokens and syncing repository env files
5
+ Author-email: Chestor <your.email@example.com>
6
+ License-Expression: MIT
7
+ Keywords: cli,environment,dotenv,security
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: typer>=0.12.0
11
+ Requires-Dist: requests>=2.31.0
12
+ Requires-Dist: rich>=13.0.0
13
+ Requires-Dist: pydantic>=2.7.0
14
+ Requires-Dist: pydantic-settings>=2.0.0
15
+ Requires-Dist: python-dotenv>=1.0.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
18
+ Requires-Dist: build>=1.0.0; extra == "dev"
19
+
20
+ ## Hashenv
21
+
22
+ CLI tool for populating envs in secure systems. Built for security and speed.
23
+
24
+ ## Local Setup
25
+
26
+ ### Prerequisites
27
+
28
+ - Python 3.8 or newer
29
+ - Git (optional if you already have the repository locally)
30
+
31
+ ### Install dependencies and package
32
+
33
+ 1. Open a terminal in the repository root:
34
+
35
+ ```powershell
36
+ cd C:\Users\chestor\Documents\GitHub\hashenv
37
+ ```
38
+
39
+ 2. Create and activate a virtual environment:
40
+
41
+ ```terminal
42
+ python -m venv venv
43
+ venv/Scripts/Activate
44
+ ```
45
+
46
+ 3. Upgrade `pip` and install project dependencies:
47
+
48
+ ```powershell
49
+ python -m pip install --upgrade pip
50
+ python -m pip install -r requirements.txt
51
+ ```
52
+
53
+ 4. Install the package in editable mode:
54
+
55
+ ```powershell
56
+ python -m pip install -e .
57
+ ```
58
+
59
+ ### Verify installation
60
+
61
+ Run the built CLI help to confirm the command is available:
62
+
63
+ ```powershell
64
+ hashenv --help
65
+ ```
66
+
67
+ ## Usage Examples
68
+
69
+ - Print a quick hello message:
70
+
71
+ ```powershell
72
+ hashenv hello
73
+ ```
74
+
75
+ - Verify the CLI is working:
76
+
77
+ ```powershell
78
+ hashenv ping
79
+ ```
80
+
81
+ - Log in with a token (writes `.env` in the repository root):
82
+
83
+ ```powershell
84
+ hashenv login <token>
85
+ ```
86
+
87
+ - Show repository data using the `--all` option:
88
+
89
+ ```powershell
90
+ hashenv show-repository --all
91
+ ```
92
+
93
+ - Run environment installation logic:
94
+
95
+ ```powershell
96
+ hashenv install
97
+ ```
98
+
99
+ ## Project Structure
100
+
101
+ - `pyproject.toml` - package metadata and dependencies
102
+ - `requirements.txt` - development/runtime dependency list
103
+ - `src/hashenv/cli.py` - CLI entry point and commands
104
+ - `src/helpers/` - helper modules used by the CLI
105
+
106
+ ## Architecture for Hashenv including integration with data server
107
+
108
+ <img width="671" height="681" alt="hashenv-final-overview drawio" src="https://github.com/user-attachments/assets/baa96c15-eb2e-43b2-8ef4-f12ef6e2a4cb" />
109
+
@@ -0,0 +1,90 @@
1
+ ## Hashenv
2
+
3
+ CLI tool for populating envs in secure systems. Built for security and speed.
4
+
5
+ ## Local Setup
6
+
7
+ ### Prerequisites
8
+
9
+ - Python 3.8 or newer
10
+ - Git (optional if you already have the repository locally)
11
+
12
+ ### Install dependencies and package
13
+
14
+ 1. Open a terminal in the repository root:
15
+
16
+ ```powershell
17
+ cd C:\Users\chestor\Documents\GitHub\hashenv
18
+ ```
19
+
20
+ 2. Create and activate a virtual environment:
21
+
22
+ ```terminal
23
+ python -m venv venv
24
+ venv/Scripts/Activate
25
+ ```
26
+
27
+ 3. Upgrade `pip` and install project dependencies:
28
+
29
+ ```powershell
30
+ python -m pip install --upgrade pip
31
+ python -m pip install -r requirements.txt
32
+ ```
33
+
34
+ 4. Install the package in editable mode:
35
+
36
+ ```powershell
37
+ python -m pip install -e .
38
+ ```
39
+
40
+ ### Verify installation
41
+
42
+ Run the built CLI help to confirm the command is available:
43
+
44
+ ```powershell
45
+ hashenv --help
46
+ ```
47
+
48
+ ## Usage Examples
49
+
50
+ - Print a quick hello message:
51
+
52
+ ```powershell
53
+ hashenv hello
54
+ ```
55
+
56
+ - Verify the CLI is working:
57
+
58
+ ```powershell
59
+ hashenv ping
60
+ ```
61
+
62
+ - Log in with a token (writes `.env` in the repository root):
63
+
64
+ ```powershell
65
+ hashenv login <token>
66
+ ```
67
+
68
+ - Show repository data using the `--all` option:
69
+
70
+ ```powershell
71
+ hashenv show-repository --all
72
+ ```
73
+
74
+ - Run environment installation logic:
75
+
76
+ ```powershell
77
+ hashenv install
78
+ ```
79
+
80
+ ## Project Structure
81
+
82
+ - `pyproject.toml` - package metadata and dependencies
83
+ - `requirements.txt` - development/runtime dependency list
84
+ - `src/hashenv/cli.py` - CLI entry point and commands
85
+ - `src/helpers/` - helper modules used by the CLI
86
+
87
+ ## Architecture for Hashenv including integration with data server
88
+
89
+ <img width="671" height="681" alt="hashenv-final-overview drawio" src="https://github.com/user-attachments/assets/baa96c15-eb2e-43b2-8ef4-f12ef6e2a4cb" />
90
+
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "hashenv"
3
+ version = "0.1.0"
4
+ description = "CLI tool for managing environment tokens and syncing repository env files"
5
+ readme = "README.md"
6
+ requires-python = ">=3.9"
7
+ license = "MIT"
8
+ authors = [
9
+ { name = "Chestor", email = "your.email@example.com" }
10
+ ]
11
+ keywords = ["cli", "environment", "dotenv", "security"]
12
+ dependencies = [
13
+ "typer>=0.12.0",
14
+ "requests>=2.31.0",
15
+ "rich>=13.0.0",
16
+ "pydantic>=2.7.0",
17
+ "pydantic-settings>=2.0.0",
18
+ "python-dotenv>=1.0.0",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ dev = [
23
+ "pytest>=8.0.0",
24
+ "build>=1.0.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ hashenv = "hashenv.cli:app"
29
+
30
+ [build-system]
31
+ requires = ["setuptools>=68.0"]
32
+ build-backend = "setuptools.build_meta"
33
+
34
+ [tool.setuptools]
35
+ package-dir = {"" = "src"}
36
+
37
+ [tool.setuptools.packages.find]
38
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ from pathlib import Path
2
+ from pydantic_settings import BaseSettings, SettingsConfigDict
3
+
4
+ BASE_DIR = Path(__file__).resolve().parent.parent.parent
5
+
6
+
7
+ class Settings(BaseSettings):
8
+
9
+ SERVER_URL: str = "https://resign-model-server.onrender.com"
10
+ LOCAL_SERVER_URL: str = "http://localhost:3000"
11
+ DEBUG: bool = False
12
+
13
+ model_config = SettingsConfigDict(
14
+ env_file=BASE_DIR / ".env",
15
+ extra="ignore",
16
+ )
17
+
18
+ settings = Settings()
File without changes
@@ -0,0 +1,55 @@
1
+ import typer
2
+
3
+ from services.repository_processing_and_query_service import process_repository_service
4
+ from helpers.get_repo_list import get_repo_list
5
+ from helpers.env_recieve import env_recieve
6
+ from helpers.ping_backend_server import ping_backend_server
7
+ from helpers.get_env_from_backend import get_env_from_backend
8
+ app = typer.Typer()
9
+
10
+
11
+
12
+ @app.command()
13
+ def login(token: str):
14
+ with open(".env", "w") as f:
15
+ f.write(token)
16
+ print('Logged in!')
17
+
18
+ @app.command()
19
+ def ping():
20
+ print('status: working!')
21
+
22
+
23
+ @app.command()
24
+ def show_repository(all: bool = typer.Option(False, "--all"), r: bool = typer.Option(False, "--r")):
25
+ if all:
26
+ res = get_repo_list()
27
+ print(res)
28
+ elif r:
29
+ print('Showing repository for --r flag')
30
+ else:
31
+ print('Nothing passed as parameter, returning nothing')
32
+
33
+ @app.command()
34
+ def install(r: bool = typer.Option(False, "--r")):
35
+ if r:
36
+ try:
37
+ process_repository_service()
38
+ except Exception.__traceback__ as e:
39
+ print(f"An error occurred: {e}")
40
+ else:
41
+ env_recieve("org-unique")
42
+
43
+
44
+ #test commands can and will usually go here
45
+ @app.command()
46
+ def ping_server():
47
+ ping_backend_server()
48
+ env_data = get_env_from_backend('backend-api')
49
+ print(env_data)
50
+
51
+
52
+
53
+ if __name__ == "__main__":
54
+ app()
55
+
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: hashenv
3
+ Version: 0.1.0
4
+ Summary: CLI tool for managing environment tokens and syncing repository env files
5
+ Author-email: Chestor <your.email@example.com>
6
+ License-Expression: MIT
7
+ Keywords: cli,environment,dotenv,security
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: typer>=0.12.0
11
+ Requires-Dist: requests>=2.31.0
12
+ Requires-Dist: rich>=13.0.0
13
+ Requires-Dist: pydantic>=2.7.0
14
+ Requires-Dist: pydantic-settings>=2.0.0
15
+ Requires-Dist: python-dotenv>=1.0.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
18
+ Requires-Dist: build>=1.0.0; extra == "dev"
19
+
20
+ ## Hashenv
21
+
22
+ CLI tool for populating envs in secure systems. Built for security and speed.
23
+
24
+ ## Local Setup
25
+
26
+ ### Prerequisites
27
+
28
+ - Python 3.8 or newer
29
+ - Git (optional if you already have the repository locally)
30
+
31
+ ### Install dependencies and package
32
+
33
+ 1. Open a terminal in the repository root:
34
+
35
+ ```powershell
36
+ cd C:\Users\chestor\Documents\GitHub\hashenv
37
+ ```
38
+
39
+ 2. Create and activate a virtual environment:
40
+
41
+ ```terminal
42
+ python -m venv venv
43
+ venv/Scripts/Activate
44
+ ```
45
+
46
+ 3. Upgrade `pip` and install project dependencies:
47
+
48
+ ```powershell
49
+ python -m pip install --upgrade pip
50
+ python -m pip install -r requirements.txt
51
+ ```
52
+
53
+ 4. Install the package in editable mode:
54
+
55
+ ```powershell
56
+ python -m pip install -e .
57
+ ```
58
+
59
+ ### Verify installation
60
+
61
+ Run the built CLI help to confirm the command is available:
62
+
63
+ ```powershell
64
+ hashenv --help
65
+ ```
66
+
67
+ ## Usage Examples
68
+
69
+ - Print a quick hello message:
70
+
71
+ ```powershell
72
+ hashenv hello
73
+ ```
74
+
75
+ - Verify the CLI is working:
76
+
77
+ ```powershell
78
+ hashenv ping
79
+ ```
80
+
81
+ - Log in with a token (writes `.env` in the repository root):
82
+
83
+ ```powershell
84
+ hashenv login <token>
85
+ ```
86
+
87
+ - Show repository data using the `--all` option:
88
+
89
+ ```powershell
90
+ hashenv show-repository --all
91
+ ```
92
+
93
+ - Run environment installation logic:
94
+
95
+ ```powershell
96
+ hashenv install
97
+ ```
98
+
99
+ ## Project Structure
100
+
101
+ - `pyproject.toml` - package metadata and dependencies
102
+ - `requirements.txt` - development/runtime dependency list
103
+ - `src/hashenv/cli.py` - CLI entry point and commands
104
+ - `src/helpers/` - helper modules used by the CLI
105
+
106
+ ## Architecture for Hashenv including integration with data server
107
+
108
+ <img width="671" height="681" alt="hashenv-final-overview drawio" src="https://github.com/user-attachments/assets/baa96c15-eb2e-43b2-8ef4-f12ef6e2a4cb" />
109
+
@@ -0,0 +1,24 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/core/config.py
4
+ src/hashenv/__init__.py
5
+ src/hashenv/cli.py
6
+ src/hashenv.egg-info/PKG-INFO
7
+ src/hashenv.egg-info/SOURCES.txt
8
+ src/hashenv.egg-info/dependency_links.txt
9
+ src/hashenv.egg-info/entry_points.txt
10
+ src/hashenv.egg-info/requires.txt
11
+ src/hashenv.egg-info/top_level.txt
12
+ src/helpers/env_recieve.py
13
+ src/helpers/get_env_from_backend.py
14
+ src/helpers/get_repo_details_from_git.py
15
+ src/helpers/get_repo_list.py
16
+ src/helpers/ping_backend_server.py
17
+ src/helpers/push_env_to_backend.py
18
+ src/helpers/repo_searcher.py
19
+ src/helpers/environment_processors/get_env_variables_from_local.py
20
+ src/helpers/environment_processors/ping_db_for_repository_check.py
21
+ src/helpers/local_env_parsing_helpers/check_local_env_for_content.py
22
+ src/services/env_parsing_service.py
23
+ src/services/local_environment_parsing_and_write_service.py
24
+ src/services/repository_processing_and_query_service.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ hashenv = hashenv.cli:app
@@ -0,0 +1,10 @@
1
+ typer>=0.12.0
2
+ requests>=2.31.0
3
+ rich>=13.0.0
4
+ pydantic>=2.7.0
5
+ pydantic-settings>=2.0.0
6
+ python-dotenv>=1.0.0
7
+
8
+ [dev]
9
+ pytest>=8.0.0
10
+ build>=1.0.0
@@ -0,0 +1,4 @@
1
+ core
2
+ hashenv
3
+ helpers
4
+ services
@@ -0,0 +1,10 @@
1
+ #recieves env from endpoint. This function has already recieved what repository to target and what env file it needs to fetch
2
+ from core.config import settings
3
+
4
+ def env_recieve(env_data: dict):
5
+
6
+ with open(".env", "w") as f:
7
+ for key, value in env_data.items():
8
+ f.write(f'{key}="{value}"\n')
9
+
10
+
@@ -0,0 +1,7 @@
1
+ from pathlib import Path
2
+ from dotenv import dotenv_values
3
+
4
+ def get_env_variables_from_local():
5
+ env_path = Path.cwd() / ".env"
6
+ env_data = dotenv_values(env_path)
7
+ return env_data
@@ -0,0 +1,10 @@
1
+ import requests
2
+ from core.config import settings
3
+
4
+ LOCAL_SERVER_URL = settings.LOCAL_SERVER_URL
5
+ SERVER_URL = settings.SERVER_URL
6
+
7
+ def ping_db_for_repository_check(repository: str):
8
+ response = requests.get(f"{SERVER_URL}/env/{repository}")
9
+ if response.status_code == 200:
10
+ return False if len(response.json()) == 0 else True
@@ -0,0 +1,11 @@
1
+ import requests
2
+ from core.config import settings
3
+
4
+ SERVER_URL = settings.SERVER_URL
5
+
6
+ def get_env_from_backend(repository: str):
7
+ response = requests.get(f"{SERVER_URL}/env/{repository}")
8
+ env_data = None
9
+ if response.status_code == 200:
10
+ env_data = response.json()
11
+ return None if len(env_data) == 0 else env_data
@@ -0,0 +1,15 @@
1
+ import subprocess
2
+
3
+
4
+ def get_repo_details_from_git():
5
+ try:
6
+ url = subprocess.check_output(
7
+ ["git", "remote", "get-url", "origin"],
8
+ text=True
9
+ ).strip()
10
+ DATABASE_KEY = url.split("/")[-1].replace(".git", "")
11
+ return DATABASE_KEY
12
+ except subprocess.CalledProcessError:
13
+ print('This repository is not connected to a remote origin. Please connect it to a ' \
14
+ 'remote repository and try again.')
15
+ return None
@@ -0,0 +1,8 @@
1
+ from .repo_searcher import repo_searcher
2
+
3
+
4
+ def get_repo_list():
5
+ repo_list = repo_searcher()
6
+ return repo_list
7
+
8
+
@@ -0,0 +1,7 @@
1
+ from pathlib import Path
2
+ from dotenv import dotenv_values
3
+
4
+ def check_local_env_for_content():
5
+ env_data = dotenv_values(Path(__file__).resolve().parent.parent.parent.parent / ".env")
6
+
7
+ return bool(env_data)
@@ -0,0 +1,16 @@
1
+ import requests
2
+ from core.config import settings
3
+
4
+ SERVER_URL = settings.SERVER_URL
5
+
6
+ def ping_backend_server():
7
+ try:
8
+ response = requests.get(f"{SERVER_URL}/health")
9
+ if response.status_code == 200:
10
+ print('Server is healthy!')
11
+ else:
12
+ print(f'Server responded with status code: {response.status_code}')
13
+ except requests.exceptions.RequestException as e:
14
+ print(f'Error connecting to server: {e}')
15
+
16
+
@@ -0,0 +1,13 @@
1
+ import requests
2
+ from core.config import settings
3
+
4
+ SERVER_URL = settings.SERVER_URL
5
+ LOCAL_SERVER_URL = settings.LOCAL_SERVER_URL
6
+
7
+ def push_env_to_backend(repository: str, payload: dict):
8
+ response = requests.post(f"{SERVER_URL}/env-recieve", json = {"repository_name": repository, "envs": payload})
9
+ if response.status_code == 200:
10
+ print("Environment variables successfully pushed to the backend")
11
+ else:
12
+ print("Failed to push environment variables to backend with status code: ", response.status_code)
13
+ print(response.text)
@@ -0,0 +1,11 @@
1
+ import os
2
+
3
+ def repo_searcher():
4
+ repos = []
5
+
6
+ for root, dirs, files in os.walk("/Users/chestor"):
7
+ if ".git" in dirs:
8
+ repos.append(root)
9
+ dirs.remove(".git")
10
+ return repos
11
+
@@ -0,0 +1,30 @@
1
+ from typing import Dict
2
+ from services.local_environment_parsing_and_write_service import local_env_parsing_and_write_service
3
+
4
+
5
+ def env_parsing_service(local_env_data: Dict[str, str], recieved_env_data: Dict[str, str]):
6
+ differ = False
7
+ if len(local_env_data) != 0:
8
+ for key, value in recieved_env_data.items():
9
+ if key not in local_env_data or local_env_data[key] != value:
10
+ differ = True
11
+
12
+ if differ:
13
+ print('The environment variables in the backend differ from you local .env file.')
14
+ print('Would you like to update your local .env file with the backend environment variables? (y/n)')
15
+ choice = input().lower()
16
+ if choice == 'y':
17
+ local_env_parsing_and_write_service(env_data=recieved_env_data)
18
+ else:
19
+ print('Keeping local .env file unchanged.')
20
+ elif len(local_env_data) == 0:
21
+ print('A local .env file does not exist in this repository but a remote env has been found. Do you wish to populate this repo with it? (y/n)')
22
+ choice = input().lower()
23
+ if choice == 'y':
24
+ local_env_parsing_and_write_service(env_data=recieved_env_data)
25
+ else:
26
+ print('Making no changes.')
27
+
28
+ else:
29
+ print('The environment variables in the backend are the same as your local .env file. No changes needed.')
30
+
@@ -0,0 +1,22 @@
1
+ from helpers.local_env_parsing_helpers.check_local_env_for_content import check_local_env_for_content
2
+ from helpers.env_recieve import env_recieve
3
+
4
+ def local_env_parsing_and_write_service(env_data: dict):
5
+ local_env_has_content = check_local_env_for_content()
6
+ if local_env_has_content:
7
+ print("Local .env file has content, do you wish to overwrite this content? (y/n)")
8
+ choice = input().lower()
9
+ if choice == 'y':
10
+ print("Overwriting local .env file with environment variables from backend...")
11
+ env_recieve(env_data=env_data)
12
+ print("local .env file has been updated with environment variables from backend.")
13
+ else:
14
+ print("Keeping existing local .env file content. No changes made.")
15
+ else:
16
+ print("Writing environment variables from backend... ")
17
+ env_recieve(env_data=env_data)
18
+
19
+ print("env populated!")
20
+
21
+
22
+
@@ -0,0 +1,38 @@
1
+ from helpers.get_repo_details_from_git import get_repo_details_from_git
2
+ from helpers.get_env_from_backend import get_env_from_backend
3
+ from helpers.env_recieve import env_recieve
4
+ from helpers.push_env_to_backend import push_env_to_backend
5
+ from helpers.environment_processors.get_env_variables_from_local import get_env_variables_from_local
6
+ from helpers.environment_processors.ping_db_for_repository_check import ping_db_for_repository_check
7
+ from services.env_parsing_service import env_parsing_service
8
+
9
+ #This service handles the processing of git environment, processing current repository details and querying the backend for
10
+ #for details about current repository. If it doesn't find details, it will ask the user to create a new
11
+ #new .env file and the cli will provide the option to add the current repository to the db
12
+
13
+ def process_repository_service():
14
+ DATABASE_KEY = get_repo_details_from_git()
15
+ if DATABASE_KEY is not None:
16
+ repository_exists = ping_db_for_repository_check(DATABASE_KEY)
17
+ if repository_exists:
18
+ print('Repository found in backend, receiving environment variables...')
19
+ env_data = get_env_from_backend(DATABASE_KEY)
20
+ env_parsing_service(get_env_variables_from_local(), env_data)
21
+
22
+
23
+
24
+ else:
25
+ print('This repository is not registered in the backend.')
26
+ print('Would you like to add it? (y/n)')
27
+ choice = input().lower()
28
+ if choice == 'y':
29
+ local_env_data = get_env_variables_from_local()
30
+ push_env_to_backend(repository=DATABASE_KEY, payload=local_env_data)
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+