(names []string, valueFn func(string) string)
| 18 | var safeOutputsConfigGenLog = logger.New("workflow:safe_outputs_config_generation_helpers") |
| 19 | |
| 20 | func buildNormalizedSortedJSON(names []string, valueFn func(string) string) (string, error) { |
| 21 | values := make(map[string]string, len(names)) |
| 22 | for _, name := range names { |
| 23 | normalizedName := stringutil.NormalizeSafeOutputIdentifier(name) |
| 24 | values[normalizedName] = valueFn(normalizedName) |
| 25 | } |
| 26 | |
| 27 | keys := sliceutil.SortedKeys(values) |
| 28 | |
| 29 | ordered := make(map[string]string, len(keys)) |
| 30 | for _, k := range keys { |
| 31 | ordered[k] = values[k] |
| 32 | } |
| 33 | |
| 34 | jsonBytes, err := json.Marshal(ordered) |
| 35 | if err != nil { |
| 36 | return "", err |
| 37 | } |
| 38 | return string(jsonBytes), nil |
| 39 | } |
| 40 | |
| 41 | // buildCustomSafeOutputJobsJSON builds a JSON mapping of custom safe output job names to empty |
| 42 | // strings, for use in the GH_AW_SAFE_OUTPUT_JOBS env var of the handler manager step. |
no test coverage detected