Skip to content

chore: Update how we download CFN documentation #3406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ prepare-companion-stack:
fetch-schema-data:
mkdir -p .tmp

curl -o .tmp/cfn-docs.json https://github.com/raw/aws/aws-cdk/main/packages/%40aws-cdk/cfnspec/spec-source/cfn-docs/cfn-docs.json
# aws-cdk updated where they store the cfn doc json files. See https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cfnspec/README.md
bin/git_lfs_download.sh "https://github.com/raw/cdklabs/awscdk-service-spec/main/sources/CloudFormationDocumentation/CloudFormationDocumentation.json"

curl -o .tmp/cloudformation.schema.json https://github.com/raw/awslabs/goformation/master/schema/cloudformation.schema.json

Expand Down
38 changes: 38 additions & 0 deletions bin/git_lfs_download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eux

# Here is the reference I found on how to download Git LFS file
# https://gist.github.com/fkraeutli/66fa741d9a8c2a6a238a01d17ed0edc5#retrieving-lfs-files

# Check if a URL parameter is provided
if [ $# -eq 0 ]; then
echo "Script Usage: $0 <URL>"
exit 1
fi

# Get the URL from the first command-line parameter
url="$1"

# Fetch the metadata from the URL
response=$(curl -s "$url")

# Extract oid and size from the metadata
oid=$(echo "$response" | grep '^oid' | cut -d: -f2)
size=$(echo "$response" | grep 'size' | cut -d ' ' -f 2)

# String interpolation to create the request JSON content
request_json=$(jq -nc --arg oid "$oid" --argjson size "$size" '{"operation":"download","objects":[{"oid":$oid,"size":$size}],"transfers":["basic"]}')

# Send a POST request to Git LFS with the retrieved metadata JSON content
response=$(curl \
-X POST \
-H "Accept: application/vnd.git-lfs+json" \
-H "Content-type: application/json" \
-d "$request_json" \
https://github.com/cdklabs/awscdk-service-spec.git/info/lfs/objects/batch)

# The above command should return a JSON object that tells you where the file is stored
href=$(echo "$response" | jq -r '.objects[0].actions.download.href')

# Download the file and store it in .tmp/cfn-docs.json
curl -o .tmp/cfn-docs.json $href
Loading