harbor_cli.config
Attributes
DEFAULT_CONFIG_FILE = CONFIG_DIR / 'config.toml'
module-attribute
DEFAULT_HISTORY_FILE = DATA_DIR / 'history'
module-attribute
ENV_VAR_PREFIX = 'HARBOR_CLI_'
module-attribute
Classes
EnvVar
Bases: StrEnum
Source code in harbor_cli/config.py
Attributes
CONFIG = env_var('config')
class-attribute
instance-attribute
URL = env_var('url')
class-attribute
instance-attribute
USERNAME = env_var('username')
class-attribute
instance-attribute
SECRET = env_var('secret')
class-attribute
instance-attribute
BASICAUTH = env_var('basicauth')
class-attribute
instance-attribute
CREDENTIALS_FILE = env_var('credentials_file')
class-attribute
instance-attribute
HARBOR_VALIDATE_DATA = env_var('harbor_validate_data')
class-attribute
instance-attribute
HARBOR_RAW_MODE = env_var('harbor_raw_mode')
class-attribute
instance-attribute
HARBOR_VERIFY_SSL = env_var('harbor_verify_ssl')
class-attribute
instance-attribute
HARBOR_RETRY_ENABLED = env_var('harbor_retry_enabled')
class-attribute
instance-attribute
HARBOR_RETRY_MAX_TRIES = env_var('harbor_retry_max_tries')
class-attribute
instance-attribute
HARBOR_RETRY_MAX_TIME = env_var('harbor_retry_max_time')
class-attribute
instance-attribute
TABLE_DESCRIPTION = env_var('table_description')
class-attribute
instance-attribute
TABLE_MAX_DEPTH = env_var('table_max_depth')
class-attribute
instance-attribute
TABLE_COMPACT = env_var('table_compact')
class-attribute
instance-attribute
JSON_INDENT = env_var('json_indent')
class-attribute
instance-attribute
JSON_SORT_KEYS = env_var('json_sort_keys')
class-attribute
instance-attribute
OUTPUT_FORMAT = env_var('output_format')
class-attribute
instance-attribute
PAGING = env_var('paging')
class-attribute
instance-attribute
PAGER = env_var('pager')
class-attribute
instance-attribute
CONFIRM_DELETION = env_var('confirm_deletion')
class-attribute
instance-attribute
CONFIRM_ENUMERATION = env_var('confirm_enumeration')
class-attribute
instance-attribute
WARNINGS = env_var('warnings')
class-attribute
instance-attribute
Functions
BaseModel
Bases: BaseModel
Base model shared by all config models.
Source code in harbor_cli/config.py
Attributes
model_config = ConfigDict(extra='allow', validate_assignment=True)
class-attribute
instance-attribute
HarborCredentialsKwargs
Bases: TypedDict
Source code in harbor_cli/config.py
Attributes
url: str
instance-attribute
username: str
instance-attribute
secret: str
instance-attribute
basicauth: str
instance-attribute
credentials_file: Optional[Path]
instance-attribute
RetrySettings
Bases: BaseModel
Retry settings for API requests.
Source code in harbor_cli/config.py
Attributes
enabled: bool = True
class-attribute
instance-attribute
max_tries: int = 5
class-attribute
instance-attribute
max_time: float = 10.0
class-attribute
instance-attribute
HarborSettings
Bases: BaseModel
Source code in harbor_cli/config.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
Attributes
url: str = ''
class-attribute
instance-attribute
username: str = ''
class-attribute
instance-attribute
secret: SecretStr = SecretStr('')
class-attribute
instance-attribute
basicauth: SecretStr = SecretStr('')
class-attribute
instance-attribute
credentials_file: Optional[Path] = None
class-attribute
instance-attribute
validate_data: bool = Field(default=True, alias='validate')
class-attribute
instance-attribute
raw_mode: bool = False
class-attribute
instance-attribute
verify_ssl: bool = True
class-attribute
instance-attribute
retry: RetrySettings = RetrySettings()
class-attribute
instance-attribute
keyring: bool = False
class-attribute
instance-attribute
secret_value: str
property
Returns the secret value from the keyring if enabled, otherwise returns the secret value from the config file.
has_auth_method: bool
property
Returns True if any of the auth methods are set.
credentials: HarborCredentialsKwargs
property
Fetches kwargs that can be passed to HarborAsyncClient for user authentication.
Returns:
Type | Description |
---|---|
HarborCredentialsKwargs
|
A dictionary with either base64 credentials, username and password or a path to a credentials file. |
Functions
ensure_authable() -> bool
Ensures that the credentials are sufficient to authenticate with the Habror API. Raises CredentialsError if not.
Source code in harbor_cli/config.py
clear_credentials() -> None
Clears the credentials from the current configuration.
Source code in harbor_cli/config.py
set_username_secret(current_username: str, current_secret: str) -> None
Source code in harbor_cli/config.py
LoggingSettings
Bases: BaseModel
Source code in harbor_cli/config.py
Attributes
enabled: bool = True
class-attribute
instance-attribute
level: LogLevel = LogLevel.WARNING
class-attribute
instance-attribute
directory: Path = LOGS_DIR
class-attribute
instance-attribute
filename: str = 'harbor-cli.log'
class-attribute
instance-attribute
datetime_format: str = Field(default='%Y-%m-%d', validation_alias=AliasChoices('datetime_format', 'timeformat'))
class-attribute
instance-attribute
retention: int = 30
class-attribute
instance-attribute
path: Path
property
Full time-formatted path to log file.
TableStyleSettings
Bases: BaseModel
Source code in harbor_cli/config.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
Attributes
title: Optional[str] = None
class-attribute
instance-attribute
header: Optional[str] = STYLE_TABLE_HEADER
class-attribute
instance-attribute
rows: Optional[Tuple[str, str]] = None
class-attribute
instance-attribute
border: Optional[str] = None
class-attribute
instance-attribute
footer: Optional[str] = None
class-attribute
instance-attribute
caption: Optional[str] = None
class-attribute
instance-attribute
expand: bool = True
class-attribute
instance-attribute
show_header: bool = True
class-attribute
instance-attribute
bool_emoji: bool = False
class-attribute
instance-attribute
Functions
as_rich_kwargs() -> RichTableKwargs
Converts the TableStyleSettings to a dictionary that can be passed to Rich's Table constructor.
Returns:
Type | Description |
---|---|
RichTableKwargs
|
A dictionary of Rich Table style settings. |
Source code in harbor_cli/config.py
TableSettings
Bases: BaseModel
Settings for the table output format.
Source code in harbor_cli/config.py
Attributes
description: bool = False
class-attribute
instance-attribute
max_depth: int = 0
class-attribute
instance-attribute
compact: bool = True
class-attribute
instance-attribute
style: TableStyleSettings = TableStyleSettings()
class-attribute
instance-attribute
Functions
check_max_depth(v: Any) -> Any
classmethod
Converts max_depth to an integer, and checks that it is not negative.
Source code in harbor_cli/config.py
JSONSettings
OutputSettings
Bases: BaseModel
Source code in harbor_cli/config.py
Attributes
format: OutputFormat = OutputFormat.TABLE
class-attribute
instance-attribute
paging: bool = Field(default=False, description='Show output in pager (if supported). Default pager does not support color output currently.')
class-attribute
instance-attribute
pager: str = Field(default='', description='Pager to use if paging is enabled.')
class-attribute
instance-attribute
table: TableSettings = Field(default_factory=TableSettings)
class-attribute
instance-attribute
JSON: JSONSettings = Field(default_factory=JSONSettings, alias='json')
class-attribute
instance-attribute
model_config = ConfigDict(populate_by_name=True)
class-attribute
instance-attribute
Functions
set_pager(v: Optional[str]) -> Optional[str]
classmethod
Validator that sets the MANPAGER environment variable if a pager is set. https://rich.readthedocs.io/en/stable/console.html#paging
Source code in harbor_cli/config.py
GeneralSettings
Bases: BaseModel
General settings for Harbor CLI.
Source code in harbor_cli/config.py
Attributes
confirm_deletion: bool = Field(default=True, description='Show confirmation prompt for resource deletion commands. E.g. `project delete`')
class-attribute
instance-attribute
confirm_enumeration: bool = Field(default=True, description='Show confirmation prompt for certain resource enumeration commands when invoked without a limit or filter. E.g. `auditlog list`')
class-attribute
instance-attribute
warnings: bool = Field(default=True, description='Show warning messages in terminal. Warnings are always logged regardless of this option.')
class-attribute
instance-attribute
REPLSettings
Bases: BaseModel
Source code in harbor_cli/config.py
Attributes
history: bool = Field(default=True, description='Enable persistent history in the REPL.')
class-attribute
instance-attribute
history_file: Path = Field(default=DEFAULT_HISTORY_FILE, description='Path to custom location of history file.')
class-attribute
instance-attribute
CacheSettings
Bases: BaseModel
DEPRECATED: Caching was removed in 0.2.0. This class is left here for compatibility.
Source code in harbor_cli/config.py
Attributes
enabled: bool = Field(default=False, description='Enable in-memory caching of API responses. This can significantly speed up Harbor CLI, but should be considered experimental for now.')
class-attribute
instance-attribute
ttl: int = Field(default=300, description='Time to live for cached responses, in seconds.')
class-attribute
instance-attribute
HarborCLIConfig
Bases: BaseModel
Source code in harbor_cli/config.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
Attributes
harbor: HarborSettings = Field(default_factory=HarborSettings)
class-attribute
instance-attribute
general: GeneralSettings = Field(default_factory=GeneralSettings)
class-attribute
instance-attribute
output: OutputSettings = Field(default_factory=OutputSettings)
class-attribute
instance-attribute
repl: REPLSettings = Field(default_factory=REPLSettings)
class-attribute
instance-attribute
cache: CacheSettings = Field(default_factory=CacheSettings)
class-attribute
instance-attribute
logging: LoggingSettings = Field(default_factory=LoggingSettings)
class-attribute
instance-attribute
config_file: Optional[Path] = Field(default=None, exclude=True, description='Path to config file (if any).')
class-attribute
instance-attribute
Functions
from_file(config_file: Path | None = DEFAULT_CONFIG_FILE, create: bool = False) -> HarborCLIConfig
classmethod
Create a Config object from a TOML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file |
Path
|
Path to the TOML file.
If |
DEFAULT_CONFIG_FILE
|
create |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
Config
|
A Config object. |
Source code in harbor_cli/config.py
save(path: Path | None = None) -> None
Source code in harbor_cli/config.py
toml(expose_secrets: bool = True, tomli_kwargs: dict[str, Any] | None = {}, **kwargs: Any) -> str
Return a TOML representation of the config object. None values are replaced with empty strings (bad?)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expose_secrets |
bool
|
If |
True
|
tomli_kwargs |
dict
|
Dict of keyword arguments passed to |
{}
|
**kwargs |
Any
|
Keyword arguments passed to |
{}
|
Returns:
Type | Description |
---|---|
str
|
TOML representation of the config as a string. |
Source code in harbor_cli/config.py
Functions
config_env_var(key: str) -> str
env_var(option: str) -> str
load_toml_file(config_file: Path) -> dict[str, Any]
Load a TOML file and return the contents as a dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file |
(Path)
|
Path to the TOML file to load. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A TOML file as a dictionary |
Source code in harbor_cli/config.py
create_config(config_path: Path | None, overwrite: bool = False) -> Path
Source code in harbor_cli/config.py
load_config(config_path: Path | None = None) -> HarborCLIConfig
Load the config file.
Source code in harbor_cli/config.py
save_config(config: HarborCLIConfig, config_path: Path) -> None
Save the config file.
Source code in harbor_cli/config.py
sample_config(exclude_none: bool = False) -> str
Returns the contents of a sample config file as a TOML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exclude_none |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
str
|
Sample config file contents in TOML format. |