Skip to content

Commit

Permalink
Add a run wrapper for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Sep 10, 2020
1 parent 29e4e9e commit 4bf60ee
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
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
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/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/install.sh"
update: "$HELM_PLUGIN_DIR/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: "$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}"
}
6 changes: 6 additions & 0 deletions wrapper/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:; exec "$@" #
:; exit $? #

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

:: If HELM_SECRETS_WINDOWS_SHELL is provided, use it.
if "%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
C:\Program^ Files\Git\bin\bash.exe -c exit >nul 2>&1

IF %ERRORLEVEL% EQU 0 GOTO :GITBASH

:: check for git-bash (32-bit)
C:\Program^ Files^ (x86)\Git\bin\bash.exe -c exit >nul 2>&1

IF %ERRORLEVEL% EQU 0 GOTO :GITBASH32

:: check for wsl
wsl sh -c exit >nul 2>&1

IF %ERRORLEVEL% EQU 0 GOTO :WSL

GOTO :NOSHELL

:ENVSH
%HELM_SECRETS_WINDOWS_SHELL% "%*"
GOTO :EOF

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

:GITBASH
C:\Program^ Files\Git\bin\bash.exe "%*"
GOTO :EOF

:GITBASH32
C:\Program^ Files^ (x86)\Git\bin\bash.exe "%*"
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 -x -c "%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

0 comments on commit 4bf60ee

Please sign in to comment.