Skip to content

Commit f83a8e5

Browse files
nizar-mshahidhk
authored andcommitted
rename access-key to admin-secret (close hasura#1347) (hasura#1540)
Rename the admin secret key header used to access GraphQL engine from X-Hasura-Access-Key to X-Hasura-Admin-Secret. Server CLI and console all support the older flag but marks it as deprecated.
1 parent 51dd615 commit f83a8e5

File tree

143 files changed

+1256
-653
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+1256
-653
lines changed

.circleci/config.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ refs:
9696
GRAPHQL_ENGINE: '/build/_server_output/graphql-engine'
9797
command: |
9898
apt-get update
99-
apt install --yes jq
99+
apt install --yes jq curl
100100
OUTPUT_FOLDER=/build/_server_test_output/$PG_VERSION .circleci/test-server.sh
101101
- run:
102102
name: Generate coverage report
@@ -214,6 +214,37 @@ jobs:
214214
- image: circleci/postgres:9.5-alpine-postgis
215215
<<: *test_pg_env
216216

217+
test_cli_with_last_release:
218+
docker:
219+
- image: hasura/graphql-engine-cli-builder:v0.3
220+
- image: circleci/postgres:10-alpine
221+
environment:
222+
POSTGRES_USER: gql_test
223+
POSTGRES_DB: gql_test
224+
working_directory: /go/src/github.com/hasura/graphql-engine
225+
steps:
226+
- checkout
227+
- attach_workspace:
228+
at: /build
229+
- restore_cache:
230+
keys:
231+
- cli-vendor-{{ checksum "cli/Gopkg.toml" }}-{{ checksum "cli/Gopkg.lock" }}
232+
- run:
233+
name: get cli dependencies
234+
working_directory: cli
235+
command: make deps
236+
- save_cache:
237+
key: cli-vendor-{{ checksum "cli/Gopkg.toml" }}-{{ checksum "cli/Gopkg.lock" }}
238+
paths:
239+
- cli/vendor
240+
- *wait_for_postgres
241+
- run:
242+
name: test cli
243+
command: .circleci/test-cli-with-last-release.sh
244+
- store_artifacts:
245+
path: /build/_cli_output
246+
destination: cli
247+
217248
# test and build cli
218249
test_and_build_cli:
219250
docker:
@@ -350,6 +381,8 @@ workflows:
350381
- pytest_server_pg_10.6
351382
- pytest_server_pg_9.6
352383
- pytest_server_pg_9.5
384+
- test_cli_with_last_release:
385+
<<: *filter_only_vtags
353386
- test_and_build_cli:
354387
<<: *filter_only_vtags
355388
requires:
@@ -358,6 +391,7 @@ workflows:
358391
<<: *filter_only_vtags
359392
requires:
360393
- test_and_build_cli
394+
- test_cli_with_last_release
361395
- deploy:
362396
<<: *filter_only_vtags_dev_release_branches
363397
requires:

.circleci/deploy.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ setup_gcloud() {
103103
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
104104
}
105105

106+
# push the server binary to google cloud storage
107+
push_server_binary() {
108+
gsutil cp /build/_server_output/graphql-engine \
109+
gs://graphql-engine-cdn.hasura.io/server/latest/linux-amd64
110+
}
111+
106112
# skip deploy for pull requests
107113
if [[ -n "${CIRCLE_PR_NUMBER:-}" ]]; then
108114
echo "not deploying for PRs"
@@ -134,6 +140,7 @@ deploy_console
134140
deploy_server
135141
if [[ ! -z "$CIRCLE_TAG" ]]; then
136142
deploy_server_latest
143+
push_server_binary
137144
build_and_push_cli_migrations_image
138145
CHANGELOG_TEXT=$(changelog server)
139146
CHANGELOG_TEXT+=$(changelog cli)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
CLI_ROOT="${BASH_SOURCE[0]%/*}/../cli"
6+
7+
wait_for_port() {
8+
local PORT=$1
9+
echo "waiting for $PORT"
10+
for i in `seq 1 60`;
11+
do
12+
nc -z localhost $PORT && echo "port $PORT is ready" && return
13+
echo -n .
14+
sleep 1
15+
done
16+
echo "Failed waiting for $PORT" && exit 1
17+
}
18+
19+
# get latest cli
20+
wget -O /bin/graphql-engine https://graphql-engine-cdn.hasura.io/server/latest/linux-amd64
21+
chmod +x /bin/graphql-engine
22+
23+
cd "$CLI_ROOT"
24+
mkdir -p /build/_cli_output
25+
touch /build/_cli_output/server-last-release.log
26+
touch /build/_cli_output/server-last-release-secret.log
27+
28+
# start graphql-engine without admin secret
29+
/bin/graphql-engine \
30+
--database-url postgres://gql_test@localhost:5432/gql_test serve > /build/_cli_output/server-last-release.log 2>&1 &
31+
PID=$!
32+
33+
wait_for_port 8080
34+
35+
# test cli
36+
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" make test
37+
38+
# kill the running server
39+
kill $PID
40+
41+
# start graphql-engine with admin secret
42+
psql -U gql_test -h localhost -c 'CREATE DATABASE "gql_test_with_admin_secret";'
43+
/bin/graphql-engine \
44+
--database-url postgres://gql_test@localhost:5432/gql_test_with_admin_secret serve --access-key "abcd" > /build/_cli_output/server-last-release-secret.log 2>&1 &
45+
PID=$!
46+
47+
wait_for_port 8080
48+
49+
# test cli
50+
GOCACHE=off HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd" make test
51+
kill $PID

.circleci/test-cli.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ wait_for_port() {
1919
cd "$CLI_ROOT"
2020
mkdir -p /build/_cli_output
2121
touch /build/_cli_output/server.log
22+
touch /build/_cli_output/server-secret.log
2223

23-
# start graphql-engine without access key
24+
# start graphql-engine without admin secret
2425
/build/_server_output/graphql-engine \
2526
--database-url postgres://gql_test@localhost:5432/gql_test serve > /build/_cli_output/server.log 2>&1 &
2627
PID=$!
@@ -31,14 +32,14 @@ wait_for_port 8080
3132
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" make test
3233
kill $PID
3334

34-
# start graphql-engine with access key
35-
psql -U gql_test -h localhost -c 'CREATE DATABASE "gql_test_with_access";'
35+
# start graphql-engine with admin secret
36+
psql -U gql_test -h localhost -c 'CREATE DATABASE "gql_test_with_admin_secret";'
3637
/build/_server_output/graphql-engine \
37-
--database-url postgres://gql_test@localhost:5432/gql_test_with_access serve --access-key "abcd" > /build/_cli_output/server.log 2>&1 &
38+
--database-url postgres://gql_test@localhost:5432/gql_test_with_admin_secret serve --admin-secret "abcd" > /build/_cli_output/server-secret.log 2>&1 &
3839
PID=$!
3940

4041
wait_for_port 8080
4142

4243
# test cli
43-
GOCACHE=off HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" HASURA_GRAPHQL_TEST_ACCESS_KEY="abcd" make test
44+
GOCACHE=off HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd" make test
4445
kill $PID
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CIRCLECI_FOLDER="${BASH_SOURCE[0]%/*}"
5+
cd $CIRCLECI_FOLDER
6+
CIRCLECI_FOLDER="$PWD"
7+
8+
SERVER_ROOT="$CIRCLECI_FOLDER/../server"
9+
10+
i=1
11+
echoInfo() {
12+
echo -e "\033[36m$i. $*\033[0m"
13+
i=$[i+1]
14+
}
15+
16+
fail_if_port_busy() {
17+
local PORT=$1
18+
if nc -z localhost $PORT ; then
19+
echo "Port $PORT is busy. Exiting"
20+
exit 1
21+
fi
22+
}
23+
24+
wait_for_port() {
25+
local PORT=$1
26+
echo "waiting for $PORT"
27+
for _ in $(seq 1 30);
28+
do
29+
nc -z localhost $PORT && echo "port $PORT is ready" && return
30+
echo -n .
31+
sleep 0.2
32+
done
33+
echo "Failed waiting for $PORT" && exit 1
34+
}
35+
36+
test_export_metadata_with_access_key() {
37+
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Access-Key: $1" > /dev/null
38+
}
39+
40+
cd $SERVER_ROOT
41+
42+
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
43+
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
44+
exit 1
45+
fi
46+
47+
if ! stack --allow-different-user exec -- which graphql-engine > /dev/null && [ -z "${GRAPHQL_ENGINE:-}" ] ; then
48+
echo "Do 'stack build' before tests, or export the location of executable in the GRAPHQL_ENGINE envirnoment variable"
49+
exit 1
50+
fi
51+
52+
GRAPHQL_ENGINE=${GRAPHQL_ENGINE:-"$(stack --allow-different-user exec -- which graphql-engine)"}
53+
if ! [ -x "$GRAPHQL_ENGINE" ] ; then
54+
echo "$GRAPHQL_ENGINE is not present or is not an executable"
55+
exit 1
56+
fi
57+
58+
HGE_PID=""
59+
60+
run_hge_with_flags() {
61+
fail_if_port_busy 8080
62+
set -x
63+
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* > "$OUTPUT_FOLDER/graphql-engine.log" & HGE_PID=$!
64+
set +x
65+
wait_for_port 8080
66+
}
67+
68+
kill_hge() {
69+
kill $HGE_PID || true
70+
wait $HGE_PID || true
71+
}
72+
73+
trap kill_hge ERR
74+
trap kill_hge INT
75+
76+
OUTPUT_FOLDER=${OUTPUT_FOLDER:-"$CIRCLECI_FOLDER/test-server-flags-output"}
77+
mkdir -p "$OUTPUT_FOLDER"
78+
79+
################### Test deprecated flag --access-key
80+
81+
key="HGE$RANDOM$RANDOM"
82+
83+
run_hge_with_flags --access-key="$key"
84+
85+
echoInfo "Test deprecated flag --access-key=XXXX"
86+
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null
87+
test_export_metadata_with_access_key "$key"
88+
89+
kill_hge
90+
91+
################## Test deprecated EnvVar HASURA_GRAPHQL_ACCESS_KEY=XXXX
92+
93+
key="HGE$RANDOM$RANDOM"
94+
95+
export HASURA_GRAPHQL_ACCESS_KEY="$key"
96+
97+
run_hge_with_flags
98+
99+
echoInfo "Test deprecated EnvVar HASURA_GRAPHQL_ACCESS_KEY=XXXX"
100+
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
101+
test_export_metadata_with_access_key "$key"
102+
103+
kill_hge
104+
105+
unset $HASURA_GRAPHQL_ACCESS_KEY

0 commit comments

Comments
 (0)