Commit d466b3bf authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

make it parametric

parent 6a01486c
node_modules
docs
.DS_Store
config.json
{
"test": {
"wsdl": "https://test.gsis.gr/esbpilot/notificationCenterElementsService?wsdl"
},
"prod": {
"wsdl": "https://www1.gsis.gr/esb/notificationCenterElementsService?wsdl"
}
}
import { AuditRecord } from '@digigov-oss/gsis-audit-record-db';
export declare type Overides = {
test?: boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
};
export declare const getIdentity: (afm: string, user: string, pass: string, overides?: Overides | undefined) => Promise<any>;
export default getIdentity;
import soap from './soap';
import { generateAuditRecord } from '@digigov-oss/gsis-audit-record-db';
import config from './config.json';
export const getIdentity = async (afm, user, pass, overides) => {
const test = overides?.test ?? false;
const auditInit = overides?.auditInit ?? {};
const auditStoragePath = overides?.auditStoragePath ?? "/tmp";
const wsdl = test == true ? config.test.wsdl : config.prod.wsdl;
const auditRecord = generateAuditRecord(auditInit, auditStoragePath);
if (!auditRecord)
throw new Error('Audit record is not initialized');
try {
const s = new soap(wsdl, user, pass, auditRecord);
const Identity = await s.getIdentity(afm);
return Identity;
}
catch (error) {
throw (error);
}
};
export default getIdentity;
import soap from 'soap';
import { AuditRecord } from '@digigov-oss/gsis-audit-record-db';
declare class Soap {
private _client;
private _wsdl;
private _username;
private _password;
private _auditRecord;
constructor(wsdl: string, username: string, password: string, auditRecord: AuditRecord);
init(): Promise<soap.Client>;
getIdentity(vat: string): Promise<any>;
}
export default Soap;
import soap from 'soap';
class Soap {
_client;
_wsdl;
_username;
_password;
_auditRecord;
constructor(wsdl, username, password, auditRecord) {
this._wsdl = wsdl;
this._username = username;
this._password = password;
this._auditRecord = auditRecord;
}
async init() {
try {
const client = await soap.createClientAsync(this._wsdl, {
wsdl_headers: {
'Authorization': 'Basic ' + Buffer.from(`${this._username}:${this._password}`).toString('base64'),
},
});
this._client = client;
return client;
}
catch (e) {
throw e;
}
}
async getIdentity(vat) {
try {
const client = await this.init();
var options = {
hasNonce: true,
actor: 'actor'
};
var wsSecurity = new soap.WSSecurity(this._username, this._password, options);
client.setSecurity(wsSecurity);
const auditRecord = this._auditRecord;
const args = {
auditRecord: auditRecord,
getNncIdentityInputRecord: {
afm: vat
}
};
const result = await client.getNncIdentityAsync(args);
return result[0].getNncIdentityOutputRecord;
}
catch (e) {
throw e;
}
}
}
export default Soap;
import { AuditRecord } from '@digigov-oss/gsis-audit-record-db';
export declare const getIdentity: (afm: string, auditInit?: AuditRecord, auditStoragePath?: string) => Promise<any>;
export declare type Overides = {
test?: boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
};
export declare const getIdentity: (afm: string, user: string, pass: string, overides?: Overides | undefined) => Promise<any>;
export default getIdentity;
import soap from './soap';
import { generateAuditRecord } from '@digigov-oss/gsis-audit-record-db';
import config from '../config.json'; //TODO replace with args
export const getIdentity = async (afm, auditInit = {}, auditStoragePath = '/tmp') => {
import config from '../config.json';
export const getIdentity = async (afm, user, pass, overides) => {
const test = overides?.test ?? false;
const auditInit = overides?.auditInit ?? {};
const auditStoragePath = overides?.auditStoragePath ?? "/tmp";
const wsdl = test ? config.test.wsdl : config.prod.wsdl;
const auditRecord = generateAuditRecord(auditInit, auditStoragePath);
if (!auditRecord)
throw new Error('Audit record is not initialized');
try {
const s = new soap(config.test.wsdl, config.test.user, config.test.pass, auditRecord);
const Identity = await s.getIdentity("019285930");
const s = new soap(wsdl, user, pass, auditRecord);
const Identity = await s.getIdentity(afm);
return Identity;
}
catch (error) {
......
{
"test":{
"wsdl":"https://test.gsis.gr/esbpilot/notificationCenterElementsService?wsdl"
},
"prod":{
"wsdl":"https://www1.gsis.gr/esb/notificationCenterElementsService?wsdl"
}
}
\ No newline at end of file
import soap from './soap';
import {generateAuditRecord,AuditRecord} from '@digigov-oss/gsis-audit-record-db';
import config from '../config.json'; //TODO replace with args
export const getIdentity = async (afm:string, auditInit: AuditRecord={}, auditStoragePath: string='/tmp') => {
export type Overides = {
test?:boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
}
import config from './config.json';
export const getIdentity = async (afm:string, user:string, pass:string, overides?:Overides) => {
const test = overides?.test ?? false;
const auditInit = overides?.auditInit ?? {} as AuditRecord;
const auditStoragePath = overides?.auditStoragePath ?? "/tmp"
const wsdl = test==true? config.test.wsdl : config.prod.wsdl;
const auditRecord = generateAuditRecord(auditInit, auditStoragePath);
if (!auditRecord) throw new Error('Audit record is not initialized');
try {
const s = new soap(config.test.wsdl, config.test.user, config.test.pass, auditRecord);
const Identity = await s.getIdentity("019285930");
const s = new soap(wsdl, user, pass, auditRecord);
const Identity = await s.getIdentity(afm);
return Identity;
} catch (error) {
throw(error);
}
};
export default getIdentity;
......
Set a `config.json` file based on template to run the test.
\ No newline at end of file
{
"user":"username",
"pass":"password"
}
\ No newline at end of file
import getIdentity from '../src/index';
import config from './config.json';
const test = async () => {
const overides = {
test:true,
auditInit: {
auditUnit: 'test',
},
auditStoragePath: '/tmp',
}
try {
const Identity = await getIdentity("052704062");
const Identity = await getIdentity("052704062", config.user, config.pass,overides);
console.log("getNncIdentityOutputRecord=", Identity);
} catch (error) {
console.log(error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment