From fed4ec66cbffeb8b6219317b8558ed42ab1d6664 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 24 Jun 2015 20:29:33 -0400 Subject: [PATCH] enhancements to support portal handler in manageags/administration.py new sample to test changes --- samples/view_hosting_servers_details.py | 59 +++++++++++++++++++++++++ src/arcrest/manageags/administration.py | 42 ++++++++++++++---- src/arcresthelper/_abstract/abstract.py | 47 +++++++++++--------- 3 files changed, 118 insertions(+), 30 deletions(-) create mode 100644 samples/view_hosting_servers_details.py diff --git a/samples/view_hosting_servers_details.py b/samples/view_hosting_servers_details.py new file mode 100644 index 0000000..73fd3cf --- /dev/null +++ b/samples/view_hosting_servers_details.py @@ -0,0 +1,59 @@ +from arcrest.security import AGSTokenSecurityHandler,PortalTokenSecurityHandler +from arcrest.manageags import AGSAdministration +import arcrest +if __name__ == "__main__": + username = "" + password = "" + url = "" + proxy_port = None + proxy_url = None + + sH = PortalTokenSecurityHandler(username=username, + password=password, + org_url=url, + proxy_url=proxy_url, + proxy_port=proxy_port) + + admin = arcrest.manageorg.Administration(url=url, + securityHandler=sH) + try: + hostingServers = admin.hostingServers() + for hostingServer in hostingServers: + if isinstance(hostingServer, AGSAdministration): + print str(hostingServer.data.rootDataItems) + print str(hostingServer.clusters) + print str(hostingServer.services) + print str(hostingServer.usagereports) + print str(hostingServer.logs) + print str(hostingServer.kml.items) + print str(hostingServer.security.resources) + print str(hostingServer.system) + + except Exception,e: + print e + try: + username = "" + password = "" + token_url = "https:////sharing/rest/generateToken" + url = "http:///arcgis/admin" + proxy_port = None + proxy_url = None + + sH = AGSTokenSecurityHandler(username=username, + password=password, + token_url=token_url) + + hostingServer = AGSAdministration(url=url, securityHandler=sH, + proxy_url=None, + proxy_port=None, + initialize=False) + print str(hostingServer.data.rootDataItems) + print str(hostingServer.clusters) + print str(hostingServer.services) + print str(hostingServer.usagereports) + print str(hostingServer.logs) + print str(hostingServer.kml.items) + print str(hostingServer.security.resources) + print str(hostingServer.system) + except Exception,e: + print e \ No newline at end of file diff --git a/src/arcrest/manageags/administration.py b/src/arcrest/manageags/administration.py index 7a76d03..56a315f 100644 --- a/src/arcrest/manageags/administration.py +++ b/src/arcrest/manageags/administration.py @@ -151,7 +151,6 @@ def createSite(self, url = self._url + "/createNewSite" params = { "f" : "json", - "token" : self._securityHandler.token, "cluster" : cluster, "directories" : directories, "username" : username, @@ -160,6 +159,11 @@ def createSite(self, "logSettings" : logsSettings, "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, @@ -190,11 +194,15 @@ def joinSite(self, adminURL, username, password): url = self._url + "/joinSite" params = { "f" : "json", - "token" : self._securityHandler.token, "adminURL" : adminURL, "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 return self._do_post(url=url, param_dict=params, proxy_url=self._proxy_url, @@ -218,9 +226,13 @@ def deleteSite(self): """ url = self._url + "/deleteSite" 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, @@ -242,9 +254,13 @@ def exportSite(self, location=None): """ url = self._url + "/exportSite" 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 location is not None: params['location'] = location return self._do_post(url=url, @@ -275,9 +291,13 @@ def importSite(self, location): url = self._url + "/importSite" params = { "f" : "json", - "token" : self._securityHandler.token, "location" : location } + 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, @@ -288,9 +308,13 @@ def publicKey(self): """gets the public key""" url = self._url + "/publicKey" 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, diff --git a/src/arcresthelper/_abstract/abstract.py b/src/arcresthelper/_abstract/abstract.py index 3741273..9a2cd37 100644 --- a/src/arcresthelper/_abstract/abstract.py +++ b/src/arcresthelper/_abstract/abstract.py @@ -11,7 +11,7 @@ import os from .. import common import gc - +import urllib2 ######################################################################## class baseToolsClass(object): @@ -91,26 +91,31 @@ def __init__(self, hostingServers = admin.hostingServers() for hostingServer in hostingServers: if isinstance(hostingServer, AGSAdministration): - serData = hostingServer.data - - dataItems = serData.rootDataItems - if 'rootItems' in dataItems: - for rootItem in dataItems['rootItems']: - if rootItem == '/enterpriseDatabases': - rootItems = serData.findDataItems(ancestorPath=rootItem,type='fgdb,egdb') - if not rootItems is None and 'items' in rootItems: - for item in rootItems['items']: - if 'info' in item: - if 'isManaged' in item['info'] and item['info']['isManaged'] == True: - conStrDic = {} - conStr = item['info']['connectionString'].split(";") - for conStrValue in conStr: - spltval = conStrValue.split("=") - conStrDic[spltval[0]] = spltval[1] - if 'DBCLIENT' in conStrDic: - if str(conStrDic['DBCLIENT']).upper() == 'postgresql'.upper(): - self._featureServiceFieldCase = 'lower' - except e as Exception: + try: + serData = hostingServer.data + + dataItems = serData.rootDataItems + if 'rootItems' in dataItems: + for rootItem in dataItems['rootItems']: + if rootItem == '/enterpriseDatabases': + rootItems = serData.findDataItems(ancestorPath=rootItem,type='fgdb,egdb') + if not rootItems is None and 'items' in rootItems: + for item in rootItems['items']: + if 'info' in item: + if 'isManaged' in item['info'] and item['info']['isManaged'] == True: + conStrDic = {} + conStr = item['info']['connectionString'].split(";") + for conStrValue in conStr: + spltval = conStrValue.split("=") + conStrDic[spltval[0]] = spltval[1] + if 'DBCLIENT' in conStrDic: + if str(conStrDic['DBCLIENT']).upper() == 'postgresql'.upper(): + self._featureServiceFieldCase = 'lower' + except urllib2.HTTPError, err: + print err + except Exception, e: + print e + except Exception, e: print e #if 'error' in self._securityHandler.message and token is None: #if self._securityHandler.message['error']== 401: