File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11version : 2
2- module_version : 5.4.1
2+ module_version : 5.4.2
33
44tests :
55 - name : AMD64-based workerpool
Original file line number Diff line number Diff line change @@ -65,12 +65,26 @@ spacelift () {(
6565 echo " Making the Spacelift launcher executable" >> /var/log/spacelift/info.log
6666 chmod 755 /usr/bin/spacelift-launcher 2>> /var/log/spacelift/error.log
6767
68+ validate_metadata () {
69+ local value=" $1 "
70+ local name=" $2 "
71+ if [[ -z " $value " ]] || [[ " $value " == " null" ]] || [[ " $value " == " None" ]]; then
72+ echo " ERROR: $name is null or empty. EC2 metadata service returned invalid data." >> /var/log/spacelift/error.log
73+ return 1
74+ fi
75+ return 0
76+ }
77+
6878 echo " Retrieving EC2 instance id and AMI id" >> /var/log/spacelift/info.log
6979 export SPACELIFT_METADATA_instance_id=$( ec2-metadata --instance-id | cut -d ' ' -f2)
80+ validate_metadata " $SPACELIFT_METADATA_instance_id " " instance_id" || return 1
81+
7082 export SPACELIFT_METADATA_ami_id=$( ec2-metadata --ami-id | cut -d ' ' -f2)
83+ validate_metadata " $SPACELIFT_METADATA_ami_id " " ami_id" || return 1
7184
7285 echo " Retrieving EC2 ASG ID" >> /var/log/spacelift/info.log
7386 export SPACELIFT_METADATA_asg_id=$( aws autoscaling --region=${region} describe-auto-scaling-instances --instance-ids $SPACELIFT_METADATA_instance_id | jq -r ' .AutoScalingInstances[0].AutoScalingGroupName' )
87+ validate_metadata " $SPACELIFT_METADATA_asg_id " " asg_id" || return 1
7488
7589 echo " Starting the Spacelift binary" >> /var/log/spacelift/info.log
7690 /usr/bin/spacelift-launcher 1>> /var/log/spacelift/info.log 2>> /var/log/spacelift/error.log
Original file line number Diff line number Diff line change @@ -77,11 +77,25 @@ create_spacelift_launcher_script () {(
7777#!/bin/bash
7878join_strings () { local d="$1 "; echo -n "$2 "; shift 2 && printf '%s' "$$ {!@/#/$d }"; }
7979
80+ validate_metadata() {
81+ local value="\$ 1"
82+ local name="\$ 2"
83+ if [[ -z "\$ value" ]] || [[ "\$ value" == "null" ]] || [[ "\$ value" == "None" ]]; then
84+ echo "ERROR: \$ name is null or empty. EC2 metadata service returned invalid data." >> /var/log/spacelift/error.log
85+ exit 1
86+ fi
87+ }
88+
8089echo "Retrieving EC2 instance ID and ami ID" >> /var/log/spacelift/info.log
8190export SPACELIFT_METADATA_instance_id=\$ (ec2-metadata --instance-id | cut -d ' ' -f2)
91+ validate_metadata "\$ SPACELIFT_METADATA_instance_id" "instance_id"
92+
8293export SPACELIFT_METADATA_ami_id=\$ (ec2-metadata --ami-id | cut -d ' ' -f2)
94+ validate_metadata "\$ SPACELIFT_METADATA_ami_id" "ami_id"
95+
8396echo "Retrieving EC2 ASG ID" >> /var/log/spacelift/info.log
8497export SPACELIFT_METADATA_asg_id=\$ (aws autoscaling --region=${region} describe-auto-scaling-instances --instance-ids \$ SPACELIFT_METADATA_instance_id | jq -r '.AutoScalingInstances[0].AutoScalingGroupName')
98+ validate_metadata "\$ SPACELIFT_METADATA_asg_id" "asg_id"
8599if [[ "${http_proxy_config} " != "" || "${https_proxy_config} " != "" || "${no_proxy_config} " != "" ]]; then
86100 whitelisted_vars=()
87101 echo "Configuring HTTP proxy information" >> /var/log/spacelift/info.log
You can’t perform that action at this time.
0 commit comments