Repository navigation
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·90 lines (80 loc) · 2.93 KB
/
Copy pathverify.sh
File metadata and controls
executable file
·90 lines (80 loc) · 2.93 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
. "$ROOT_DIR/scripts/registry.sh"
registry_initialize "$@"
verify_grpc_artifact() {
local group_id="$1"
local artifact_id="$2"
local artifact_path="$SCHEMA_DIR/$3"
local payload
registry_request GET "$REGISTRY_API/groups/$group_id" application/json
case "$REGISTRY_STATUS" in
200) ;;
404)
if jq -e '.name == "GroupNotFoundException"' <<< "$REGISTRY_BODY" >/dev/null; then
echo "[SchemaRegistry]: new group - $group_id/$artifact_id"
return
fi
registry_fail "Failed to find registry group $group_id" ;;
*)
registry_fail "Failed to find registry group $group_id" ;;
esac
payload="$(
jq -n \
--arg artifactId "$artifact_id" \
--rawfile content "$artifact_path" \
'{
artifactId: $artifactId,
artifactType: "PROTOBUF",
firstVersion: {
content: {
content: $content,
contentType: "text/plain"
}
}
}'
)"
registry_request POST "$REGISTRY_API/groups/$group_id/artifacts?ifExists=FIND_OR_CREATE_VERSION&canonical=true&dryRun=true" application/json <<< "$payload"
case "$REGISTRY_STATUS" in
200)
echo "[SchemaRegistry]: verified - $group_id/$artifact_id" ;;
*)
registry_fail "Failed to verify $group_id/$artifact_id" ;;
esac
}
verify_kafka_subject() {
local subject="$1"
local artifact_path="$SCHEMA_DIR/$2"
local payload
payload="$(
jq -n \
--rawfile content "$artifact_path" \
'{ schema: $content, schemaType: "JSON" }'
)"
registry_request POST "$REGISTRY_CCOMPAT/compatibility/subjects/$subject/versions/latest" \
"application/vnd.schemaregistry.v1+json" <<< "$payload"
case "$REGISTRY_STATUS" in
404)
if jq -e '.error_code == 40401' <<< "$REGISTRY_BODY" >/dev/null; then
echo "[SchemaRegistry]: new subject - $subject"
else
registry_fail "Failed to find subject $subject"
fi ;;
200)
if jq -e '.is_compatible == true' <<< "$REGISTRY_BODY" >/dev/null; then
echo "[SchemaRegistry]: verified - $subject"
else
registry_fail "Incompatible schema for subject $subject"
fi ;;
*)
registry_fail "Failed to verify $subject" ;;
esac
}
while IFS=$'\t' read -r group_id artifact_id protocol path; do
if [ "$protocol" = "kafka" ]; then
verify_kafka_subject "$artifact_id" "$path"
else
verify_grpc_artifact "$group_id" "$artifact_id" "$path"
fi
done < <(jq -r '.artifacts[] | [.groupId, .artifactId, .protocol, .path] | @tsv' "$CATALOG_FILE")