feat: implement role-based configuration system for CLI with automatic API key management
- Add role detection to command groups (admin, client, miner, blockchain)
- Load role-specific config files (~/.aitbc/{role}-config.yaml)
- Add role field to Config class with environment variable support
- Implement automatic role detection from invoked subcommand
- Add development mode API key bypass for testing (APP_ENV=dev)
- Update CLI checklist with role-based configuration documentation
- Add configuration override priority and
This commit is contained in:
@@ -9,6 +9,17 @@ from typing import Optional
|
||||
|
||||
from . import __version__
|
||||
from .config import get_config
|
||||
|
||||
|
||||
def with_role(role: str):
|
||||
"""Decorator to set role for command groups"""
|
||||
def decorator(func):
|
||||
@click.pass_context
|
||||
def wrapper(ctx, *args, **kwargs):
|
||||
ctx.parent.detected_role = role
|
||||
return func(ctx, *args, **kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
from .utils import output, setup_logging
|
||||
from .commands.client import client
|
||||
from .commands.miner import miner
|
||||
@@ -107,8 +118,26 @@ def cli(ctx, url: Optional[str], api_key: Optional[str], output: str,
|
||||
# Setup logging based on verbosity
|
||||
log_level = setup_logging(verbose, debug)
|
||||
|
||||
# Load configuration
|
||||
config = get_config(config_file)
|
||||
# Detect role from command name (before config is loaded)
|
||||
role = None
|
||||
|
||||
# Check invoked_subcommand first
|
||||
if ctx.invoked_subcommand:
|
||||
if ctx.invoked_subcommand == 'client':
|
||||
role = 'client'
|
||||
elif ctx.invoked_subcommand == 'miner':
|
||||
role = 'miner'
|
||||
elif ctx.invoked_subcommand == 'blockchain':
|
||||
role = 'blockchain'
|
||||
elif ctx.invoked_subcommand == 'admin':
|
||||
role = 'admin'
|
||||
|
||||
# Also check if role was already set by command group
|
||||
if not role:
|
||||
role = getattr(ctx, 'detected_role', None)
|
||||
|
||||
# Load configuration with role
|
||||
config = get_config(config_file, role=role)
|
||||
|
||||
# Override config with command line options
|
||||
if url:
|
||||
|
||||
Reference in New Issue
Block a user