66package env
77
88import (
9+ "bytes"
910 "encoding/json"
1011 "fmt"
1112 "os"
@@ -16,17 +17,23 @@ import (
1617 "github.com/DataDog/dd-trace-go/v2/internal/log"
1718)
1819
20+ type configurationImplementation struct {
21+ Implementation string `json:"implementation"`
22+ Type string `json:"type"`
23+ Default * string `json:"default"`
24+ Aliases []string `json:"aliases,omitempty"`
25+ }
26+
1927// SupportedConfiguration represents the content of the supported_configurations.json file.
20- type SupportedConfiguration struct {
21- SupportedConfigurations map [ string ][] string `json:"supportedConfigurations "`
22- Aliases map [string ][]string `json:"aliases "`
28+ type supportedConfiguration struct {
29+ Version string `json:"version "`
30+ SupportedConfigurations map [string ][]configurationImplementation `json:"supportedConfigurations "`
2331}
2432
2533var (
2634 configFilePath string
2735 once sync.Once
2836 mu sync.Mutex
29- skipLock bool
3037)
3138
3239// getConfigFilePath returns the path to the supported_configurations.json file
@@ -65,34 +72,47 @@ func addSupportedConfigurationToFile(name string) {
6572 }
6673
6774 if _ , ok := cfg .SupportedConfigurations [name ]; ! ok {
68- cfg .SupportedConfigurations [name ] = []string {"A" }
75+ defaultValue := "FIX_ME"
76+ cfg .SupportedConfigurations [name ] = []configurationImplementation {
77+ {
78+ Implementation : "A" ,
79+ Type : defaultValue ,
80+ Default : & defaultValue ,
81+ },
82+ }
6983 }
7084
7185 if err := writeSupportedConfigurations (filePath , cfg ); err != nil {
7286 log .Error ("config: failed to write supported configurations: %s" , err .Error ())
7387 }
7488}
7589
76- func readSupportedConfigurations (filePath string ) (* SupportedConfiguration , error ) {
90+ func readSupportedConfigurations (filePath string ) (* supportedConfiguration , error ) {
7791 // read the json file
7892 jsonFile , err := os .ReadFile (filePath )
7993 if err != nil {
8094 return nil , fmt .Errorf ("failed to open supported_configurations.json: %w" , err )
8195 }
8296
83- var cfg SupportedConfiguration
97+ var cfg supportedConfiguration
8498 if err := json .Unmarshal (jsonFile , & cfg ); err != nil {
8599 return nil , fmt .Errorf ("failed to unmarshal SupportedConfiguration: %w" , err )
86100 }
87101 return & cfg , nil
88102}
89103
90- func writeSupportedConfigurations (filePath string , cfg * SupportedConfiguration ) error {
91- // write the json file - Go's json.MarshalIndent automatically sorts map keys
92- jsonFile , err := json .MarshalIndent (cfg , "" , " " )
93- if err != nil {
104+ func writeSupportedConfigurations (filePath string , cfg * supportedConfiguration ) error {
105+ // Write the JSON file. We explicitly disable HTML escaping so strings like "&"
106+ // remain readable (and stable across test runs) instead of being rendered as
107+ // "\u0026". Map keys are still deterministically sorted by encoding/json.
108+ var buf bytes.Buffer
109+ enc := json .NewEncoder (& buf )
110+ enc .SetEscapeHTML (false )
111+ enc .SetIndent ("" , " " )
112+ if err := enc .Encode (cfg ); err != nil {
94113 return fmt .Errorf ("failed to marshal SupportedConfiguration: %w" , err )
95114 }
115+ jsonFile := bytes .TrimRight (buf .Bytes (), "\n " )
96116
97117 if err := os .WriteFile (filePath , jsonFile , 0644 ); err != nil {
98118 return fmt .Errorf ("failed to write supported_configurations.json: %w" , err )
0 commit comments