Skip to content

Commit

Permalink
feat: Disable short-name repository with config value (#1227)
Browse files Browse the repository at this point in the history
Co-authored-by: jthegedus <jthegedus@hey.com>
  • Loading branch information
jrbeverly and jthegedus committed Jun 27, 2022
1 parent 9eea851 commit 18caea3
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17 deletions.
34 changes: 33 additions & 1 deletion docs/manage/configuration.md
Expand Up @@ -7,7 +7,9 @@ Configuration of `asdf` encompasses both the sharable `.tool-versions` files as
Whenever `.tool-versions` file is present in a directory, the tool versions it declares will be used in that directory and any subdirectories.

::: warning Note

Global defaults can be set in the file `$HOME/.tool-versions`

:::

This is what a `.tool-versions` file looks like:
Expand Down Expand Up @@ -57,6 +59,7 @@ legacy_version_file = no
use_release_candidates = no
always_keep_download = no
plugin_repository_last_check_duration = 60
disable_plugin_short_name_repository = no
```

### `legacy_version_file`
Expand Down Expand Up @@ -88,14 +91,43 @@ Configure the `asdf install` command to keep or delete the source code or binary

### `plugin_repository_last_check_duration`

Configure the duration since the last asdf plugin repository sync to the next. Commands `asdf plugin add <name>` or `asdf plugin list all` will trigger a check of the duration, if the duration has passed then a sync occurs.
Configure the duration since the last asdf plugin repository sync to the next. Sync events will trigger a check of the duration, if the duration has passed then a sync occurs.

| Options | Description |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- |
| integer in range `1` to `999999999` <br/> `60` is <Badge type="tip" text="default" vertical="middle" /> | Sync on trigger event if duration since last sync has passed |
| `0` | Sync on each trigger event |
| `never` | Never sync |

Sync events occur when the following commands are executed:

- `asdf plugin add <name>`
- `asdf plugin list all`

`asdf plugin add <name> <git-url>` does NOT trigger a plugin sync.

### `disable_plugin_short_name_repository`

Disable synchronization of the asdf plugin short-name repository. Sync events will exit early if the short-name repository is disabled.

| Options | Description |
| :--------------------------------------------------------- | :-------------------------------------------------------- |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Clone or update the asdf plugin repository on sync events |
| `yes` | Disable short-name plugin repository |

Sync events occur when the following commands are executed:

- `asdf plugin add <name>`
- `asdf plugin list all`

`asdf plugin add <name> <git-url>` does NOT trigger a plugin sync.

::: warning Note

Disabling the plugin short-name repository does not remove plugins previously installed from this source. Plugins can be removed with `asdf plugin remove <name>`. Removing a plugin will remove all installed versions of the managed tool.

:::

## Environment Variables

- `ASDF_CONFIG_FILE` - Defaults to `~/.asdfrc` as described above. Can be set to any location.
Expand Down
15 changes: 10 additions & 5 deletions docs/manage/plugins.md
Expand Up @@ -21,7 +21,9 @@ asdf plugin add <name>
```

::: tip Recommendation

Prefer the longer `git-url` method as it is independent of the short-name repo.

:::

## List Installed
Expand Down Expand Up @@ -72,10 +74,13 @@ asdf plugin remove <name>

Removing a plugin will remove all installations of the tool made with the plugin. This can be used as a shorthand for cleaning/pruning many unused versions of a tool.

## Syncing the Short-name Repository
## Syncing the asdf Short-name Repository

The short-name repo is synced to your local machine and periodically refreshed. This period is determined by the following method:
The short-name repo is synced to your local machine and periodically refreshed. This method to determine a sync is as follows:

- commands `asdf plugin add <name>` or `asdf plugin list all` can trigger a sync
- a sync occurs if there has not been one in the last `X` minutes
- `X` defaults to `60`, but can be configured in your `.asdfrc` via the `plugin_repository_last_check_duration` option. See the [asdf config docs](/manage/configuration.md) for more.
- sync events are triggered by commands:
- `asdf plugin add <name>`
- `asdf plugin list all`
- if configuration option `disable_plugin_short_name_repository` is set to `yes`, then sync is aborted early. See the [asdf config docs](/manage/configuration.md) for more.
- if there has not been a synchroniztion in the last `X` minutes then the sync will occur.
- `X` defaults to `60`, but can be configured in your `.asdfrc` via the `plugin_repository_last_check_duration` option. See the [asdf config docs](/manage/configuration.md) for more.
6 changes: 6 additions & 0 deletions lib/utils.bash
Expand Up @@ -412,6 +412,12 @@ initialize_or_update_repository() {
local repository_url
local repository_path

disable_plugin_short_name_repo="$(get_asdf_config_value "disable_plugin_short_name_repository")"
if [ "yes" == "$disable_plugin_short_name_repo" ]; then
printf "Short-name plugin repository is disabled\\n" >&2
exit 1
fi

repository_url=$(asdf_repository_url)
repository_path=$(asdf_data_dir)/repository

Expand Down
29 changes: 25 additions & 4 deletions test/plugin_add_command.bats
Expand Up @@ -16,7 +16,7 @@ teardown() {
run asdf plugin add "plugin_with-all-valid-CHARS-123" "${BASE_DIR}/repo-plugin_with-all-valid-CHARS-123"
[ "$status" -eq 0 ]

run asdf plugin-list
run asdf plugin list
[ "$output" = "plugin_with-all-valid-CHARS-123" ]
}

Expand Down Expand Up @@ -52,18 +52,39 @@ teardown() {
run asdf plugin add "elixir"
[ "$status" -eq 0 ]

run asdf plugin-list
# whitespace between 'elixir' and url is from printf %-15s %s format
run asdf plugin list
[ "$output" = "elixir" ]
}

@test "plugin_add command with no URL specified adds a plugin when short name repository is enabled" {
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo "disable_plugin_short_name_repository=no" >$ASDF_CONFIG_DEFAULT_FILE

run asdf plugin add "elixir"
[ "$status" -eq 0 ]

local expected="elixir"
run asdf plugin list
[ "$output" = "$expected" ]
}

@test "plugin_add command with no URL specified fails to add a plugin when disabled" {
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo "disable_plugin_short_name_repository=yes" >$ASDF_CONFIG_DEFAULT_FILE
local expected="Short-name plugin repository is disabled"

run asdf plugin add "elixir"
[ "$status" -eq 1 ]
[ "$output" = "$expected" ]
}

@test "plugin_add command with URL specified adds a plugin using repo" {
install_mock_plugin_repo "dummy"

run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
[ "$status" -eq 0 ]

run asdf plugin-list
run asdf plugin list
# whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "dummy" ]
}
Expand Down
27 changes: 20 additions & 7 deletions test/plugin_list_all_command.bats
Expand Up @@ -12,51 +12,64 @@ teardown() {
clean_asdf_dir
}

@test "plugin_list_all should exit before syncing the plugin repo if disabled" {
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo 'disable_plugin_short_name_repository=yes' >$ASDF_CONFIG_DEFAULT_FILE
local expected="Short-name plugin repository is disabled"

run asdf plugin list all
[ "$status" -eq 1 ]
[ "$output" = "$expected" ]
}

@test "plugin_list_all should sync repo when check_duration set to 0" {
echo 'plugin_repository_last_check_duration = 0' >$HOME/.asdfrc
run asdf plugin-list-all
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo 'plugin_repository_last_check_duration = 0' >$ASDF_CONFIG_DEFAULT_FILE
local expected_plugin_repo_sync="updating plugin repository..."
local expected_plugins_list="\
bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo"

run asdf plugin list all
[ "$status" -eq 0 ]
[[ "$output" =~ "$expected_plugin_repo_sync" ]]
[[ "$output" =~ "$expected_plugins_list" ]]
}

@test "plugin_list_all no immediate repo sync expected because check_duration is greater than 0" {
echo 'plugin_repository_last_check_duration = 10' >$HOME/.asdfrc
run asdf plugin-list-all
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo 'plugin_repository_last_check_duration = 10' >$ASDF_CONFIG_DEFAULT_FILE
local expected="\
bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo"

run asdf plugin list all
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

@test "plugin_list_all skips repo sync because check_duration is set to never" {
echo 'plugin_repository_last_check_duration = never' >$HOME/.asdfrc
run asdf plugin-list-all
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo 'plugin_repository_last_check_duration = never' >$ASDF_CONFIG_DEFAULT_FILE
local expected="\
bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo"

run asdf plugin list all
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

@test "plugin_list_all list all plugins in the repository" {
run asdf plugin-list-all
local expected="\
bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo"

run asdf plugin list all
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

0 comments on commit 18caea3

Please sign in to comment.