@@ -14,8 +14,6 @@ CONFIDENCE_RESOLVER_STATE_URL=${CONFIDENCE_RESOLVER_STATE_URL:=}
1414CONFIDENCE_RESOLVER_STATE_ETAG_URL=${CONFIDENCE_RESOLVER_STATE_ETAG_URL:= }
1515CONFIDENCE_CLIENT_ID=${CONFIDENCE_CLIENT_ID:= }
1616CONFIDENCE_CLIENT_SECRET=${CONFIDENCE_CLIENT_SECRET:= }
17- CONFIDENCE_API_HOST=${CONFIDENCE_API_HOST:= }
18- CONFIDENCE_IAM_HOST=${CONFIDENCE_IAM_HOST:= }
1917NO_DEPLOY=${NO_DEPLOY:= }
2018FORCE_DEPLOY=${FORCE_DEPLOY:= }
2119
@@ -39,7 +37,7 @@ if test -z "$CONFIDENCE_RESOLVER_STATE_URL"; then
3937
4038 # Ensure jq is available for JSON parsing
4139 if ! command -v jq > /dev/null 2>&1 ; then
42- echo " jq is required but not installed. Please install jq (e.g., brew install jq) or provide CONFIDENCE_RESOLVER_STATE_URL. "
40+ echo " jq is required but not installed. Please install jq (e.g., brew install jq) or provide CONFIDENCE_RESOLVER_STATE_URL"
4341 exit 1
4442 fi
4543
@@ -50,79 +48,61 @@ if test -z "$CONFIDENCE_RESOLVER_STATE_URL"; then
5048 fi
5149
5250 fetch_access_token () {
53- local hosts=()
54- if [ -n " $CONFIDENCE_IAM_HOST " ]; then
55- hosts=(" $CONFIDENCE_IAM_HOST " )
51+ local url=" https://iam.confidence.dev/v1/oauth/token"
52+ local resp http_status body token
53+ resp=$( curl -s -w " %{http_code}" -H " Content-Type: application/json" \
54+ -d " {\" clientId\" :\" $CONFIDENCE_CLIENT_ID \" ,\" clientSecret\" :\" $CONFIDENCE_CLIENT_SECRET \" ,\" grantType\" :\" client_credentials\" }" \
55+ " ${url} " )
56+ http_status=" ${resp: -3} "
57+ body=" ${resp% ???} "
58+ if [ " $http_status " -eq 200 ] && [ -n " $body " ]; then
59+ token=$( printf " %s" " $body " | jq -r ' .accessToken // .access_token // empty' )
60+ if [ -n " $token " ]; then
61+ printf " %s" " $token "
62+ return 0
63+ fi
5664 else
57- hosts=( " iam.eu.confidence.dev " " iam.us. confidence.dev" " iam.confidence.dev " )
65+ echo " ⚠️ Failed to request access token from iam.confidence.dev: HTTP ${http_status} " >&2
5866 fi
59-
60- for host in " ${hosts[@]} " ; do
61- local url=" https://${host} /v1/oauth/token"
62- local resp http_status body token
63- resp=$( curl -s -w " %{http_code}" -H " Content-Type: application/json" \
64- -d " {\" clientId\" :\" $CONFIDENCE_CLIENT_ID \" ,\" clientSecret\" :\" $CONFIDENCE_CLIENT_SECRET \" ,\" grantType\" :\" client_credentials\" }" \
65- " ${url} " )
66- http_status=" ${resp: -3} "
67- body=" ${resp% ???} "
68- if [ " $http_status " -eq 200 ] && [ -n " $body " ]; then
69- token=$( printf " %s" " $body " | jq -r ' .accessToken // .access_token // empty' )
70- if [ -n " $token " ]; then
71- printf " %s" " $token "
72- return 0
73- fi
74- else
75- echo " ⚠️ Failed to request access token from ${host} : HTTP ${http_status} " >&2
76- fi
77- done
7867 return 1
7968 }
8069
8170 fetch_resolver_state_url () {
82- local hosts=()
83- if [ -n " $CONFIDENCE_API_HOST " ]; then
84- hosts=(" $CONFIDENCE_API_HOST " )
85- else
86- hosts=(" flags.eu.confidence.dev" " flags.us.confidence.dev" )
87- fi
8871 local token
8972 if ! token=$( fetch_access_token) ; then
9073 echo " ❌ Unable to obtain access token from IAM API"
9174 return 1
9275 fi
9376
9477 # HTTP using REST transcoding
95- for host in " ${hosts[@]} " ; do
96- local url=" https://${host} /v1/resolverState:resolverStateUri"
97- local resp
98- resp=$( curl -s -w " %{http_code}" -H " Authorization: Bearer ${token} " " ${url} " )
99- local http_status=" ${resp: -3} "
100- local body=" ${resp% ???} "
101-
102- if [ " $http_status " -eq 200 ] && [ -n " $body " ]; then
103- local signed_uri
104- signed_uri=$( printf " %s" " $body " | jq -r ' .signedUri // .signed_uri // empty' )
105- if [ -n " $signed_uri " ]; then
106- CONFIDENCE_RESOLVER_STATE_URL=" $signed_uri "
107- echo " ⤵️ Retrieved resolver state URL from ${host} "
108- return 0
109- fi
110- else
111- echo " ⚠️ Failed to fetch resolver state URL from ${host} : HTTP ${http_status} " >&2
78+ local url=" https://flags.confidence.dev/v1/resolverState:resolverStateUri"
79+ local resp
80+ resp=$( curl -s -w " %{http_code}" -H " Authorization: Bearer ${token} " " ${url} " )
81+ local http_status=" ${resp: -3} "
82+ local body=" ${resp% ???} "
83+
84+ if [ " $http_status " -eq 200 ] && [ -n " $body " ]; then
85+ local signed_uri
86+ signed_uri=$( printf " %s" " $body " | jq -r ' .signedUri // .signed_uri // empty' )
87+ if [ -n " $signed_uri " ]; then
88+ CONFIDENCE_RESOLVER_STATE_URL=" $signed_uri "
89+ echo " ⤵️ Retrieved resolver state URL from flags.confidence.dev"
90+ return 0
11291 fi
113- done
114-
92+ else
93+ echo " ⚠️ Failed to fetch resolver state URL from flags.confidence.dev: HTTP ${http_status} " >&2
94+ fi
11595 return 1
11696 }
11797
11898 if ! fetch_resolver_state_url; then
119- echo " ❌ Unable to obtain resolver state URL from API. Please set CONFIDENCE_RESOLVER_STATE_URL explicitly. "
99+ echo " ❌ Unable to obtain resolver state URL from API. Please set CONFIDENCE_RESOLVER_STATE_URL explicitly"
120100 exit 1
121101 fi
122102fi
123103
124104echo " Starting CloudFlare deployment for $CONFIDENCE_ACCOUNT_ID "
125- echo " CloudFlare API token: ${CLOUDFLARE_API_TOKEN: 0: 5} ... "
105+ echo " CloudFlare API token: ${CLOUDFLARE_API_TOKEN: 0: 5} .."
126106echo " CloudFlare account ID: $CLOUDFLARE_ACCOUNT_ID "
127107
128108mkdir -p data
@@ -149,24 +129,24 @@ if [ -n "$CONFIDENCE_RESOLVER_STATE_ETAG_URL" ]; then
149129 if [ -n " $PREV_ETAG " ]; then
150130 echo " ⤵️ Previous ETag from resolver: $PREV_ETAG "
151131 else
152- echo " ⚠️Resolver returned empty ETag. "
132+ echo " ⚠️Resolver returned empty ETag"
153133 fi
154134 if [ -n " $PREV_DEPLOYER_VERSION " ]; then
155135 echo " ⤵️ Previous Resolver Version from resolver: $PREV_DEPLOYER_VERSION "
156136 else
157- echo " ⚠️ Previous Resolver Version empty from resolver. "
137+ echo " ⚠️ Previous Resolver Version empty from resolver"
158138 fi
159139 else
160140 PREV_ETAG=$( tr -d ' \r' < " $ETAG_BODY_TMP " )
161141 PREV_ETAG=$( echo -n " $PREV_ETAG " | tr -d ' \n' )
162142 if [ -n " $PREV_ETAG " ]; then
163143 echo " ⤵️ Previous ETag from resolver: $PREV_ETAG "
164144 else
165- echo " ⚠️ Resolver returned empty ETag. "
145+ echo " ⚠️ Resolver returned empty ETag"
166146 fi
167147 fi
168148 else
169- echo " ❌ Could not fetch ETag from resolver (HTTP $ETAG_STATUS ). "
149+ echo " ❌ Could not fetch ETag from resolver (HTTP $ETAG_STATUS )"
170150 fi
171151 rm -f " $ETAG_BODY_TMP "
172152fi
@@ -177,10 +157,10 @@ if [ -n "${COMMIT_SHA:-}" ]; then
177157 DEPLOYER_VERSION=" $( printf ' %s' " $COMMIT_SHA " | tr -d ' \n' | cut -c1-12) "
178158 echo " 🔖 Deployer version (env): ${DEPLOYER_VERSION} "
179159elif command -v git > /dev/null 2>&1 ; then
180- if DEPLOYER_VERSION=$( git -C .. rev-parse --short=12 HEAD 2> /dev/null) ; then
160+ if DEPLOYER_VERSION=$( git rev-parse --short=12 HEAD 2> /dev/null) ; then
181161 echo " 🐙 Deployer version (commit): ${DEPLOYER_VERSION} "
182162 else
183- echo " ❌ git rev-parse failed. "
163+ echo " ❌ git rev-parse failed"
184164 fi
185165else
186166 echo " ❌ git not found in PATH and COMMIT_SHA not set"
189169
190170# If version changed, force download to bypass ETag and ensure fresh deploy
191171if [ -n " $PREV_DEPLOYER_VERSION " ] && [ -n " $DEPLOYER_VERSION " ] && [ " $PREV_DEPLOYER_VERSION " != " $DEPLOYER_VERSION " ]; then
192- echo " ☑️ Deployer version changed ($PREV_DEPLOYER_VERSION -> $DEPLOYER_VERSION ); forcing state download and redeploy. "
172+ echo " ☑️ Deployer version changed ($PREV_DEPLOYER_VERSION -> $DEPLOYER_VERSION ); forcing state download and redeploy"
193173 FORCE_DEPLOY=1
194174fi
195175
@@ -198,20 +178,20 @@ if [ -n "$PREV_ETAG" ]; then
198178 EXTRA_HEADER+=(" -H" " If-None-Match: $PREV_ETAG " )
199179 echo " Using If-None-Match: $PREV_ETAG "
200180 else
201- echo " ⚠️ FORCE_DEPLOY is set; ignoring existing ETag. "
181+ echo " ⚠️ FORCE_DEPLOY is set; ignoring existing ETag"
202182 fi
203183fi
204184
205185TMP_HEADER=$( mktemp)
206186HTTP_STATUS=$( curl -sS -w " %{http_code}" -D " $TMP_HEADER " -o " $RESPONSE_FILE " ${EXTRA_HEADER[@]+" ${EXTRA_HEADER[@]} " } " $CONFIDENCE_RESOLVER_STATE_URL " )
207187
208188if [ " $HTTP_STATUS " = " 304" ]; then
209- echo " ✅ Resolver state not modified (HTTP 304). Skipping the deployment. "
189+ echo " ✅ Resolver state not modified (HTTP 304). Skipping the deployment"
210190 # No changes; keep previous ETag
211191 rm -f " $TMP_HEADER "
212192 exit 0
213193elif [ " $HTTP_STATUS " = " 200" ]; then
214- echo " ✅ Download of resolver state successful. "
194+ echo " ✅ Download of resolver state successful"
215195 # Extract ETag and normalize
216196 ETAG_RAW=$( awk -F' : ' ' tolower($1)=="etag"{print $2}' " $TMP_HEADER " | tr -d ' \r' )
217197 rm -f " $TMP_HEADER "
@@ -221,13 +201,13 @@ elif [ "$HTTP_STATUS" = "200" ]; then
221201 ETAG_TOML=$( printf ' %s' " $ETAG_STRIPPED " | sed ' s/\\/\\\\/g; s/\"/\\\"/g' )
222202 fi
223203else
224- echo " ❌ Error downloading resolver state: HTTP status code $HTTP_STATUS . "
204+ echo " ❌ Error downloading resolver state: HTTP status code $HTTP_STATUS "
225205 # Print response body if the file is not empty
226206 if [ -s " $RESPONSE_FILE " ]; then
227207 echo " Server response:"
228208 cat " $RESPONSE_FILE "
229209 else
230- echo " No response body received. "
210+ echo " No response body received"
231211 fi
232212 rm -f " $TMP_HEADER "
233213 exit 1
@@ -242,7 +222,7 @@ check_file() {
242222 echo " ❌ Error: $1 was not created or is empty!" >&2
243223 exit 1
244224 else
245- echo " ✅ $1 exists and is not empty. "
225+ echo " ✅ $1 exists and is not empty"
246226 fi
247227}
248228
@@ -251,7 +231,7 @@ check_file "data/resolver_state_current.pb"
251231check_file " data/account_id"
252232check_file " data/encryption_key"
253233
254- echo " All files successfully created and verified. 🚀 "
234+ echo " 🚀 All files successfully created and verified"
255235
256236cd confidence-cloudflare-resolver
257237
@@ -264,7 +244,7 @@ if [ -n "$CLOUDFLARE_ACCOUNT_ID" ]; then
264244 mv " $tmpfile " wrangler.toml
265245 echo " ✅ account_id set to \" $CLOUDFLARE_ACCOUNT_ID \" in wrangler.toml"
266246else
267- echo " ⚠️ CLOUDFLARE_ACCOUNT_ID environment variable is not set. This is required if the CloudFlare API token is of type Account, while User tokens with the correct permissions don't need this env variable set. "
247+ echo " ⚠️ CLOUDFLARE_ACCOUNT_ID environment variable is not set. This is required if the CloudFlare API token is of type Account, while User tokens with the correct permissions don't need this env variable set"
268248fi
269249
270250# Prepare ALLOWED_ORIGIN for TOML (escape quotes and backslashes)
0 commit comments