salopensource / sal-scripts

Apache License 2.0
23 stars 31 forks source link

Pump up those profiles #32

Closed grahamgilbert closed 6 years ago

grahamgilbert commented 6 years ago

Just send up the output of profiles -C -o /sometemp.plist. The real smarts will be in the server. PTAL @sheagcraig

grahamgilbert commented 6 years ago

@clburlison

>>> import os
>>> ServerURL = 'http://localhost:8000'
>>> os.path.join(ServerURL, 'profiles/submit', '')
'http://localhost:8000/profiles/submit/'
>>> os.path.join(ServerURL, 'profiles/submit')
'http://localhost:8000/profiles/submit'
sheagcraig commented 6 years ago

@clburlison Djangofy your URLs with a trailing ''!

grahamgilbert commented 6 years ago

Although I'm sure there is probably a better URL-specific library we could use, but meh, it works and is in stdlib.

sheagcraig commented 6 years ago

This looks good, but I have one suggestion that I think is pretty slick:

Tempfile has a context manager... like so:

with tempfile.TemporaryDirectory() as temp_dir:
    profile_out = os.path.join(temp_dir, 'profiles.plist')
    cmd = ['/usr/bin/profiles', '-C', '-o', profile_out]
    try:
        subprocess.call(cmd, stdout=devnull)
    except OSError:
        munkicommon.display_debug2("Couldn't output profiles.")
        return

    profiles, _ = utils.get_file_and_hash(profile_out)

This way you don't have to worry about cleaning it up or anything

grahamgilbert commented 6 years ago

As per slack, looks like this isn't in Python 2. Gonna merge unless anyone has any objections?