Skip to content

Commit

Permalink
feat: update to support monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Apr 19, 2023
1 parent 971c7dd commit 51c4997
Show file tree
Hide file tree
Showing 17 changed files with 4,132 additions and 2,861 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
dist
lib
coverage
.test
22 changes: 20 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
root: true

extends:
- 'plugin:@typescript-eslint/recommended'
- plugin:node/recommended
- plugin:github/recommended
- plugin:promise/recommended
Expand All @@ -15,6 +16,7 @@ extends:
- prettier

plugins:
- '@typescript-eslint'
- node
- github
- promise
Expand All @@ -33,7 +35,7 @@ parser: '@typescript-eslint/parser'

parserOptions:
ecmaVersion: 2020
project: './tsconfig.json'
project: './tsconfig.*'

overrides:
- files: '*.ts'
Expand All @@ -42,12 +44,17 @@ overrides:
- plugin:import/typescript
- xo-typescript
- prettier
parserOptions:
ecmaVersion: 2020
project: './tsconfig.*'
rules:
'@typescript-eslint/naming-convention':
[
error,
{ selector: default, format: [camelCase] },
{ selector: default, modifiers: [static], format: [PascalCase] },
{ selector: objectLiteralProperty, format: null },
{ selector: enumMember, format: [PascalCase] },
{ selector: typeProperty, format: null },

{
Expand All @@ -72,6 +79,17 @@ overrides:
]
'@typescript-eslint/restrict-template-expressions': off
'@typescript-eslint/no-shadow': warn
'@typescript-eslint/no-unused-vars':
[
warn,
{
args: after-used,
ignoreRestSiblings: true,
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
},
]
'@typescript-eslint/consistent-type-definitions': [warn, interface]

rules:
notice/notice:
Expand Down Expand Up @@ -105,7 +123,7 @@ rules:
unicorn/filename-case: off
i18n-text/no-en: off
eslint-comments/no-use: off
no-secrets/no-secrets: error
no-secrets/no-secrets: [error, { tolerance: 5 }]
no-empty-label: off
no-warning-comments: off
node/no-missing-import: off
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Qlever LLC
# Copyright 2022 Qlever LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,20 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build and push docker image
name: Build, test, and push service images

on:
push:
pull_request:

jobs:
call-build-and-push-service:
#yarn:
# name: yarn CI
# uses: qlever-llc/workflows/.github/workflows/build-and-publish-package.yml@master
# secrets:
# npm_token: ${{ secrets.NPM_AUTH_TOKEN }}
# with:
# # Remove this line if your tests don't need an OADA instance
# oada: true
# publish: false
docker:
name: Docker CI
# Wait for yarn tests to pass?
#needs:
# - yarn
uses: qlever-llc/workflows/.github/workflows/build-and-push-service.yml@master
secrets:
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_repo: ${{ secrets.DOCKER_REPO }}
snyk_org: ${{ secrets.SNYK_ORG }}
# Actual secrets
github_token: ${{ secrets.GITHUB_TOKEN }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
snyk_token: ${{ secrets.SNYK_TOKEN }}
cosign_key: ${{ secrets.COSIGN_KEY }}
cosign_password: ${{ secrets.COSIGN_PASSWORD }}
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@
"cois",
"jobid",
"luxon",
"pino",
"Snyk",
"sonarjs",
"trellisfw"
],
"npm.packageManager": "yarn",
"debug.javascript.autoAttachFilter": "smart",
"debug.javascript.breakOnConditionalError": true,
"debug.javascript.defaultRuntimeExecutable": {
"node": "yarn",
"pwa-node": "yarn"
},
"debug.javascript.autoAttachSmartPattern": [
"${workspaceFolder}/**",
"!**/node_modules/**",
"**/$KNOWN_TOOLS$/**",
"!**/yarn-*",
"!**/ava-*/**/cli.mjs"
]
}
340 changes: 259 additions & 81 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

768 changes: 0 additions & 768 deletions .yarn/releases/yarn-3.1.1.cjs

