From 25afc81647edeef38d9c4536c6b6c37195cb2049 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Wed, 18 Oct 2023 10:20:58 +0200 Subject: [PATCH] Add script for schema download from specified ref --- Makefile | 4 ++++ scripts/download_schema.sh | 6 ++++++ scripts/helpers.sh | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100755 scripts/download_schema.sh diff --git a/Makefile b/Makefile index b9e67dc..e0e21ca 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,10 @@ sync-deps: @echo ">synchronizing python dependencies" $(ps) requirements.txt devel-requirements.txt $$([ -f local-requirements.txt ] && echo 'local-requirements.txt') +download-schema: + @echo ">downloading Component Registry OpenAPI schema for ref \"$(ref)\"" + scripts/download_schema.sh $(ref) + patch-release: @echo ">preparing patch release" scripts/patch_release.sh diff --git a/scripts/download_schema.sh b/scripts/download_schema.sh new file mode 100755 index 0000000..20f26e3 --- /dev/null +++ b/scripts/download_schema.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# download OpenAPI schema file from specified ref + +source scripts/helpers.sh + +get_schema ${1} diff --git a/scripts/helpers.sh b/scripts/helpers.sh index fa565aa..3cefb39 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -119,3 +119,20 @@ review() { fi echo } + +# Get OpenAPI schema from github API +# $1: version (defaults to "master") +get_schema() { + local version=${1:-master} + + echo "Downloading Comopnent Registry schema version " + local response=$(curl -s "https://raw.githubusercontent.com/RedHatProductSecurity/component-registry/${version}/openapi.yml" \ + -o component_registry_bindings/openapi_schema.yml -f -w 'HTTPSTATUS:%{http_code}\n') + + local status=$(echo ${response} | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/') + + if [ ! ${status} -eq 200 ]; then + echo "Error accessing \"https://raw.githubusercontent.com/RedHatProductSecurity/component-registry/${version}/openapi.yml\" [HTTP status: ${status}]" + exit 1 + fi +}