Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
enhancements to support portal handler in manageags/administration.py
Browse files Browse the repository at this point in the history
new sample to test changes
  • Loading branch information
MikeMillerGIS committed Jun 25, 2015
1 parent 6c70474 commit fed4ec6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 30 deletions.
59 changes: 59 additions & 0 deletions samples/view_hosting_servers_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from arcrest.security import AGSTokenSecurityHandler,PortalTokenSecurityHandler
from arcrest.manageags import AGSAdministration
import arcrest
if __name__ == "__main__":
username = "<Username>"
password = "<Password>"
url = "<Org 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 = "<UserName>"
password = "<Password>"
token_url = "https://<ServerURL>/<Instance>/sharing/rest/generateToken"
url = "http://<ServerURL>/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
42 changes: 33 additions & 9 deletions src/arcrest/manageags/administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def createSite(self,
url = self._url + "/createNewSite"
params = {
"f" : "json",
"token" : self._securityHandler.token,
"cluster" : cluster,
"directories" : directories,
"username" : username,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
47 changes: 26 additions & 21 deletions src/arcresthelper/_abstract/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os
from .. import common
import gc

import urllib2

########################################################################
class baseToolsClass(object):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fed4ec6

Please sign in to comment.