Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All resources are visible to WK/C #53

Closed
jannewmarch opened this issue Dec 21, 2016 · 1 comment
Closed

All resources are visible to WK/C #53

jannewmarch opened this issue Dec 21, 2016 · 1 comment

Comments

@jannewmarch
Copy link

The draft-ietf-core-resource-directory-09 adds a Resource Directory (RD) to CoAP. It adds a number of resources such as rd.core-lookup which should be findable through WK/C but also a number of resources such as rd.core-lookup/res which probably should not. Remote resources added to the RD almost certainly should not be findable from WK/C. I suggest the following changes to resource.py to add another attribute to a resource. There should be no changes required to existing programs. This conforms to RFC 6690 Section 4 " It is, however, up to the application which links are included and how they are organized."

def add_resource(self, path, resource, dont_add_to_WKC=False):
    # Parameter dont_add_to_WKC is to make resource invisible to WKC
    # Default is visible
    self._resources[tuple(path)] = resource
    if dont_add_to_WKC:
        # set a new attribute on the resource
        resource.dont_add_to_WKC = True

and

def get_resources_as_linkheader(self):
    import link_header

    links = []
    for path, resource in self._resources.items():
        # skip resources with dont_add_to_WKC set
        if hasattr(resource, 'dont_add_to_WKC'):
            continue
        if hasattr(resource, "get_link_description"):
            details = resource.get_link_description()
        else:
            details = {}
        lh = link_header.Link('/' + '/'.join(path), **details)

        links.append(lh)
    return link_header.LinkHeader(links)

Called by

# visible to WK/C, standard use
root.add_resource(('rd-lookup',),
                  ResourceDirectoryLookup(resource_directory))
# not visible to WKC
root.add_resource(('rd-lookup','res'),
                  ResourceDirectoryLookupResources(resource_directory),
                  True)
@chrysn
Copy link
Owner

chrysn commented Dec 21, 2016 via email

@chrysn chrysn closed this as completed in 2c715c5 Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants