Skip to content

Commit 4ecf5c5

Browse files
authored
Merge pull request #10 from LeoTN/development
Development
2 parents 0563e4c + 0f6d892 commit 4ecf5c5

19 files changed

Lines changed: 3016 additions & 892 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/dist
2-
step_cli_tools/__pycache__
2+
__pycache__/
33
poetry.lock

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ sct
3030

3131
| Feature | Description |
3232
|---------|-------------|
33-
| 📜 **Manage Root CA Certificates** | Install & uninstall your **root CA certificate** easily |
33+
| 📜 **Manage** root CA certificates | Install & uninstall your root CA certificate easily |
34+
| 📝 **Request** certificates | Request TLS certificates from your step-ca server |
3435

3536
ℹ️ More features are planned.
3637

assets/readme.gif

1.37 MB
Loading

assets/readme.tape

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Output readme.gif
22

3+
Require powershell
34
Require sct
45

56
Set Shell powershell
@@ -13,7 +14,9 @@ Enter
1314

1415
Sleep 5s
1516

16-
# Select the first operation
17+
18+
19+
# Install root CA certificate operation
1720
Enter
1821

1922
Sleep 3s
@@ -30,7 +33,68 @@ Type@200ms y
3033

3134
Sleep 5s
3235

33-
# Select the second operation
36+
37+
38+
# Request certificate operation
39+
Down@200ms 2
40+
Sleep 3s
41+
Enter
42+
43+
Sleep 3s
44+
45+
# Enter the server name
46+
Type@200ms my-step-ca-server
47+
Sleep 1s
48+
Enter
49+
50+
Sleep 3s
51+
52+
# Change subject name
53+
Enter
54+
Sleep 3s
55+
Backspace@200ms 9
56+
Sleep 1s
57+
Type@200ms demo.com
58+
Sleep 1s
59+
Enter
60+
61+
Sleep 3s
62+
63+
# Change SAN entries
64+
Down@200ms 2
65+
Sleep 1s
66+
Enter
67+
Sleep 1s
68+
Down
69+
Sleep 1s
70+
Enter
71+
Sleep 1s
72+
Type@200ms demonstration.com
73+
Sleep 1s
74+
Enter
75+
Sleep 3s
76+
Down@200ms 2
77+
Sleep 1s
78+
Enter
79+
80+
Sleep 5s
81+
82+
# Proceed with request
83+
Down@200ms 5
84+
Sleep 1s
85+
Enter
86+
Sleep 1s
87+
Enter
88+
Sleep 1s
89+
# A published password!? :D
90+
Type oCYsOa1NMUWhrU7EZHGHLHQ4i09hAO80JfONwzTV
91+
Enter
92+
93+
Sleep 5s
94+
95+
96+
97+
# Uninstall root CA certificate operation
3498
Down
3599
Sleep 3s
36100
Enter

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ packages = [
3535
]
3636

3737
[tool.poetry.dependencies]
38-
python = ">=3.10,<4.0"
38+
# Can be unlocked once https://github.com/tmbo/questionary/issues/473 is resolved
3939
cryptography = "^46.0.3"
4040
packaging = "^25.0"
41-
questionary = "^2.1.1"
41+
python = ">=3.10,<4.0"
42+
questionary = "==2.1.1"
43+
requests = "^2.32.5"
4244
rich = "^14.2.0"
4345
ruamel-yaml = "^0.19.1"
4446

step_cli_tools/common.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
# --- Standard library imports ---
22
import logging
3-
from logging.handlers import RotatingFileHandler
4-
import os
53
import platform
4+
from logging.handlers import RotatingFileHandler
5+
from pathlib import Path
6+
from urllib.parse import urlparse
67

78
# --- Third-party imports ---
89
import questionary
910
from rich.console import Console
1011
from rich.logging import RichHandler
1112
from rich.theme import Theme
1213

