Skip to content

Commit 4d1ab5b

Browse files
authored
Merge pull request #110 from deploymenttheory/dev
Added back in support for jamf pro api username and password as part of a downstream feature request
2 parents 5c07bc9 + fd8afe5 commit 4d1ab5b

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

httpclient/httpclient_client_configuration.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
168174
func 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

Comments
 (0)