Use github actions for test and build
4 files changed
tree: 0629e7cec21d8a4b540db82c39e44f789d893fbe
  1. .github/
  2. examples/
  3. src/
  4. test/
  5. .eslintrc.js
  6. .gitignore
  7. .prettierrc
  8. jest.config.js
  9. LICENSE
  10. package-lock.json
  11. package.json
  12. README.md
  13. tsconfig.json
README.md

pubsub-watcher

NPM version CI

Google Cloud Pub/Sub watcher for node-casbin

Installation

# NPM
npm install --save @casbin/pubsub-watcher

# Yarn
yarn add @casbin/pubsub-watcher

Simple Example

import { PubsubWatcher } from '@casbin/pubsub-watcher';
import { newEnforcer } from 'casbin';

// Initialize the watcher.
// You need to create Pubsub topic and subscription(per casbin instance) first
const watcher = await PubsubWatcher.newWatcher();

// Initialize the enforcer.
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');

enforcer.setWatcher(watcher);

// By default, the watcher's callback is automatically set to the
// enforcer's loadPolicy() in the setWatcher() call.
// We can change it by explicitly setting a callback.
watcher.setUpdateCallback(() => console.log('Casbin need update'));

Test

Set GOOGLE_APPLICATION_CREDENTIALS in environment variable and npm run test

Test uses Pub/Sub emulator

gcloud beta emulators pubsub start --project=casbin
PUBSUB_EMULATOR_HOST=localhost:8085 PUBSUB_PROJECT_ID=casbin npm run test