Repository navigation
Expand file tree
/
Copy pathapply.sh
More file actions
executable file
·84 lines (72 loc) · 2.44 KB
/
Copy pathapply.sh
File metadata and controls
executable file
·84 lines (72 loc) · 2.44 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
. "$ROOT_DIR/scripts/registry.sh"
registry_initialize "$@"
create_group() {
local group_id="$1"
local payload
payload="$(jq -n --arg groupId "$group_id" '{ groupId: $groupId }')"
registry_request POST "$REGISTRY_API/groups" application/json <<< "$payload"
case "$REGISTRY_STATUS" in
200 | 204 | 409) ;;
*)
registry_fail "Failed to create registry group $group_id" ;;
esac
}
publish_grpc_artifact() {
local group_id="$1"
local artifact_id="$2"
local artifact_path="$SCHEMA_DIR/$3"
local payload
create_group "$group_id"
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" application/json <<< "$payload"
case "$REGISTRY_STATUS" in
200)
echo "[SchemaRegistry]: applied - $group_id/$artifact_id" ;;
*)
registry_fail "Failed to apply $group_id/$artifact_id" ;;
esac
}
publish_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/subjects/$subject/versions" \
"application/vnd.schemaregistry.v1+json" <<< "$payload"
case "$REGISTRY_STATUS" in
200)
echo "[SchemaRegistry]: applied - $subject" ;;
409)
registry_fail "Incompatible schema for subject $subject" ;;
*)
registry_fail "Failed to apply $subject" ;;
esac
}
while IFS=$'\t' read -r group_id artifact_id protocol path; do
if [ "$protocol" = "kafka" ]; then
publish_kafka_subject "$artifact_id" "$path"
else
publish_grpc_artifact "$group_id" "$artifact_id" "$path"
fi
done < <(jq -r '.artifacts[] | [.groupId, .artifactId, .protocol, .path] | @tsv' "$CATALOG_FILE")