Commit 9d240305 authored by Sigmund Augdal's avatar Sigmund Augdal

Added support for using a subscription when talking to SPF

This requires that /Microsoft.Management.Odata.svc is no longer part of the baseurl
passed to the constructor. For backwards compatibility we strip it away for now
parent c03c320a
......@@ -22,6 +22,8 @@ namespaces = {
'm': "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
}
ODATA_SUFFIX = "/Microsoft.Management.Odata.svc"
def namespace_split(tagname):
if not '}' in tagname:
......@@ -60,13 +62,21 @@ class ODataException(Exception):
class Client(object):
passman = None
def __init__(self, baseurl, username, password):
def __init__(self, baseurl, username, password, subscription=None):
if baseurl.endswith("/"):
baseurl = baseurl[:-1]
if baseurl.endswith(ODATA_SUFFIX):
baseurl = baseurl[:-len(ODATA_SUFFIX)]
self.baseurl = baseurl
self.auth = HTTPBasicAuth(username, password)
self.session = requests.Session()
self.subscription = subscription
def _format_url(self, resource, query=None, args=None, subresource=None, expand=None):
url = self.baseurl
if self.subscription:
url += "/" + self.subscription
url += ODATA_SUFFIX
fragments = {}
if resource:
url += "/" + resource
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment