Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a run wrapper for windows #42

Merged
merged 11 commits into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ root = true
end_of_line = lf
insert_final_newline = true

[*.cmd]
end_of_line = crlf

[*.{sh,bash,bats}]
indent_style = space
indent_size = 4
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Allow override sops version on installation

## [Unreleased]

### Added
- Better lookup for unix shells on Windows (https://github.com/jkroepke/helm-secrets/pull/42)

## [3.3.4] - 2020-09-09

### Added
Expand Down
6 changes: 3 additions & 3 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description: |-
This plugin provides secrets values encryption for Helm charts secure storing
useTunnel: false
hooks:
install: "$HELM_PLUGIN_DIR/scripts/install.sh"
update: "$HELM_PLUGIN_DIR/scripts/install.sh"
install: "$HELM_PLUGIN_DIR/scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh"
update: "$HELM_PLUGIN_DIR/scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh"

command: "$HELM_PLUGIN_DIR/scripts/run.sh"
platformCommand:
- os: windows
command: "sh $HELM_PLUGIN_DIR/scripts/run.sh"
command: "cmd /c $HELM_PLUGIN_DIR/wrapper/sh.cmd $HELM_PLUGIN_DIR/scripts/run.sh"
12 changes: 7 additions & 5 deletions scripts/drivers/sops.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env sh

_SOPS="${HELM_SECRETS_SOPS_BIN:-sops}"

driver_is_file_encrypted() {
input="${1}"

Expand All @@ -12,9 +14,9 @@ driver_encrypt_file() {
output="${3}"

if [ "${input}" = "${output}" ]; then
sops --encrypt --input-type "${type}" --output-type "${type}" --in-place "${input}"
$_SOPS --encrypt --input-type "${type}" --output-type "${type}" --in-place "${input}"
else
sops --encrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}"
$_SOPS --encrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}"
fi
}

Expand All @@ -25,15 +27,15 @@ driver_decrypt_file() {
output="${3:-}"

if [ "${output}" != "" ]; then
sops --decrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}"
$_SOPS --decrypt --input-type "${type}" --output-type "${type}" --output "${output}" "${input}"
else
sops --decrypt --input-type "${type}" --output-type "${type}" "${input}"
$_SOPS --decrypt --input-type "${type}" --output-type "${type}" "${input}"
fi
}

driver_edit_file() {
type="${1}"
input="${2}"

sops --input-type yaml --output-type yaml "${input}"
$_SOPS --input-type yaml --output-type yaml "${input}"
}
5 changes: 5 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ load_secret_driver() {

load_secret_driver "$SECRET_DRIVER"

# ./run.sh vs bash run.sh
if [ "$(basename "$1")" = "run.sh" ]; then
shift
fi

while true; do
case "${1:-}" in
enc)
Expand Down
9 changes: 9 additions & 0 deletions scripts/wrapper/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:; exec "$@" #
:; exit $? #

:: .bat bash hybrid script
:: https://stackoverflow.com/a/17623721

@echo off
%HELM_PLUGIN_DIR%\wrapper\sh.cmd %*
exit /b
117 changes: 117 additions & 0 deletions scripts/wrapper/sh.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@setlocal enableextensions enabledelayedexpansion
@echo off

:: If HELM_SECRETS_WINDOWS_SHELL is provided, use it.
if not "%HELM_SECRETS_WINDOWS_SHELL%"=="" GOTO :ENVSH


:: check for cygwin installation or git for windows is inside %PATH%
"sh" -c exit >nul 2>&1
IF %ERRORLEVEL% EQU 0 GOTO :SH


:: check for git-bash
"%programfiles%\Git\bin\bash.exe" -c exit >nul 2>&1
IF %ERRORLEVEL% EQU 0 GOTO :GITBASH


:: check for git-bash (32-bit)
"%programfiles(x86)%\Git\bin\bash.exe" -c exit >nul 2>&1
IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32


:: check git for windows
where.exe git.exe >nul 2>&1
IF %ERRORLEVEL% EQU 0 GOTO :GITBASH_CUSTOM
:RETURN_GITBASH


:: check for wsl
wsl sh -c exit >nul 2>&1
IF %ERRORLEVEL% EQU 0 GOTO :WSL

GOTO :NOSHELL



:ENVSH
IF "%HELM_SECRETS_WINDOWS_SHELL%"=="wsl" GOTO :WSL

"%HELM_SECRETS_WINDOWS_SHELL%" "%HELM_PLUGIN_DIR%\scripts\run.sh" %*
GOTO :EOF




:SH
"sh" "%HELM_PLUGIN_DIR%\scripts\run.sh" %*
GOTO :EOF




:GITBASH
"%programfiles%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %*
GOTO :EOF





:GITBASH32
"%programfiles(x86)%\Git\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %*
GOTO :EOF




:GITBASH_CUSTOM
:: CMD output to variable - https://stackoverflow.com/a/6362922/8087167
FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe git.exe`) DO (
SET GIT_FILEPATH=%%F
)

IF "%GIT_FILEPATH%"=="" GOTO :RETURN_GITBASH

FOR %%F in ("%GIT_FILEPATH%") DO SET GIT_DIRPATH=%%~dpF

:: check for git-bash
"%GIT_DIRPATH%..\bin\bash.exe" -c exit >nul 2>&1

IF %ERRORLEVEL% NEQ 0 GOTO :RETURN_GITBASH

"%GIT_DIRPATH%..\bin\bash.exe" "%HELM_PLUGIN_DIR%\scripts\run.sh" %*
GOTO :EOF




:WSL
:: Use WSL, but convert all paths (script + arguments) to wsl paths
SET ARGS=

:: Loop through all parameters - https://stackoverflow.com/a/34019557/8087167
:LOOP
if "%1"=="" goto ENDLOOP

:: CMD output to variable - https://stackoverflow.com/a/6362922/8087167
FOR /F "tokens=* USEBACKQ" %%F IN (`wsl wslpath "%1"`) DO (
SET WSLPATH=%%F
)
SET ARGS=%ARGS% %WSLPATH%

shift
goto LOOP
:ENDLOOP

wsl bash %ARGS%
GOTO :EOF




:NOSHELL
:: If no *nix shell found, raise an error.
echo helm-secrets needs a unix shell. Please install WSL, cygwin or Git for Windows.
exit /B 1
GOTO :EOF