Skip to content

Commit f3ef2df

Browse files
committed
add images to newly created models
1 parent 04b96d2 commit f3ef2df

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

jamf2snipe

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import configparser
5454
import argparse
5555
import logging
5656
import datetime
57+
from base64 import b64encode
5758
from requests import Session
5859
from requests.adapters import HTTPAdapter
5960
from urllib3 import Retry
@@ -68,6 +69,7 @@ runtimeargs.add_argument("--do_not_update_jamf", help="Does not update Jamf with
6869
runtimeargs.add_argument('--do_not_verify_ssl', help="Skips SSL verification for all requests. Helpful when you use self-signed certificate.", action="store_false")
6970
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")
7071
runtimeargs.add_argument("-f", "--force", help="Updates the Snipe asset with information from Jamf every time, despite what the timestamps indicate.", action="store_true")
72+
runtimeargs.add_argument("-i", "--add_images", help="Attempts to add an image from appledb.dev to any newly created models", action="store_true")
7173
runtimeargs.add_argument("--version", help="Prints the version and exits.", action="store_true")
7274
user_opts = runtimeargs.add_mutually_exclusive_group()
7375
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")
@@ -549,6 +551,10 @@ def get_snipe_user_id(username):
549551
# Function that creates a new Snipe Model - not an asset - with a JSON payload
550552
def create_snipe_model(payload):
551553
api_url = '{}/api/v1/models'.format(snipe_base)
554+
if user_args.add_images:
555+
response = session.get('https://img.appledb.dev/device@1024/{}/0.png'.format(payload["model_number"]))
556+
payload["image"] = "data:" + response.headers['Content-Type'] + ";" + "base64," + b64encode(response.content).decode("utf-8")
557+
552558
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))
553559
response = session.post(api_url, headers=snipeheaders, json=payload, verify=user_args.do_not_verify_ssl, hooks={'response': request_handler})
554560
if response.status_code == 200:

0 commit comments

Comments
 (0)