Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/dist
step_cli_tools/__pycache__
__pycache__/
poetry.lock
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ sct

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

ℹ️ More features are planned.

Expand Down
Binary file modified assets/readme.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 66 additions & 2 deletions assets/readme.tape
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Output readme.gif

Require powershell
Require sct

Set Shell powershell
Expand All @@ -13,7 +14,9 @@ Enter

Sleep 5s

# Select the first operation


# Install root CA certificate operation
Enter

Sleep 3s
Expand All @@ -30,7 +33,68 @@ Type@200ms y

Sleep 5s

# Select the second operation


# Request certificate operation
Down@200ms 2
Sleep 3s
Enter

Sleep 3s

# Enter the server name
Type@200ms my-step-ca-server
Sleep 1s
Enter

Sleep 3s

# Change subject name
Enter
Sleep 3s
Backspace@200ms 9
Sleep 1s
Type@200ms demo.com
Sleep 1s
Enter

Sleep 3s

# Change SAN entries
Down@200ms 2
Sleep 1s
Enter
Sleep 1s
Down
Sleep 1s
Enter
Sleep 1s
Type@200ms demonstration.com
Sleep 1s
Enter
Sleep 3s
Down@200ms 2
Sleep 1s
Enter

Sleep 5s

# Proceed with request
Down@200ms 5
Sleep 1s
Enter
Sleep 1s
Enter
Sleep 1s
# A published password!? :D
Type oCYsOa1NMUWhrU7EZHGHLHQ4i09hAO80JfONwzTV
Enter

Sleep 5s



# Uninstall root CA certificate operation
Down
Sleep 3s
Enter
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ packages = [
]

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

Expand Down
71 changes: 45 additions & 26 deletions step_cli_tools/common.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
# --- Standard library imports ---
import logging
from logging.handlers import RotatingFileHandler
import os
import platform
from logging.handlers import RotatingFileHandler
from pathlib import Path
from urllib.parse import urlparse

# --- Third-party imports ---
import questionary
from rich.console import Console
from rich.logging import RichHandler
from rich.theme import Theme

__all__ = [
"console",
"qy",
"DEFAULT_QY_STYLE",
"SCRIPT_HOME_DIR",
"SCRIPT_LOGGING_DIR",
"STEP_BIN",
"logger",
]


custom_logging_theme = Theme(
{
"logging.level.info": "none",
Expand All @@ -42,28 +32,37 @@
)

# --- Directories and files ---
SCRIPT_HOME_DIR = os.path.expanduser("~/.step-cli-tools")
SCRIPT_LOGGING_DIR = os.path.normpath(os.path.join(SCRIPT_HOME_DIR, "logs"))
SCRIPT_HOME_DIR = Path.home() / ".step-cli-tools"
SCRIPT_CACHE_DIR = SCRIPT_HOME_DIR / ".cache"
SCRIPT_CERT_DIR = SCRIPT_HOME_DIR / "certs"
SCRIPT_LOGGING_DIR = SCRIPT_HOME_DIR / "logs"

ALL_DIRS = [
SCRIPT_HOME_DIR,
SCRIPT_CACHE_DIR,
SCRIPT_CERT_DIR,
SCRIPT_LOGGING_DIR,
]


def _get_step_binary_path() -> str:
def _get_step_binary_path() -> Path:
"""
Get the absolute path to the step-cli binary based on the operating system.

Returns:
str: Absolute path to the step binary.
The absolute path to the step-cli binary.
"""

bin_dir = os.path.join(SCRIPT_HOME_DIR, "bin")
bin_dir = SCRIPT_HOME_DIR / "bin"
system = platform.system()
if system == "Windows":
binary = os.path.join(bin_dir, "step.exe")
binary = bin_dir / "step.exe"
elif system in ("Linux", "Darwin"):
binary = os.path.join(bin_dir, "step")
binary = bin_dir / "step"
else:
raise OSError(f"Unsupported platform: {system}")

return os.path.normpath(binary)
return binary


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

def _setup_logger(
name: str,
log_file: str = "step-cli-tools.log",
level=logging.DEBUG,
log_file: Path = SCRIPT_LOGGING_DIR / "step-cli-tools.log",
level: int = logging.DEBUG,
console: Console = console,
max_bytes: int = 5_000_000,
backup_count: int = 5,
Expand All @@ -95,8 +94,8 @@ def _setup_logger(
"""

# Ensure log directory exists
if os.path.dirname(log_file):
os.makedirs(os.path.dirname(log_file), exist_ok=True)
if log_file.parent:
log_file.parent.mkdir(parents=True, exist_ok=True)

logger = logging.getLogger(name)
logger.setLevel(level)
Expand Down Expand Up @@ -128,5 +127,25 @@ def _setup_logger(

logger = _setup_logger(
name="main",
log_file=os.path.join(SCRIPT_LOGGING_DIR, "step-cli-tools.log"),
)


def get_masked_url_for_logging(url: str) -> str:
"""
Return a masked version of the URL suitable for logging.

Args:
url: The URL to mask

Returns:
A string containing only the scheme, hostname, and optional port
"""

parsed_url = urlparse(url)
scheme = parsed_url.scheme or "unknown"
hostname = parsed_url.hostname or "unknown"
port = parsed_url.port

if port:
return f"{scheme}://{hostname}:{port}"
return f"{scheme}://{hostname}"
Loading