Skip to content

Commit 95ff675

Browse files
committed
feat: Initial commit.
0 parents  commit 95ff675

20 files changed

+9636
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
/notes.md
3+
/dist
4+
/types
5+
/.nyc_output
6+
/coverage
7+
/npm-debug.log
8+
/yarn-error.log
9+
/yarn.lock
10+
/.yo-rc.json

.markdownlint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"line-length": false,
3+
"no-inline-html": {
4+
"allowed_elements": [
5+
"a"
6+
]
7+
},
8+
"no-trailing-punctuation": {
9+
"punctuation": ".,;:!"
10+
}
11+
}

.nycrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extension": [".ts"],
3+
"exclude": ["**/*.d.ts"],
4+
"include": ["src/**/*.ts"],
5+
"reporter": ["html", "text-summary", "lcov"],
6+
"all": true
7+
}

.travis.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: node_js
2+
node_js:
3+
- node
4+
- '10'
5+
- '8'
6+
- '6'
7+
cache:
8+
directories:
9+
- ~/.npm
10+
before_install:
11+
- npm install -g npm
12+
- npm install -g nsp
13+
install:
14+
- travis_retry npm install
15+
before_script:
16+
- nsp check
17+
after_script: null
18+
after_success:
19+
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
20+
jobs:
21+
include:
22+
- stage: release
23+
node_js: lts/*
24+
before_install:
25+
- npm install -g npm
26+
install:
27+
- travis_retry npm install
28+
before_script: skip
29+
script: npm run semantic-release
30+
after_success: skip
31+
after_failure: skip
32+
after_script: skip

@types/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Custom .d.ts files go here.

@types/json-ptr/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'json-ptr' {
2+
export function encodePointer(path: string[]) : string;
3+
export function decode(pointer: string) : string[];
4+
}

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Contributing
2+
3+
This project uses [semantic-release](https://github.com/semantic-release/semantic-release)
4+
so commit messages should follow [Angular commit message conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines).

README.md

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# exegesis-plugin-roles
2+
3+
[![NPM version](https://badge.fury.io/js/exegesis-plugin-roles.svg)](https://npmjs.org/package/exegesis-plugin-roles)
4+
[![Build Status](https://travis-ci.org/exegesis-js/exegesis-plugin-roles.svg)](https://travis-ci.org/exegesis-js/exegesis-plugin-roles)
5+
[![Coverage Status](https://coveralls.io/repos/exegesis-js/exegesis-plugin-roles/badge.svg)](https://coveralls.io/r/exegesis-js/exegesis-plugin-roles)
6+
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7+
8+
## Description
9+
10+
Adds support for the "x-exegesis-roles" vendor extension, which adds support for
11+
restricting which operations are available to which users after they have been
12+
authenticated. Authenticators can optionally return "roles" for a user.
13+
"x-exegesis-roles" can be specified either as an array of "role" strings, or as
14+
an array of such arrays.
15+
16+
For example:
17+
18+
```yaml
19+
x-exegesis-roles:
20+
- a
21+
- b
22+
```
23+
24+
would only allow access to an operation if a user has both the 'a' and 'b'
25+
role, or:
26+
27+
```yaml
28+
x-exegesis-roles:
29+
- [a]
30+
- [b, c]
31+
```
32+
33+
would only allow access to an operation if a user has the 'a' role, or has
34+
both the 'b' and 'c' role.
35+
36+
"x-exegesis-roles" can be defined on the root OpenAPI object, in which case
37+
all operations in the document will require those roles. This can be overridden
38+
by specifying "x-exegesis-roles" in an individual operation. An empty array
39+
indicates a user requires no roles:
40+
41+
```yaml
42+
x-exegesis-roles: []
43+
```
44+
45+
If "x-exegesis-roles" is defined on an operation which has no security
46+
requirements defined, this will throw an error.
47+
48+
Roles do not apply to security schemes with the "oauth2" type; scopes apply
49+
there instead.
50+
51+
Allowed in:
52+
53+
* [OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oasObject)
54+
* [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#operationObject)
55+
56+
## Installation
57+
58+
```sh
59+
npm install exegesis-plugin-roles
60+
```
61+
62+
## Example
63+
64+
Add this to your Exegesis options:
65+
66+
```js
67+
import exegesisRolesPlugin from 'exegesis-roles-plugin';
68+
69+
options = {
70+
plugins: [
71+
exegesisRolesPlugin({
72+
// List of all allowed roles. If you try to use any roles that
73+
// aren't in this list in your document, an error will be thrown.
74+
allowedRoles: ['user', 'admin', 'ops']
75+
})
76+
]
77+
};
78+
```
79+
80+
In your OpenAPI 3.x document:
81+
82+
```yaml
83+
paths:
84+
'/kittens':
85+
get:
86+
description: Get a list of kittens
87+
security:
88+
- basicAuth: []
89+
- oauth: ['readOnly']
90+
post:
91+
description: Add a new kitten
92+
security:
93+
- basicAuth: []
94+
- oauth: ['readWrite']
95+
x-exegesis-roles: ['admin'] # Only users with the "admin" role may call this.
96+
```
97+
98+
The "get" operation can only be executed if the request matches one of the two
99+
listed security requirements. The "post" operation can only be executed if
100+
the security requirements are matched, and the current "user" has the "admin"
101+
role.
102+
103+
Copyright 2018 Jason Walton

0 commit comments

Comments
 (0)