Principle:AI Northstar Tech Vector io Interactive Credential Collection
| Knowledge Sources | |
|---|---|
| Domains | CLI, Security, User_Interaction |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
A user interaction pattern for collecting sensitive configuration values from multiple sources with a priority chain: existing values, environment variables, and interactive prompts with hidden input for secrets.
Description
Interactive Credential Collection provides a layered approach to gathering CLI arguments and credentials. Rather than requiring all values on the command line (which exposes secrets in shell history) or hardcoding them, the pattern checks a priority chain:
- Existing value: If the argument is already set (e.g. via CLI flag), skip prompting.
- Environment variable: Check a named env var (e.g. PINECONE_API_KEY).
- Interactive prompt: Prompt the user via input() for general values or getpass() for passwords (hidden input).
This solves the problem of securely collecting database credentials in CLI tools. By defaulting to environment variables for CI/CD pipelines and falling back to interactive prompts for ad-hoc usage, the pattern supports both automated and interactive workflows without compromising security.
Additional features include type coercion (converting string input to int, etc.), default values (used when the user enters empty input), and choice validation (restricting input to a predefined set).
Usage
Use this principle when designing CLI tools that need to collect credentials or configuration from users. It is suited for:
- Tools that connect to external services requiring API keys or passwords
- Tools used both interactively (ad-hoc) and non-interactively (CI/CD via env vars)
- Tools where not all arguments can be known at CLI construction time
Theoretical Basis
The priority chain for credential resolution:
# Abstract algorithm (NOT real implementation)
def collect_arg(args, arg_name, env_var, prompt, is_secret=False):
# 1. Already set? Skip.
if arg_name in args and args[arg_name] is not None:
return
# 2. Environment variable?
if env_var and os.getenv(env_var) is not None:
args[arg_name] = os.getenv(env_var)
return
# 3. Interactive prompt
if is_secret:
args[arg_name] = getpass(prompt) # Hidden input
else:
args[arg_name] = input(prompt) # Visible input