@@ -68,6 +68,12 @@ func LoadConfigFromEnv(config *ClientConfig) (*ClientConfig, error) {
6868 }
6969
7070 // AuthConfig
71+ config .Auth .Username = getEnvOrDefault ("USERNAME" , config .Auth .Username )
72+ log .Printf ("Username env value found and set to: %s" , config .Auth .Username )
73+
74+ config .Auth .Password = getEnvOrDefault ("PASSWORD" , config .Auth .Password )
75+ log .Printf ("Password env value found and set" )
76+
7177 config .Auth .ClientID = getEnvOrDefault ("CLIENT_ID" , config .Auth .ClientID )
7278 log .Printf ("ClientID env value found and set to: %s" , config .Auth .ClientID )
7379
@@ -168,19 +174,15 @@ func parseDuration(value string, defaultVal time.Duration) time.Duration {
168174func validateMandatoryConfiguration (config * ClientConfig ) error {
169175 var missingFields []string
170176
171- // Check for missing mandatory fields and add them to the missingFields slice if necessary.
172- if config .Auth .ClientID == "" {
173- missingFields = append (missingFields , "Auth.ClientID" )
174- }
175- if config .Auth .ClientSecret == "" {
176- missingFields = append (missingFields , "Auth.ClientSecret" )
177- }
177+ // Check for mandatory fields related to the environment
178178 if config .Environment .InstanceName == "" {
179179 missingFields = append (missingFields , "Environment.InstanceName" )
180180 }
181181 if config .Environment .APIType == "" {
182182 missingFields = append (missingFields , "Environment.APIType" )
183183 }
184+
185+ // Check for mandatory fields related to the client options
184186 if config .ClientOptions .LogLevel == "" {
185187 missingFields = append (missingFields , "ClientOptions.LogLevel" )
186188 }
@@ -191,12 +193,32 @@ func validateMandatoryConfiguration(config *ClientConfig) error {
191193 missingFields = append (missingFields , "ClientOptions.LogConsoleSeparator" )
192194 }
193195
194- // If there are missing fields, return an error detailing what is missing.
196+ // Check for either OAuth credentials pair or Username and Password pair
197+ usingOAuth := config .Auth .ClientID != "" && config .Auth .ClientSecret != ""
198+ usingBasicAuth := config .Auth .Username != "" && config .Auth .Password != ""
199+
200+ if ! (usingOAuth || usingBasicAuth ) {
201+ if config .Auth .ClientID == "" {
202+ missingFields = append (missingFields , "Auth.ClientID" )
203+ }
204+ if config .Auth .ClientSecret == "" {
205+ missingFields = append (missingFields , "Auth.ClientSecret" )
206+ }
207+ if config .Auth .Username == "" {
208+ missingFields = append (missingFields , "Auth.Username" )
209+ }
210+ if config .Auth .Password == "" {
211+ missingFields = append (missingFields , "Auth.Password" )
212+ }
213+ }
214+
215+ // If there are missing fields, construct and return an error message detailing what is missing
195216 if len (missingFields ) > 0 {
196- return fmt .Errorf ("mandatory configuration missing: %s" , strings .Join (missingFields , ", " ))
217+ errorMessage := fmt .Sprintf ("Mandatory configuration missing: %s. Ensure that either OAuth credentials (ClientID and ClientSecret) or Basic Auth credentials (Username and Password) are fully provided." , strings .Join (missingFields , ", " ))
218+ return fmt .Errorf (errorMessage )
197219 }
198220
199- // If no fields are missing, return nil indicating the configuration is complete.
221+ // If no fields are missing, return nil indicating the configuration is complete
200222 return nil
201223}
202224
0 commit comments