Skip to content

Commit

Permalink
fix: base64 encode OPA policy.wasm (#24)
Browse files Browse the repository at this point in the history
The GitHub Action on remote repos does not have access to the
action repo's assets.  This change base64 encodes the policy.wasm
so that it gets compiled into the action's `dist/index.js` entrypoint.
  • Loading branch information
patheard authored Jun 29, 2021
1 parent fac7413 commit 2a48818
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ inputs:
runs:
using: 'node12'
main: 'dist/index.js'

branding:
icon: 'layers'
color: 'purple'
22 changes: 19 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/opa-policy.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/opa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const fs = require("fs");
const { loadPolicy } = require("@open-policy-agent/opa-wasm");
const { policyWasmBase64 } = require("./opa-policy.js");

/**
* Uses ./policy/resource-changes.rego OPA policy to examine the JSON generated
Expand All @@ -10,9 +10,9 @@ const { loadPolicy } = require("@open-policy-agent/opa-wasm");
* @returns {Object} Resource and output changes in the tfplan
*/
const getPlanChanges = async (planJson) => {
const policyWasm = fs.readFileSync("./policy/policy.wasm");

const policyWasm = Buffer.from(policyWasmBase64, "base64");
const policy = await loadPolicy(policyWasm);

const results = policy.evaluate(planJson);

let changes;
Expand Down

0 comments on commit 2a48818

Please sign in to comment.