-
Notifications
You must be signed in to change notification settings - Fork 1
Add real-time device enrollment notifications via AMAPI Pub/Sub. #129
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74eeb85
Add real-time device enrollment notifications via AMAPI Pub/Sub.
Copilot cb1548f
Fix test.
simonkagwi c0cda88
Merge branch 'main' into 116-android-mdm-notifications
simonkagwi 1457b30
Improve docs.
simonkagwi 906bbdd
Separate enterprise patching from non-enterprise-specific Pub/Sub con…
simonkagwi fac3dcb
Merge branch 'main' into 116-android-mdm-notifications
simonkagwi 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,50 @@ | ||
| import structlog | ||
| from django.core.management.base import BaseCommand, CommandError | ||
|
|
||
| from apps.mdm.mdms import AndroidEnterprise | ||
|
|
||
| logger = structlog.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = ( | ||
| "Configure AMAPI Pub/Sub notifications for the Android Enterprise enterprise. " | ||
| "Creates the Pub/Sub topic and subscription (if they do not exist), grants " | ||
| "Android Device Policy the right to publish to the topic, and patches the " | ||
| "enterprise resource with the topic name. " | ||
| "The topic and subscription are automatically derived from the service account " | ||
| "credentials (projects/{project_id}/topics/publish-mdm and " | ||
| "projects/{project_id}/subscriptions/publish-mdm). " | ||
| "The push endpoint is built as https://{domain}/mdm/api/amapi/notifications/?token=<token>. " | ||
| "When --push-endpoint-domain is omitted, the domain is taken from the current Site object." | ||
| ) | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| "--push-endpoint-domain", | ||
| default=None, | ||
| help=( | ||
| "Domain (without scheme, e.g. example.com) used to build the full " | ||
| "Pub/Sub push endpoint. HTTPS is always used. " | ||
| "Defaults to the domain from the current Site object." | ||
| ), | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| mdm = AndroidEnterprise() | ||
| if not mdm.is_configured: | ||
| raise CommandError( | ||
| "Android Enterprise is not configured. " | ||
| "Set ANDROID_ENTERPRISE_ID and ANDROID_ENTERPRISE_SERVICE_ACCOUNT_FILE." | ||
| ) | ||
|
|
||
| push_endpoint_domain = options["push_endpoint_domain"] | ||
| result = mdm.configure_pubsub(push_endpoint_domain=push_endpoint_domain) | ||
| enabled = result.get("enabledNotificationTypes", []) | ||
| self.stdout.write( | ||
| self.style.SUCCESS( | ||
| f"Pub/Sub notifications configured for enterprise " | ||
| f"'{mdm.enterprise_name}' with topic '{mdm.pubsub_topic}'." | ||
| f"\nEnabled notification types: {', '.join(enabled)}" | ||
| ) | ||
| ) | ||
Oops, something went wrong.
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.