Skip to content

Commit 063b10a

Browse files
WIP 8
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 50d199a commit 063b10a

25 files changed

Lines changed: 171 additions & 949 deletions

utils/shared/handle_api_url.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Shared handler for API_URL environment variable
3+
# Sets API_URL to default localhost if not provided
4+
# Usage: . ./utils/shared/handle_api_url.sh
5+
6+
if [ -z "$API_URL" ]
7+
then
8+
export API_URL="http://localhost:5001"
9+
fi

utils/shared/handle_auth.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Shared handler for authentication (TOKEN + XACL)
3+
# Sources both handle_token.sh and handle_xacl.sh
4+
# Usage: . ./utils/shared/handle_auth.sh
5+
6+
# Get the directory where this script is located
7+
SHARED_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
# Source token and XACL handlers
10+
. "$SHARED_DIR/handle_token.sh"
11+
. "$SHARED_DIR/handle_xacl.sh"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Shared handler for curl execution with DEBUG support
3+
# Expects variables: API (curl URL), CURL_CMD (curl command), USE_JQ (true/false)
4+
# Usage:
5+
# API="https://example.com/api"
6+
# CURL_CMD="curl -s -XGET -H \"Content-Type: application/json\""
7+
# USE_JQ=true
8+
# . ./utils/shared/handle_curl_execution.sh
9+
10+
if [ -z "$API" ] || [ -z "$CURL_CMD" ]
11+
then
12+
echo "Error: API and CURL_CMD variables must be set before sourcing handle_curl_execution.sh"
13+
exit 1
14+
fi
15+
16+
# Build full curl command
17+
FULL_CURL_CMD="${CURL_CMD} \"${API}\""
18+
19+
if [ ! -z "$DEBUG" ]
20+
then
21+
echo "$FULL_CURL_CMD"
22+
eval $FULL_CURL_CMD
23+
else
24+
if [ "$USE_JQ" = "true" ]
25+
then
26+
eval $FULL_CURL_CMD | jq -r '.'
27+
else
28+
eval $FULL_CURL_CMD
29+
fi
30+
fi

utils/shared/handle_token.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Shared handler for TOKEN environment variable
3+
# Reads from token.secret if TOKEN not already set
4+
# Exits with error code 1 if token cannot be obtained
5+
# Usage: . ./utils/shared/handle_token.sh
6+
7+
if [ -z "$TOKEN" ]
8+
then
9+
TOKEN="$(cat ./token.secret 2>/dev/null || echo '')"
10+
fi
11+
12+
if [ -z "$TOKEN" ]
13+
then
14+
echo "$0: TOKEN not specified and unable to obtain one"
15+
exit 1
16+
fi

utils/shared/handle_xacl.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Shared handler for XACL environment variable
3+
# Reads from x-acl.secret if XACL not already set
4+
# Exits with error code 2 if XACL cannot be obtained
5+
# Usage: . ./utils/shared/handle_xacl.sh
6+
7+
if [ -z "$XACL" ]
8+
then
9+
XACL="$(cat ./x-acl.secret 2>/dev/null || echo '')"
10+
fi
11+
12+
if [ -z "$XACL" ]
13+
then
14+
echo "$0: XACL not specified and unable to obtain one"
15+
exit 2
16+
fi

utils/v3/COMPLETE_CURL_SCRIPTS_SUMMARY.md

Lines changed: 0 additions & 146 deletions
This file was deleted.

utils/v3/README.md

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)