Skip to content

Commit

Permalink
Merge pull request #2267 from aws-observability/rapphil-fix-control-s…
Browse files Browse the repository at this point in the history
…cript-sed

Fix control script to avoid sed special characters
  • Loading branch information
rapphil authored Aug 11, 2023
2 parents 3d239c5 + 0b69a1f commit f583d3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/scripts/test-collector-ctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,33 @@ test_collector_ctl_does_not_overwrite_env() {
echo "${FUNCNAME[0]} ... OK"
}

test_collector_ctl_with_sed_special_chars() {
# ampersand is a special character in sed
cfg="https://example.com?test=1&test=2"
$ADOT_CTL -a start -c "$cfg"

expected_string="^config=\"--config '${cfg}'\"$"

if ! grep -q "${expected_string}" "$ENV_FILE"; then
echo "Configuration is incorrect"
exit 1
fi

cfg="./config.yaml"
$ADOT_CTL -a start -c "$cfg"

expected_string="^config=\"--config /opt/aws/aws-otel-collector/etc/config.yaml\"$"
if ! grep -q "${expected_string}" "$ENV_FILE"; then
echo "Configuration is incorrect"
exit 1
fi

echo "${FUNCNAME[0]} ... OK"
}


setup

## Tests
test_collector_ctl_does_not_overwrite_env
test_collector_ctl_with_sed_special_chars
7 changes: 5 additions & 2 deletions tools/ctl/linux/aws-otel-collector-ctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ UsageString="
aoc_config_remote_uri() {
config="${1:-}"

sed -i 's#^config=.*$#config="--config '"${config}"'"#' $ENV_FILE
sed -i '/^config=.*$/d' $ENV_FILE
echo "config=\"--config '${config}'\"" >> $ENV_FILE
}


Expand All @@ -63,7 +64,9 @@ aoc_config_local_uri() {
# Strip the file scheme in case it is present
config="${config#file:}"

sed -i 's#^config=.*$#config="--config /opt/aws/aws-otel-collector/etc/config.yaml"#' $ENV_FILE
sed -i '/^config=.*$/d' $ENV_FILE
echo "config=\"--config /opt/aws/aws-otel-collector/etc/config.yaml\"" >> $ENV_FILE


if [ -n "$config" ] && [ -f "$config" ]; then
cp "$config" $CONFDIR/config.yaml
Expand Down

0 comments on commit f583d3e

Please sign in to comment.