1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00

Compare commits

...

5 commits

Author SHA1 Message Date
Rustam
eed9a2d259
Merge 43079320a2 into 367e9381df 2024-09-23 19:03:45 +02:00
Carlo Sala
367e9381df
chore(git): fix typo 2024-09-23 17:32:44 +02:00
dependabot[bot]
f11cc8fea1
chore(deps): bump idna in /.github/workflows/dependencies (#12688)
Bumps [idna](https://github.com/kjd/idna) from 3.9 to 3.10.
- [Release notes](https://github.com/kjd/idna/releases)
- [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst)
- [Commits](https://github.com/kjd/idna/compare/v3.9...v3.10)

---
updated-dependencies:
- dependency-name: idna
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-22 16:20:33 +02:00
Rustam Tagaev
43079320a2
#new-plugin follow Conventions 2020-06-01 20:17:41 +03:00
Rustam Tagaev
ee19e2b847
#new-plugin add a new plugin "vault-switch" 2020-06-01 20:03:41 +03:00
5 changed files with 88 additions and 2 deletions

View file

@ -1,6 +1,6 @@
certifi==2024.8.30
charset-normalizer==3.3.2
idna==3.9
idna==3.10
PyYAML==6.0.2
requests==2.32.3
semver==3.0.2

View file

@ -163,7 +163,7 @@ function git_current_branch() {
}
# Outputs the name of the previously checked out branch
# Usage example: git pull origin $(git_current_branch)
# Usage example: git pull origin $(git_previous_branch)
# rev-parse --symbolic-full-name @{-1} only prints if it is a branch
function git_previous_branch() {
local ref

View file

@ -0,0 +1,29 @@
# Vault-switch plugin
## Description
This plugin can switch among nodes of Vault - HashiCorp
## Configuration
For using a plugin you should add VAULT_NODES to **~/.zshrc**
Variable **VAULT_NODES** must look as
```bash
VAULT_NODES="node1,https://vault1.example.com,secret_token1;node2,https://vault2.example.com,secret_token2"
```
If you want to skip verify checking of ssl then add true to end of the string.
```bash
VAULT_NODES="node1,https://vault1.example.com,secret_token1,true;node2,https://vault2.example.com,secret_token2"
```
Name of a node, address, token are separating comma. Other nodes separate semicolon.
After need to add the name of the plugin to **~/.zshrc** to variable **plugins=(vault-switch)**
**Example usage:**
![vault-switch](example.png)
State of restoring stored in **~/.vault-switch/credentials**

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -0,0 +1,57 @@
autoload -U add-zsh-hook
add-zsh-hook precmd _restore_cache
FILE_CREDENTIALS="${HOME}/.vault-switch/credentials"
_restore_cache(){
[ ! -d ${HOME}/.vault-switch ] && mkdir -p ${HOME}/.vault-switch
[ ! -f $FILE_CREDENTIALS ] && touch ${FILE_CREDENTIALS}
source ${FILE_CREDENTIALS}
}
_get-nodes(){
IFS=";" read -A NODES <<< ${VAULT_NODES}
}
_set-color(){
echo "\e[1;32m$1\e[0m"
}
_list-nodes(){
INDEX=1
for i in ${NODES[@]}
do
NODE=$(echo $i | cut -d "," -f 1)
[[ "${NODE}" == "${VAULT_SELECT_NODE}" ]] && ASTERISK="*"
echo "${INDEX}) ${NODE} $(_set-color ${ASTERISK})"
INDEX=$[$INDEX+1]
unset ASTERISK
done
}
_set-work-node(){
if [ $1 -gt ${#NODES[@]} ]
then
echo "Number of node not found"
else
VAULT_SELECT_NODE=$(echo ${NODES[$1]} | cut -d "," -f 1)
VAULT_ADDR=$(echo ${NODES[$1]} | cut -d "," -f 2)
VAULT_TOKEN=$(echo ${NODES[$1]} | cut -d "," -f 3)
VAULT_SKIP_VERIFY=$(echo ${NODES[$1]} | cut -d "," -f 4)
echo > ${FILE_CREDENTIALS}
echo "export VAULT_SELECT_NODE=${VAULT_SELECT_NODE}" >> ${FILE_CREDENTIALS}
echo "export VAULT_ADDR=${VAULT_ADDR}" >> ${FILE_CREDENTIALS}
echo "export VAULT_TOKEN=${VAULT_TOKEN}" >> ${FILE_CREDENTIALS}
[[ $VAULT_SKIP_VERIFY ]] && echo "export VAULT_SKIP_VERIFY=true" >> ${FILE_CREDENTIALS}
_list-nodes
fi
}
vault-switch() {
_get-nodes
[ ! $1 ] && _list-nodes
[ $1 ] && _set-work-node $1
}