From 16ad465c45b05de94bf5c96df47acc2acd48f9af Mon Sep 17 00:00:00 2001 From: Shea Craig Date: Tue, 21 Jul 2015 15:15:51 -0400 Subject: [PATCH] Move `JSS._url` and `JSS.base_url` to @properties. - rstrip URL's with a trailing slash. This is a common mistake and barrier to use. --- CHANGELOG.md | 4 +++- jss/__init__.py | 2 +- jss/jss.py | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c05f0..229e92d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,14 @@ All notable changes to this project will be documented in this file. This projec - ndg-httpsclient - Previous two required for cipher change support. - TODO: Updated documentation to describe this requirement for developer (i.e. anyone who does not use the egg or wheel files to install). +- `JSS.base_url` (Get and Set) and `JSS._url` (Read only) are now proper properties. ### Fixed - Changes the default cipher list for requests/urllib3 to work with recommended changes in JSS >= v9.73. -- `jss.JSS.verify_ssl` is now a computed property and will properly update the requests session if changed after instantiation. +- `jss.JSS.ssl_verify` is now a computed property and will properly update the requests session if changed after instantiation. - casper package's `Casper` class did not use the requests session on the JSS object passed to it. +- JSS URL's with a trailing slash will be sanitized to remove that slash upon JSS instantiation or `base_url` update. ## [1.1.0] - 2015-06-10 - Velvet Nachos diff --git a/jss/__init__.py b/jss/__init__.py index 7c89093..468d0b2 100644 --- a/jss/__init__.py +++ b/jss/__init__.py @@ -31,4 +31,4 @@ JSSUnsupportedFileType, JSSError) from tools import is_osx, is_linux -__version__ = "1.2.0" +__version__ = "1.2.0rc2" diff --git a/jss/jss.py b/jss/jss.py index 79ce02e..e0e7674 100755 --- a/jss/jss.py +++ b/jss/jss.py @@ -26,6 +26,7 @@ import copy import subprocess import ssl +import urlparse from .exceptions import ( JSSPrefsMissingFileError, JSSPrefsMissingKeyError, JSSGetError, @@ -147,8 +148,6 @@ def __init__(self, jss_prefs=None, url=None, user=None, password=None, # Used by some non-API methods. self.base_url = url - # Used for all API calls. - self._url = '%s/JSSResource' % url self.user = user self.password = password self.repo_prefs = repo_prefs @@ -185,6 +184,22 @@ def _error_handler(self, exception_cls, response): exception.status_code = response.status_code raise exception + @property + def _url(self): + """The URL to the Casper JSS API endpoints. Get only.""" + return urlparse.urljoin(self.base_url, "JSSResource") + + @property + def base_url(self): + """The URL to the Casper JSS, including port if needed.""" + return self._base_url + + @base_url.setter + def base_url(self, url): + """The URL to the Casper JSS, including port if needed.""" + # Remove the frequently included yet incorrect trailing slash. + self._base_url = url.rstrip("/") + @property def ssl_verify(self): """Boolean value for whether to verify SSL traffic."""