Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
dezren39 committed Mar 12, 2024
1 parent 5136f6f commit 5c65210
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion sources/identity/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
gopkg.in/go-jose/go-jose.v2 v2.6.3
)

replace github.com/charmbracelet/charm => github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac
replace github.com/charmbracelet/charm => github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398

require (
github.com/FZambia/eagle v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions sources/identity/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac h1:tPq59hN7UOMb0D4LKjS2ZG+OYFUvzKf/A4pxCDarZYQ=
github.com/developing-today-forks/charm v0.12.7-0.20240312075138-411f9ff4f8ac/go.mod h1:6xzxrach+U21VLDQYKlWRMq+Basc95gD4AQ8v7LLEhE=
github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398 h1:BEOlq80FE03qDV8V077hA18KIwnGPNZe7SGkq1xfwEE=
github.com/developing-today-forks/charm v0.12.7-0.20240312114852-48e1a5469398/go.mod h1:6xzxrach+U21VLDQYKlWRMq+Basc95gD4AQ8v7LLEhE=
github.com/dgraph-io/badger/v3 v3.2103.5 h1:ylPa6qzbjYRQMU6jokoj4wzcaweHylt//CH0AKt0akg=
github.com/dgraph-io/badger/v3 v3.2103.5/go.mod h1:4MPiseMeDQ3FNCYwRbbcBOGJLf5jsE0PPFzRiKjtcdw=
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
Expand Down
17 changes: 12 additions & 5 deletions sources/identity/init.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_21.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt update
apt install -y curl nodejs npm ucspi-tcp unzip
apt install -y curl nodejs npm ucspi-tcp unzip xxd
npm install -g npm@latest
npm --version
node --version
Expand All @@ -55,16 +55,16 @@ else
dpkg -i powershell_7.4.1-1.deb_amd64.deb
apt install -f
fi
cd ~$USER
cd ~
if [ ! -d "code" ]; then
git clone https://github.com/developing-today/code
else
echo "code directory already exists"
fi
cd code/src/identity
chmod +x *.ps1
chmod +x *.ps1 *.sh
./build-libsql.ps1
"CHARM_LINK_URL=$CHARM_LINK_URL" ./provider.sh &
CHARM_LINK_URL="$CHARM_LINK_URL" ./provider.sh &
get_http_status() {
local url=$1
curl -o /dev/null -s -w "%{http_code}\n" "$url"
Expand All @@ -85,7 +85,7 @@ while : ; do
echo "Checking URL: $CHARM_LINK_URL - HTTP status: $http_status"

if [ "$http_status" -eq 405 ]; then
echo "Received 405 code, exiting."
echo "Verified charm link url is working, breaking loop."
break
fi

Expand All @@ -98,6 +98,13 @@ fi
response=$(curl -sL "$CHARM_LINK_URL" --data-urlencode "keys=$(./identity charm keys --simple | tr '\n' ',' | sed 's/,$//')")

if [ -n "$response" ]; then
extracted_value=$(echo "$response" | sed -n 's/.*HTTP\/1\.1 200 \(.*\)\r.*/\1/p')

if [ -n "$extracted_value" ]; then
echo "Unexpected response: $extracted_value"
exit 1
fi

CHARM_LINK=$response
else
echo "Failed to obtain charm link"
Expand Down
40 changes: 21 additions & 19 deletions sources/identity/provider/pages/link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ if [[ "$REQUEST_METHOD" != "POST" ]]; then
return $(status_code 405)
fi
random() {
echo $(dd if=/dev/urandom bs=1 count=64 2>/dev/null | xxd -p)
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"
./identity charm link -d -o "$LINK_CODE_PATH" -keys "${FORM_DATA[$key]}" &

max_wait=60 # seconds
wait_interval=1 # seconds
elapsed_time=0
mkdir -p "$(dirname "$LINK_CODE_PATH")"

while [[ ! -f "$LINK_CODE_PATH" && $elapsed_time -lt $max_wait ]]; do
sleep $wait_interval
((elapsed_time+=wait_interval))
done
~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" > /dev/null 2>&1
max_wait=60 # seconds
wait_interval=1 # seconds
elapsed_time=0

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."
fi
while [[ ! -f "$LINK_CODE_PATH" && $elapsed_time -lt $max_wait ]]; do
sleep $wait_interval
((elapsed_time+=wait_interval))
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."
fi
fi
done

0 comments on commit 5c65210

Please sign in to comment.