-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Add support for authenticating the Jamf collector with API client #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d3vzer0
wants to merge
12
commits into
main
Choose a base branch
from
feature/clientauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5879b00
Make most fields optional if they're unused (for now)
d3vzer0 6ba19d4
Add USER_INITIATED trigger
d3vzer0 50bc8ea
Email should be optional
d3vzer0 aef604e
Changed justfile to include default args for testing
d3vzer0 70b0cb2
Loosen computer field requirements
d3vzer0 d7ddf30
Loosen policy field requirements
d3vzer0 32bc279
Add client-based auth for Jamf + conditionally parse the right config
d3vzer0 c71b894
Merge with main
d3vzer0 6ebe96e
Check self.token value after acquiring lock
d3vzer0 4f6650e
Updated test data to represent the actual API response
d3vzer0 86fb8e6
Split collection test between user/pass based login and client based …
d3vzer0 fe8e409
Add API endpoint for testing client auth
d3vzer0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| from threading import Lock | ||
|
|
||
| from dlt.common.configuration import configspec | ||
| from dlt.common.configuration.specs import CredentialsConfiguration | ||
| from dlt.sources.helpers import requests | ||
| from dlt.sources.helpers.rest_client.auth import AuthConfigBase | ||
|
|
||
|
|
||
| @configspec | ||
| class JamfCredentials(CredentialsConfiguration): | ||
| host: str = None | ||
|
|
||
| def auth(self): | ||
| pass | ||
|
|
||
|
|
||
| @configspec | ||
| class JamfPasswordCredentials(JamfCredentials): | ||
| username: str = None | ||
| password: str = None | ||
|
|
||
| @property | ||
| def auth(self): | ||
| return "password" | ||
|
|
||
| @property | ||
| def token(self): | ||
| response = requests.post( | ||
| f"{self.host}/api/v1/auth/token", | ||
| auth=(self.username, self.password), | ||
| ) | ||
| response.raise_for_status() | ||
| return response.json()["token"] | ||
|
|
||
|
|
||
| @configspec | ||
| class JamfClientCredentials(JamfCredentials): | ||
| client_id: str = None | ||
| client_secret: str = None | ||
|
|
||
| @property | ||
| def auth(self): | ||
| return "client" | ||
|
|
||
| @property | ||
| def token(self): | ||
| response = requests.post( | ||
| f"{self.host}/api/v1/oauth/token", | ||
| data={ | ||
| "grant_type": "client_credentials", | ||
| "client_id": self.client_id, | ||
| "client_secret": self.client_secret, | ||
| }, | ||
| ) | ||
| response.raise_for_status() | ||
| return response.json()["access_token"] | ||
|
|
||
|
|
||
| @configspec | ||
| class JamfAuth(AuthConfigBase): | ||
| def __init__(self, credentials: JamfPasswordCredentials | JamfClientCredentials): | ||
| self.credentials = credentials | ||
| self.token: str | None = None | ||
| self._token_lock = Lock() | ||
|
|
||
| def get_token(self) -> str: | ||
| if not self.token: | ||
| with self._token_lock: | ||
| if not self.token: | ||
| self.token = self.credentials.token | ||
|
|
||
| return self.token | ||
|
|
||
| def __call__(self, request): | ||
| request.headers["Authorization"] = f"Bearer {self.get_token()}" | ||
| return request | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,33 @@ | ||
| { | ||
| "id": 1, | ||
| "name": "John Smith", | ||
| "directory_user": true, | ||
| "full_name": "John Smith", | ||
| "email": "john.smith@company.com", | ||
| "email_address": "john.smith@company.com", | ||
| "enabled": "Enabled", | ||
| "ldap_server": { | ||
| "account": { | ||
| "id": 1, | ||
| "name": "Directory Server Name" | ||
| }, | ||
| "force_password_change": true, | ||
| "access_level": "Full Access", | ||
| "privilege_set": "Administrator", | ||
| "site": { | ||
| "id": -1, | ||
| "name": "None" | ||
| }, | ||
| "privileges": { | ||
| "jss_objects": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "jss_settings": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "jss_actions": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "recon": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "casper_admin": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "casper_remote": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ], | ||
| "casper_imaging": [ | ||
| { | ||
| "privilege": "string" | ||
| } | ||
| ] | ||
| "name": "John Smith", | ||
| "directory_user": true, | ||
| "full_name": "John Smith", | ||
| "email": "john.smith@company.com", | ||
| "email_address": "john.smith@company.com", | ||
| "enabled": "Enabled", | ||
| "ldap_server": { | ||
| "id": 1, | ||
| "name": "Directory Server Name" | ||
| }, | ||
| "force_password_change": true, | ||
| "access_level": "Full Access", | ||
| "privilege_set": "Administrator", | ||
| "site": { | ||
| "id": -1, | ||
| "name": "None" | ||
| }, | ||
| "privileges": { | ||
| "jss_objects": [ | ||
| "string" | ||
| ], | ||
| "jss_settings": [ | ||
| "string" | ||
| ], | ||
| "jss_actions": [ | ||
| "string" | ||
| ] | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.