Skip to content

Commit

Permalink
Merge pull request #36 from cloud-native-toolkit/bump-lb
Browse files Browse the repository at this point in the history
Bumps libs to latest & unit tests
  • Loading branch information
NoeSamaille authored Nov 10, 2022
2 parents 65006c3 + 8ca4be9 commit a87b9f0
Show file tree
Hide file tree
Showing 54 changed files with 18,089 additions and 9,011 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
/dist
# Cache used by TypeScript's incremental build
*.tsbuildinfo
14 changes: 8 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
initDatabase.js
updateServices.js
dist
express-app
node_modules/
dist/
coverage/
.eslintrc.js

*.ignore.js
scripts/*.js
build/
express-app/
scripts/
data/
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '@loopback/eslint-config',
};
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exit": true,
"recursive": true,
"require": "source-map-support/register"
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
*.json
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"bracketSpacing": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all",
"arrowParens": "avoid"
}
6 changes: 6 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@loopback/cli": {
"packageManager": "npm",
"version": "4.1.4"
}
}
3 changes: 0 additions & 3 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ Install the following extensions:
suite and lint the code for both programming and style errors. You should run
this command manually whenever you have new changes to test. Test failures
and linter errors will be printed to the terminal.



45 changes: 25 additions & 20 deletions express-app/express-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const express = require("express");
const request = require('request');
const axios = require('axios');

const app = (module.exports = express());

Expand Down Expand Up @@ -37,29 +37,34 @@ if (process.env.NODE_ENV !== "dev" && process.env.NODE_ENV !== "test") {
const editorMethods = [];
app.use((req, res, next) => {
if (process.env.OCP_API_URL && req.headers['authorization']) {
request({
axios({
method: 'get',
url: `${process.env.OCP_API_URL}/apis/user.openshift.io/v1/users/~`,
headers: {
'Authorization': req.headers['authorization']
}
}, (err, response, body) => {
const user = JSON.parse(body);
req.scopes = ["view_controls", "edit"];
if (user?.groups?.includes("ascent-admins")) {
req.scopes.push("super_edit");
}
if (!editorMethods.includes(req.method) || req.scopes.includes("edit")) {
req.user = user;
req.user.email = req.user?.metadata?.name?.replace('IAM#', '');
next();
} else {
res.status(401).json({
error: {
message: "You must have editor role to perform this request."
}
});
}
});
})
.then((response) => {
const user = response.data;
req.scopes = ["view_controls", "edit"];
if (user?.groups?.includes("ascent-admins")) {
req.scopes.push("super_edit");
}
if (!editorMethods.includes(req.method) || req.scopes.includes("edit")) {
req.user = user;
req.user.email = req.user?.metadata?.name?.replace('IAM#', '');
next();
} else {
res.status(401).json({
error: {
message: "You must have editor role to perform this request."
}
});
}
})
.catch(function (error) {
console.log(error);
})
} else if (process.env.OCP_API_URL) {
res.status(401).json({
error: {
Expand Down
5 changes: 0 additions & 5 deletions jsconfig.json

This file was deleted.

Loading

0 comments on commit a87b9f0

Please sign in to comment.