Files
releases/internal/ref/ref.go
T
Torin Sandall 73619ee8a2 internal/ref: Add helper package for parsing refs
This logic was duplicated for config processing and is useful inside
the new build command when dealing with entrypoints so just move it
into an internal package.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-05-18 08:32:38 -04:00

20 lines
572 B
Go

// Copyright 2020 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
// Package ref implements internal helpers for references
package ref
import (
"strings"
"github.com/open-policy-agent/opa/ast"
)
// ParseDataPath returns a ref from the slash separated path s rooted at data.
// All path segments are treated as identifier strings.
func ParseDataPath(s string) (ast.Ref, error) {
s = strings.Replace(strings.Trim(s, "/"), "/", ".", -1)
return ast.ParseRef("data." + s)
}