def _register_endpoint(endpoint):

            # create a M2mPoc with the endpoint as contact info in the NSCL
            # (onlineStatus=ONLINE)
            uri = self.nscl_uri + "/" + "scls/" + self.gscl_id + "/" + "m2mPocs"
            m2mpoc = M2mPoc()
            m2mpoc.onlineStatus = "ONLINE"
            m2mpoc.contactInfo = endpoint.base_uri
            m2mpoc.expirationTime = self._gscl.expirationTime

            rq = CreateRequestIndication(uri, m2mpoc)
            rq.requestingEntity = self.config.get("requesting_entity")
            p = self.api.send_request_indication(rq).then(
                lambda evt, m2mpoc=m2mpoc: _start_endpoint_refresher(
                    evt, m2mpoc))

            return p
 def create_gscl():
     rq = CreateRequestIndication(uri, gscl)
     rq.requestingEntity = self.config.get("requesting_entity")
     return self.api.send_request_indication(rq)
def map_request_to_request_indication(request):
    path = request.path
    method = request.method
    if method == RequestMethod.create:
        req_ind = CreateRequestIndication(path=path, resource=request.payload,
                                          content_type=request.content_type)
    elif method == RequestMethod.retrieve:
        req_ind = RetrieveRequestIndication(path)
        if path.endswith(("/contentInstances", "/discovery")):
            args = request.params
            filter_criteria = {k: v for k, v in args.items() if
                               k not in ("ifNoneMatch", "searchString",
                                         "contentType", "searchPrefix",
                                         "maxSize")}
            filter_criteria = FilterCriteria(**filter_criteria)
            if_none_match = args.getlist("ifNoneMatch")
            if if_none_match:
                filter_criteria.ifNoneMatch = if_none_match
            search_string = args.getlist("searchString")
            if search_string:
                filter_criteria.searchString = search_string
            content_type = args.getlist("contentType")
            if content_type:
                filter_criteria.contentType = content_type
            req_ind.filterCriteria = filter_criteria
            if path.endswith("/discovery"):
                req_ind.searchPrefix = args.get("searchPrefix")
                req_ind.maxSize = args.get("maxSize")
            # obtain some filter-criteria from HTTP headers, where appropriate
            # TODO: kca: not sure if this is actually standard compliant, but it
            # seems like common sense. Check if its in the standard, if not,
            # allow to turn it off via config
            # TODO: use generic format
            environ = request.metadata
            for n in ("if_None_Match", "if_Unmodified_Since",
                      "if_Modified_Since"):
                try:
                    header = environ["HTTP_" + n.upper()]
                except KeyError:
                    pass
                else:
                    filter_criteria.setdefault(n.replace("_", ""), header)

    elif method == RequestMethod.update:
        req_ind = UpdateRequestIndication(path=path,
                                          resource=request.payload,
                                          content_type=request.content_type)
    elif method == RequestMethod.delete:
        req_ind = DeleteRequestIndication(path)
    elif method == RequestMethod.notify:
        req_ind = NotifyRequestIndication(path=path,
                                          resource=request.payload,
                                          content_type=request.content_type)
    else:
        raise ErrorResponse(ResponseCode.method_not_allowed)
# TODO: set correlationID, rcat, trpdt
    req_ind.requestingEntity = get_requesting_entity(request)
    via = request.via
    if via:
        req_ind.via = request.via
    return req_ind