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

add images to newly created models #129

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ options:
to the standard 120/minute rate limit
-f, --force Updates the Snipe asset with information from Jamf
every time, despite what the timestamps indicate.
-i, --add_images Attempts to add an image from appledb.dev to any
newly created models
--version Prints the version and exits.
-u, --users Checks out the item to the current user in Jamf if
it's not already deployed
Expand Down
6 changes: 6 additions & 0 deletions jamf2snipe
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import configparser
import argparse
import logging
import datetime
from base64 import b64encode
from requests import Session
from requests.adapters import HTTPAdapter
from urllib3 import Retry
Expand All @@ -68,6 +69,7 @@ runtimeargs.add_argument("--do_not_update_jamf", help="Does not update Jamf with
runtimeargs.add_argument('--do_not_verify_ssl', help="Skips SSL verification for all requests. Helpful when you use self-signed certificate.", action="store_false")
runtimeargs.add_argument("-r", "--ratelimited", help="Puts a half second delay between API calls to adhere to the standard 120/minute rate limit", action="store_true")
runtimeargs.add_argument("-f", "--force", help="Updates the Snipe asset with information from Jamf every time, despite what the timestamps indicate.", action="store_true")
runtimeargs.add_argument("-i", "--add_images", help="Attempts to add an image from appledb.dev to any newly created models", action="store_true")
runtimeargs.add_argument("--version", help="Prints the version and exits.", action="store_true")
user_opts = runtimeargs.add_mutually_exclusive_group()
user_opts.add_argument("-u", "--users", help="Checks out the item to the current user in Jamf if it's not already deployed", action="store_true")
Expand Down Expand Up @@ -549,6 +551,10 @@ def get_snipe_user_id(username):
# Function that creates a new Snipe Model - not an asset - with a JSON payload
def create_snipe_model(payload):
api_url = '{}/api/v1/models'.format(snipe_base)
if user_args.add_images:
response = session.get('https://img.appledb.dev/device@1024/{}/0.png'.format(payload["model_number"]))
payload["image"] = "data:" + response.headers['Content-Type'] + ";" + "base64," + b64encode(response.content).decode("utf-8")

logging.debug('Calling to create new snipe model type against: {}\nThe payload for the POST request is:{}\nThe request headers can be found near the start of the output.'.format(api_url, payload))
response = session.post(api_url, headers=snipeheaders, json=payload, verify=user_args.do_not_verify_ssl, hooks={'response': request_handler})
if response.status_code == 200:
Expand Down