godrl

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 7 Imported by: 1

README

odrl-opa

Go module for the usage as additional OPA builtIn function, usage see https://github.com/Posedio/gaiax-opa

Usage

see the test folder.

Contributing

Contributions are welcome, just open a pull request, please add/extend tests if you add new features.

Contributor

Philipp Seifert-Kehrer, Posedio GmbH

Stefan Dumss, Posedio GmbH

License

Released under MIT License, see the LICENCE file

Copyright (c) 2025 Posedio GmbH

Documentation

Index

Constants

View Source
const (
	Simple actionType = iota
	Complex
)
View Source
const (
	JustPolicy policyType = "policy"
	Set                   = "Set"
	Offer                 = "Offer"
	Agreement             = "Agreement"
)
View Source
const (
	Permit     conflictResolution = "perm"
	Prohibit                      = "prohibit"
	Invalidate                    = "invalid"
)
View Source
const (
	Equal            operator = "eq"
	NotEqual         operator = "neq"
	GreaterThan      operator = "gt"
	GreaterThanEqual operator = "geq"
	LessThan         operator = "lt"
	LessThanEqual    operator = "leq"
	IsAnyOf          operator = "isAnyOf"
)

Variables

View Source
var (
	Aggregate       = newChildless("aggregate")
	Annotate        = newChildless("annotate")
	Anonymize       = newChildless("anonymize")
	Archive         = newChildless("archive")
	Attribute       = newChildless("attribute")
	Attribution     = newChildless("attribution")
	CommercialUse   = newChildless("commercialUse")
	Compensate      = newChildless("compensate")
	ConcurrentUse   = newChildless("concurrentUse")
	Delete          = newChildless("delete")
	Derive          = newChildless("derive")
	DerivativeWorks = newChildless("derivativeWorks")
	Digitive        = newChildless("digitive")
	Display         = newChildless("display")
	Distribute      = newChildless("distribute")
	Play            = actionVerb{"play", []actionVerb{Display}}
	Present         = newChildless("present")
	Print           = newChildless("print")
	Read            = newChildless("read")
	Reproduce       = newChildless("reproduce")
	Reproduction    = newChildless("reproduction")
	ReviewPolicy    = newChildless("reviewPolicy")
	Sharing         = newChildless("sharing")
	SourceCode      = newChildless("sourceCode")
	Stream          = newChildless("stream")
	Synchronize     = newChildless("synchronize")
	TextToSpeech    = newChildless("textToSpeech")
	Transform       = newChildless("transform")
	Translate       = newChildless("translate")
	Uninstall       = newChildless("uninstall")
	Watermark       = newChildless("watermark")

	Use = actionVerb{"use", []actionVerb{Aggregate, Annotate, Anonymize, Archive, Attribute,
		Attribution, CommercialUse, Compensate, ConcurrentUse, Delete, Derive, DerivativeWorks, Digitive,
		Distribute, Play, Present, Print, Read, Reproduce, Reproduction, ReviewPolicy, Sharing, SourceCode, Stream,
		Synchronize, TextToSpeech, Transform, Translate, Uninstall, Watermark}}

	Give actionVerb = newChildless("give")
	Sell actionVerb = newChildless("sell")

	Transfer = actionVerb{"transfer", []actionVerb{Give, Sell}}
)

Functions

func Of

func Of(str string) (*actionVerb, error)

Types

type Action

type Action struct {
	Verb       actionVerb    `json:"verb"`
	Refinement *[]Constraint `json:"refinement"`
}

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte) error

type Constraint

type Constraint interface {
	// contains filtered or unexported methods
}

type DesiredAction

type DesiredAction struct {
	Verb    actionVerb  `json:"value"`
	Context interface{} `json:"context"`
}

func (*DesiredAction) UnmarshalJSON

func (d *DesiredAction) UnmarshalJSON(data []byte) error

type EvalContext

type EvalContext struct {
	Exercised []ExercisedAction
}

type EvalReport

type EvalReport []string

func Evaluate

func Evaluate(policy *PolicyHandle, req OdrlRequest) (bool, EvalReport, error)

type ExercisedAction

type ExercisedAction struct {
	Action   DesiredAction
	Target   string
	Assigner string
}

type OdrlRequest

type OdrlRequest struct {
	Principal      string         `json:"principal"`
	Target         string         `json:"target"`
	DesiredAction  DesiredAction  `json:"action"`
	RequestContext RequestContext `json:"requestContext"`
	EvalContext    EvalContext    `json:"evalContext"`
}

type PolicyHandle

type PolicyHandle struct {
	// contains filtered or unexported fields
}

func LoadPolicy

func LoadPolicy(policyJson []byte) (*PolicyHandle, error)

type RequestContext

type RequestContext struct {
	DateTime   time.Time `json:"dateTime"`
	PayAmount  float64   `json:"payAmount"`
	Purpose    string    `json:"purpose"`
	Media      string    `json:"media"`
	Version    string    `json:"version"`
	Unit       string    `json:"unit"`
	Event      string    `json:"event"`
	Industry   string    `json:"industry"`
	FileFormat string    `json:"fileFormat"`
	Language   string    `json:"language"`
	Percentage float64   `json:"percentage"`
	Product    string    `json:"product"`
	Resolution int       `json:"resolution"`
	Vcs        Vcs       `json:"vcs"`
}

type Vcs

type Vcs struct {
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL