@@ -186,23 +186,53 @@ func WriteConfigToYAML(filePath string, config *Config) error {
186186 return nil
187187}
188188
189+ func (c * Config ) Compare (other * Config ) bool {
190+ if len (c .Servers ) != len (other .Servers ) {
191+ return false
192+ }
193+
194+ for key , server := range c .Servers {
195+ if otherServer , exists := other .Servers [key ]; ! exists || ! server .Compare (& otherServer ) {
196+ return false
197+ }
198+ }
199+
200+ return true
201+ }
202+
203+ func (s * Server ) Compare (other * Server ) bool {
204+ return s .Host == other .Host &&
205+ s .Port == other .Port &&
206+ s .Username == other .Username &&
207+ s .Password == other .Password &&
208+ s .Domain == other .Domain &&
209+ s .ClientID == other .ClientID &&
210+ s .ClientSecret == other .ClientSecret &&
211+ s .OAuthTokenUrl == other .OAuthTokenUrl &&
212+ s .APIPath == other .APIPath &&
213+ s .SkipTLSVerify == other .SkipTLSVerify &&
214+ s .CACertPath == other .CACertPath &&
215+ s .AuthType == other .AuthType
216+ }
217+
189218// MergeConfigFromFile merges the configuration from a file into the existing Config.
190- func MergeConfigFromFile (filePath string , config * Config ) error {
219+ func MergeConfigFromFile (filePath string , config * Config ) ( * Config , error ) {
191220 // Read the file content
192221 data , err := os .ReadFile (filePath )
193222 if err != nil {
194- return fmt .Errorf ("failed to read config file: %w" , err )
223+
224+ return nil , fmt .Errorf ("failed to read config file: %w" , err )
195225 }
196226
197227 // Determine the file type (JSON or YAML) and unmarshal accordingly
198228 var tempConfig Config
199229 if json .Valid (data ) {
200230 if err := json .Unmarshal (data , & tempConfig ); err != nil {
201- return fmt .Errorf ("failed to unmarshal JSON config: %w" , err )
231+ return nil , fmt .Errorf ("failed to unmarshal JSON config: %w" , err )
202232 }
203233 } else {
204234 if err := yaml .Unmarshal (data , & tempConfig ); err != nil {
205- return fmt .Errorf ("failed to unmarshal YAML config: %w" , err )
235+ return nil , fmt .Errorf ("failed to unmarshal YAML config: %w" , err )
206236 }
207237 }
208238
@@ -213,7 +243,7 @@ func MergeConfigFromFile(filePath string, config *Config) error {
213243 }
214244 }
215245
216- return nil
246+ return config , nil
217247}
218248
219249// GetAuthType returns the type of authentication to use based on the configuration params.
0 commit comments