diff --git a/src/arcrest/manageags/_clusters.py b/src/arcrest/manageags/_clusters.py index 16c270b..15c2096 100644 --- a/src/arcrest/manageags/_clusters.py +++ b/src/arcrest/manageags/_clusters.py @@ -1,6 +1,8 @@ from .._abstract.abstract import BaseAGSServer import json from parameters import ClusterProtocol +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + ######################################################################## class Clusters(BaseAGSServer): """ @@ -39,9 +41,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, @@ -85,12 +91,16 @@ def createCluster(self, clusterName, machineNames="", tcpClusterPort=None): """ url = self._url + "/create" params = { - "token" : self._securityHandler.token, "f" : "json", "clusterName" : clusterName, "machineNames" : machineNames, "tcpClusterPort" : tcpClusterPort } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -105,9 +115,13 @@ def getAvailableMachines(self): """ url = self._url + "/getAvailableMachines" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -152,9 +166,13 @@ def __init__(self, url, securityHandler, proxy_url=None, proxy_port=None, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, @@ -234,9 +252,13 @@ def start(self): operation reports an error. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/start" return self._do_post(url=url, param_dict=params, @@ -251,9 +273,13 @@ def stop(self): be reached, then this operation reports an error. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/stop" return self._do_post(url=url, param_dict=params, @@ -268,9 +294,13 @@ def delete(self): also stopped. Deleting a cluster does not delete your GIS services. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/delete" return self._do_post(url=url, param_dict=params, @@ -286,9 +316,13 @@ def servicesInCluster(self): This resource was added at ArcGIS 10.1 Service Pack 1. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/services" return self._do_post(url=url, param_dict=params, @@ -306,9 +340,13 @@ def machinesInCluster(self): """ url = self._url + "/machines" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -328,9 +366,13 @@ def addMachinesToCluster(self, machineNames): url = self._url + "/machines/add" params = { "f" : "json", - "token" : self._securityHandler.token, "machineNames" : machineNames } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -349,9 +391,13 @@ def removeMachinesFromCluster(self, url = self._url + "/machines/remove" params = { "f" : "json", - "token" : self._securityHandler.token, "machineNames" : machineNames } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -368,9 +414,13 @@ def editProtocol(self, clusterProtocolObj): url = self._url + "/editProtocol" params = { "f" : "json", - "token" : self._securityHandler.token, "clusterProtocol" : str(clusterProtocolObj) } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, diff --git a/src/arcrest/manageags/_data.py b/src/arcrest/manageags/_data.py index bf420fd..37f6e6d 100644 --- a/src/arcrest/manageags/_data.py +++ b/src/arcrest/manageags/_data.py @@ -1,4 +1,6 @@ from .._abstract.abstract import BaseAGSServer +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + import json ######################################################################## class Data(BaseAGSServer): @@ -46,9 +48,13 @@ def datastoreConfiguration(self): published can reference data. Values: true | false """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token dURL = self._url + "/config" return self._do_get(url=dURL, param_dict=params, proxy_url=self._proxy_url, @@ -67,9 +73,13 @@ def updateDatastoreConfiguration(self, datastoreConfig={}): """ params = { "f" : "json", - "token" : self._securityHandler.token, "datastoreConfig" : datastoreConfig } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/config/update" return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -89,9 +99,13 @@ def computeTotalRefCount(self, path): cURL = self._url + "/computeTotalRefCount" params = { "f" : "json", - "token" : self._securityHandler.token, "path" : path } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=cURL, param_dict=params, proxy_url=self._proxy_url, @@ -112,9 +126,13 @@ def findDataItems(self, parentPath=None, ancestorPath=None, dictionary """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if parentPath is not None: params['parentPath'] = parentPath if ancestorPath is not None: @@ -139,9 +157,13 @@ def registerDataItem(self, item): """ params = { "item" : item, - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token rURL = self._url + "/registerItem" return self._do_post(url=rURL, param_dict=params, proxy_url=self._proxy_url, @@ -154,9 +176,13 @@ def rootDataItems(self): """ url = self._url + "/items" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -166,8 +192,12 @@ def rootDataItems(self): def validateAllDataItems(self): """ validates all the items in the datastore """ params = { - "f" : "json", - "token": self._securityHandler.token} + "f" : "json"} + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/validateAllDataItems" return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -191,9 +221,13 @@ def validateDataItem(self, item): """ params = { "f" : "json", - "token" : self._securityHandler.token, "item" : item } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/ validateDataItem" return self._do_post(url=url, param_dict=params, @@ -208,9 +242,13 @@ def makePrimary(self, dataStoreName, machineName): """ url = self._url + "/items/enterpriseDatabases/%s/machines/%s/makePrimary" % (dataStoreName, machineName) params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -227,9 +265,13 @@ def removeDataStoreMachine(self, dataStoreItemName, machineName): """ url = self._url + "/items/enterpriseDatabases/%s/machines/%s/remove" % (dataStoreItemName, machineName) params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -244,9 +286,13 @@ def startDataStoreMachine(self, dataStoreItemName, machineName): """ url = self._url + "/items/enterpriseDatabases/%s/machines/%s/start" % (dataStoreItemName, machineName) params = { - "f": "json", - "token" : self._securityHandler.token + "f": "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -261,9 +307,13 @@ def stopDataStoreMachine(self, dataStoreItemName, machineName): """ url = self._url + "/items/enterpriseDatabases/%s/machines/%s/stop" % (dataStoreItemName, machineName) params = { - "f": "json", - "token" : self._securityHandler.token + "f": "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -283,9 +333,13 @@ def unregisterDataItem(self, path): url = self._url + "/unregisterItem" params = { "f" : "json", - "token" : self._securityHandler.token, "path" : path } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -301,9 +355,13 @@ def validateDataStore(self, dataStoreName, machineName): """ url = self._url + "/items/enterpriseDatabases/%s/machines/%s/validate" % (dataStoreName, machineName) params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, diff --git a/src/arcrest/manageags/_info.py b/src/arcrest/manageags/_info.py index 8e33af3..8d2f4ae 100644 --- a/src/arcrest/manageags/_info.py +++ b/src/arcrest/manageags/_info.py @@ -1,5 +1,6 @@ import json from .._abstract.abstract import BaseAGSServer +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler ######################################################################## class Info(BaseAGSServer): @@ -38,9 +39,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -122,8 +127,11 @@ def healthCheck(self): params = { "f" : "json" } - if not self._securityHandler is None: - params['token'] = self._securityHandler.token + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -136,9 +144,13 @@ def getAvailableTimeZones(self): """ url = self._url + "/getAvailableTimeZones" params = { - "token" : self._securityHandler.token, "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url, params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) \ No newline at end of file diff --git a/src/arcrest/manageags/_kml.py b/src/arcrest/manageags/_kml.py index 56f986e..1a02663 100644 --- a/src/arcrest/manageags/_kml.py +++ b/src/arcrest/manageags/_kml.py @@ -1,5 +1,6 @@ import json from .._abstract.abstract import BaseAGSServer +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler ######################################################################## class KML(BaseAGSServer): @@ -29,9 +30,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, @@ -56,9 +61,13 @@ def createKMZ(self, kmz_as_json): kmlURL = self._url + "/createKmz" params = { "f" : "json", - "token" : self._securityHandler.token, "kml" : kmz_as_json } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=kmlURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) diff --git a/src/arcrest/manageags/_logs.py b/src/arcrest/manageags/_logs.py index dc85391..3ee0eff 100644 --- a/src/arcrest/manageags/_logs.py +++ b/src/arcrest/manageags/_logs.py @@ -1,6 +1,8 @@ from .._abstract.abstract import BaseAGSServer from datetime import datetime import csv, json +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + ######################################################################## class Log(BaseAGSServer): """ Log of a server """ @@ -32,9 +34,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -81,9 +87,13 @@ def countErrorReports(self, machine="*"): """ params = { "f": "json", - "token" : self._securityHandler.token, "machine" : machine } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=self._url + "/countErrorReports", param_dict=params, proxy_url=self._proxy_url, @@ -92,9 +102,13 @@ def countErrorReports(self, machine="*"): def clean(self): """ Deletes all the log files on all server machines in the site. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=self._url + "/clean", param_dict=params, proxy_url=self._proxy_url, @@ -104,9 +118,13 @@ def clean(self): def logSettings(self): """ returns the current log settings """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token sURL = self._url + "/settings" return self._do_get(url=sURL, param_dict=params, proxy_url=self._proxy_url, @@ -132,8 +150,12 @@ def editLogSettings(self, allowed_levels = ("OFF", "SEVERE", "WARNING", "INFO", "FINE", "VERBOSE", "DEBUG") currentSettings= self.logSettings currentSettings["f"] ="json" - currentSettings["token"] = self._securityHandler.token - + + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + currentSettings['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + currentSettings['token'] = self._securityHandler.token if logLevel.upper() in allowed_levels: currentSettings['logLevel'] = logLevel.upper() if logDir is not None: @@ -182,10 +204,14 @@ def query(self, qFilter['codes'] = codes params = { "f" : "json", - "token" : self._securityHandler.token, "sinceServerStart" : sinceServerStart, "pageSize" : 10000 } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if startTime is not None and \ isinstance(startTime, datetime): params['startTime'] = startTime.strftime("%Y-%m-%dT%H:%M:%S") diff --git a/src/arcrest/manageags/_security.py b/src/arcrest/manageags/_security.py index 1327247..c164f7d 100644 --- a/src/arcrest/manageags/_security.py +++ b/src/arcrest/manageags/_security.py @@ -1,5 +1,7 @@ from .._abstract.abstract import BaseAGSServer import json +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + ######################################################################## class Security(BaseAGSServer): """ The security resource is a container for all resources and @@ -37,9 +39,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -78,10 +84,14 @@ def addRole(self, name, description=""): """ params = { "f" : "json", - "token" : self._securityHandler.token, "name" : name, "description" : description } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token aURL = self._url + "/roles/add" return self._do_post(url=aURL, param_dict=params, proxy_url=self._proxy_url, @@ -101,10 +111,14 @@ def addUser(self, username, password, """ params = { "f" : "json", - "token" : self._securityHandler.token, "username" : username, "password" : password, } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if fullname is not None: params['fullname'] = fullname if description is not None: @@ -120,10 +134,14 @@ def addUsersToRole(self, rolename, users): """ Assigns a role to multiple users """ params = { "f" : "json", - "token" : self._securityHandler.token, "rolename" : rolename, "users" : users } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token rURL = self._url + "/roles/addUsersToRole" return self._do_post(url=rURL, param_dict=params, proxy_url=self._proxy_url, @@ -158,10 +176,14 @@ def assignPrivilege(self, rolename, privilege="ACCESS"): aURL = self._url + "/roles/assignPrivilege" params = { "f" : "json", - "token" : self._securityHandler.token, "rolename" : rolename, "privilege" : privilege } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=aURL, param_dict=params, proxy_url=self._proxy_url, @@ -183,10 +205,14 @@ def assignRoles(self, username, roles): """ params = { "f" : "json", - "token" : self._securityHandler.token, "username" : username, "roles" : roles } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/users/assignRoles" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -201,9 +227,13 @@ def disablePrimarySiteAdministrator(self): """ dURL = self._url + "/psa/disable" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=dURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -223,9 +253,13 @@ def enablePrimarySiteAdministrator(self): """ eURL = self._url + "/psa/enable" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=eURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -240,9 +274,13 @@ def getPrivilegeForRole(self, rolename): """ params = { "f" : "json", - "token" : self._securityHandler.token, "rolename" : rolename } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token pURL = self._url + "/roles/getPrivilege" return self._do_post(url=pURL, param_dict=params, @@ -259,9 +297,13 @@ def getPrivilegeForUser(self, username): """ params = { "f" : "json", - "token" : self._securityHandler.token, "username" : username } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/users/getPrivilege" return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -284,10 +326,14 @@ def getRoles(self, startIndex=0, pageSize=10): uURL = self._url + "/roles/getRoles" params = { "f" : "json", - "token" : self._securityHandler.token, "startIndex" : startIndex, "pageSize" : pageSize } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -303,9 +349,13 @@ def getRolesByPrivilege(self, privilege): uURL = self._url + "/roles/getRolesByPrivilege" params = { "f" : "json", - "token" : self._securityHandler.token, "privilege" : privilege } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -322,9 +372,13 @@ def getRolesForUser(self, username, filter=None, maxCount=None): uURL = self._url + "/roles/getRolesForUser" params = { "f" : "json", - "token" : self._securityHandler.token, "username" : username } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if filter is not None: params['filter'] = filter @@ -352,10 +406,14 @@ def getUsers(self, startIndex=0, pageSize=10): uURL = self._url + "/users/getUsers" params={ "f" : "json", - "token" : self._securityHandler.token, "startIndex" : startIndex, "pageSize" : pageSize } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -375,10 +433,14 @@ def getUsersWithinRole(self, rolename, filter=None, maxCount=20): uURL = self._url + "/roles/getUsersWithinRole" params = { "f" : "json", - "token" : self._securityHandler.token, "rolename" : rolename, "maxCount" : maxCount } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if filter is not None and \ isinstance(filter, str): params['filter'] = filter @@ -390,9 +452,13 @@ def getUsersWithinRole(self, rolename, filter=None, maxCount=20): def primarySiteAdministrator(self): """ returns if the primary site admin has been disabled """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/psa" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -410,9 +476,13 @@ def removeRole(self, rolename): """ params = { "f" : "json", - "token" : self._securityHandler.token, "rolename" : rolename } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/roles/remove" return self._do_post(url=uURL, param_dict=params, @@ -433,10 +503,14 @@ def removeRoles(self, username, roles): uURL = self._url + "/users/removeRoles" params = { "f" : "json", - "token" : self._securityHandler.token, "username" : username, "roles" : roles } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -451,9 +525,13 @@ def removeUser(self, username): """ params = { "f" : 'json', - "token" : self._securityHandler.token, "username" : username } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/users/remove" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -470,10 +548,14 @@ def removeUsersFromRole(self, rolename, users): """ params = { "f" : 'json', - "token" : self._securityHandler.token, "rolename" : rolename, "users" : users } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/roles/removeUsersFromRole" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -485,9 +567,13 @@ def roles(self): returns the number of roles for AGS """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/roles" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -506,10 +592,14 @@ def searchRoles(self, filter="", maxCount=""): """ params = { "f" : "json", - "token" : self._securityHandler.token, "filter" : filter, "maxCount" : maxCount } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/roles/search" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -528,10 +618,14 @@ def searchUsers(self, filter="", maxCount=""): """ params = { "f" : "json", - "token" : self._securityHandler.token, "filter" : filter, "maxCount" : maxCount } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/users/search" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, diff --git a/src/arcrest/manageags/_services.py b/src/arcrest/manageags/_services.py index 5cbe8cc..2397d85 100644 --- a/src/arcrest/manageags/_services.py +++ b/src/arcrest/manageags/_services.py @@ -1,4 +1,6 @@ from .._abstract.abstract import BaseAGSServer +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + from parameters import Extension import os import json @@ -42,9 +44,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._currentURL, param_dict=params, proxy_url=self._proxy_url, @@ -136,9 +142,13 @@ def services(self): """ returns the services in the current folder """ self._services = [] params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._currentURL, param_dict=params, proxy_url=self._proxy_url, @@ -176,9 +186,13 @@ def find_services(self, service_type="*"): if v.upper() not in allowed_service_types: return {"message" : "%s is not an allowed service type." % v} params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token type_services = [] folders = self.folders folders.append("") @@ -223,10 +237,14 @@ def addFolderPermission(self, principal, isAllowed=True, folder=None): uURL = self._url + "/permissions/add" params = { "f" : "json", - "token" : self._securityHandler.token, "principal" : principal, "isAllowed" : isAllowed } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -243,9 +261,13 @@ def cleanPermsissions(self, principal): uURL = self._url + "/permissions/clean" params = { "f" : "json", - "token" : self._securityHandler.token, "principal" : principal } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -261,10 +283,14 @@ def createFolder(self, folderName, description=""): """ params = { "f" : "json", - "token" : self._securityHandler.token, "folderName" : folderName, "description" : description } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/createFolder" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -279,9 +305,13 @@ def deleteFolder(self, folderName): JSON message as dictionary """ params = { - "f" : "json", - "token" : self._securityHandler.token, + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if folderName in self.folders: uURL = self._url + "/%s/delete" % folderName return self._do_post(url=uURL, param_dict=params, @@ -309,9 +339,13 @@ def deleteService(self, serviceName, serviceType, folder=None): serviceName, serviceType) params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -330,9 +364,13 @@ def service_report(self, folder=None): uURL = self._url + "/%s/report" % folder params = { "f" : "json", - "token" : self._securityHandler.token, "parameters" : items } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -341,9 +379,13 @@ def service_report(self, folder=None): def types(self): """ returns the allowed services types """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/types" return self._do_get(url=uURL, param_dict=params, @@ -365,11 +407,15 @@ def rename_service(self, serviceName, serviceType, """ params = { "f" : "json", - "token" : self._securityHandler.token, "serviceName" : serviceName, "serviceType" : serviceType, "serviceNewName" : serviceNewName } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if folder is None: uURL = self._url + "/renameService" else: @@ -385,9 +431,13 @@ def createService(self, service): """ url = self._url + "/createService" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if isinstance(service, str): params['service'] = service elif isinstance(service, dict): @@ -420,9 +470,13 @@ def stopServices(self, services ): url = self._url + "/stopServices" params = { "f" : "json", - "token" : self._securityHandler.token, "service" : json.dumps(services) } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -497,9 +551,13 @@ def __init__(self, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._currentURL, param_dict=params, proxy_url=self._proxy_url, @@ -736,9 +794,13 @@ def serviceName(self): def start_service(self): """ starts the specific service """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/start" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -747,9 +809,13 @@ def start_service(self): def stop_service(self): """ stops the current service """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/stop" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -764,9 +830,13 @@ def restart_services(self): def delete_service(self): """deletes a service from arcgis server""" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/delete" return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -776,9 +846,13 @@ def delete_service(self): def status(self): """ returns the status of the service """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/status" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -787,9 +861,13 @@ def status(self): def statistics(self): """ returns the stats for the service """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/statistics" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -798,9 +876,13 @@ def statistics(self): def permissions(self): """ returns the permissions for the service """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/permissions" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -810,9 +892,13 @@ def permissions(self): def iteminfo(self): """ returns the item information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token uURL = self._url + "/iteminfo" return self._do_get(url=uURL, param_dict=params, proxy_url=self._proxy_url, @@ -832,10 +918,13 @@ def itemInfoUpload(self, folder, filePath): import urlparse params = { "f" : "json", - "folder" : folder, - "token" : self._securityHandler.token - + "folder" : folder } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token files.append(('file', filePath, os.path.basename(filePath))) parsed = urlparse.urlparse(url) return self._post_multipart(host=parsed.hostname, @@ -862,9 +951,13 @@ def editItemInfo(self, json_dict): url = self._url + "/iteminfo/edit" params = { "f" : "json", - "token" : self._securityHandler.token, "serviceItemInfo" : json.dumps(json_dict) } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -886,8 +979,12 @@ def serviceManifest(self, fileType="json"): url = self._url + "/iteminfo/manifest/manifest.%s" % fileType params = { - "token" : self._securityHandler.token } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token f = self._download_file(url=url, save_path=tempfile.gettempdir(), file_name=os.path.basename(url), param_dict=params, proxy_url=self._proxy_url, @@ -908,10 +1005,14 @@ def addPermission(self, principal, isAllowed=True): uURL = self._url + "/permissions/add" params = { "f" : "json", - "token" : self._securityHandler.token, "principal" : principal, "isAllowed" : isAllowed } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=uURL, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -925,10 +1026,14 @@ def edit(self, service): """ url = self._url + "/edit" params = { - "f" : "json", - "token" : self._securityHandler.token, + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if isinstance(service, str): params['service'] = service elif isinstance(service, dict): diff --git a/src/arcrest/manageags/_system.py b/src/arcrest/manageags/_system.py index 28efce6..bfd14db 100644 --- a/src/arcrest/manageags/_system.py +++ b/src/arcrest/manageags/_system.py @@ -1,4 +1,6 @@ from .._abstract.abstract import BaseAGSServer +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + import json ######################################################################## class System(BaseAGSServer): @@ -33,9 +35,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -78,9 +84,13 @@ def serverDirectories(self): directs = [] url = self._url + "/directories" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token res = self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -104,10 +114,13 @@ def licenses(self): """ url = self._url + "/licenses" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } - + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -135,9 +148,13 @@ def webAdaptors(self): """ url = self._url + "/webadaptors" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -153,9 +170,13 @@ def webAdaptorsConfiguration(self): """ url = self._url + "/webadaptors/config" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -173,9 +194,13 @@ def updateWebAdaptorsConfiguration(self, webAdaptorConfig): url = self._url + "/webadaptors/config/update" params = { "f" : "json", - "token" : self._securityHandler.token, "webAdaptorConfig" : webAdaptorConfig } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -220,9 +245,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -300,12 +329,16 @@ def edit(self, typeValue, url = self._url + "/edit" params = { "f" : "json", - "token" : self._securityHandler.token, "type" : typeValue, "connectionString" : connectionString, "move" : move, "runAsync" : runAsync } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -343,9 +376,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -383,9 +420,13 @@ def getJobDetails(self, jobId): """ url = self._url + "/%s" % jobId params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -505,9 +546,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -534,9 +579,13 @@ def updateServerProperties(self, properties): url = self._url + "/update" params = { "f" : "json", - "token" : self._securityHandler.token, "properties" : properties } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -597,9 +646,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -697,12 +750,16 @@ def edit(self, url = self._url + "/edit" params = { "f" : "json", - "token" : self._securityHandler.token, "physicalPath" : physicalPath, "cleanupMode" : cleanupMode, "maxFileAge" : maxFileAge, "description" : description } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -720,9 +777,13 @@ def clean(self): """ url = self._url + "/clean" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -736,9 +797,13 @@ def unregisterDirectory(self): """ url = self._url + "/unregister" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, diff --git a/src/arcrest/manageags/_uploads.py b/src/arcrest/manageags/_uploads.py index dd18ff4..fe57d27 100644 --- a/src/arcrest/manageags/_uploads.py +++ b/src/arcrest/manageags/_uploads.py @@ -1,5 +1,7 @@ from .._abstract.abstract import BaseAGSServer import os +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + ######################################################################## class Uploads(BaseAGSServer): """ @@ -34,9 +36,13 @@ def uploads(self): the server. """ params = { - "f" :"json", - "token" : self._securityHandler.token + "f" :"json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=self._url, param_dict=params, header={}, @@ -52,9 +58,13 @@ def deleteItem(self, itemId): """ url = self._url + "/%s/delete" % itemId params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -75,9 +85,13 @@ def item(self, itemId): """ url = self._url + "/%s" % itemId params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_get(url=url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -87,9 +101,13 @@ def uploadItem(self, filePath, description): import urlparse url = self._url + "/upload" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token files = [] files.append(('itemFile', filePath, os.path.basename(filePath))) parsed = urlparse.urlparse(url) diff --git a/src/arcrest/manageags/_usagereports.py b/src/arcrest/manageags/_usagereports.py index 0bd7dd9..e341c62 100644 --- a/src/arcrest/manageags/_usagereports.py +++ b/src/arcrest/manageags/_usagereports.py @@ -1,5 +1,7 @@ from .._abstract.abstract import BaseAGSServer from urllib import urlencode, quote_plus +from ..security.security import ArcGISTokenSecurityHandler,AGOLTokenSecurityHandler, PortalTokenSecurityHandler, OAuthSecurityHandler, PortalServerSecurityHandler + import json ######################################################################## class UsageReports(BaseAGSServer): @@ -35,9 +37,13 @@ def __init__(self, url, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -97,9 +103,13 @@ def usageReportSettings(self): statistics are persisted forever. """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/settings" return self._do_get(url=url, param_dict=params, @@ -127,11 +137,15 @@ def editUsageReportSettings(self, samplingInterval, """ params = { "f" : "json", - "token" : self._securityHandler.token, "maxHistory" : maxHistory, "enabled" : enabled, "samplingInterval" : samplingInterval } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/settings/edit" return self._do_post(url=url, param_dict=params, @@ -248,12 +262,16 @@ def createUsageReport(self, params = { "f" : "json", - "token" : self._securityHandler.token, "reportname" : reportname, "since" : since, "metadata" : metadata } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token if isinstance(queries, dict): params["queries"] = [queries] elif isinstance(queries, list): @@ -308,9 +326,13 @@ def __init__(self, url, securityHandler, def __init(self): """ populates server admin information """ params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token json_dict = self._do_get(url=self._url, param_dict=params, proxy_url=self._proxy_url, proxy_port=self._proxy_port) @@ -441,9 +463,13 @@ def edit(self): } params = { "f" : "json", - "token": self._securityHandler.token, "usagereport" : json.dumps(usagereport_dict) } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/edit" return self._do_post(url=url, param_dict=params, @@ -454,9 +480,13 @@ def delete(self): """deletes the current report""" url = self._url + "/delete" params = { - "f" : "json", - "token" : self._securityHandler.token + "f" : "json" } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -490,9 +520,13 @@ def query(self, queryFilter): """ params = { "f" : "json", - "token" : self._securityHandler.token, "filter" : queryFilter } + if self._securityHandler is not None: + if isinstance(self._securityHandler , PortalTokenSecurityHandler): + params['token'] = self._securityHandler.servertoken(serverURL=self._url,referer=self._url) + else: + params['token'] = self._securityHandler.token url = self._url + "/query" return self._do_post(url=url, param_dict=params,