Improve template detection

This commit is contained in:
Guillaume Delacour 2020-06-26 21:43:44 +02:00
parent f1d1b1cbe2
commit eb8cf40bf5
No known key found for this signature in database
GPG key ID: 9986518B9AAAA0A5
4 changed files with 49 additions and 3 deletions

View file

@ -0,0 +1,16 @@
{
"Resources" : {
"myDNSRecord" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"HostedZoneId" : "Z8VLZEXAMPLE",
"Name" : "test.example.com",
"ResourceRecords" : [
"192.0.2.99"
],
"Ttl" : 300,
"Type" : "A"
}
}
}
}

View file

@ -0,0 +1,16 @@
{
"Resources" : {
"myDNSRecord" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"HostedZoneId" : "Z8VLZEXAMPLE",
"Name" : "test.example.com",
"ResourceRecords" : [
"192.0.2.99"
],
"TTL" : 300,
"Type" : "A"
}
}
}
}

View file

@ -53,7 +53,7 @@ RUN mkdir -p /opt/microsoft/powershell/7 \
# Run Pip3 Installs #
#####################
RUN pip3 --no-cache-dir install --upgrade --no-cache-dir \
yamllint pylint yq cfn-lint
yamllint pylint yq cfn-lint shyaml
####################
# Run NPM Installs #

View file

@ -616,11 +616,25 @@ DetectOpenAPIFile()
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html
DetectCloudFormationFile()
{
# AWSTemplateFormatVersion is optional
# grep -E '("|)AWSTemplateFormatVersion("|):'
if grep 'AWSTemplateFormatVersion' "${1}" > /dev/null; then
return 0
else
return 1
fi
if cat "${1}" | shyaml --quiet get-type AWSTemplateFormatVersion > /dev/null; then
return 0
fi
if cat "${1}" | jq -e 'has("Resources")' > /dev/null 2>&1; then
if cat "${1}" | jq ".Resources[].Type" 2>/dev/null | grep -q -E "(AWS|Alexa|Custom)"; then
return 0
fi
fi
if cat "${1}" | shyaml values-0 Resources | grep -q -E "Type: (AWS|Alexa|Custom)"; then
return 0
fi
return 1
}
################################################################################