def buildEndpoint(entityClass, entityName=None, namespace=None, owner=None, hostPath=None, **unused): ''' Returns the proper URI endpoint for a given type of entity ''' # set 'all user' name if none passed owner = owner or EMPTY_OWNER_NAME if isinstance(entityClass, list): entityClass = quotePath(entityClass) else: # We just use safeURLQuote here because calling quoteEntity # would escape any forward slashes. # e.g. 'saved/searches' would become 'saved%252Fsearches' if # quoteEntity was used entityClass = util.safeURLQuote(entityClass.strip('/')) if namespace: uri = '/servicesNS/%s/%s/%s' % (quoteEntity(owner), quoteEntity(namespace), entityClass) else: uri = '/services/%s' % entityClass if entityName: uri += '/' + quoteEntity(entityName) if hostPath: uri = hostPath + uri return uri
def quoteEntity(entity_name): ''' This function purposefully double encodes forward slashes '/'. This is because many applications that handle http requests assume a %2F encoding of a forward slash actually represents a forward slash. Hence, splunkd should always receive double encoded forward slashes when they are to appear in entity names. e.g. "foo/bar" should be "foo%252Fbar". Do not erase this or the unquoteEntity method. ''' return util.safeURLQuote(util.toUnicode(entity_name).replace('/', '%2F'))
def getEndpointPath(self, conf=None, stanza=None, key=None): ''' Returns the splunkd URI for the specified combination of conf file, stanza, and key name. The namespace and owner context are pulled from the current Conf() instance. ''' path = [entity.buildEndpoint('properties', namespace=self.namespace, owner=self.owner)] parts = [] if conf: parts.append(conf) if stanza: parts.append(stanza) if key: parts.append(key) path.extend([util.safeURLQuote(shard, '') for shard in parts]) return '/'.join(path)
def getEndpointPath(self, conf=None, stanza=None, key=None): ''' Returns the splunkd URI for the specified combination of conf file, stanza, and key name. The namespace and owner context are pulled from the current Conf() instance. ''' path = [ entity.buildEndpoint('properties', namespace=self.namespace, owner=self.owner) ] parts = [] if conf: parts.append(conf) if stanza: parts.append(stanza) if key: parts.append(key) path.extend([util.safeURLQuote(shard, '') for shard in parts]) return '/'.join(path)