Skip to content

Commit

Permalink
Merge pull request #30 from RedHatProductSecurity/download-script
Browse files Browse the repository at this point in the history
minor - script for schema download
  • Loading branch information
JakubFrejlach authored Oct 18, 2023
2 parents 9710a18 + 7043bc3 commit 1e62dfd
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 "main")
get_schema() {
local version=${1:-main}

echo "Downloading Component 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 1e62dfd

Please sign in to comment.