Skip to content

Commit 526763e

Browse files
committed
declare lic
1 parent 06f45e6 commit 526763e

4 files changed

Lines changed: 83 additions & 6 deletions

File tree

OpenFlow/src/Logger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as winston from "winston";
22
import { Config } from "./Config";
3-
import { otel } from "./otelspec";
3+
import { LicenseFile, otel } from "./otelspec";
44
const path = require('path');
55

66
export class Logger {
77
public static otel: otel;
8+
public static License: LicenseFile;
89
static configure(): winston.Logger {
910
const filename = path.join(Config.logpath, "openflow.log");
1011
const options: any = {

OpenFlow/src/cli-lic.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
import * as fs from "fs";
33
import { LicenseFile, license_data } from "./license-file";
4+
import { Logger } from "./Logger";
45
function printusage() {
56
console.log("openflow-cli [--months 3][--email email] domain");
67
console.log(" --months - Set number of months, default 3");
@@ -32,18 +33,18 @@ try {
3233
process.exit();
3334
}
3435
const data: license_data = {} as any;
35-
let template = LicenseFile.template_v1;
36+
let template = Logger.License.template_v1;
3637
data.licenseVersion = 1;
3738
data.email = options.email;
3839
if (options.domain) {
39-
template = LicenseFile.template_v2;
40+
template = Logger.License.template_v2;
4041
data.licenseVersion = 2;
4142
data.domain = options.domain;
4243
}
4344
var dt = new Date(new Date().toISOString());
4445
dt.setMonth(dt.getMonth() + months);
4546
data.expirationDate = dt.toISOString() as any;
46-
const licenseFileContent = LicenseFile.generate({
47+
const licenseFileContent = Logger.License.generate({
4748
privateKeyPath: 'config/private_key.pem',
4849
template,
4950
data: data

OpenFlow/src/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,31 @@ import { DatabaseConnection } from "./DatabaseConnection";
77
import { Crypt } from "./Crypt";
88
import { Config } from "./Config";
99
import { amqpwrapper, QueueMessageOptions } from "./amqpwrapper";
10-
import { WellknownIds, Role, Rights, User, Base } from "@openiap/openflow-api";
10+
import { WellknownIds, Role, Rights, User, Base, NoderedUtil } from "@openiap/openflow-api";
1111
import { DBHelper } from "./DBHelper";
1212
import { OAuthProvider } from "./OAuthProvider";
1313
import { Span } from "@opentelemetry/api";
1414

1515
Logger.configure();
1616

17+
let _lic_require: any = null;
18+
try {
19+
_lic_require = require("./license-file");
20+
} catch (error) {
21+
}
22+
if (_lic_require != null) {
23+
Logger.License = new _lic_require.LicenseFile();
24+
} else {
25+
Logger.License = {} as any;
26+
Logger.License.ofid = function () {
27+
if (!NoderedUtil.IsNullEmpty(this._ofid)) return this._ofid;
28+
var crypto = require('crypto');
29+
const openflow_uniqueid = Config.openflow_uniqueid || crypto.createHash('md5').update(Config.domain).digest("hex");
30+
Config.openflow_uniqueid = openflow_uniqueid;
31+
this._ofid = openflow_uniqueid;
32+
return openflow_uniqueid;
33+
};
34+
}
1735
let _otel_require: any = null;
1836
try {
1937
_otel_require = require("./otel");
@@ -49,7 +67,6 @@ if (_otel_require != null) {
4967
}
5068
} as any;
5169
}
52-
5370
Config.db = new DatabaseConnection(Config.mongodb_url, Config.mongodb_db);
5471

5572

OpenFlow/src/otelspec.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,64 @@ import { HrTime, Span, setSpan } from "@opentelemetry/api";
44
import { ValueRecorder } from "@opentelemetry/api-metrics";
55
import { Labels } from "@opentelemetry/api-metrics";
66

7+
export declare class license_data {
8+
licenseVersion: number;
9+
email: string;
10+
expirationDate: Date;
11+
domain: string;
12+
}
13+
/**
14+
* LicenseFile Class
15+
*/
16+
export declare class LicenseFile {
17+
template_v1: string;
18+
template_v2: string;
19+
license_public_key: string;
20+
privateKey: string;
21+
validlicense: boolean;
22+
licenserror: string;
23+
data: license_data;
24+
private _ofid;
25+
ofid(): any;
26+
validate(): void;
27+
private validateTimer;
28+
/**
29+
* Generate license file
30+
*
31+
* @param options
32+
* @param options.data {object|string} - data to sign
33+
* @param options.template - custom license file template
34+
* @param [options.privateKeyPath] {string} - path to private key
35+
* @param [options.privateKey] {string} - private key content
36+
*/
37+
generate(options: any): any;
38+
/**
39+
* Parse license file
40+
*
41+
* @param options
42+
* @param options.template - custom license file template
43+
* @param [options.publicKeyPath] {string} - path to public key
44+
* @param [options.publicKey] {string} - path to public key
45+
* @param [options.licenseFilePath] {string} - path to license file
46+
* @param [options.licenseFile] {string} - license file content
47+
*/
48+
parse(options: any): {
49+
valid: boolean;
50+
serial: string;
51+
data: {};
52+
};
53+
/**
54+
*
55+
* @param options
56+
* @param options.data
57+
* @param options.privateKey
58+
* @private
59+
*/
60+
_generateSerial(options: any): string;
61+
_render(template: any, data: any): any;
62+
_prepareDataObject(data: any): {};
63+
}
64+
765
export declare class otel {
866
default_boundaries: number[];
967
static fakespan: {

0 commit comments

Comments
 (0)