Skip to content
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

Version 1.1.2 #50

Merged
merged 189 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
b6bd5ae
Create unit-test.yml
almenscorner Jul 10, 2022
06fde13
Adding 1.1.2 information and additional build badges
almenscorner Jul 10, 2022
11a5990
Adding pycache and pytest cache
almenscorner Jul 10, 2022
5c069d8
Bump version 1.1.1 -> 1.1.2
almenscorner Jul 10, 2022
0924c0f
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ec6bd2b
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
725880a
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
568018f
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
3af6310
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
2c0f353
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ef3d668
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
0ec944c
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ac26259
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
3accb6c
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
6cd7a2b
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
9965026
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
0c09d9c
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
fc9de75
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
508b4c9
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
7c37c68
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ae17040
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
6e8b803
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
2bf82ca
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
75ec521
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
39fffbe
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
4e7964c
Adding function to check if file is JSON or YAML
almenscorner Jul 10, 2022
0a627e8
Improved documentation and code readability
almenscorner Jul 10, 2022
15bd3a2
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
34d79a9
Improved documentation and code readability
almenscorner Jul 10, 2022
9590be9
Improved documentation and code readability
almenscorner Jul 10, 2022
12bbcf0
Adding function to get diff output as string
almenscorner Jul 10, 2022
f22e22d
Improved documentation and code readability
almenscorner Jul 10, 2022
70137db
Improved documentation and code readability
almenscorner Jul 10, 2022
12cecd8
Adding function to load JSON and YAML files
almenscorner Jul 10, 2022
0cbed70
Adding function to remove unwanted keys
almenscorner Jul 10, 2022
fb2bd61
Adding count, improved documentation, code readability, frontend func…
almenscorner Jul 10, 2022
79b8051
Improved documentation and code readability
almenscorner Jul 10, 2022
21395be
Adding count, improved documentation, code readability, frontend func…
almenscorner Jul 10, 2022
1d2b0ea
Adding function to save configuration as JSON or YAML
almenscorner Jul 10, 2022
0750e0b
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
866cdef
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ed116f0
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
ad7681a
Improved documentation and code readability
almenscorner Jul 10, 2022
69034ff
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
f014eb1
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
96e77fb
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
2544ffc
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
6736f22
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
be31fd5
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
bbdb74d
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
a1d94d7
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
154b3ab
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
2998050
Adding count, improved documentation and code readability
almenscorner Jul 10, 2022
88c7104
Adding unit tests
almenscorner Jul 10, 2022
727b024
added check for returned data
almenscorner Jul 18, 2022
5780d5a
added check for returned data
almenscorner Jul 18, 2022
920bd81
Changed how config count is counted
almenscorner Jul 18, 2022
7dfe83d
Changed how config count is counted
almenscorner Jul 18, 2022
b18389e
Changed how config count is counted
almenscorner Jul 18, 2022
ef67108
formatting
almenscorner Jul 18, 2022
2389d2f
added check for data returned
almenscorner Jul 18, 2022
f81f9b6
removed unused function
almenscorner Jul 18, 2022
474e775
Changed how config count is counted
almenscorner Jul 18, 2022
5cdc32d
Changed how config count is counted
almenscorner Jul 18, 2022
aba32eb
Update clean_filename.py
almenscorner Jul 18, 2022
beac676
formatting
almenscorner Jul 18, 2022
0d04477
Output is now returned as a list
almenscorner Jul 19, 2022
3fa14d0
Formatting
almenscorner Jul 19, 2022
0c60d06
Adding 503 check to call with q params
almenscorner Jul 19, 2022
f325753
Update load_file.py
almenscorner Jul 19, 2022
8b80d69
Update save_output.py
almenscorner Jul 19, 2022
1038153
Update update_appConfiguration.py
almenscorner Jul 19, 2022
f940219
Update update_appleEnrollmentProfile.py
almenscorner Jul 19, 2022
f9de088
Update update_appProtection.py
almenscorner Jul 19, 2022
705d9ca
Update update_assignment.py
almenscorner Jul 19, 2022
b4474d0
Update update_compliance.py
almenscorner Jul 19, 2022
f0b318d
Update update_frontend.py
almenscorner Jul 19, 2022
65ba3bd
typo
almenscorner Jul 19, 2022
f9b7d1c
typo
almenscorner Jul 19, 2022
03bdfd3
Adding unit tests
almenscorner Jul 19, 2022
b9b2cc1
Update .gitignore
almenscorner Jul 19, 2022
e3e7dd8
Update to print diff output
almenscorner Jul 19, 2022
769fa48
Update to print diff output
almenscorner Jul 19, 2022
0e3512d
Update update_configurationPolicies.py
almenscorner Jul 19, 2022
5012ac1
Update to print diff output
almenscorner Jul 19, 2022
b09ea1d
Update to print diff output
almenscorner Jul 19, 2022
6ae756d
Update to print diff output
almenscorner Jul 19, 2022
b7ff141
Update to print diff output
almenscorner Jul 19, 2022
460cb31
Update to print diff output
almenscorner Jul 19, 2022
3050af5
Update update_shellScripts.py
almenscorner Jul 19, 2022
3ef29d8
Update to print diff output
almenscorner Jul 19, 2022
0ce17cc
If name is main check
almenscorner Jul 19, 2022
546ee69
If name is main check
almenscorner Jul 19, 2022
2bf45d3
If name is main check
almenscorner Jul 19, 2022
d0b90f8
If name is main check
almenscorner Jul 19, 2022
e9c83da
If name is main check
almenscorner Jul 19, 2022
55b164d
If name is main check
almenscorner Jul 19, 2022
8ca018d
If name is main check
almenscorner Jul 19, 2022
8551e36
If name is main check
almenscorner Jul 19, 2022
42c1245
If name is main check
almenscorner Jul 19, 2022
1ddc962
If name is main check
almenscorner Jul 19, 2022
9b2af80
If name is main check
almenscorner Jul 19, 2022
27f8940
If name is main check
almenscorner Jul 19, 2022
4f416c0
If name is main check
almenscorner Jul 19, 2022
e248681
If name is main check
almenscorner Jul 19, 2022
671e13d
If name is main check
almenscorner Jul 19, 2022
bb5f3e1
If name is main check
almenscorner Jul 19, 2022
850152f
If name is main check
almenscorner Jul 19, 2022
d51144d
If name is main check
almenscorner Jul 19, 2022
efc7edd
If name is main check
almenscorner Jul 19, 2022
6609575
If name is main check
almenscorner Jul 19, 2022
07c623b
If name is main check
almenscorner Jul 19, 2022
b069b2d
If name is main check
almenscorner Jul 19, 2022
a4fba81
If name is main check
almenscorner Jul 19, 2022
167447d
If name is main check
almenscorner Jul 19, 2022
cdf47de
If name is main check
almenscorner Jul 19, 2022
f6e654d
If name is main check
almenscorner Jul 19, 2022
afb59c8
If name is main check
almenscorner Jul 19, 2022
9bac7ed
If name is main check
almenscorner Jul 19, 2022
9938a31
If name is main check
almenscorner Jul 19, 2022
ced91f2
If name is main check
almenscorner Jul 19, 2022
18391f8
If name is main check
almenscorner Jul 19, 2022
86e6911
If name is main check
almenscorner Jul 19, 2022
25117f2
If name is main check
almenscorner Jul 19, 2022
7fa2606
If name is main check
almenscorner Jul 19, 2022
882cde8
If name is main check
almenscorner Jul 19, 2022
c84d4f9
If name is main check
almenscorner Jul 19, 2022
d37a02d
If name is main check
almenscorner Jul 19, 2022
61277d8
If name is main check
almenscorner Jul 19, 2022
e0d0cb4
If name is main check
almenscorner Jul 19, 2022
ab72409
If name is main check
almenscorner Jul 19, 2022
106ba6c
If name is main check
almenscorner Jul 19, 2022
2803f7e
If name is main check
almenscorner Jul 19, 2022
8e04745
If name is main check
almenscorner Jul 19, 2022
13afea6
If name is main check
almenscorner Jul 19, 2022
1a010c5
If name is main check
almenscorner Jul 19, 2022
f1b8b72
If name is main check
almenscorner Jul 19, 2022
ccfab26
Remove unused var
almenscorner Jul 19, 2022
66dae24
Remove unused import and lint
almenscorner Jul 19, 2022
d496211
Linting
almenscorner Jul 19, 2022
8a7cda3
Linting
almenscorner Jul 19, 2022
f3f5382
Linting
almenscorner Jul 19, 2022
c90897a
Linting
almenscorner Jul 19, 2022
d425b6e
Linting
almenscorner Jul 19, 2022
23ad9e6
Linting
almenscorner Jul 19, 2022
04673b5
Linting
almenscorner Jul 19, 2022
ef7c1ad
Linting
almenscorner Jul 19, 2022
05fd13d
Linting
almenscorner Jul 19, 2022
1caf574
Linting
almenscorner Jul 19, 2022
9b9632b
Linting
almenscorner Jul 19, 2022
01c08bb
Linting
almenscorner Jul 19, 2022
6ac9b6f
Linting
almenscorner Jul 19, 2022
5b52f08
Linting
almenscorner Jul 19, 2022
5885acf
Linting
almenscorner Jul 19, 2022
ebbfa3d
Linting
almenscorner Jul 19, 2022
2c7d8f3
Linting
almenscorner Jul 19, 2022
dc07697
Linting
almenscorner Jul 19, 2022
1622ce4
Linting
almenscorner Jul 19, 2022
ca4e21e
Linting
almenscorner Jul 19, 2022
eb58506
Linting
almenscorner Jul 19, 2022
2cbedeb
Linting
almenscorner Jul 19, 2022
b9190dc
Linting
almenscorner Jul 19, 2022
2f058cd
Linting
almenscorner Jul 19, 2022
7be37f4
Linting
almenscorner Jul 19, 2022
8dcd64c
Linting
almenscorner Jul 19, 2022
e22d12f
Linting
almenscorner Jul 19, 2022
29ea09a
Linting
almenscorner Jul 19, 2022
e809aa4
Linting
almenscorner Jul 19, 2022
d15179a
Linting
almenscorner Jul 19, 2022
e8391ae
Linting
almenscorner Jul 19, 2022
de89587
Linting
almenscorner Jul 19, 2022
46f4699
Linting
almenscorner Jul 19, 2022
590cd24
Linting
almenscorner Jul 19, 2022
f797828
Update test-requirements.txt
almenscorner Jul 19, 2022
a4dc45a
Increase coverage
almenscorner Jul 19, 2022
957fec4
Update for codecov
almenscorner Jul 19, 2022
d631163
Ignore certain files
almenscorner Jul 19, 2022
669e433
Additional requirements
almenscorner Jul 19, 2022
f388d84
Simplify return and remove app description
almenscorner Aug 9, 2022
a6b80e0
Remove unnecessary else and de-indent code
almenscorner Aug 9, 2022
b107423
Remove unnecessary else and de-indent code
almenscorner Aug 9, 2022
9060987
Remove unnecessary else and de-indent code
almenscorner Aug 9, 2022
a37e3a1
Remove unnecessary elif
almenscorner Aug 9, 2022
bf76e25
Corrected print output
almenscorner Aug 9, 2022
0e26c0e
Added ability to configure line 1-4 with a json string
almenscorner Aug 9, 2022
494094e
Added additional 1.1.2 information
almenscorner Aug 9, 2022
053cd35
Remove 1.0.9 information
almenscorner Aug 9, 2022
e4b348e
Only upload to codecov once
almenscorner Aug 9, 2022
b8c57da
Merge pull request #49 from almenscorner/intunecd-monitor
almenscorner Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Unit tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=35 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest --cov-report=xml --cov=src/IntuneCD tests/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == 3.8
with:
files: ./coverage.xml
flags: unittests
fail_ci_if_error: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.idea/
.idea/
__pycache__/
.pytest_cache/
.coverage
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/IntuneCD?style=flat-square)
![PyPI](https://img.shields.io/pypi/v/IntuneCD?style=flat-square)
![Maintenance](https://img.shields.io/maintenance/yes/2022?style=flat-square)
![Unit tests](https://github.com/almenscorner/IntuneCD/actions/workflows/unit-test.yml/badge.svg)
![Publish](https://github.com/almenscorner/IntuneCD/actions/workflows/pypi-publish.yml/badge.svg)

![IntuneCDlogo2](https://user-images.githubusercontent.com/78877636/156755733-b66a4381-9a9a-4663-9d27-e55a1281e1fa.png)

Expand All @@ -14,6 +16,19 @@ The main function is to back up configurations from Intune to a Git repository f

The package can also be run standalone outside a pipeline, or in one to only backup data. Since 1.0.4, configurations are also created if they cannot be found. This means this tool could be used in a tenant to tenant migration scenario as well.

## What's new in 1.1.2
- Added new exclusions for backup and update, it's now possible to exclude certain configurations from backup and update.
- Example to exclude in backup: `IntuneCD-startbackup -e assignments AppConfigurations Profiles`
- Example to exclude in update: `IntuneCD-startupdate -e AppConfigurations Profiles`
- Added capabilities to update the IntuneCD frontend with data
- Once the frontend is available all that will be needed to update with data is to add `-f <frontend_url>` to startbackup and startupdate command and set the API key in ENV variables.
- Added ability to configure title, intro, tenant and updated lines in the documentation using a JSON string, example:
- `-j "{\"title\": \"demo\", \"intro\": \"demo\", \"tenant\": \"demo\", \"updated\": \"demo\"}"`
- Added unit tests
- Changed deprecated OptionParser to ArgumentParser
- Improved the documentation
- Improved overall code readability

## What's new in 1.1.1
- Added ability to split documentation into categories using `-s Y` in `intunecd-startdocumentation`
- Added ability to set max length of output in documentation using `-m {int_value}` in `intunecd-startdocumentation`
Expand All @@ -26,28 +41,6 @@ The package can also be run standalone outside a pipeline, or in one to only bac
- Bugfix for Windows Autopilot profiles not being able to update assignment in a tenant to tenant scenario
- Bugfix for assignment updates where updating assignments when creating new configurations were not possible if the group does not exist

## What's new in 1.0.9
- Bugfix where the script exited with "local variable referenced before assignment" if a management intent does not exist
- Added a new parameter to let you exclude assignments from backups. To exclude assignments from backup, you can now use `-e assignments` when running IntuneCD-startbackup.

## What's new in 1.0.8
Main focus for this release has been to improve the performance as large setups can take a while to backup/update. With these enhancements, I was able to cut the run time by 80% in most cases

- Added module to use MS Graph batching to get assignments instead on getting them for each configuration individually
- General code clean up
- Added new module for getting and updating assignments, the old one was quite messy
- For some configurations, additional information is appended to the filename, this is because there might be configurations with the same name
- App Configurations (appends odata type)
- App Protections (appends management type for ios/android and odata type for windows)
- Applications (for Windows it now appends the app type e.g. Win32 and version)
- Compliance (appends odata type)
- Profiles (appends odata type)
- All configurations are now requested from the start and matched in script with displayName and/or odata type instead of requesting each configuration based on displayName
- Management intents are now batched using the new batching module
- Assignments are now batched using the new batching module
- If 504 or 502 is encountered while getting configurations, the tool will now try again to get the configuration
- For Windows apps in documentation, detection scripts etc will now have a "Click to expand..." instead of showing the whole script

## Install this package
```python
pip install IntuneCD
Expand Down
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ignore:
- "src/IntuneCD/run_backup.py"
- "src/IntuneCD/run_update.py"
- "src/IntuneCD/run_documentation.py"
- "src/IntuneCD/get_accesstoken.py"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = IntuneCD
version = 1.1.1
version = 1.1.2
author = Tobias Almén
author_email = [email protected]
description = Tool to backup and update configurations in Intune
Expand Down
78 changes: 39 additions & 39 deletions src/IntuneCD/backup_AppProtection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@

"""
This module backs up all App Protection Polices in Intune.

Parameters
----------
path : str
The path to save the backup to
output : str
The format the backup will be saved as
token : str
The token to use for authenticating the request
"""

import json
import os
import yaml

from .clean_filename import clean_filename
from .graph_request import makeapirequest
from .graph_batch import batch_assignment, get_object_assignment
from .save_output import save_output
from .remove_keys import remove_keys

# Set MS Graph endpoint
ENDPOINT = "https://graph.microsoft.com/beta/deviceAppManagement/managedAppPolicies"

## Set MS Graph endpoint
endpoint = "https://graph.microsoft.com/beta/deviceAppManagement/managedAppPolicies"

## Get all App Protection policies and save them in specified path
# Get all App Protection policies and save them in specified path
def savebackup(path, output, exclude, token):
configpath = path+"/"+"App Protection/"
data = makeapirequest(endpoint, token)
"""
Saves all App Protection policies in Intune to a JSON or YAML file.

assignment_responses = batch_assignment(data,f'deviceAppManagement/','/assignments',token,app_protection=True)
:param path: Path to save the backup to
:param output: Format the backup will be saved as
:param token: Token to use for authenticating the request
"""
config_count = 0
configpath = path + "/" + "App Protection/"
data = makeapirequest(ENDPOINT, token)

## If profile is ManagedAppConfiguration, skip to next
assignment_responses = batch_assignment(
data,
'deviceAppManagement/',
'/assignments',
token,
app_protection=True)

# If profile is ManagedAppConfiguration, skip to next
for profile in data['value']:
if profile['@odata.type'] == "#microsoft.graph.targetedManagedAppConfiguration":
continue


config_count += 1

if "assignments" not in exclude:
assignments = get_object_assignment(profile['id'],assignment_responses)
assignments = get_object_assignment(
profile['id'], assignment_responses)
if assignments:
profile['assignments'] = assignments

remove_keys = {'id', 'createdDateTime', 'version',
'lastModifiedDateTime', 'deployedAppCount', 'isAssigned'}
for k in remove_keys:
profile.pop(k, None)

profile = remove_keys(profile)

print("Backing up App Protection: " + profile['displayName'])
if os.path.exists(configpath) == False:
os.mkdir(configpath)

if 'targetedAppManagementLevels' in profile:
fname = clean_filename(f"{profile['displayName']}_{profile['targetedAppManagementLevels']}")
fname = clean_filename(
f"{profile['displayName']}_{profile['targetedAppManagementLevels']}")
else:
fname = clean_filename(f"{profile['displayName']}_{str(profile['@odata.type'].split('.')[2])}")
fname = clean_filename(
f"{profile['displayName']}_{str(profile['@odata.type'].split('.')[2])}")

## Save App Protection as JSON or YAML depending on configured value in "-o"
if output != "json":
with open(configpath+fname+".yaml", 'w') as yamlFile:
yaml.dump(profile, yamlFile, sort_keys=False,
default_flow_style=False)
else:
with open(configpath+fname+".json", 'w') as jsonFile:
json.dump(profile, jsonFile, indent=10)
# Save App Protection as JSON or YAML depending on configured value in
# "-o"
save_output(output, configpath, fname, profile)

return config_count
57 changes: 25 additions & 32 deletions src/IntuneCD/backup_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,40 @@

"""
This module backs up Apple Push Notification setting in Intune.

Parameters
----------
path : str
The path to save the backup to
output : str
The format the backup will be saved as
token : str
The token to use for authenticating the request
"""

import json
import os
import yaml

from .clean_filename import clean_filename
from .graph_request import makeapirequest
from .save_output import save_output
from .remove_keys import remove_keys

## Set MS Graph endpoint
endpoint = "https://graph.microsoft.com/beta/deviceManagement/applePushNotificationCertificate"
# Set MS Graph endpoint
ENDPOINT = "https://graph.microsoft.com/beta/deviceManagement/applePushNotificationCertificate"

## Get APNs information and save in specified path

# Get APNs information and save in specified path
def savebackup(path, output, token):
configpath = path+"/"+"Apple Push Notification/"
data = makeapirequest(endpoint, token)
"""
Save Apple Push Notification setting to a JSON or YAML file.

:param path: Path to save the backup to
:param output: Format the backup will be saved as
:param token: Token to use for authenticating the request
"""

config_count = 0

configpath = path + "/" + "Apple Push Notification/"
data = makeapirequest(ENDPOINT, token)

if data:
remove_keys = {'id', 'version', 'topicIdentifier', 'certificate'}
for k in remove_keys:
data.pop(k, None)
config_count += 1
data = remove_keys(data)
print("Backing up Apple Push Notification: " + data['appleIdentifier'])
if os.path.exists(configpath) == False:
os.mkdir(configpath)

## Get filename without illegal characters
# Get filename without illegal characters
fname = clean_filename(data['appleIdentifier'])
## Save APNs as JSON or YAML depending on configured value in "-o"
if output != "json":
with open(configpath+fname+".yaml", 'w') as yamlFile:
yaml.dump(data, yamlFile, sort_keys=False,
default_flow_style=False)
else:
with open(configpath+fname+".json", 'w') as jsonFile:
json.dump(data, jsonFile, indent=10)
# Save APNs as JSON or YAML depending on configured value in "-o"
save_output(output, configpath, fname, data)

return config_count
Loading