Skip to content

Commit

Permalink
Add script for schema download from specified ref
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubFrejlach committed Oct 18, 2023
1 parent 9710a18 commit 5aec86f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions scripts/download_schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# download OpenAPI schema file from specified ref

source scripts/helpers.sh

get_schema ${1}
17 changes: 17 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5aec86f

Please sign in to comment.