Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/node-casbin/pubsub-watcher
Google Cloud Pub/Sub watcher for Node-Casbin
https://github.com/node-casbin/pubsub-watcher
abac acl auth authorization authz casbin gcp google-cloud middleware pubsub rbac watcher
Last synced: 6 days ago
JSON representation
Google Cloud Pub/Sub watcher for Node-Casbin
- Host: GitHub
- URL: https://github.com/node-casbin/pubsub-watcher
- Owner: node-casbin
- License: apache-2.0
- Created: 2020-08-17T09:41:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-08T05:57:51.000Z (over 1 year ago)
- Last Synced: 2024-11-20T12:33:07.701Z (2 months ago)
- Topics: abac, acl, auth, authorization, authz, casbin, gcp, google-cloud, middleware, pubsub, rbac, watcher
- Language: JavaScript
- Homepage: https://github.com/casbin/node-casbin
- Size: 88.9 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pubsub-watcher
[![NPM version][npm-image]][npm-url]
![CI](https://github.com/node-casbin/pubsub-watcher/workflows/CI/badge.svg)[npm-image]: https://img.shields.io/npm/v/@casbin/pubsub-watcher.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@casbin/pubsub-watcherGoogle Cloud Pub/Sub watcher for node-casbin
# Installation
```shell script
# NPM
npm install --save @casbin/pubsub-watcher# Yarn
yarn add @casbin/pubsub-watcher
```# Simple Example
```typescript
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](https://cloud.google.com/pubsub/docs/emulator)
```sh
gcloud beta emulators pubsub start --project=casbin
PUBSUB_EMULATOR_HOST=localhost:8085 PUBSUB_PROJECT_ID=casbin npm run test
```