示例#1
0
def call_peer(remote_host, remote_user, local_host, local_user, ts, nonce,
              signature):
    ''' make remote REST call to retreive foreign sessionKey '''
    postargs = {
        'name': '_create',
        'userid': local_user,
        'peername': local_host,
        'username': remote_user,
        'ts': ts,
        'nonce': nonce,
        'sig': signature
    }

    resp, cont = rest.simpleRequest(remote_host + REMOTE_ENDPOINT,
                                    postargs=postargs)

    if resp.status not in [200, 201]:
        logger.error('unable to get session key from remote peer %s' %
                     remote_host)

        return None

    try:
        atomEntry = rest.format.parseFeedDocument(cont)
        ret = atomEntry.toPrimitive()[remote_user][remote_user]
        return ret
    except Exception, ex:
        logger.error('unable to parse response from remote peer %s' %
                     remote_host)
        logger.exception(ex)
        return None
示例#2
0
文件: sc_rest.py 项目: TPLink32/spnk1
 def handleRemove(self, confInfo):
     try:
         self.delete()
     except BaseException as ex:
         logger.exception(
             'handleRemove Failed - arguments = %s, exception = %s' %
             (self.callerArgs, ex))
示例#3
0
def call_peer(remote_host, remote_user, local_host, local_user, ts, nonce, signature):
    ''' make remote REST call to retreive foreign sessionKey '''
    postargs = {
        'name': '_create',
        'userid': local_user,
        'peername': local_host,
        'username': remote_user,
        'ts': ts,
        'nonce': nonce,
        'sig': signature
    }
    
    resp, cont = rest.simpleRequest(remote_host + REMOTE_ENDPOINT, postargs=postargs)

    if resp.status not in [200, 201]:
        logger.error('unable to get session key from remote peer %s' % remote_host)
        
        return None

    try:
        atomEntry = rest.format.parseFeedDocument(cont)
        ret = atomEntry.toPrimitive()[remote_user][remote_user]
        return ret
    except Exception, ex:
        logger.error('unable to parse response from remote peer %s' % remote_host)
        logger.exception(ex) 
        return None
示例#4
0
文件: sc_rest.py 项目: parth88/GitHub
    def handleEdit(self, confInfo):
        logger.debug("handleEdit is called. -- action = %s, id = %s" % (self.customAction, self.callerArgs.id))

        try:
            args = self.getCallerArgs()
            self.update(**args)
            self.handleList(confInfo)
        except BaseException as ex:
            logger.exception("handleEdit Failed - arguments = %s, exception = %s" % (self.callerArgs, ex))
示例#5
0
文件: sc_rest.py 项目: TPLink32/spnk1
    def handleEdit(self, confInfo):
        logger.debug('handleEdit is called. -- action = %s, id = %s' %
                     (self.customAction, self.callerArgs.id))

        try:
            args = self.getCallerArgs()
            self.update(**args)
            self.handleList(confInfo)
        except BaseException as ex:
            logger.exception(
                'handleEdit Failed - arguments = %s, exception = %s' %
                (self.callerArgs, ex))
示例#6
0
文件: sc_rest.py 项目: TPLink32/spnk1
    def handleACL(self, confInfo):
        try:
            ent = self.get()
            meta = ent[admin.EAI_ENTRY_ACL]

            # for POST acl only.
            if self.requestedAction in [
                    admin.ACTION_CREATE, admin.ACTION_EDIT
            ] and len(self.callerArgs.data) > 0:

                # control only update acl data, no more other fields
                ent.properties = dict()

                ent['sharing'] = meta['sharing']
                ent['owner'] = meta['owner']

                # SPL-69050 and SPL-68306
                ent['perms.read'] = [None]
                ent['perms.write'] = [None]
                '''                
                if meta.has_key('perms'):
                    perms = meta['perms']
                    
                    # SPL-67185
                    if perms and isinstance(perms, dict):
                        if perms.has_key('write'):
                            ent['perms.write'] = perms['write'] 
                        if perms.has_key('read'):
                            ent['perms.read'] = perms['read']
                '''

                # user should not POST non acl related fields, if so, it will throw errors anyway.
                for k, v in self.callerArgs.data.items():
                    ent[k] = v

                en.setEntity(ent, self.getSessionKey(), uri=ent.id + '/acl')
                ent = self.get()

            confItem = confInfo[self.callerArgs.id]
            acl = copy.deepcopy(meta)
            confItem.actions = self.requestedAction
            confItem.setMetadata(admin.EAI_ENTRY_ACL, acl)

        except splunk.ResourceNotFound as ex:
            logger.exception(
                'handleACL Failed - arguments = %s, exception = %s' %
                (self.callerArgs, ex))
示例#7
0
文件: sc_rest.py 项目: parth88/GitHub
    def handleACL(self, confInfo):
        try:
            ent = self.get()
            meta = ent[admin.EAI_ENTRY_ACL]

            # for POST acl only.
            if self.requestedAction in [admin.ACTION_CREATE, admin.ACTION_EDIT] and len(self.callerArgs.data) > 0:

                # control only update acl data, no more other fields
                ent.properties = dict()

                ent["sharing"] = meta["sharing"]
                ent["owner"] = meta["owner"]

                # SPL-69050 and SPL-68306
                ent["perms.read"] = [None]
                ent["perms.write"] = [None]

                """                
                if meta.has_key('perms'):
                    perms = meta['perms']
                    
                    # SPL-67185
                    if perms and isinstance(perms, dict):
                        if perms.has_key('write'):
                            ent['perms.write'] = perms['write'] 
                        if perms.has_key('read'):
                            ent['perms.read'] = perms['read']
                """

                # user should not POST non acl related fields, if so, it will throw errors anyway.
                for k, v in self.callerArgs.data.items():
                    ent[k] = v

                en.setEntity(ent, self.getSessionKey(), uri=ent.id + "/acl")
                ent = self.get()

            confItem = confInfo[self.callerArgs.id]
            acl = copy.deepcopy(meta)
            confItem.actions = self.requestedAction
            confItem.setMetadata(admin.EAI_ENTRY_ACL, acl)

        except splunk.ResourceNotFound as ex:
            logger.exception("handleACL Failed - arguments = %s, exception = %s" % (self.callerArgs, ex))
示例#8
0
文件: sc_rest.py 项目: parth88/GitHub
 def handleRemove(self, confInfo):
     try:
         self.delete()
     except BaseException as ex:
         logger.exception("handleRemove Failed - arguments = %s, exception = %s" % (self.callerArgs, ex))