Skip to content

Commit

Permalink
Support escape path for MacOs, Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhntd committed Jun 24, 2022
1 parent ca3b885 commit b456998
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ GOIMPORTS_OPT?= -w -local $(CW_AGENT_IMPORT_PATH)
GOIMPORTS = $(TOOLS_BIN_DIR)/goimports
SHFMT = $(TOOLS_BIN_DIR)/shfmt
LINTER = $(TOOLS_BIN_DIR)/golangci-lint
release: clean build package-rpm package-deb
release: clean test build package-rpm package-deb package-win package-darwin

nightly-release: release

build: cwagent-otel-collector amazon-cloudwatch-agent config-translator start-amazon-cloudwatch-agent amazon-cloudwatch-agent-config-wizard config-downloader
build: check_secrets cwagent-otel-collector amazon-cloudwatch-agent config-translator start-amazon-cloudwatch-agent amazon-cloudwatch-agent-config-wizard config-downloader

check_secrets::
if grep --exclude-dir=build --exclude-dir=vendor -E "(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}|(\"|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\\s*(:|=>|=)\\s*(\"|')?[A-Za-z0-9/\\+=]{40}(\"|')?" -Rn .; then echo "check_secrets failed"; exit 1; fi;
Expand Down Expand Up @@ -91,21 +91,29 @@ config-translator: copy-version-file
@echo Building config-translator
$(LINUX_AMD64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator
$(LINUX_ARM64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator
$(WIN_BUILD)/config-translator.exe github.com/aws/amazon-cloudwatch-agent/cmd/config-translator
$(DARWIN_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator

start-amazon-cloudwatch-agent: copy-version-file
@echo Building start-amazon-cloudwatch-agent
$(LINUX_AMD64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(LINUX_ARM64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(WIN_BUILD)/start-amazon-cloudwatch-agent.exe github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(DARWIN_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent

amazon-cloudwatch-agent-config-wizard: copy-version-file
@echo Building amazon-cloudwatch-agent-config-wizard
$(LINUX_AMD64_BUILD)/amazon-cloudwatch-agent-config-wizard github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent-config-wizard
$(LINUX_ARM64_BUILD)/amazon-cloudwatch-agent-config-wizard github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent-config-wizard
$(WIN_BUILD)/amazon-cloudwatch-agent-config-wizard.exe github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent-config-wizard
$(DARWIN_BUILD)/amazon-cloudwatch-agent-config-wizard github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent-config-wizard

config-downloader: copy-version-file
@echo Building config-downloader
$(LINUX_AMD64_BUILD)/config-downloader github.com/aws/amazon-cloudwatch-agent/cmd/config-downloader
$(LINUX_ARM64_BUILD)/config-downloader github.com/aws/amazon-cloudwatch-agent/cmd/config-downloader
$(WIN_BUILD)/config-downloader.exe github.com/aws/amazon-cloudwatch-agent/cmd/config-downloader
$(DARWIN_BUILD)/config-downloader github.com/aws/amazon-cloudwatch-agent/cmd/config-downloader

# A fast build that only builds amd64, we don't need wizard and config downloader
build-for-docker: build-for-docker-amd64
Expand Down
3 changes: 0 additions & 3 deletions cmd/config-downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,16 @@ func main() {
switch locationArray[0] {
case locationDefault:
outputFilePath = locationDefault
log.Printf("Abot",outputFilePath)
if multiConfig != "remove" {
config, err = defaultJsonConfig(mode)
}
case locationSSM:
outputFilePath = locationSSM + "_" + EscapeFilePath(locationArray[1])
log.Printf("Read",outputFilePath)
if multiConfig != "remove" {
config, err = downloadFromSSM(region, locationArray[1], mode, cc.CredentialsMap())
}
case locationFile:
outputFilePath = locationFile + "_" + EscapeFilePath(filepath.Base(locationArray[1]))
log.Printf("Test",outputFilePath)
if multiConfig != "remove" {
config, err = readFromFile(locationArray[1])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func translateConfig() error {
log.Printf("I! Return exit error: exit code=%d\n", status.ExitStatus())

if status.ExitStatus() == config.ERR_CODE_NOJSONFILE {
log.Printf("I! there is no json configuration when running translator\n")
log.Printf("I! No json config files found, please provide config, exit now\n")
os.Exit(0)
}
}
Expand Down
12 changes: 5 additions & 7 deletions packaging/darwin/amazon-cloudwatch-agent-ctl
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,19 @@ cwa_config() {
if [ "${config_location}" = "${ALL_CONFIG}" ]; then
rm -rf "${JSON_DIR}"/*
else
runDownloaderCommand="${CMDDIR}/config-downloader --output-dir ${JSON_DIR} --download-source ${config_location} --mode ${mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
echo ${runDownloaderCommand}
${runDownloaderCommand}
runDownloaderCommand=`"${CMDDIR}/config-downloader" --output-dir "${JSON_DIR}" --download-source "${config_location}" --mode ${mode} --config "${COMMON_CONIG}" --multi-config ${multi_config}`
echo "${runDownloaderCommand}"
fi

if [ ! "$(ls ${JSON_DIR})" ]; then
echo "all amazon-cloudwatch-agent configurations have been removed"
rm -f "${TOML}"
else
runTranslatorCommand="${CMDDIR}/config-translator --input ${JSON} --input-dir ${JSON_DIR} --output ${TOML} --mode ${mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
echo ${runTranslatorCommand}
${runTranslatorCommand}
runTranslatorCommand=`"${CMDDIR}/config-translator" --input "${JSON}" --input-dir "${JSON_DIR}" --output "${TOML}" --mode ${mode} --config "${COMMON_CONIG}" --multi-config ${multi_config}`
echo "${runTranslatorCommand}"

runAgentSchemaTestCommand="${CMDDIR}/amazon-cloudwatch-agent -schematest -config ${TOML}"
echo ${runAgentSchemaTestCommand}
echo "${runAgentSchemaTestCommand}"
# We will redirect the verbose error message out
if ! ${runAgentSchemaTestCommand} >${CV_LOG_FILE} 2>&1; then
echo "Configuration validation second phase failed"
Expand Down
12 changes: 5 additions & 7 deletions packaging/dependencies/amazon-cloudwatch-agent-ctl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ cwa_config() {
rm -rf "${JSON_DIR}"/*
else
runDownloaderCommand=`"${CMDDIR}/config-downloader" --output-dir "${JSON_DIR}" --download-source "${cwa_config_location}" --mode ${param_mode} --config "${COMMON_CONIG}" --multi-config ${multi_config}`
echo "${runDownloaderCommand}" || return
echo ${runDownloaderCommand} || return
fi

if [ ! "$(ls ${JSON_DIR})" ]; then
Expand Down Expand Up @@ -419,9 +419,8 @@ cwoc_config() {
cp "${PREDEFINED_CONFIG_DATA}" "${YAML_DIR}/default.tmp"
echo "Successfully fetched the config and saved in ${YAML_DIR}/default.tmp"
else
runDownloaderCommand="${CMDDIR}/config-downloader --output-dir ${YAML_DIR} --download-source ${cwoc_config_location} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
echo "${runDownloaderCommand}"
${runDownloaderCommand} || return
runDownloaderCommand=`"${CMDDIR}/config-downloader" --output-dir "${YAML_DIR}" --download-source "${cwoc_config_location}" --mode ${param_mode} --config "${COMMON_CONIG}" --multi-config ${multi_config}`
echo "${runDownloaderCommand}" || return
fi

if [ ! "$(ls ${YAML_DIR})" ]; then
Expand Down Expand Up @@ -465,9 +464,8 @@ set_log_level_all() {
;;
esac

runEnvConfigCommand="${CMDDIR}/amazon-cloudwatch-agent -setenv CWAGENT_LOG_LEVEL=${log_level} -envconfig ${ENV_CONFIG}"
echo "${runEnvConfigCommand}"
${runEnvConfigCommand} || return
runEnvConfigCommand=`"${CMDDIR}/amazon-cloudwatch-agent" -setenv CWAGENT_LOG_LEVEL=${log_level} -envconfig "${ENV_CONFIG}"`
echo "${runEnvConfigCommand}" || return
echo "Set CWAGENT_LOG_LEVEL to ${log_level}"
}

Expand Down
6 changes: 2 additions & 4 deletions translator/jsonconfig/mergeJsonConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package jsonconfig

import (
"fmt"
"log"
"os"
"sort"
Expand All @@ -22,15 +21,14 @@ func MergeJsonConfigMaps(jsonConfigMapMap map[string]map[string]interface{}, def
if os.Getenv(config.USE_DEFAULT_CONFIG) == config.USE_DEFAULT_CONFIG_TRUE {
// When USE_DEFAULT_CONFIG is true, ECS and EKS will be supposed to use different default config. EKS default config logic will be added when necessary
if ecsutil.GetECSUtilSingleton().IsECS() {
fmt.Println("No json config files found, use the default ecs config")
log.Println("No json config files found, use the default ecs config")
return util.GetJsonMapFromJsonBytes([]byte(config.DefaultECSJsonConfig()))
}
}
if multiConfig == "remove" {
fmt.Println("No json config files found, please provide config, exit now")
os.Exit(config.ERR_CODE_NOJSONFILE)
} else {
fmt.Println("No json config files found, use the default one")
log.Println("No json config files found, use the default one")
}
return defaultJsonConfigMap, nil
}
Expand Down

0 comments on commit b456998

Please sign in to comment.