fix: add plugin support back and disable release needing test/lint

This commit is contained in:
Alexis Tyler
2020-01-23 16:06:06 +10:30
parent af54e9ccea
commit 8a6263c6d8
6 changed files with 159 additions and 93 deletions

View File

@@ -5,77 +5,77 @@ on:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
# test:
# runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v1
# steps:
# - name: Checkout repo
# uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
- name: Add SSH deploy key
run: |
mkdir ~/.ssh/
# Add keys
echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY_PUB }}" > ~/.ssh/id_rsa.pub
# Verifiy keys
ssh-keygen -l -f ~/.ssh/id_rsa.pub
# Add github.com to known hosts
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# Set correct permissions
chmod 600 ~/.ssh/id_rsa
# - name: Add SSH deploy key
# run: |
# mkdir ~/.ssh/
# # Add keys
# echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY }}" > ~/.ssh/id_rsa
# echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY_PUB }}" > ~/.ssh/id_rsa.pub
# # Verifiy keys
# ssh-keygen -l -f ~/.ssh/id_rsa.pub
# # Add github.com to known hosts
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# # Set correct permissions
# chmod 600 ~/.ssh/id_rsa
- name: Installing node deps
run: npm ci
# - name: Installing node deps
# run: npm ci
- name: Test
run: npm test
# uses: omgimalexis/ava-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Test
# run: npm test
# # uses: omgimalexis/ava-action@master
# # env:
# # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
# lint:
# runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v1
# steps:
# - name: Checkout repo
# uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
- name: Add SSH deploy key
run: |
mkdir ~/.ssh/
# Add keys
echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY_PUB }}" > ~/.ssh/id_rsa.pub
# Verifiy keys
ssh-keygen -l -f ~/.ssh/id_rsa.pub
# Add github.com to known hosts
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# Set correct permissions
chmod 600 ~/.ssh/id_rsa
# - name: Add SSH deploy key
# run: |
# mkdir ~/.ssh/
# # Add keys
# echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY }}" > ~/.ssh/id_rsa
# echo "${{ secrets.GITHUB_READONLY_DEPLOY_KEY_PUB }}" > ~/.ssh/id_rsa.pub
# # Verifiy keys
# ssh-keygen -l -f ~/.ssh/id_rsa.pub
# # Add github.com to known hosts
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# # Set correct permissions
# chmod 600 ~/.ssh/id_rsa
- name: Installing node deps
run: npm install
# - name: Installing node deps
# run: npm install
- name: Lint
uses: omgimalexis/xo-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Lint
# uses: omgimalexis/xo-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
runs-on: ubuntu-latest
needs: [lint, test]
# needs: [lint, test]
strategy:
matrix:

68
package-lock.json generated
View File

