-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd "${0%/*}" | ||
|
||
[[ -f 'config.sh' ]] && source config.sh | ||
|
||
execute_file() { | ||
local file=$1 | ||
echo "Executing file: $file" | ||
chmod +x "$BACKGROUND_JOB_EXECUTING_DIR/$file" | ||
if bash "$BACKGROUND_JOB_EXECUTING_DIR/$file"; then | ||
echo "File executed successfully: $file" | ||
mv "$BACKGROUND_JOB_EXECUTING_DIR/$file" "$BACKGROUND_JOB_COMPLETE_DIR/" | ||
else | ||
echo "File execution failed: $file" | ||
mv "$BACKGROUND_JOB_EXECUTING_DIR/$file" "$BACKGROUND_JOB_FAILED_DIR/" | ||
fi | ||
} | ||
monitor_files() { | ||
while true; do | ||
for file in "$BACKGROUND_JOB_DIR"/*; do | ||
if [ -f "$file" ]; then | ||
mv "$file" "$BACKGROUND_JOB_EXECUTING_DIR/" | ||
execute_file "$(basename "$file")" & | ||
fi | ||
done | ||
sleep 1 | ||
done | ||
} | ||
mkdir -p "$BACKGROUND_JOB_EXECUTING_DIR" "$BACKGROUND_JOB_COMPLETE_DIR" "$BACKGROUND_JOB_FAILED_DIR" | ||
mv "$BACKGROUND_JOB_EXECUTING_DIR"/* "$BACKGROUND_JOB_FAILED_DIR/" 2>/dev/null | ||
monitor_files & |
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,6 @@ | ||
#!/usr/bin/env bash | ||
CHARM_DIR="/mnt/c/Users/drewr/code/source/identity/data/charms/a1f88a4bb72f92dcf61546ecad235d6aa69135ed968d2338d02e25ef0873 | ||
/mnt/c/Users/drewr/code/sources/identity/provider/e2c1ecb06855c73be5d4caff283830bff53d9ded9853cb4dc5f16d942fdc | ||
/mnt/c/Users/drewr/code/sources/identity/provider/1a49f078/714abdbbb40c14a8a45cd16e6c3d4d5be03c8d5eca7d8ebc9a63db25975cd713" ~/code/src/identity/identity charm link -d -o "/mnt/c/Users/drewr/code/source/identity/data/charms/a1f88a4bb72f92dcf61546ecad235d6aa69135ed968d2338d02e25ef0873 | ||
/mnt/c/Users/drewr/code/sources/identity/provider/e2c1ecb06855c73be5d4caff283830bff53d9ded9853cb4dc5f16d942fdc | ||
/mnt/c/Users/drewr/code/sources/identity/provider/1a49f078/714abdbbb40c14a8a45cd16e6c3d4d5be03c8d5eca7d8ebc9a63db25975cd713/.link" -k "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIByQfvwjrZj1k3QKZgayCc2ESn3iYO1RLM2Dv07ySqS8,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICcB2drOfxskb9DPYUUSHFTeC/ZOBkCaUfOQlgN0ksJW,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICVuZZlEpHfQADiUoofkUI2dQKbgRnlnODlCefwBOPIi,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDrsT5Eest3+VnbXZmXidY5CZFscxe7wDYsnHs/Muc/x,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE6z33ZduBR8BvZA9GUTz14TrvEebgMG8nTxXy76ZCcd,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEzWRyTB2o5V2GsChvTUYCd1Vcr0okj4KdWD9Qz3tY8G,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFdz0QkZImiBwH6XVdH79T8oAkDhuNFoytqjcKweNHrt,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM2XPD+Wsn+Ziwemd3TB1mU1u4OR2H8Gk82x1BSRFsP,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILt3T+gVAJsbYfEDbUfhVxkeBpyCd2XGK8WJDXZkCaBY,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMFQBfv63aVT4g4zU4ysYCNsvuWELe/0mAMkzh7Xz/iQ,ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINo8of8l94GaN9GnpaObO7h/J7v5Nl8uHiLoMsmEfg7q" |
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 +1,13 @@ | ||
PROJECT_NAME=provider | ||
if [[ -z "$BACKGROUND_JOB_DIR" ]]; then | ||
BACKGROUND_JOB_DIR="$(realpath "${0%/*}")/.." | ||
fi | ||
if [[ -z "$BACKGROUND_JOB_EXECUTING_DIR" ]]; then | ||
BACKGROUND_JOB_EXECUTING_DIR="$BACKGROUND_JOB_DIR/executing" | ||
fi | ||
if [[ -z "$BACKGROUND_JOB_COMPLETE_DIR" ]]; then | ||
BACKGROUND_JOB_COMPLETE_DIR="$BACKGROUND_JOB_DIR/complete" | ||
fi | ||
if [[ -z "$BACKGROUND_JOB_FAILED_DIR" ]]; then | ||
BACKGROUND_JOB_FAILED_DIR="$BACKGROUND_JOB_DIR/failed" | ||
fi |
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,37 +1,48 @@ | ||
if [[ "$REQUEST_METHOD" != "POST" ]]; then | ||
return $(status_code 405) | ||
fi | ||
else | ||
random() { | ||
dd if=/dev/urandom bs=1 count="${1:-32}" 2>/dev/null | xxd -p | tr -d '[:space:]' | ||
} | ||
for key in "${!FORM_DATA[@]}"; do | ||
if [[ "$key" == "keys" ]]; then | ||
CHARM_DIR=$CHARM_DIR/$(random) | ||
mkdir -p "$CHARM_DIR" | ||
LINK_CODE_PATH=$CHARM_DIR/.link | ||
rm -rf "$LINK_CODE_PATH" | ||
|
||
KEYS="${FORM_DATA[$key]}" | ||
break | ||
fi | ||
done | ||
if [[ -z "$KEYS" ]]; then | ||
return $(status_code 405) | ||
fi | ||
CHARM_DIR=$(realpath $CHARM_DIR)"/$(random)" | ||
mkdir -p "$CHARM_DIR" | ||
LINK_CODE_PATH=$CHARM_DIR/.link | ||
rm -rf "$LINK_CODE_PATH" | ||
mkdir -p "$(dirname "$LINK_CODE_PATH")" | ||
|
||
~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" > /dev/null 2>&1 | ||
cat << EOF > "$BACKGROUND_JOB_DIR/$(basename "$(dirname "$CHARM_DIR")").sh" | ||
#!/usr/bin/env bash | ||
CHARM_DIR="$CHARM_DIR" ~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" | ||
EOF | ||
echo "Created background job: $BACKGROUND_JOB_DIR/$(basename "$(dirname "$CHARM_DIR")").sh" >&2 | ||
max_wait=60 # seconds | ||
wait_interval=1 # seconds | ||
elapsed_time=0 | ||
|
||
while [[ ! -f "$LINK_CODE_PATH" && $elapsed_time -lt $max_wait ]]; do | ||
sleep $wait_interval | ||
((elapsed_time+=wait_interval)) | ||
echo "Waiting for link code: $elapsed_time seconds elapsed" >&2 | ||
done | ||
|
||
if [[ -f "$LINK_CODE_PATH" ]]; then | ||
LINK_CODE=$(cat "$LINK_CODE_PATH") | ||
if [[ -z "$LINK_CODE" ]]; then | ||
respond 405 "Failure." | ||
else | ||
respond 200 "$LINK_CODE" | ||
fi | ||
else | ||
respond 405 "Failure." | ||
echo "Elapsed time: $elapsed_time" >&2 | ||
if [[ "$elapsed_time" -ge $max_wait ]]; then | ||
return $(status_code 405) | ||
fi | ||
fi | ||
done | ||
if [[ ! -f "$LINK_CODE_PATH" ]]; then | ||
return $(status_code 405) | ||
fi | ||
LINK_CODE=$(cat "$LINK_CODE_PATH") | ||
if [[ -z "$LINK_CODE" ]]; then | ||
return $(status_code 405) | ||
fi | ||
echo "Obtained charm link code: $LINK_CODE" >&2 | ||
respond 200 "$LINK_CODE" | ||
fi | ||
echo "Done" >&2 |
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 |
---|---|---|
|
@@ -21,6 +21,8 @@ mkdir -p sessions | |
mkdir -p pubsub | ||
mkdir -p data | ||
mkdir -p uploads | ||
mkdir -p exec | ||
|
||
|
||
PORT=${PORT:-3333} | ||
|
||
|