basic

command
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Basic Wasm Module Evaluation Example

The main.go example demonstrates the loading and executing of OPA produced wasm policy binary.

Setup

The example directory includes some Rego source files. The first step is to compile them into Wasm modules. Run:

opa build -t wasm -e example/allow ./example-1.rego

This will generate a bundle.tar.gz in your current directory which has the Wasm module included. Extract the module with:

tar -zxvf bundle.tar.gz /policy.wasm
mv policy.wasm example-1.wasm

Repeat the process for the second example Wasm binary:

opa build -t wasm -e example/allow ./example-2.rego
tar -zxvf bundle.tar.gz /policy.wasm
mv policy.wasm example-2.wasm

The final result should be two Wasm modules:

example-1.wasm
example-2.wasm

Running the Example

After the Wasm binaries are available run the example with

go run main.go .

This should be run from the same directory as main.go, alternatively provide a path to the directory which contains the Wasm binaries.

Documentation

Overview

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.

Jump to

Keyboard shortcuts

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