Esempio n. 1
0
    def __init__(self,
                 username,
                 password,
                 org_url=None,
                 token_url=None,
                 proxy_url=None,
                 proxy_port=None):
        """Constructor"""
        self._org_url = org_url
        self._username = username
        self._password = password
        self._proxy_url = proxy_url
        self._proxy_port = proxy_port
        self._token_url = token_url
        if self._org_url is None or self._org_url == '':
            self._org_url = 'http://www.arcgis.com'
        if self._org_url is None or '.arcgis.com' in self._org_url:
            self._securityHandler = arcrest.AGOLTokenSecurityHandler(
                username=self._username,
                password=self._password,
                org_url=self._org_url,
                token_url=self._token_url,
                proxy_url=self._proxy_url,
                proxy_port=self._proxy_port)
            token = self._securityHandler.token
            #if 'error' in self._securityHandler.message and token is None:
            #if self._securityHandler.message['error']['code'] == 400:

            #self._securityHandler = arcrest.OAuthSecurityHandler(client_id='',
            #secret_id='',
            #org_url=self._org_url,
            #proxy_url=self._proxy_url,
            #proxy_port=self._proxy_port)
            #token = self._securityHandler.token
        else:

            self._securityHandler = arcrest.PortalTokenSecurityHandler(
                username=self._username,
                password=self._password,
                org_url=self._org_url,
                proxy_url=self._proxy_url,
                proxy_port=self._proxy_port)
            token = self._securityHandler.token
    import traceback, inspect
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    filename = inspect.getfile(inspect.currentframe())
    # script name + line number
    line = tbinfo.split(", ")[1]
    # Get Python syntax error
    #
    synerror = traceback.format_exc().splitlines()[-1]
    return line, filename, synerror


if __name__ == "__main__":

    username = ""
    password = ""
    url = "www.arcgis.com"
    try:
        sh = arcrest.PortalTokenSecurityHandler(username=username,
                                                password=password,
                                                org_url=url)
        admin = arcrest.manageorg.Administration(url=url, securityHandler=sh)

        hostingServers = admin.hostingServers()
        for server in hostingServers:
            print(server.currentVersion)
    except:
        line, filename, synerror = trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
Esempio n. 3
0
    def __init__(self,
                 username,
                 password,
                 org_url=None,
                 token_url=None,
                 proxy_url=None,
                 proxy_port=None):
        """Constructor"""
        self._org_url = org_url
        self._username = username
        self._password = password
        self._proxy_url = proxy_url
        self._proxy_port = proxy_port
        self._token_url = token_url
        if self._org_url is None or self._org_url == '':
            self._org_url = 'http://www.arcgis.com'
        if self._username == "" or self._password == "":
            self._message = "No username or password, no security handler generated"
            self._valid = True
        else:
            if self._org_url is None or '.arcgis.com' in self._org_url:
                self._securityHandler = arcrest.AGOLTokenSecurityHandler(
                    username=self._username,
                    password=self._password,
                    org_url=self._org_url,
                    token_url=self._token_url,
                    proxy_url=self._proxy_url,
                    proxy_port=self._proxy_port)
                token = self._securityHandler.token

                #if self._securityHandler.message['error']['code'] == 400:

                #self._securityHandler = arcrest.OAuthSecurityHandler(client_id='',
                #secret_id='',
                #org_url=self._org_url,
                #proxy_url=self._proxy_url,
                #proxy_port=self._proxy_port)
                #token = self._securityHandler.token
            else:

                self._securityHandler = arcrest.PortalTokenSecurityHandler(
                    username=self._username,
                    password=self._password,
                    org_url=self._org_url,
                    proxy_url=self._proxy_url,
                    proxy_port=self._proxy_port)
                token = self._securityHandler.token
                #if 'error' in self._securityHandler.message and token is None:
                #if self._securityHandler.message['error']== 401:

                #self._securityHandler = arcrest.OAuthSecurityHandler(client_id='s5CKlHcJoNSm07TP',
                #secret_id='6015feb0f44c4a5fa00e1e9486de8c48',
                #org_url=self._org_url,
                #proxy_url=self._proxy_url,
                #proxy_port=self._proxy_port)
                #token = self._securityHandler.token
            if 'error' in self._securityHandler.message and token is None:
                self._message = self._securityHandler.message
                self._valid = False

            else:
                self._message = self._securityHandler.message
                self._valid = True
Esempio n. 4
0
    def __init__(self,
                 username,
                 password,
                 org_url=None,
                 token_url=None,
                 proxy_url=None,
                 proxy_port=None):
        """Constructor"""
        self._org_url = org_url
        self._username = username
        self._password = password
        self._proxy_url = proxy_url
        self._proxy_port = proxy_port
        self._token_url = token_url

        if self._org_url is None or self._org_url == '':
            self._org_url = 'http://www.arcgis.com'
        if self._username == "" or self._password == "":
            self._message = "No username or password, no security handler generated"
            self._valid = True
        else:
            if self._org_url is None or '.arcgis.com' in self._org_url:
                self._securityHandler = arcrest.AGOLTokenSecurityHandler(
                    username=self._username,
                    password=self._password,
                    org_url=self._org_url,
                    token_url=self._token_url,
                    proxy_url=self._proxy_url,
                    proxy_port=self._proxy_port)
                token = self._securityHandler.token

                #if self._securityHandler.message['error']['code'] == 400:

                #self._securityHandler = arcrest.OAuthSecurityHandler(client_id='',
                #secret_id='',
                #org_url=self._org_url,
                #proxy_url=self._proxy_url,
                #proxy_port=self._proxy_port)
                #token = self._securityHandler.token
            else:

                self._securityHandler = arcrest.PortalTokenSecurityHandler(
                    username=self._username,
                    password=self._password,
                    org_url=self._org_url,
                    proxy_url=self._proxy_url,
                    proxy_port=self._proxy_port)
                token = self._securityHandler.token

                admin = arcrest.manageorg.Administration(
                    url=self._org_url, securityHandler=self._securityHandler)

                hostingServers = admin.hostingServers()
                for hostingServer in hostingServers:
                    serData = hostingServer.data
                    serData
                    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'

                #if 'error' in self._securityHandler.message and token is None:
                #if self._securityHandler.message['error']== 401:

                #self._securityHandler = arcrest.OAuthSecurityHandler(client_id='s5CKlHcJoNSm07TP',
                #secret_id='6015feb0f44c4a5fa00e1e9486de8c48',
                #org_url=self._org_url,
                #proxy_url=self._proxy_url,
                #proxy_port=self._proxy_port)
                #token = self._securityHandler.token
            if 'error' in self._securityHandler.message and token is None:
                self._message = self._securityHandler.message
                self._valid = False

            else:
                self._message = self._securityHandler.message
                self._valid = True