Functions

import {
  createPolicy,
  policySourceFromEnv,
  deploymentBundle,
  readBundle,
  disclose,
  jsonLinesLogger,
  erase,
  PolicyUnavailableError,
  BundleRejectedError,
} from '@fairgarden/policy'
import { decisionLogTable, drizzleLogger, revisionTable, drizzleRevisions, toEntry, newestFirst } from '@fairgarden/policy/drizzle'
import { buildBundle, testLayers, findLayers, findOpa } from '@fairgarden/policy/build'

createPolicy(options)

Option
packagethe service's Rego package, as a path or dotted
builtIna function per decision: the rules when the policy has none
sourcethe organization's policy; usually policySourceFromEnv()
loggerswhere every decision is recorded
onRevisiongiven each revision of the policy the first time it runs, to keep it
labelsadded to every entry's labels
eraseJSON pointers per decision, left out of the log
timeoutMsan OPA server's time to answer; default 2000
fetchfor URLs and servers; default the global

Returns:

source is { engine: 'bundle', source, publicKey?, allowUnsigned? } — source a path, an https URL or the bytes — or { engine: 'server', url }.

policySourceFromEnv(env?)

The source every service in a deployment shares: FG_POLICY_OPA_URL, or FG_POLICY_BUNDLE (with FG_POLICY_PUBLIC_KEY), or the deployment's own bundle (deploymentBundle()), or undefined for the built-in rules. See Deploying.

Bundles

Building

From @fairgarden/policy/build, which needs Node and the opa CLI:

Loggers

Postgres, through Drizzle

drizzle-orm is an optional peer dependency, only needed for these.

erase(entry, pointers)

The entry without what the pointers name, and with them listed in erased. createPolicy does this with erase; it is exported for loggers that want their own.