Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ clean:

prepare:
$(CURDIR)/load-docs.sh
$(CURDIR)/cli-docs.sh

serve:
hugo server \
Expand Down
43 changes: 43 additions & 0 deletions cli-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Step 1: Clone the required repositories
HARBOR_CLI_REPO="https://github.com/goharbor/harbor-cli.git"

# Clone both repos if not already cloned
if [ ! -d "harbor-cli" ]; then
git clone $HARBOR_CLI_REPO
fi

# Define the paths for relevant folders
HARBOR_CLI_DOCS="harbor-cli/doc/cli-docs"
WEBSITE_CLI_DOCS="content/cli-docs/cli-docs"

# Step 2: Check for missing files
# List files in both directories

CLI_FILES_HARBOR_CLI=$(ls $HARBOR_CLI_DOCS)
CLI_FILES_WEBSITE=$(ls $WEBSITE_CLI_DOCS)

# Find files in harbor-cli that are not present in website's cli-docs folder

MISSING_FILES=()
for FILE in $CLI_FILES_HARBOR_CLI; do
FILENAME=$(basename "$FILE")
if [ ! -f "$WEBSITE_CLI_DOCS/$FILENAME" ]; then
MISSING_FILES+=("$FILENAME")
fi
done

# Step 3: Copy missing files
if [ ${#MISSING_FILES[@]} -eq 0 ]; then
echo "No missing files."
else
echo "Copying missing files..."
for FILE in "${MISSING_FILES[@]}"; do
cp "$HARBOR_CLI_DOCS/$FILE" "./content/cli-docs/cli-docs"
echo "Copied $FILE successfully"
done

fi

rm -rf harbor-cli
13 changes: 13 additions & 0 deletions content/cli-docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Harbor CLI Documentation

This is the main table of contents for the Harbor CLI documentation.

## Harbor CLI Documentation

This section provides detailed documentation for the Harbor CLI, which allows users to interact with the Harbor using command-line commands.

- [harbor artifact](cli-docs/harbor-artifact.md)
- [harbor project](cli-docs/harbor-project.md)
- [harbor registry](cli-docs/harbor-registry.md)
- [harbor repo](cli-docs/harbor-repo.md)
- [harbor user](cli-docs/harbor-user.md)
20 changes: 20 additions & 0 deletions content/cli-docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Harbor CLI Documentation
---

Welcome to the Harbor CLI documentation. This provides detailed documentation for the Harbor CLI.

## Harbor CLI Documentation

This section describes the comprehensive set of commands provided by the Harbor CLI, which enables you to efficiently manage and interact with your Harbor registry.

- `harbor` - Configure the Harbor CLI and set global flags to customize your experience.
- `harbor artifact` - Manage artifacts in Harbor Repository
- `harbor project` - Manage projects and assign resources to them
- `harbor registry` - Manage registries in Harbor
- `harbor repo` - Manage repositories in Harbor context
- `harbor user` - Administer users in Harbor, including creating, updating, and managing user accounts

## Access the Documentation Source Files

The source files for this documentation set are located in the [Harbor CLI repository on Github](https://github.com/goharbor/harbor-cli/tree/main/doc/cli-docs).
110 changes: 110 additions & 0 deletions content/cli-docs/cli-config/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: Harbor CLI Config Management
weight: 25
---

# Harbor CLI Configuration Management

> **Note**
> The Harbor CLI follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) for configuration and data storage by default.

## Introduction
Harbor CLI is a flexible command-line tool that lets you manage various Harbor environments with different credentials. Whether you need a production-ready setup or quick testing configurations, the CLI's hierarchical structure and XDG support help keep things organized.


## Understanding the Configuration Structure
The Harbor CLI can manage multiple credentials and keep track of which credential is currently active. This setup allows you to maintain separate contexts for different Harbor instances or user accounts without having to rewrite configuration files manually. While the Harbor CLI configuration file manages your credentials, passwords themselves are never stored in plain text. Instead, they are secured using the AES-GCM encryption described in the [Harbor CLI Encryption documentation](../cli-config).

### Example Configuration File
Below is a simplified example of a typical Harbor CLI configuration file:
```yaml
current-credential-name: example@demo-harbor
credentials:
- name: example@demo-harbor
username: example-user
password: example-password
serveraddress: https://demo.goharbor.io
```

In this configuration:
- **current-credential-name** references the active credential by name.
- **credentials** holds one or more sets of user credentials, each following the same structure.

## Managing Multiple Credentials
If you need to work with multiple sets of credentials—such as development, staging, or production — Harbor CLI makes it easy to create and switch between them.

> **Note**: For more login command details please refer to the [login command reference](../cli-docs/harbor-login.md).
### Creating a New Credentials Entry
Use the `harbor login` command with the required arguments to store new credentials:
```bash
harbor login --name my-new-credential \
--username myuser \
--password mypass \
https://my-harbor-instance.com
```
This adds a new entry to your credentials list, allowing you to manage different Harbor accounts from the same CLI.

### Switching Between Credentials
To switch to another credential set, run:
```bash
harbor login --name <name-of-credential>
```
The CLI will then set the specified credential as the active one, eliminating the need to manually edit your configuration files. This will overwrite the `current-credential-name`.


## Configuration Hierarchy (Highest to Lowest Priority)

1. **Explicit Config Flag**
Provide a custom config file at runtime using `--config`:
```bash
harbor --config /path/to/custom/config.yaml artifact list
```

2. **Environment Variable**
Set a persistent configuration through the `HARBOR_CLI_CONFIG` environment variable:
```bash
export HARBOR_CLI_CONFIG="$HOME/.custom/harbor-config.yaml"
harbor artifact list # Uses the environment-specified config
```

3. **XDG Default Paths**
Automatically discover configuration in the following order:
```bash
${XDG_CONFIG_HOME}/harbor-cli/config.yaml # If XDG_CONFIG_HOME is set
~/.config/harbor-cli/config.yaml # Fallback default
```

## Data Storage Management
### Data File Location

- **Primary Path**: `$XDG_DATA_HOME/harbor-cli/data.yaml`
- **Fallback Path**: `$HOME/.local/share/harbor-cli/data.yaml`

> **Important**
> The data file automatically tracks the last-used configuration file path

## Configuration Precedence Summary
| Priority | Method | Example |
|----------|----------------------------|---------------------------------------|
| 1 | --config flag | harbor --config ./test.yaml ... |
| 2 | HARBOR_CLI_CONFIG env var | export HARBOR_CLI_CONFIG=... |
| 3 | XDG Default Locations | ~/.config/harbor-cli/config.yaml |

## Practical Usage Examples
### Scenario 1: Temporary Config Override
```bash
harbor --config ./experimental.yaml project create "new-project"
```

### Scenario 2: Persistent Environment-based Config
```bash
echo 'export HARBOR_CLI_CONFIG="$HOME/work/configs/prod-harbor.yaml"' >> ~/.zshrc
source ~/.zshrc
harbor config list # Uses production config
```

### Scenario 3: Reset to Default Configuration
```bash
unset HARBOR_CLI_CONFIG
harbor config delete --current # Deletes current context
```
13 changes: 13 additions & 0 deletions content/cli-docs/cli-docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Harbor CLI Commands
weight: 25
---

This section describes the comprehensive set of commands provided by the Harbor CLI, which enables you to efficiently manage and interact with your Harbor registry. The Harbor CLI commands are categorized by function,

- `harbor` - Configure the Harbor CLI and set global flags to customize your experience.
- `harbor artifact` - Manage artifacts in Harbor Repository
- `harbor project` - Manage projects and assign resources to them
- `harbor registry` - Manage registries in Harbor
- `harbor repo` - Manage repositories in Harbor context
- `harbor user` - Administer users in Harbor, including creating, updating, and managing user accounts
32 changes: 32 additions & 0 deletions content/cli-docs/cli-docs/harbor-artifact-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: harbor artifact delete
weight: 35
---
## harbor artifact delete

### Description

##### delete an artifact

```sh
harbor artifact delete [flags]
```

### Options

```sh
-h, --help help for delete
```

### Options inherited from parent commands

```sh
--config string config file (default is $HOME/.harbor/config.yaml) (default "/home/user/.harbor/config.yaml")
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact](harbor-artifact.md) - Manage artifacts

42 changes: 42 additions & 0 deletions content/cli-docs/cli-docs/harbor-artifact-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: harbor artifact info
weight: 25
---
## harbor artifact info

### Description

##### Get info of an artifact

### Synopsis

Get info of an artifact

```sh
harbor artifact info [flags]
```

### Examples

```sh
harbor artifact info <project>/<repository>/<reference>
```

### Options

```sh
-h, --help help for info
```

### Options inherited from parent commands

```sh
--config string config file (default is $HOME/.harbor/config.yaml) (default "/home/user/.harbor/config.yaml")
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact](harbor-artifact.md) - Manage artifacts

32 changes: 32 additions & 0 deletions content/cli-docs/cli-docs/harbor-artifact-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: harbor artifact list
weight: 30
---
## harbor artifact list

### Description

##### list artifacts within a repository

```sh
harbor artifact list [flags]
```

### Options

```sh
-h, --help help for list
```

### Options inherited from parent commands

```sh
--config string config file (default is $HOME/.harbor/config.yaml) (default "/home/user/.harbor/config.yaml")
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact](harbor-artifact.md) - Manage artifacts

42 changes: 42 additions & 0 deletions content/cli-docs/cli-docs/harbor-artifact-scan-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: harbor artifact scan start
weight: 45
---
## harbor artifact scan start

### Description

##### Start a scan of an artifact

### Synopsis

Start a scan of an artifact in Harbor Repository

```sh
harbor artifact scan start [flags]
```

### Examples

```sh
harbor artifact scan start <project>/<repository>/<reference>
```

### Options

```sh
-h, --help help for start
```

### Options inherited from parent commands

```sh
--config string config file (default is $HOME/.harbor/config.yaml) (default "/home/user/.harbor/config.yaml")
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact scan](harbor-artifact-scan.md) - Scan an artifact

Loading