Skip to content

Commit

Permalink
Merge pull request #243 from deploymenttheory/staging-version2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
thejoeker12 authored Jun 19, 2024
2 parents 704c3ac + d4bdf67 commit f1fdb0b
Show file tree
Hide file tree
Showing 49 changed files with 517 additions and 3,852 deletions.
112 changes: 1 addition & 111 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,117 +20,7 @@ This HTTP client is intended to be used with targetted SDK's and terraform provi
- **API Handler Interface**: Provides a flexible and extensible way to interact with different APIs, including encoding and decoding requests and responses, managing authentication endpoints, and handling API-specific logic.
- **Configuration via JSON or Environment Variables**: The Go API HTTP Client supports configuration via JSON files or environment variables, providing flexibility in defining authentication credentials, API endpoints, logging settings, and other parameters.

- **Cookie Jar Support**: Incorporates an optional cookie jar to manage cookies effortlessly across requests, enhancing session management and statefulness with APIs that require cookie-based authentication or tracking. This feature allows for automatic storage and sending of cookies with subsequent requests, mirroring browser-like interaction with web services. It can be enabled or disabled based on configuration, providing flexibility in how stateful interactions are handled with the target API.

## API Handler

The `APIHandler` interface abstracts the functionality needed to interact with various APIs, making the HTTP client adaptable to different API implementations. It includes methods for constructing resource and authentication endpoints, marshaling requests, handling responses, and managing API-specific headers.

### Implementations

Currently, the HTTP client supports the following API handlers:

- **Jamf Pro**: Tailored for interacting with Jamf Pro's API, providing specialized methods for device management and configuration.
- **Microsoft Graph**: Designed for Microsoft Graph API, enabling access to various Microsoft 365 services.

## Getting Started

## HTTP Client Build Flow

The HTTP client build flow can be initiated using a number of methods. The primary methods include:

Using the SDK `BuildClientWithConfigFile` function, which reads the configuration from a JSON file and constructs the client accordingly. The configuration file specifies the authentication details, API environment settings, and client options, such as logging level, retry attempts, and concurrency limits.

Or using the SDK `BuildClientWithEnvironmentVariables` function, which reads the configuration from environment variables and constructs the client accordingly. This method allows for more flexible configuration management, particularly in containerized environments or when using orchestration tools.

There is also the option to the build the client manually by creating a new `Client` struct and setting the required fields directly. This method provides the most granular control over the client configuration and can be useful for advanced use cases or when integrating with existing configuration management systems. This is the approached used in related terraform providers.

![HTTP Client Build Flow](docs/media/BuildClient.png)

### Installation

To use this HTTP client in your project, add the package to your Go module dependencies:

```bash
go get github.com/yourusername/go-api-http-client
```

### Usage

Example usage with a configuration file using the jamfpro SDK client builder function:

```go
package main

import (
"encoding/xml"
"fmt"
"log"

"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)

func main() {
// Define the path to the JSON configuration file
configFilePath := "/path/to/your/clientconfig.json"

// Initialize the Jamf Pro client with the HTTP client configuration
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
if err != nil {
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
}
}

```

Example configuration file (clientconfig.json):

```json
{
"Auth": {
"ClientID": "client-id", // set this for oauth2 based authentication
"ClientSecret": "client-secret", // set this for oauth2 based authentication
"Username": "username", // set this for basic auth
"Password": "password" // set this for basic auth
},
"Environment": {
"APIType": "", // define the api integration e.g "jamfpro" / "msgraph"
"InstanceName": "yourinstance", // used for "jamfpro"
"OverrideBaseDomain": "", // used for "jamfpro"
"TenantID": "tenant-id", // used for "msgraph"h
"TenantName ": "resource", // used for "msgraph"
},
"ClientOptions": {
"Logging": {
"LogLevel": "LogLevelDebug", // "LogLevelDebug" / "LogLevelInfo" / "LogLevelWarn" / "LogLevelError" / "LogLevelFatal" / "LogLevelPanic"
"LogOutputFormat": "console", // "console" / "json"
"LogConsoleSeparator": " ", // " " / "\t" / "," / etc.
"LogExportPath": "/your/log/path/folder",
"HideSensitiveData": true // redacts sensitive data from logs
},
"Cookies": {
"EnableCookieJar": true, // enable cookie jar support
"CustomCookies": { // set custom cookies as an alternative to cookie jar
"sessionId": "abc123",
"authToken": "xyz789"
}
},
"Retry": {
"MaxRetryAttempts": 5, // set number of retry attempts
"EnableDynamicRateLimiting": true // enable dynamic rate limiting
},
"Concurrency": {
"MaxConcurrentRequests": 3 // set number of concurrent requests
},
"Redirect": {
"FollowRedirects": true, // follow redirects
"MaxRedirects": 5 // set number of redirects to follow
}
}
}
```


TBC


## Reporting Issues and Feedback
Expand Down
55 changes: 0 additions & 55 deletions apiintegrations/apihandler/apihandler.go

This file was deleted.

66 changes: 0 additions & 66 deletions apiintegrations/apihandler/apihandler_test.go.TODO

This file was deleted.

38 changes: 0 additions & 38 deletions apiintegrations/jamfpro/README.MD

This file was deleted.

45 changes: 0 additions & 45 deletions apiintegrations/jamfpro/jamfpro_api_exceptions.go

This file was deleted.

18 changes: 0 additions & 18 deletions apiintegrations/jamfpro/jamfpro_api_exceptions_configuration.json

This file was deleted.

12 changes: 0 additions & 12 deletions apiintegrations/jamfpro/jamfpro_api_handler.go

This file was deleted.

Loading

0 comments on commit f1fdb0b

Please sign in to comment.