Browse Source

start of Service Node (OAuth2 Client) management

pull/1/head
Rob Colbert 3 years ago
parent
commit
4675a34652
  1. 1
      app/controllers/admin.js
  2. 50
      app/controllers/admin/service-node.js
  3. 3
      app/models/oauth2-client.js
  4. 17
      app/services/oauth2.js
  5. 7
      app/views/admin/components/menu.pug
  6. 30
      app/views/admin/service-node/index.pug

1
app/controllers/admin.js

@ -48,6 +48,7 @@ class AdminController extends SiteController {
router.use('/job-queue', await this.loadChild(path.join(__dirname, 'admin', 'job-queue')));
router.use('/log', await this.loadChild(path.join(__dirname, 'admin', 'log')));
router.use('/settings', await this.loadChild(path.join(__dirname, 'admin', 'settings')));
router.use('/service-node',await this.loadChild(path.join(__dirname, 'admin', 'service-node')));
router.use('/user', await this.loadChild(path.join(__dirname, 'admin', 'user')));
router.get('/diagnostics', this.getDiagnostics.bind(this));

50
app/controllers/admin/service-node.js

@ -0,0 +1,50 @@
// admin/service-node.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const express = require('express');
const { SiteController } = require('../../../lib/site-lib');
class ServiceNodeController extends SiteController {
constructor (dtp) {
super(dtp, module.exports);
}
async start ( ) {
const router = express.Router();
router.use(async (req, res, next) => {
res.locals.currentView = 'admin';
res.locals.adminView = 'service-node';
return next();
});
router.get('/', this.getIndex.bind(this));
return router;
}
async getIndex (req, res, next) {
const { oauth2: oauth2Service } = this.dtp.services;
try {
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.serviceNodes = await oauth2Service.getClients({ }, res.locals.pagination);
res.render('admin/service-node/index');
} catch (error) {
this.log.error('failed to render Service Node home', { error });
return next(error);
}
}
}
module.exports = {
name: 'Admin: Service Node',
slug: 'admin:service-node',
create: async (dtp) => {
let controller = new ServiceNodeController(dtp);
return controller;
},
};

3
app/models/oauth2-client.js

@ -21,6 +21,9 @@ const OAuth2ClientSchema = new Schema({
secret: { type: String, required: true },
scopes: { type: [String], required: true },
callbackUrl: { type: String, required: true },
flags: {
isActive: { type: Boolean, default: true, required: true, index: 1 },
},
});
OAuth2ClientSchema.index({

17
app/services/oauth2.js

@ -301,6 +301,23 @@ class OAuth2Service extends SiteService {
return client.toObject();
}
async getClients (search, pagination) {
search = search || { };
let query = OAuth2Client
.find(search)
.sort({ 'site.domainKey': 1 });
if (pagination) {
query = query
.skip(pagination.skip)
.limit(pagination.cpp);
}
const clients = await query.lean();
return clients;
}
async getClientById (clientId) {
const client = await OAuth2Client
.findOne({ _id: clientId })

7
app/views/admin/components/menu.pug

@ -32,6 +32,13 @@ ul.uk-nav.uk-nav-default
span.nav-item-icon
i.fas.fa-project-diagram
span.uk-margin-small-left Core Nodes
li(class={ 'uk-active': (adminView === 'core-node') })
a(href="/admin/service-node")
span.nav-item-icon
i.fas.fa-puzzle-piece
span.uk-margin-small-left Service Nodes
li(class={ 'uk-active': (adminView === 'host') })
a(href="/admin/host")
span.nav-item-icon

30
app/views/admin/service-node/index.pug

@ -0,0 +1,30 @@
extends ../layouts/main
block content
h1 Service Nodes
if Array.isArray(serviceNodes) && (serviceNodes.length > 0)
ul.uk-list
each node in serviceNodes
.uk-tile.uk-tile-default.uk-tile-small
.uk-margin
div(uk-grid)
.uk-width-auto
+renderCell('Name', node.site.name)
.uk-width-auto
+renderCell('Company', node.meta.company)
.uk-width-auto
+renderCell('Domain', node.site.domain)
.uk-width-auto
+renderCell('Domain Key', node.site.domainKey)
.uk-width-auto
+renderCell('Connected', moment(node.created).format('MMM DD, YYYY'))
.uk-width-auto
+renderCell('Updated', moment(node.updated).format('MMM DD, YYYY'))
.uk-margin
div(uk-grid)
.uk-width-auto
+renderCell('Connected', node.flags.isConnected)
else
p There are no registered service nodes.
Loading…
Cancel
Save