13-
__all__ = [
14-
"console",
15-
"qy",
16-
"DEFAULT_QY_STYLE",
17-
"SCRIPT_HOME_DIR",
18-
"SCRIPT_LOGGING_DIR",
19-
"STEP_BIN",
20-
"logger",
21-
]
22-
23-
2414
custom_logging_theme = Theme(
2515
{
2616
"logging.level.info": "none",
@@ -42,28 +32,37 @@
4232
)
4333

4434
# --- Directories and files ---
45-
SCRIPT_HOME_DIR = os.path.expanduser("~/.step-cli-tools")
46-
SCRIPT_LOGGING_DIR = os.path.normpath(os.path.join(SCRIPT_HOME_DIR, "logs"))
35+
SCRIPT_HOME_DIR = Path.home() / ".step-cli-tools"
36+
SCRIPT_CACHE_DIR = SCRIPT_HOME_DIR / ".cache"
37+
SCRIPT_CERT_DIR = SCRIPT_HOME_DIR / "certs"
38+
SCRIPT_LOGGING_DIR = SCRIPT_HOME_DIR / "logs"
39+
40+
ALL_DIRS = [
41+
SCRIPT_HOME_DIR,
42+
SCRIPT_CACHE_DIR,
43+
SCRIPT_CERT_DIR,
44+
SCRIPT_LOGGING_DIR,
45+
]
4746

4847

49-
def _get_step_binary_path() -> str:
48+
def _get_step_binary_path() -> Path:
5049
"""
5150
Get the absolute path to the step-cli binary based on the operating system.
5251
5352
Returns:
54-
str: Absolute path to the step binary.
53+
The absolute path to the step-cli binary.
5554
"""
5655

57-
bin_dir = os.path.join(SCRIPT_HOME_DIR, "bin")
56+
bin_dir = SCRIPT_HOME_DIR / "bin"
5857
system = platform.system()
5958
if system == "Windows":
60-
binary = os.path.join(bin_dir, "step.exe")
59+
binary = bin_dir / "step.exe"
6160
elif system in ("Linux", "Darwin"):
62-
binary = os.path.join(bin_dir, "step")
61+
binary = bin_dir / "step"
6362
else:
6463
raise OSError(f"Unsupported platform: {system}")
6564

66-
return os.path.normpath(binary)
65+
return binary
6766

6867

6968
STEP_BIN = _get_step_binary_path()
@@ -73,8 +72,8 @@ def _get_step_binary_path() -> str:
7372

7473
def _setup_logger(
7574
name: str,
76-
log_file: str = "step-cli-tools.log",
77-
level=logging.DEBUG,
75+
log_file: Path = SCRIPT_LOGGING_DIR / "step-cli-tools.log",
76+
level: int = logging.DEBUG,
7877
console: Console = console,
7978
max_bytes: int = 5_000_000,
8079
backup_count: int = 5,
@@ -95,8 +94,8 @@ def _setup_logger(
9594
"""
9695

9796
# Ensure log directory exists
98-
if os.path.dirname(log_file):
99-
os.makedirs(os.path.dirname(log_file), exist_ok=True)
97+
if log_file.parent:
98+
log_file.parent.mkdir(parents=True, exist_ok=True)
10099

101100
logger = logging.getLogger(name)
102101
logger.setLevel(level)
@@ -128,5 +127,25 @@ def _setup_logger(
128127

129128
logger = _setup_logger(
130129
name="main",
131-
log_file=os.path.join(SCRIPT_LOGGING_DIR, "step-cli-tools.log"),
132130
)
131+
132+
133+
def get_masked_url_for_logging(url: str) -> str:
134+
"""
135+
Return a masked version of the URL suitable for logging.
136+
137+
Args:
138+
url: The URL to mask
139+
140+
Returns:
141+
A string containing only the scheme, hostname, and optional port
142+
"""
143+
144+
parsed_url = urlparse(url)
145+
scheme = parsed_url.scheme or "unknown"
146+
hostname = parsed_url.hostname or "unknown"
147+
port = parsed_url.port
148+
149+
if port:
150+
return f"{scheme}://{hostname}:{port}"
151+
return f"{scheme}://{hostname}"

0 commit comments

Comments
 (0)