grahampugh / jamf-upload

Scripts for uploading packages to Jamf Cloud
Apache License 2.0
149 stars 37 forks source link

Create JamfPackageCleaner.py #98

Closed cr3ation closed 1 year ago

cr3ation commented 1 year ago

A new processor for cleaning packages. Keeping a set number of latest uploads and deletes oldest (based on package id).

Supported attributes:

    "JSS_URL": {
        "required": True,
        "description": "URL to a Jamf Pro server that the API user has write access "
        "to, optionally set as a key in the com.github.autopkg "
        "preference file.",
    },
    "API_USERNAME": {
        "required": True,
        "description": "Username of account with appropriate access to "
        "jss, optionally set as a key in the com.github.autopkg "
        "preference file.",
    },
    "API_PASSWORD": {
        "required": True,
        "description": "Password of api user, optionally set as a key in "
        "the com.github.autopkg preference file.",
    },
    "pkg_name_match": {
        "required": False,
        "description": "The name at the beginning of the package. This is used as a base for cleaning. The default value is '%NAME%-', e.g. 'Google Chrome-'.",
        "default": "",
    },
    "versions_to_keep": {
        "required": False,
        "description": "The number of pkg_name_match values to keep in Jamf Pro. This is based on the package ID.",
        "default": 5,
    },
    "minimum_name_length": {
        "required": False,
        "description": "The minimum number of characters required in pkg_name_match. This is used as a failsafe.",
        "default": 3,
    },
    "maximum_allowed_packages_to_delete": {
        "required": False,
        "description": "The maximum number of packages that can be deleted. This is used as a failsafe.",
        "default": 20,
    },

pkg_name_mach defaults to %NAME%- if not set. Eg. Google Chrome-.

self.pkg_name_match = self.env.get("pkg_name_match") or f"{self.env.get('NAME')}-"
cr3ation commented 1 year ago

Feel free to use.