generated from asdf-vm/asdf-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: asdf-plugin-manager first version (#1)
Manage asdf plugins securely and declaratively. Fixes: - asdf-vm/asdf#166 - asdf-vm/asdf#240 - asdf-vm/asdf#829 - asdf-vm/asdf#1577
- Loading branch information
Showing
14 changed files
with
275 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Lint | ||
name: Semantic PR | ||
|
||
on: | ||
pull_request_target: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,115 @@ | ||
<div align="center"> | ||
|
||
<!-- omit in toc --> | ||
# asdf-plugin-manager [![Build](https://github.com/aabouzaid/asdf-plugin-manager/actions/workflows/build.yml/badge.svg)](https://github.com/aabouzaid/asdf-plugin-manager/actions/workflows/build.yml) [![Lint](https://github.com/aabouzaid/asdf-plugin-manager/actions/workflows/lint.yml/badge.svg)](https://github.com/aabouzaid/asdf-plugin-manager/actions/workflows/lint.yml) | ||
|
||
[plugin-manager](https://github.com/aabouzaid/asdf-plugin-manager) plugin for the [asdf version manager](https://asdf-vm.com). | ||
Manage [asdf version manager](https://asdf-vm.com) plugins securely and declaratively. | ||
|
||
Using `asdf-plugin-manager`, you can set plugins Git URL and ref for security and integrity. So it's the only plugin you need to validate manually and the rest are validated via `.plugin-versions` file. Check [example](#example) for more details. | ||
|
||
**Yes, this is an asdf plugin to manage asdf plugins!** | ||
</div> | ||
|
||
<!-- omit in toc --> | ||
# Contents | ||
|
||
- [Why?](#why) | ||
- [Dependencies](#dependencies) | ||
- [Install](#install) | ||
- [Example](#example) | ||
- [Parameters](#parameters) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
# Dependencies | ||
# Why? | ||
|
||
**TODO: adapt this section** | ||
[Asdf is a great universal version manager](https://tech.aabouzaid.com/2022/01/asdf-vm-a-universal-version-manager-tools.html). | ||
However, it lacks a secure and declarative method to manage its plugins. For example, you cannot pin a specific asdf plugin version, which means you will be easily hacked if one of the asdf plugins you use is compromised! | ||
|
||
- `bash`, `curl`, `tar`: generic POSIX utilities. | ||
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x. | ||
[Many exist requests asking to fix that](https://github.com/asdf-vm/asdf/issues/1577), but no solution has been proposed in `asdf` upstream yet! (Last check: Aug 2023) | ||
|
||
Hence, `asdf-plugin-manager` fills the gap to manage asdf plugins securely and declaratively via `.plugin-versions` file. | ||
|
||
# Dependencies | ||
|
||
- [asdf-vm](https://asdf-vm.com/): Tested with `v0.12.0` but probably will work with older versions. | ||
- `bash`, `cat`, `grep`, `tr`, `cut`, `column`: Generic POSIX utilities. | ||
- `ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME`: Set default name for the file with the list of managed plugins. | ||
Default: `.plugin-versions`. | ||
|
||
# Install | ||
|
||
Plugin: | ||
Setup `asdf-plugin-manager` asdf plugin: | ||
|
||
```shell | ||
asdf plugin add plugin-manager | ||
# or | ||
asdf plugin add plugin-manager https://github.com/aabouzaid/asdf-plugin-manager.git | ||
asdf plugin add asdf-plugin-manager https://github.com/aabouzaid/asdf-plugin-manager.git | ||
asdf plugin update asdf-plugin-manager v1.0.0 | ||
``` | ||
|
||
plugin-manager: | ||
Setup `asdf-plugin-manager` actual CLI: | ||
|
||
```shell | ||
# Show all installable versions | ||
asdf list-all plugin-manager | ||
|
||
# Install specific version | ||
asdf install plugin-manager latest | ||
asdf install asdf-plugin-manager latest | ||
|
||
# Set a version globally (on your ~/.tool-versions file) | ||
asdf global plugin-manager latest | ||
asdf global asdf-plugin-manager latest | ||
|
||
# Now asdf-plugin-manager commands are available | ||
asdf-plugin-manager version | ||
``` | ||
|
||
# Example | ||
|
||
Using `asdf-plugin-manager`, the `.plugin-versions` file will be the source of truth for asdf plugins. | ||
Its syntax as follows: | ||
|
||
``` | ||
# Plugin name Git URL Git ref (hash, tag, or branch) | ||
venom https://github.com/aabouzaid/asdf-venom.git 2d94d17 | ||
``` | ||
|
||
# Now plugin-manager commands are available | ||
asdf-plugin-manager --version | ||
You can also export the current added plugins to be managed by `asdf-plugin-manager`: | ||
|
||
```shell | ||
asdf-plugin-manager export > .plugin-versions | ||
``` | ||
|
||
From now on, you can use `.plugin-versions` to manage asdf plugins. | ||
|
||
```shell | ||
# Add all plugins according to .plugin-versions file | ||
asdf-plugin-manager add-all | ||
``` | ||
|
||
Or | ||
|
||
```shell | ||
# Add named plugin according to .plugin-versions file | ||
asdf-plugin-manager add venom | ||
``` | ||
|
||
Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to | ||
install & manage versions. | ||
# Parameters | ||
|
||
The following all `asdf-plugin-manager` parameters: | ||
|
||
``` | ||
asdf-plugin-manager help : Print this help message | ||
asdf-plugin-manager version : Print asdf-plugin-manager current version | ||
asdf-plugin-manager export : List currently installed plugins to be used in .plugin-versions | ||
asdf-plugin-manager list : List plugins in .plugin-versions file | ||
asdf-plugin-manager add <plugin-name> : Add named plugin according to .plugin-versions file | ||
asdf-plugin-manager add-all : Add all plugins according to .plugin-versions file | ||
asdf-plugin-manager remove <plugin-name> : Remove named plugin according to .plugin-versions file | ||
asdf-plugin-manager remove-all : Remove all plugins according to .plugin-versions file | ||
``` | ||
|
||
# Contributing | ||
|
||
Contributions of any kind welcome! See the [contributing guide](contributing.md). | ||
Contributions of any kind are welcome! See the [contributing guide](contributing.md). | ||
|
||
[Thanks goes to these contributors](https://github.com/aabouzaid/asdf-plugin-manager/graphs/contributors)! | ||
[Thanks go to these contributors](https://github.com/aabouzaid/asdf-plugin-manager/graphs/contributors)! | ||
|
||
# License | ||
|
||
See [LICENSE](LICENSE) © [Ahmed AbouZaid](https://github.com/aabouzaid/) | ||
See [LICENSE](LICENSE) © [Ahmed AbouZaid](https://github.com/aabouzaid/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
VERSION=1.0.0 | ||
PLUGIN_VERSIONS_FILENAME="${ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME:-.plugin-versions}" | ||
|
||
print_version() { | ||
echo "${VERSION}" | ||
} | ||
|
||
print_plugin_versions_filename() { | ||
echo "${PLUGIN_VERSIONS_FILENAME}" | ||
} | ||
|
||
print_help() { | ||
cat <<EOF | ||
Manage asdf plugins securely and declaratively via .plugin-versions file. | ||
Using asdf-plugin-manager, you can set plugins Git URL and ref for security and integrity. | ||
VARS: | ||
ASDF_PLUGIN_MANAGER_PLUGIN_VERSIONS_FILENAME: Set default name for the file with the list of managed plugins. | ||
Default: "$(print_plugin_versions_filename)". | ||
USAGE: | ||
asdf-plugin-manager help : Print this help message | ||
asdf-plugin-manager version : Print asdf-plugin-manager current version | ||
asdf-plugin-manager export : List currently installed plugins to be used in .plugin-versions | ||
asdf-plugin-manager list : List plugins in .plugin-versions file | ||
asdf-plugin-manager add <plugin-name> : Add named plugin according to .plugin-versions file | ||
asdf-plugin-manager add-all : Add all plugins according to .plugin-versions file | ||
asdf-plugin-manager remove <plugin-name> : Remove named plugin according to .plugin-versions file | ||
asdf-plugin-manager remove-all : Remove all plugins according to .plugin-versions file | ||
EOF | ||
} | ||
|
||
export_plugins() { | ||
asdf plugin-list --refs --urls | tr -s ' ' | cut -d ' ' -f 1,2,4 | column -t | ||
} | ||
|
||
list_plugins() { | ||
plugin_name=$1 | ||
if [[ -n ${plugin_name} ]]; then | ||
grep "^${plugin_name} " "$(print_plugin_versions_filename)" | ||
else | ||
grep -v "^#" "$(print_plugin_versions_filename)" | ||
fi | ||
} | ||
|
||
remove_plugins() { | ||
local managed_plugins="$1" | ||
echo "${managed_plugins}" | while read managed_plugin; do | ||
read -r plugin_name _plugin_url _plugin_ref < <(echo ${managed_plugin}) | ||
echo "[INFO] Removing: ${plugin_name}" | ||
asdf plugin remove "${plugin_name}" || true | ||
done | ||
} | ||
|
||
add_plugins() { | ||
local managed_plugins="$1" | ||
echo "${managed_plugins}" | while read managed_plugin; do | ||
read -r plugin_name plugin_url plugin_ref < <(echo ${managed_plugin}) | ||
echo "[INFO] Adding: ${plugin_name} ${plugin_url} ${plugin_ref}" | ||
remove_plugins "$(list_plugins ${plugin_name})" | ||
asdf plugin add "${plugin_name}" "${plugin_url}" | ||
# TODO: Remove the plugin update once asdf supports adding plugin with git-ref. | ||
# https://github.com/asdf-vm/asdf/pull/1204 | ||
asdf plugin update "${plugin_name}" "${plugin_ref}" | ||
echo "[INFO] Done." | ||
done | ||
} | ||
|
||
if [[ -z $1 ]]; then | ||
print_help | ||
exit 1 | ||
fi | ||
|
||
while test -n "$1"; do | ||
case "$1" in | ||
help | -h) | ||
print_help | ||
exit 1 | ||
;; | ||
version | -v) | ||
print_version | ||
exit 0 | ||
;; | ||
export) | ||
export_plugins | ||
;; | ||
list) | ||
list_plugins | ||
;; | ||
add) | ||
add_plugins "$(list_plugins $2)" | ||
;; | ||
add-all) | ||
add_plugins "$(list_plugins)" | ||
;; | ||
remove) | ||
remove_plugins "$(list_plugins $2)" | ||
;; | ||
remove-all) | ||
remove_plugins "$(list_plugins)" | ||
;; | ||
*) | ||
echo "Unknown argument: $1" | ||
print_help | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.