equatorial_daydreamer
equatorial_daydreamer

Reputation: 408

How to import policies from different files

This could potentially be a duplicate of this post but I'm still having real trouble.

I have a function defined in one file.

A.rego

package authorizer

default username := null

decode_user(jwt) := user_id {
    // logic to decode token & return user_id
}

When I try and import it into another file, I get an error when I run opa eval.

B.rego

package user

import data.authorizer

default allow := false 

user_id := x {
    x := decode_user(input.jwt)
}

allow := true {
    user_id != null
}

Output of opa eval:

{
  "errors": [
    {
      "message": "undefined function decode_user",
      "code": "rego_type_error",
      "location": {
        "file": "",
        "row": 8,
        "col": 7
      }
    }
  ]
}

How do I get the import to work? I have scenarios which effectively involve nesting policies and importing golang functions so understanding this is pretty important.

Thanks in advance!

Upvotes: 1

Views: 794

Answers (1)

Gandora
Gandora

Reputation: 368

Try either

import data.authorizer.decode_user

or if you want everything in that package

import data.authorizer.*

Upvotes: 1

Related Questions