-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfillArgoGithubCredentials.sh
More file actions
executable file
·57 lines (46 loc) · 1.86 KB
/
Copy pathfillArgoGithubCredentials.sh
File metadata and controls
executable file
·57 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Input validation
if [ "$#" -ne 6 ]; then
echo "Error: Required arguments missing"
echo "Usage: $0 CREDENTIALS_NAME ORGANIZATION_URL APP_ID INSTALLATION_ID APP_PRIVATE_KEY_PATH ARGOCD_CONFIG_REPO_URL"
exit 1
fi
TEMPLATE_PATH="./config/argocd/github-credentials-template.yaml"
CREDENTIALS_NAME=$1
ORGANIZATION_URL=$2
APP_ID=$3
INSTALLATION_ID=$4
APP_PRIVATE_KEY_PATH=$5
ARGOCD_CONFIG_REPO_URL=$6
# Validate template exists
if [ ! -f "$TEMPLATE_PATH" ]; then
echo "Error: Template file $TEMPLATE_PATH not found"
exit 1
fi
if [ ! -f "./addons/self-hosted.yaml" ]; then
echo "Error: Template file ./addons/self-hosted.yaml not found"
exit 1
fi
# Validate private key exists
if [ ! -f "$APP_PRIVATE_KEY_PATH" ]; then
echo "Error: Private key file $APP_PRIVATE_KEY_PATH not found"
exit 1
fi
# Read template for credentials
template=$(cat "$TEMPLATE_PATH")
# Base64 encode values
ORGANIZATION_URL_B64=$(echo -n "$ORGANIZATION_URL" | base64)
APP_ID_B64=$(echo -n "$APP_ID" | base64)
INSTALLATION_ID_B64=$(echo -n "$INSTALLATION_ID" | base64)
APP_PRIVATE_KEY_B64=$(cat "$APP_PRIVATE_KEY_PATH" | base64 | tr -d '\n')
# Replace placeholders
echo "$template" | \
awk -v creds="$CREDENTIALS_NAME" '{gsub(/\${CREDENTIALS_NAME}/, creds); print}' | \
awk -v org="$ORGANIZATION_URL_B64" '{gsub(/\${ORGANIZATION_URL}/, org); print}' | \
awk -v appid="$APP_ID_B64" '{gsub(/\${APP_ID}/, appid); print}' | \
awk -v instid="$INSTALLATION_ID_B64" '{gsub(/\${INSTALLATION_ID}/, instid); print}' | \
awk -v key="$APP_PRIVATE_KEY_B64" '{gsub(/\${APP_PRIVATE_KEY}/, key); print}' > ./config/argocd/main-github-credentials.yaml
# Read template for self-hosted argocd
self_hosted_template=$(cat "./addons/self-hosted.yaml")
echo "$self_hosted_template" | \
awk -v key="$ARGOCD_CONFIG_REPO_URL" '{gsub(/\${ARGOCD_CONFIG_REPO_URL}/, key); print}' > ./addons/self-hosted.yaml