Skip to content

Commit

Permalink
fix[prod] single quote and double quote issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ankita-gulati-gojek committed Nov 6, 2023
1 parent 9320256 commit 5128f11
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions client/cmd/job/run_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,8 @@ func (j *jobRunInputCommand) writeJobResponseSecretToFile(
) error {
// write all secrets into a file
secretsFileContent := ""
for key, val := range jobResponse.Secrets {
if strings.Contains(val, unsubstitutedValue) {
j.keysWithUnsubstitutedValue = append(j.keysWithUnsubstitutedValue, key)
}
secretsFileContent += fmt.Sprintf("%s='%s'\n", key, val)
}
secretsFileContent, keysWithUnsubstitutedValue := ConstructConfigEnvSourcingContent(jobResponse.Envs)
j.keysWithUnsubstitutedValue = append(j.keysWithUnsubstitutedValue, keysWithUnsubstitutedValue...)

filePath := filepath.Join(dirPath, typeSecretFileName)
writeToFileFn := utils.WriteStringToFileIndexed()
Expand All @@ -174,13 +170,8 @@ func (j *jobRunInputCommand) writeJobResponseSecretToFile(
}

func (j *jobRunInputCommand) writeJobResponseEnvToFile(jobResponse *pb.JobRunInputResponse, dirPath string) error {
envFileBlob := ""
for key, val := range jobResponse.Envs {
if strings.Contains(val, unsubstitutedValue) {
j.keysWithUnsubstitutedValue = append(j.keysWithUnsubstitutedValue, key)
}
envFileBlob += fmt.Sprintf("%s='%s'\n", key, val)
}
envFileBlob, keysWithUnsubstitutedValue := ConstructConfigEnvSourcingContent(jobResponse.Envs)
j.keysWithUnsubstitutedValue = append(j.keysWithUnsubstitutedValue, keysWithUnsubstitutedValue...)

filePath := filepath.Join(dirPath, typeEnvFileName)
writeToFileFn := utils.WriteStringToFileIndexed()
Expand All @@ -190,6 +181,17 @@ func (j *jobRunInputCommand) writeJobResponseEnvToFile(jobResponse *pb.JobRunInp
return nil
}

func ConstructConfigEnvSourcingContent(config map[string]string) (content string, keysWithUnsubstitutedValue []string) {
for key, val := range config {
if strings.Contains(val, unsubstitutedValue) {
keysWithUnsubstitutedValue = append(keysWithUnsubstitutedValue, key)
}
escapedVal := strings.ReplaceAll(val, "'", "'\\''")
content += fmt.Sprintf("%s='%s'\n", key, escapedVal)
}
return content, keysWithUnsubstitutedValue
}

func (j *jobRunInputCommand) writeJobAssetsToFiles(
jobResponse *pb.JobRunInputResponse, dirPath string,
) error {
Expand Down

0 comments on commit 5128f11

Please sign in to comment.