@@ -1126,6 +1126,7 @@
"apollo-server": "^2.9.16",
"async-exit-hook": "^2.0.1",
"async-mqtt": "2.4.2",
"backoff-promise": "1.0.0",
"bcryptjs": "^2.4.3",
"better-stack-traces": "^1.1.0",
"bolus": "github:OmgImAlexis/bolus#04cd4d9",
@@ -1176,12 +1177,15 @@
"os-uptime": "^2.0.2",
"p-iteration": "^1.1.8",
"p-props": "^3.1.0",
"p-wait-for": "3.1.0",
"p-whilst": "2.1.0",
"package-json": "^6.5.0",
"path-exists": "^4.0.0",
"pify": "^4.0.1",
"pretty-ms": "^5.1.0",
"ps-list": "^6.3.0",
"request": "^2.88.0",
"request-promise": "4.2.5",
"request-promise-native": "^1.0.8",
"semver": "^7.1.1",
"sendmail": "1.6.1",
@@ -2433,6 +2437,15 @@
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
"integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
},
"backoff-promise": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/backoff-promise/-/backoff-promise-1.0.0.tgz",
"integrity": "sha512-uW7DtRKY+J5oUbGa0bprJDoJxNh8CB37AzQhm/bOrOoYC9xvsG8xHYZy1/OpKgiVhL/ePKP6KjvkoChEgulQqw==",
"requires": {
"bluebird": "^3.5.3",
"sporks": "^1.0.1"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -6036,6 +6049,11 @@
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz",
"integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q=="
},
"events": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.1.0.tgz",
"integrity": "sha512-Rv+u8MLHNOdMjTAFeT3nCjHn2aGlx435FP/sDHNaRhDEMwyI/aB22Kj2qIN8R0cw3z28psEQLYwxVKLsKrMgWg=="
},
"execa": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz",
@@ -8114,6 +8132,11 @@
"is-unc-path": "^1.0.0"
}
},
"is-secret": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-secret/-/is-secret-1.2.1.tgz",
"integrity": "sha512-VtBantcgKL2a64fDeCmD1JlkHToh3v0bVOhyJZ5aGTjxtCgrdNcjaC9GaaRFXi19gA4/pYFpnuyoscIgQCFSMQ=="
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
@@ -10484,11 +10507,32 @@
"p-map": "^3.0.0"
}
},
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
},
"p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
},
"p-wait-for": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/p-wait-for/-/p-wait-for-3.1.0.tgz",
"integrity": "sha512-0Uy19uhxbssHelu9ynDMcON6BmMk6pH8551CvxROhiz3Vx+yC4RqxjyIDk2V4ll0g9177RKT++PK4zcV58uJ7A==",
"requires": {
"p-timeout": "^3.0.0"
}
},
"p-whilst": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/p-whilst/-/p-whilst-2.1.0.tgz",
"integrity": "sha512-uzp1HPgqzokEmZN+VpfQ9PO4YY5xm+jpLJeL9FN1NPU4d4IZh8eEV+mtQXd+/22R1P7C5j19b7Y//oUc7k0+RQ=="
},
"package-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/package-hash/-/package-hash-3.0.0.tgz",
@@ -11067,6 +11111,15 @@
"resolve": "^1.1.6"
}
},
"redact-secrets": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/redact-secrets/-/redact-secrets-1.0.0.tgz",
"integrity": "sha1-YPHbVpJP6QogO6jMs5KDzbsNkHw=",
"requires": {
"is-secret": "^1.0.0",
"traverse": "^0.6.6"
}
},
"redent": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/redent/-/redent-2.0.0.tgz",
@@ -11906,6 +11959,16 @@
}
}
},
"sporks": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sporks/-/sporks-1.0.1.tgz",
"integrity": "sha512-PYthB8v6SYkmR8LXhAEptany82SxzW6N4i1chClShrJ9BamYyDJoWyaLC2Ezy3lDskuWx57WfBWn1PDMeogBlg==",
"requires": {
"bluebird": "^3.5.3",
"events": "^3.0.0",
"inherits": "^2.0.3"
}
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
@@ -13175,6 +13238,11 @@
}
}
},
"traverse": {
"version": "0.6.6",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz",
"integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc="
},
"trim-newlines": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-2.0.0.tgz",

View File

@@ -45,6 +45,8 @@
"lodash.get": "^4.4.2",
"merge-graphql-schemas": "^1.7.6",
"p-props": "^3.1.0",
"p-wait-for": "3.1.0",
"redact-secrets": "1.0.0",
"request-promise": "4.2.5",
"set-interval-async": "^1.0.30",
"stoppable": "^1.1.0",

View File

