Skip to content

Commit

Permalink
chore: update OAS and the-usher.js
Browse files Browse the repository at this point in the history
  • Loading branch information
k1ch committed Oct 15, 2024
1 parent bac6682 commit ced52d1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
75 changes: 41 additions & 34 deletions server/the-usher-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
license:
name: MIT
url: https://opensource.org/licenses/MIT
version: 2.3.0-rc.1
version: 2.3.0
externalDocs:
description: GitHub Repository
url: https://github.com/DMGT-TECH/the-usher-server
Expand Down Expand Up @@ -327,20 +327,14 @@ paths:
- bearerAdminAuth: []
parameters:
- $ref: '#/components/parameters/clientIdQueryParam'
- name: includePermissions
in: query
description: Includes permissions for each role
required: false
schema:
type: boolean
example: true
- $ref: '#/components/parameters/includePermissionsQueryParam'
responses:
200:
description: The List of Roles
content:
application/json:
schema:
$ref: '#/components/schemas/CollectionOfRoles'
$ref: '#/components/schemas/CollectionOfRolesWithPermissions'
400:
$ref: '#/components/responses/BadRequest'
post:
Expand Down Expand Up @@ -389,20 +383,14 @@ paths:
security:
- bearerAdminAuth: []
parameters:
- name: includePermissions
in: query
description: Includes permissions for each role
required: false
schema:
type: boolean
example: true
- $ref: '#/components/parameters/includePermissionsQueryParam'
responses:
200:
description: Return a Role for the given key
content:
application/json:
schema:
$ref: '#/components/schemas/Role'
$ref: '#/components/schemas/RoleWithPermissions'
404:
$ref: '#/components/responses/NotFound'
patch:
Expand Down Expand Up @@ -460,9 +448,7 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/PermissionObject"
$ref: "#/components/schemas/ArrayOfPermissionObject"
400:
$ref: '#/components/responses/BadRequest'
401:
Expand Down Expand Up @@ -667,9 +653,7 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/PermissionObject"
$ref: "#/components/schemas/ArrayOfPermissionObject"
401:
$ref: '#/components/responses/Unauthorized'
404:
Expand Down Expand Up @@ -750,13 +734,7 @@ paths:
summary: Get a list of roles assigned to the given Persona
parameters:
- $ref: '#/components/parameters/personaKeyPathParam'
- name: includePermissions
in: query
description: Includes permissions for each role
required: false
schema:
type: boolean
example: true
- $ref: '#/components/parameters/includePermissionsQueryParam'
tags:
- Admin APIs
security:
Expand All @@ -769,7 +747,7 @@ paths:
schema:
type: array
items:
$ref: "#/components/schemas/Role"
$ref: "#/components/schemas/RoleWithPermissions"
401:
$ref: '#/components/responses/Unauthorized'
404:
Expand Down Expand Up @@ -985,6 +963,7 @@ paths:
/clients/{client_id}/roles:
parameters:
- $ref: '#/components/parameters/clientIdPathParam'
- $ref: '#/components/parameters/includePermissionsQueryParam'
get:
'x-swagger-router-controller': 'clients/roles'
operationId: listClientRoles
Expand All @@ -1000,7 +979,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/CollectionOfRoles'
$ref: '#/components/schemas/CollectionOfRolesWithPermissions'
400:
$ref: '#/components/responses/BadRequest'
401:
Expand Down Expand Up @@ -1120,14 +1099,21 @@ components:
value: the-usher
Example 3 (all client applications where persona has a role):
value: "*"
# client_id as query param
clientIdQueryParam:
name: client_id
description: Unique identifier for the client.
in: query
required: false
schema:
$ref: '#/components/schemas/EntityNameDef'
includePermissionsQueryParam:
name: includePermissions
in: query
description: Includes permissions for each role
required: false
schema:
type: boolean
example: true
roleKeyPathParam:
name: role_key
description: The unique role identifier
Expand Down Expand Up @@ -1223,7 +1209,7 @@ components:
$ref: '#/components/schemas/EntityNameDef'
description:
type: string
nullable: true # Can't use shared schema with nullable in 3.0.x
nullable: true
maxLength: 100
required:
- key
Expand All @@ -1233,6 +1219,14 @@ components:
key: 10
name: usher:admin
clientkey: fake-client

RoleWithPermissions:
allOf:
- $ref: '#/components/schemas/Role'
- type: object
properties:
permissions:
$ref: '#/components/schemas/PermissionObject'

CollectionOfRoles:
type: object
Expand All @@ -1242,6 +1236,14 @@ components:
items:
$ref: '#/components/schemas/Role'

CollectionOfRolesWithPermissions:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/RoleWithPermissions'

Permission:
type: object
properties:
Expand Down Expand Up @@ -1284,6 +1286,11 @@ components:
items:
$ref: '#/components/schemas/Permission'

ArrayOfPermissionObject:
type: array
items:
$ref: '#/components/schemas/PermissionObject'

DictionaryOfPermissions:
type: object
additionalProperties: false
Expand Down
16 changes: 8 additions & 8 deletions server/the-usher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const { verifyTokenForAdmin, verifyTokenForSelf, verifyTokenForClientAdmin } = r
const winstonLogger = require('./src/logging/winston-logger')

// Normalizes a port into a number, string, or false
function normalizePort(val) {
var port = parseInt(val, 10)
const normalizePort = (val) => {
const port = parseInt(val, 10)
if (isNaN(port)) {
return val // named pipe
}
Expand All @@ -27,7 +27,7 @@ function normalizePort(val) {
return false
}

async function seedKeysIfDbIsEmpty() {
const seedKeysIfDbIsEmpty = async () => {
try {
console.log('checking database for keys..')
if ((await keystore.selectAllKeys()).length === 0) {
Expand Down Expand Up @@ -59,7 +59,7 @@ const optionsObject = {
customErrorHandling: true
}

function preInitCheck() {
const preInitCheck = () => {
let missingKeyEnvVars = false
if (!env.ISSUER_WHITELIST) {
missingKeyEnvVars = true
Expand All @@ -76,15 +76,15 @@ expressApp.use(usherCors())
expressApp.use(winstonLogger)
oasTools.configure(optionsObject)

oasTools.initialize(oasDoc, expressApp, function () {
oasTools.initialize(oasDoc, expressApp, () => {
const exitBeforeInitialization = preInitCheck()
if (exitBeforeInitialization) {
console.log('TheUsher is not initializing because critical env vars are not configured.')
console.log('Please configure all the required environment variables before launching or deploying.')
process.exit(1)
}
const port = normalizePort(process.env.PORT || '3001')
http.createServer(expressApp).listen(port, function () {
http.createServer(expressApp).listen(port, () => {
console.log('App up and running!')
})
})
Expand All @@ -98,7 +98,7 @@ expressApp.use((err, req, res, next) => {
next(err)
})

expressApp.use(function (err, req, res, next) {
expressApp.use((err, req, res, next) => {
// handle case if headers have already been sent to client
if (res.headersSent) {
return next(err)
Expand All @@ -112,7 +112,7 @@ expressApp.use(function (err, req, res, next) {
})

// Default route to handle not found endpoints but return 405 for security
expressApp.use(function (req, res, next) {
expressApp.use((req, res, next) => {
const notFoundResponse = {
code: 405,
message: 'Method Not Allowed'
Expand Down

0 comments on commit ced52d1

Please sign in to comment.