Skip to content

Advanced

Douglas Hubler edited this page Nov 29, 2022 · 5 revisions

RESTCONF HTTP Request Access

This is useful for custom authorization or general need to access the HTTP request information

Steps:

1.) Register a request restconf.RequestFilter with RESTCONF restconf.Server instance

2.) Filter returns a context.Context that contains any custom data that you might extract from the HTTP request like HTTP header information, URL parameters or certificate information.

3.) Values from that context.Context will be made available to all your node.Node implementations

Example Code:

s := restconf.NewServer(d)
s.Filters = append(s.Filters, filter)
func filter(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, error) {
    return context.WithValue(ctx, "mykey", "my-value"), nil
}
func myNode() node.Node {
    return nodeutil.Basic{
        OnAction: func(r node.ActionRequest) (node.Node, error) {
            myval := r.Selection.Context.Value("mykey")
        }
    }
}

Transitioning to stricter RESTCONF RFC compliance

There are a number of breaking changes in FreeCONF yang and restconf libraries needed to be made to be in compliance with RFC. This is of course important so FreeCONF can be used with other libraries. In order to not break existing codebases, there are two data structures that you can use to restore previous operations until you have time to port your code over to the stricter compliance. Eventually this legacy mode will be removed.

restconf.Compliance = restconf.Simplistic
yang.Compliance = yang.Simplistic
Clone this wiki locally