@@ -13,8 +13,8 @@ import gql from 'graphql-tag';
import { typeDefs, resolvers } from './schema';
import { increaseWsConectionCount, decreaseWsConectionCount } from '../ws';
const { apiManager, errors, log, states, config } = core;
const { AppError, FatalAppError } = errors;
const { apiManager, errors, log, states, config, pluginManager } = core;
const { AppError, FatalAppError, PluginError } = errors;
const { usersState } = states;
const baseTypes = [gql`
@@ -135,6 +135,26 @@ const types = mergeTypes([
typeDefs
]);
const getCoreModule = (moduleName) => {
if (!Object.keys(core.modules).includes(moduleName)) {
throw new FatalAppError(`"${moduleName}" is not a valid core module.`);
}
return core.modules[moduleName];
};
const getPluginModule = (pluginName, pluginModuleName) => {
if (!pluginManager.isInstalled(pluginName, pluginModuleName)) {
throw new PluginError('Plugin not installed.');
}
if (!pluginManager.isActive(pluginName, pluginModuleName)) {
throw new PluginError('Plugin disabled.');
}
return pluginManager.get(pluginName, pluginModuleName);
};
/**
* Func directive
*
@@ -171,24 +191,6 @@ class FuncDirective extends SchemaDirectiveVisitor {
...directiveArgs.data,
...(operationType === 'mutation' ? input : {})
};
// let funcPath = path.join(coreCwd, moduleName + '.js');
// If we're looking for a plugin verify it's installed and active first
// if (pluginName) {
// if (!PluginManager.isInstalled(pluginName, pluginModuleName)) {
// throw new PluginError('Plugin not installed.');
// }
// if (!PluginManager.isActive(pluginName, pluginModuleName)) {
// throw new PluginError('Plugin disabled.');
// }
// const pluginModule = PluginManager.get(pluginName, pluginModuleName);
// // Update plugin funcPath
// funcPath = pluginModule.filePath;
// }
// Create func context
// If query @func(param_1, param_2, input: query?)
// If mutation @func(param_1, param_2, input: data)
const context = {
@@ -201,15 +203,15 @@ class FuncDirective extends SchemaDirectiveVisitor {
// Resolve func
let func;
if (!Object.keys(core.modules).includes(moduleName)) {
throw new FatalAppError(`"${moduleName}" is not a valid core module.`);
}
try {
func = core.modules[moduleName]
} catch (error_) {
if (pluginName) {
func = getPluginModule(pluginName, pluginModuleName);
} else {
func = getCoreModule(moduleName);
}
} catch (error) {
// Rethrow clean error message about module being missing
if (error_.code === 'MODULE_NOT_FOUND') {
if (error.code === 'MODULE_NOT_FOUND') {
throw new AppError(`Cannot find ${pluginName ? 'Plugin: "' + pluginName + '" ' : ''}Module: "${pluginName ? pluginModuleName : moduleName}"`);
}
@@ -219,14 +221,14 @@ class FuncDirective extends SchemaDirectiveVisitor {
}
// Otherwise re-throw actual error
throw error_;
throw error;
}
const pluginOrModule = pluginName ? 'Plugin:' : 'Module:';
const pluginOrModuleName = pluginModuleName || moduleName;
// Run function
let [error, result] = await Promise.resolve(func(context))
let [error, result] = await Promise.resolve(func(context, core))
.then(result => [undefined, result])
.catch(error_ => {
// Ensure we aren't leaking anything in production

View File

@@ -18,7 +18,7 @@ type InfoCpu {
# ''
revision: String!
# ''
voltage: Float
voltage: String
# '2.27'
speed: Float!
# '1.60'

View File

@@ -1,4 +1,4 @@
import { CoreResult } from '@unraid/core/interfaces';
import { CoreResult } from '@unraid/core/dist/interfaces';
import * as core from '@unraid/core'
import { getWsConectionCount } from './ws';
@@ -43,7 +43,6 @@ export const run = async (channel: string, mutation: string, options: RunOptions
const {
node,
moduleToRun,
// moduleToRun,
// filePath,
context
} = options;
@@ -63,11 +62,6 @@ export const run = async (channel: string, mutation: string, options: RunOptions
return resolve(moduleToRun(context));
});
// if (filePath) {
// const [pluginName, moduleName] = channel.split('/');
// log.debug('Plugin:', pluginName, 'Module:', moduleName, 'Result:', result);
// }
log.debug('Module:', moduleToRun.name, 'Result:', result.json);
// Update pubsub channel