Skip to content

Commit 6fe3541

Browse files
committed
Refactor authentication examples to use client configuration file and environment variables
1 parent 0749ffe commit 6fe3541

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

examples/_templates/authentication/example_client_setup_with_configfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This example demonstrates how to initialize the Jamf Pro client using the client configuration file.
12
package main
23

34
import (

examples/_templates/authentication/example_client_setup_with_env_vars.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This example demonstrates how to initialize the Jamf Pro client using configurations loaded from environment variables.
12
package main
23

34
import (
@@ -11,25 +12,30 @@ import (
1112
Ensure environment variables are set before running in this mode.
1213
You will need to set the following environment variables:
1314
15+
export LOG_LEVEL="warning"
16+
export HIDE_SENSITIVE_DATA="true"
17+
export INSTANCE_DOMAIN="your-instance-domain"
18+
export AUTH_METHOD="oauth2"
1419
export CLIENT_ID="your-client-id"
1520
export CLIENT_SECRET="your-client-secret"
16-
export INSTANCE_NAME="your-instance-name"
17-
export OVERRIDE_BASE_DOMAIN=""
18-
export API_TYPE="jamfpro"
19-
export LOG_LEVEL="LogLevelDebug"
20-
export LOG_OUTPUT_FORMAT="console"
21-
export LOG_CONSOLE_SEPARATOR=" "
22-
export HIDE_SENSITIVE_DATA="true"
21+
export BASIC_AUTH_USERNAME="your-basic-auth-username"
22+
export BASIC_AUTH_PASSWORD="your-basic-auth-password"
23+
export JAMF_LOAD_BALANCER_LOCK="true"
2324
export MAX_RETRY_ATTEMPTS="3"
24-
export ENABLE_DYNAMIC_RATE_LIMITING="true"
25-
export MAX_CONCURRENT_REQUESTS="5"
26-
export TOKEN_REFRESH_BUFFER_PERIOD="5m"
27-
export TOTAL_RETRY_DURATION="5m"
28-
export CUSTOM_TIMEOUT="10s"
25+
export ENABLE_DYNAMIC_RATE_LIMITING="false"
26+
export MAX_CONCURRENT_REQUESTS="1"
27+
export TOKEN_REFRESH_BUFFER_PERIOD_SECONDS="300"
28+
export TOTAL_RETRY_DURATION_SECONDS="60"
29+
export CUSTOM_TIMEOUT_SECONDS="60"
30+
export FOLLOW_REDIRECTS="true"
31+
export MAX_REDIRECTS="5"
32+
export ENABLE_CONCURRENCY_MANAGEMENT="true"
33+
export CUSTOM_COOKIES=""
34+
export MANDATORY_REQUEST_DELAY_MILLISECONDS="0"
35+
export RETRY_ELIGIABLE_REQUESTS="true"
2936
*/
3037

3138
func main() {
32-
3339
// Initialize the Jamf Pro client using configurations loaded from environment variables
3440
client, err := jamfpro.BuildClientWithEnv()
3541
if err != nil {

examples/_templates/authentication/example_client_setup_with_manual_conf.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1+
// this file is used to demonstrate how to set up the client with a manual configuration
12
package main
23

34
import (
45
"fmt"
56
"log"
6-
"time"
77

8-
"github.com/deploymenttheory/go-api-http-client/httpclient"
98
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
109
)
1110

1211
func main() {
13-
// Manually define the client configuration
14-
config := httpclient.ClientConfig{
15-
Environment: httpclient.EnvironmentConfig{
16-
InstanceName: "your-instance-name",
17-
OverrideBaseDomain: "", // Only required if you are not on jamfcloud.com
18-
APIType: "jamfpro", // Required to specify the API type
19-
},
20-
Auth: httpclient.AuthConfig{
21-
ClientID: "your-client-id",
22-
ClientSecret: "your-client-secret",
23-
},
24-
ClientOptions: httpclient.ClientOptions{
25-
LogLevel: "LogLevelDebug",
26-
LogOutputFormat: "console",
27-
HideSensitiveData: true,
28-
MaxRetryAttempts: 5,
29-
EnableDynamicRateLimiting: true,
30-
MaxConcurrentRequests: 10,
31-
TokenRefreshBufferPeriod: 5 * time.Minute,
32-
TotalRetryDuration: 60 * time.Second,
33-
CustomTimeout: 30 * time.Second,
34-
},
12+
// Define the configuration based on the new ConfigContainer struct
13+
config := &jamfpro.ConfigContainer{
14+
LogLevel: "warning",
15+
LogExportPath: "", // Set this if you want to export logs to a file
16+
HideSensitiveData: true,
17+
18+
InstanceDomain: "your-instance-domain",
19+
AuthMethod: "oauth2", // Use "basic" for basic authentication
20+
ClientID: "your-client-id",
21+
ClientSecret: "your-client-secret",
22+
Username: "", // Set this if using basic auth
23+
Password: "", // Set this if using basic auth
24+
JamfLoadBalancerLock: true,
25+
26+
CustomCookies: []jamfpro.CustomCookie{},
27+
MaxRetryAttempts: 3,
28+
MaxConcurrentRequests: 1,
29+
EnableDynamicRateLimiting: false,
30+
CustomTimeout: 60, // in seconds
31+
TokenRefreshBufferPeriod: 300, // in seconds
32+
TotalRetryDuration: 60, // in seconds
33+
FollowRedirects: true,
34+
MaxRedirects: 5,
35+
EnableConcurrencyManagement: true,
36+
MandatoryRequestDelay: 0, // in milliseconds
37+
RetryEligiableRequests: true,
3538
}
3639

3740
// Initialize the Jamf Pro client with the given configuration

0 commit comments

Comments
 (0)