Skip to content

Commit

Permalink
feat: Add status gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerberupo committed Oct 6, 2023
1 parent 5706273 commit 8790c8b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 38 deletions.
1 change: 0 additions & 1 deletion .github/workflows/call-lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
- name: Call AWS Lambda
run: |
payload=$(echo -n '{"environment":"dev","images_map":{${{ steps.parse.outputs.images_map }}}}' | base64)
echo $payload
aws lambda invoke --function-name ${{ secrets.LAMBDA_ARN }} --payload "$payload" outputfile.txt
- name: Show Lambda Result
run: cat outputfile.txt
Expand Down
6 changes: 4 additions & 2 deletions packages/leemons-deployment-manager/src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function modifyCTX(
await getDeploymentID(ctx);
}

if (actionName.startsWith('deployment-manager.')) {
if (actionName.startsWith('deployment-manager.') || actionName.startsWith('gateway.')) {
return ctx.__leemonsDeploymentManagerCall(actionName, params, opts);
}

Expand Down Expand Up @@ -138,9 +138,11 @@ module.exports = function ({
if (checkIfCanCallMe) {
// Si se esta intentando llamar al action leemonsDeploymentManagerEvent || leemonsMongoDBRollback lo dejamos pasar
// sin comprobar nada, ya que intenta lanzar un evento y los eventos tienen su propia seguridad
console.log(ctx.action.name);
if (
!ctx.action.name.includes('leemonsDeploymentManagerEvent') &&
!ctx.action.name.includes('leemonsMongoDBRollback')
!ctx.action.name.includes('leemonsMongoDBRollback') &&
!ctx.action.name.startsWith('gateway.')
) {
if (!isCoreService(ctx.caller) && !isCoreService(ctx.action.name)) {
if (!ctx.meta.relationshipID)
Expand Down
16 changes: 8 additions & 8 deletions packages/leemons-permissions/src/addPermissionsDeploy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const { hasKey, setKey } = require('@leemons/mongodb-helpers');

async function addPermissionsDeploy({ keyValueModel, permissions, ctx }) {
console.time('Create Permissions');
console.time('Has Key Permissions');
let startTime = new Date();
let hasKeyStartTime = new Date();
if (!(await hasKey(keyValueModel, `permissions`))) {
console.timeEnd('Has Key Permissions');
console.time('users.permissions.addMany');
console.log('Has Key Permissions: ' + (new Date() - hasKeyStartTime) + 'ms');
let addManyStartTime = new Date();
await ctx.tx.call('users.permissions.addMany', permissions);
console.timeEnd('users.permissions.addMany');
console.time('keyValueModel');
console.log('users.permissions.addMany: ' + (new Date() - addManyStartTime) + 'ms');
let keyValueModelStartTime = new Date();
await setKey(keyValueModel, `permissions`);
console.timeEnd('keyValueModel');
console.log('keyValueModel: ' + (new Date() - keyValueModelStartTime) + 'ms');
}
ctx.tx.emit('init-permissions');
console.timeEnd('Create Permissions');
console.log('Create Permissions: ' + (new Date() - startTime) + 'ms');
}

module.exports = { addPermissionsDeploy };
12 changes: 6 additions & 6 deletions packages/leemons-widgets/src/addWidgetItemsDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const _ = require('lodash');
const { hasKey, setKey } = require('@leemons/mongodb-helpers');

async function addWidgetItemsDeploy({ keyValueModel, items, ctx }) {
console.time('Create widgets items');
console.time('has widgets items KEY');
let startTime = new Date();
let hasKeyStartTime = new Date();
if (
!(await hasKey(keyValueModel, `widgets-items-zones`)) ||
process.env.RELOAD_WIDGETS_ON_EVERY_INSTALL === 'true'
) {
console.timeEnd('has widgets items KEY');
console.time('widgets items allSettled');
console.log('Has widgets items KEY: ' + (new Date() - hasKeyStartTime) + 'ms');
let allSettledStartTime = new Date();
await Promise.allSettled(
_.map(items, (config) =>
ctx.tx.call('widgets.widgets.setItemToZone', {
Expand All @@ -22,11 +22,11 @@ async function addWidgetItemsDeploy({ keyValueModel, items, ctx }) {
})
)
);
console.timeEnd('widgets items allSettled');
console.log('Widgets items allSettled: ' + (new Date() - allSettledStartTime) + 'ms');
await setKey(keyValueModel, `widgets-items-zones`);
}
ctx.tx.emit('init-widget-items');
console.timeEnd('Create widgets items');
console.log('Create widgets items: ' + (new Date() - startTime) + 'ms');
}

module.exports = { addWidgetItemsDeploy };
77 changes: 56 additions & 21 deletions plugins/leemons-plugin-gateway/backend/services/api.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const ApiGateway = require('moleculer-web');
const { parse } = require('url');
const { LeemonsDeploymentManagerMixin } = require('@leemons/deployment-manager');
const {
LeemonsMiddlewareAuthenticated,
LeemonsMiddlewareNecessaryPermits,
} = require('@leemons/middlewares');
const { LeemonsValidator } = require('@leemons/validator');
const { searchUsers } = require('leemons-plugin-families/core/users');
/**
* @typedef {import('moleculer').ServiceSchema} ServiceSchema Moleculer's Service Schema
* @typedef {import('moleculer').Context} Context Moleculer's Context
Expand All @@ -16,6 +22,18 @@ module.exports = {
LeemonsDeploymentManagerMixin({ checkIfCanCallMe: false, getDeploymentIdInCall: true }),
],

actions: {
status: {
rest: {
method: 'GET',
path: '/status',
},
async handler(ctx) {
return { status: 200, timestamp: new Date() };
},
},
},

/** @type {ApiSettingsSchema} More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html */
settings: {
cors: {
Expand All @@ -31,6 +49,19 @@ module.exports = {
use: [],

routes: [
{
path: '/',
whitelist: ['**'],
use: [],
mergeParams: true,
uthentication: true,
authorization: false,
autoAliases: true,
aliases: {
// -- Gateway (Finish) --
'GET /': 'gateway.status',
},
},
{
path: '/api',

Expand All @@ -53,6 +84,10 @@ module.exports = {
autoAliases: true,

aliases: {
// -- Gateway (Finish) --
'GET status': 'gateway.status',

// -- Deployment Manager (Finish) --
'POST deployment-manager/add-manual-deployment':
'deployment-manager.addManualDeploymentRest',
'POST package-manager/info': 'deployment-manager.infoRest',
Expand Down Expand Up @@ -516,29 +551,29 @@ module.exports = {
},

/**
* Before call hook. You can check the request.
* @param {Context} ctx
* @param {Object} route
* @param {IncomingRequest} req
* @param {ServerResponse} res
* @param {Object} data
*
onBeforeCall(ctx, route, req, res) {
// Set request headers to context meta
ctx.meta.userAgent = req.headers["user-agent"];
}, */
* Before call hook. You can check the request.
* @param {Context} ctx
* @param {Object} route
* @param {IncomingRequest} req
* @param {ServerResponse} res
* @param {Object} data
*
onBeforeCall(ctx, route, req, res) {
// Set request headers to context meta
ctx.meta.userAgent = req.headers["user-agent"];
}, */

/**
* After call hook. You can modify the data.
* @param {Context} ctx
* @param {Object} route
* @param {IncomingRequest} req
* @param {ServerResponse} res
* @param {Object} data
onAfterCall(ctx, route, req, res, data) {
// Async function which return with Promise
return doSomething(ctx, res, data);
}, */
* After call hook. You can modify the data.
* @param {Context} ctx
* @param {Object} route
* @param {IncomingRequest} req
* @param {ServerResponse} res
* @param {Object} data
onAfterCall(ctx, route, req, res, data) {
// Async function which return with Promise
return doSomething(ctx, res, data);
}, */

onBeforeCall(ctx, route, req) {
ctx.meta.clientIP =
Expand Down

0 comments on commit 8790c8b

Please sign in to comment.