This file was deleted.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.1.1.cjs
yarnPath: .yarn/releases/yarn-3.5.0.cjs
82 changes: 40 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trellisfw/ainz",
"version": "2.1.0",
"version": "3.0.0",
"description": "uservice for automating moving resources via rules",
"main": "dist/index.js",
"type": "module",
Expand All @@ -14,60 +14,58 @@
"author": "Alex Layton <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@oada/client": "^2.6.4",
"@oada/list-lib": "^2.1.10",
"@oada/types": "^1.7.0",
"ajv": "^8.8.2",
"bluebird": "^3.7.2",
"convict": "^6.2.1",
"debug": "^4.3.3",
"dotenv": "^10.0.0",
"@oada/client": "^4.5.0",
"@oada/lib-prom": "^3.8.0",
"@oada/list-lib": "^4.2.6",
"@oada/pino-debug": "^3.9.1",
"@oada/types": "^3.4.5",
"ajv": "^8.12.0",
"convict": "^6.2.4",
"debug": "^4.3.4",
"dotenv": "^16.0.3",
"handlebars": "^4.7.7",
"json-pointer": "^0.6.1",
"luxon": "^2.1.1",
"minimist": "^1.2.5",
"nconf": "^0.11.3",
"p-queue": "^7.1.0",
"tslib": "^2.3.1"
"json-ptr": "^3.1.1",
"luxon": "^3.3.0",
"minimist": "^1.2.8",
"p-queue": "^7.3.4",
"tslib": "^2.5.0"
},
"devDependencies": {
"@tsconfig/node16": "^1.0.2",
"@types/bluebird": "^3.5.36",
"@tsconfig/node16": "^1.0.3",
"@types/convict": "^6.1.1",
"@types/debug": "^4.1.7",
"@types/json-pointer": "^1.0.31",
"@types/luxon": "^2.0.7",
"@types/luxon": "^3.3.0",
"@types/minimist": "^1.2.2",
"@types/node": "^16.11.11",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"@yarnpkg/sdks": "^2.5.1-rc.4",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-xo": "^0.39.0",
"eslint-config-xo-typescript": "^0.47.1",
"eslint-formatter-pretty": "^4.1.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-plugin-array-func": "^3.1.7",
"@types/node": "^16.18.23",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@yarnpkg/sdks": "^3.0.0-rc.42",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-xo": "^0.43.1",
"eslint-config-xo-typescript": "^0.57.0",
"eslint-plugin-array-func": "^3.1.8",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-escompat": "^3.4.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-github": "^4.7.0",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-no-constructor-bind": "^2.0.4",
"eslint-plugin-no-only-tests": "^2.6.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-no-secrets": "^0.8.9",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-regexp": "^1.5.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-sonarjs": "^0.11.0",
"eslint-plugin-unicorn": "^39.0.0",
"prettier": "^2.5.0",
"typescript": "^4.4.4"
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-regexp": "^1.14.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-unicorn": "^46.0.0",
"prettier": "^2.8.7",
"typescript": "5.0.4"
},
"packageManager": "yarn@3.1.1"
"packageManager": "yarn@3.5.0"
}
18 changes: 3 additions & 15 deletions rule.example.json5
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// Copyright 2021 Qlever LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* Copyright 2020 Qlever LLC
/**
* @license
* Copyright 2020 Qlever LLC
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
Expand Down
89 changes: 42 additions & 47 deletions src/addrule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
* limitations under the License.
*/

/* eslint-disable no-console */
/* eslint-disable no-console, no-process-exit, unicorn/no-process-exit */

import { basename, resolve } from 'node:path';

import debug from 'debug';
import parse from 'minimist';

import Rule, { assert as assertRule } from '@oada/types/oada/ainz/rule';
import type Rule from '@oada/types/oada/ainz/rule.js';
import { assert as assertRule } from '@oada/types/oada/ainz/rule.js';
import { connect } from '@oada/client';

import config from './config';
import config from './config.js';

const info = debug('ainz:add:info');
const error = debug('ainz:add:error');
Expand All @@ -47,55 +48,49 @@ const {
...flags
} = parse(process.argv.slice(2), { boolean: ['s'] });

async function run() {
if (files.length === 0) {
// Print usage info
console.log('ainz add [-t token] [-d domain] [-s] FILES...');
console.log('Add all the rules from files FILES');
if (files.length === 0) {
// Print usage info
console.log('ainz add [-t token] [-d domain] [-s] FILES...');
console.log('Add all the rules from files FILES');

return;
}
process.exit(0);
}

const domain = (d as string) ?? DOMAIN;
const tokens: string[] = typeof t === 'string' ? t.split(',') : TOKENS;
const conns = await Promise.all(
tokens.map(async (token) => connect({ domain, token, connection: 'http' }))
);
const domain = (d as string) ?? DOMAIN;
const tokens: string[] = typeof t === 'string' ? t.split(',') : TOKENS;
const conns = await Promise.all(
tokens.map(async (token) => connect({ domain, token, connection: 'http' }))
);

async function addRule(rule: Rule, id?: string) {
await Promise.all(
conns.map(async (conn) =>
id
? // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
conn.put({ path: `${path}/${id}`, tree, data: rule as any })
: // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
conn.post({ path, tree, data: rule as any })
)
);
}
async function addRule(rule: Rule, id?: string) {
await Promise.all(
conns.map(async (conn) =>
id
? // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
conn.put({ path: `${path}/${id}`, tree, data: rule as any })
: // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
conn.post({ path, tree, data: rule as any })
)
);
}

try {
for (const file of files) {
info('Adding rule from file %s', file);
try {
// Load rule
// eslint-disable-next-line no-await-in-loop
const { default: out } = (await import(resolve(file))) as {
default: unknown;
};
const rule: unknown = typeof out === 'function' ? out(flags) : out;
assertRule(rule);
try {
for await (const file of files) {
info('Adding rule from file %s', file);
try {
// Load rule
const { default: out } = (await import(resolve(file))) as {
default: unknown;
};
const rule: unknown = typeof out === 'function' ? out(flags) : out;
assertRule(rule);

// Register in OADA
// eslint-disable-next-line no-await-in-loop
await addRule(rule, s && basename(file));
} catch (cError: unknown) {
error('Error adding rule %s: %O', file, cError);
}
// Register in OADA
await addRule(rule, s ? basename(file) : undefined);
} catch (cError: unknown) {
error({ error: cError, file }, 'Error adding rule');
}
} finally {
await Promise.all(conns.map(async (conn) => conn.disconnect()));
}
} finally {
await Promise.all(conns.map(async (conn) => conn.disconnect()));
}

await run();
Loading

0 comments on commit 51c4997

Please sign in to comment.