Skip to content

Commit

Permalink
fix: eslint all
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
rafaelbelchiorbd committed May 19, 2024
1 parent 8a46774 commit ac5a55a
Show file tree
Hide file tree
Showing 40 changed files with 2,582 additions and 2,197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ end
awssm --> apis: Response
apis --> apic: Formatted Response
apic --> a: GetKeychainEntryResponse
@enduml
@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@startuml
title Hyperledger Cacti SATP-Hermes\nInitialization (standalone)

skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam maxmessagesize 120
skinparam sequenceParticipant underline
skinparam autonumber true

entity "SATPGateway" as g
entity "Orchestrator (GOL)" as gol
entity "Counterparty SATP Gateway" as cg
entity "WebServices" as web
entity "Dispatcher (BLO)" as dispatcher
entity "SATPManager" as manager
component "SATP Core" as core


g --> g: constructor(options)
g --> g: ProcessGatewayCoordinatorConfig()
g --> g: basic initialization (logger, signer, etc)

== GOL Init ==
g -> gol: initialize GatewayOrchestrator(GOLoptions)
group #Yellow if { get GOLoptions.CounterpartyGateways() }
gol -> gol: basic initialization (logger, etc)
gol -> gol: connectToCounterPartyGateways()
gol -> gol: createChannel(counterpartyGateway)
gol -> gol: createConnectClients(counterpartyGateway)
gol -> cg: call healthcheck endpoint <color:red>(TBD 🚨)
else #Pink else only do basic initialization
end
gol --> g: GatewayOrchestrator

== BLO and SATP Manager Init ==
g --> bol: initialize BLODispatcher(options, GatewayOrchestrator)
bol --> bol: expose endpoints via getOrCreateWebServices()
bol --> manager: initialize SATPManager(options)
manager --> core: get SATP Service classes
core --> manager: services
manager --> manager: instantiate services (options)
manager --> core: get SATP Handler classes
core --> manager: handlers
manager --> manager: instatiate handlers (services, options)
manager --> bol: SATP manager

== Misc ==

g --> g: setup OpenAPI UI server


@enduml
2 changes: 1 addition & 1 deletion packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"generate-sdk:typescript-axios-bol": "yarn bundle-openapi-yaml && yarn bundle-openapi-json && openapi-generator-cli generate -i ./src/main/yml/bol/openapi-blo-bundled.yml -g typescript-axios -o ./src/main/typescript/generated/gateway-client/typescript-axios/ --reserved-words-mappings protected=protected --enable-post-process-file",
"generate-sdk:go": "openapi-generator-cli generate -i ./src/main/yml/bol/openapi-blo-bundled.yml -g go -o ./src/main/go/generated/gateway-client --additional-properties=packageName=generated,generateInterfaces=true,packageVersion=v0.0.1,moduleName=github.com/hyperledger/cacti/packages/cactus-plugin-satp-hermes/src/main/go/generated --git-user-id hyperledger --git-repo-id cacti/packages/cactus-plugin-satp-hermes/src/main/go/generated",
"lint": "run-p 'lint:*'",
"lint:eslint": "eslint '*/*/src/**/*.{js,ts}' --quiet --fix && cspell \"*/*/src/**/*.{js,ts}\"",
"lint:eslint": "eslint './src/**/*.{js,ts}' --quiet --fix && cspell \"*/*/src/**/*.{js,ts}\"",
"lint:oapi": "vacuum lint -d -e ./src/main/yml/bol/openapi-blo-bundled.yml",
"lint:protobuf": "buf lint --path src/main/proto --verbose",
"pretsc": "npm run generate-sdk",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "../../generated/gateway-client/typescript-axios";
import { Logger } from "@hyperledger/cactus-common";

export async function GetStatusHandler(
export async function ExecuteGetStatus(
logger: Logger,
req: StatusRequest,
): Promise<StatusResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
JsObjectSigner,
} from "@hyperledger/cactus-common";

import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

//import { GatewayIdentity, GatewayChannel } from "../core/types";
//import { GetStatusError, NonExistantGatewayIdentity } from "../core/errors";
import { GetStatusEndpointV1 } from "../web-services/blo/status-endpoint";
import { GetStatusEndpointV1 } from "../web-services/status-endpoint";

//import { GetAuditRequest, GetAuditResponse } from "../generated/gateway-client/typescript-axios";
import {
StatusRequest,
StatusResponse,
} from "../generated/gateway-client/typescript-axios";
import { GetStatusHandler } from "./admin/get-status-handler-service";
import { ExecuteGetStatus } from "./admin/get-status-handler-service";
import { ISATPManagerOptions, SATPManager } from "../gol/satp-manager";
import { GatewayOrchestrator } from "../gol/gateway-orchestrator";

export interface BLODispatcherOptions {
logger: Logger;
logLevel?: LogLevelDesc;
instanceId: string;
orchestrator: GatewayOrchestrator;
signer: JsObjectSigner;
}

export class BLODispatcher {
public static readonly CLASS_NAME = "BLODispatcher";
private readonly logger: Logger;
private endpoints: IWebServiceEndpoint[] | undefined;
private readonly instanceId: string;
private manager: SATPManager;
private orchestrator: GatewayOrchestrator;

constructor(public readonly options: BLODispatcherOptions) {
const fnTag = `${BLODispatcher.CLASS_NAME}#constructor()`;
Expand All @@ -39,6 +46,18 @@ export class BLODispatcher {
this.logger = LoggerProvider.getOrCreate({ level, label });
this.instanceId = options.instanceId;
this.logger.info(`Instantiated ${this.className} OK`);
this.orchestrator = options.orchestrator;
const signer = options.signer;
const ourGateway = this.orchestrator.ourGateway;

const SATPManagerOpts: ISATPManagerOptions = {
logLevel: "DEBUG",
instanceId: ourGateway!.id,
signer: signer,
supportedDLTs: this.orchestrator.supportedDLTs,
};

this.manager = new SATPManager(SATPManagerOpts);
}

public get className(): string {
Expand All @@ -64,9 +83,31 @@ export class BLODispatcher {
return theEndpoints;
}

private getTargetGatewayClient(id: string) {
const channels = Array.from(this.orchestrator.getChannels());
channels.filter((ch) => {
id == ch[0] && ch[1].toGatewayID == id;
});

if (channels.length == 0) {
throw new Error(`No channels with specified target gateway id ${id}`);
} else if (channels.length > 1) {
throw new Error(
`Duplicated channels with specified target gateway id ${id}`,
);
} else {
return channels[0];
}
}

public async GetStatus(req: StatusRequest): Promise<StatusResponse> {
return GetStatusHandler(this.logger, req);
return ExecuteGetStatus(this.logger, req);
}

public async Transact(req: StatusRequest): Promise<StatusResponse> {
return ExecuteGetStatus(this.logger, req);
}
// get channel by caller; give needed client from orchestrator to handler to call
// for all channels, find session id on request
// TODO implement handlers GetAudit, Transact, Cancel, Routes
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export class SATPError extends Error {
constructor(message: string, public code: number = 500, public internalErrorId?: string, public trace?: string) {
constructor(
message: string,
public code: number = 500,
public internalErrorId?: string,
public trace?: string,
) {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype); // make sure prototype chain is set to error
Expand All @@ -9,7 +14,12 @@ export class SATPError extends Error {

export class BootstrapError extends SATPError {
constructor(internalErrorId?: string, trace?: string) {
super("Bootstrap already called in this Gateway Manager", 409, internalErrorId, trace);
super(
"Bootstrap already called in this Gateway Manager",
409,
internalErrorId,
trace,
);
}
}

Expand All @@ -20,7 +30,17 @@ export class NonExistantGatewayIdentity extends SATPError {
}

export class GetStatusError extends SATPError {
constructor(sessionID: string, message: string, internalErrorId?: string, trace?: string) {
super(`Could not GetStatus at Session: with id ${sessionID}. Reason: ${message}`, 400, internalErrorId, trace);
constructor(
sessionID: string,
message: string,
internalErrorId?: string,
trace?: string,
) {
super(
`Could not GetStatus at Session: with id ${sessionID}. Reason: ${message}`,
400,
internalErrorId,
trace,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { v4 as uuidv4 } from "uuid";
import { SessionData } from "../generated/proto/cacti/satp/v02/common/session_pb";


// Define interface on protos
export interface ISATPSessionOptions {
contextID: string;
}

export class SATPSession {
private static readonly CLASS_NAME = "SATPSession";
public static readonly CLASS_NAME = "SATPSession";
private sessionData: SessionData;

constructor(ops: ISATPSessionOptions) {
this.sessionData = new SessionData();
this.sessionData.transferContextId = ops.contextID;
this.sessionData.id = this.generateSessionID();

}

private generateSessionID(): string {
return this.sessionData.id = uuidv4() + "-" + this.sessionData.transferContextId;
return (this.sessionData.id =
uuidv4() + "-" + this.sessionData.transferContextId);
}

public getSessionData(): SessionData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,92 @@
import { ConnectRouter, HandlerContext } from "@connectrpc/connect";
import { SatpStage1Service } from "../../generated/proto/cacti/satp/v02/stage_1_connect";
import { TransferCommenceRequestMessage, TransferProposalRequestMessage } from "../../generated/proto/cacti/satp/v02/stage_1_pb";
import {
TransferCommenceRequestMessage,
TransferCommenceResponseMessage,
TransferProposalReceiptMessage,
TransferProposalRequestMessage,
} from "../../generated/proto/cacti/satp/v02/stage_1_pb";
import { SATPSession } from "../satp-session";
import { Stage1ServerService } from "../stage-services/server/stage1-server-service";
import { Stage1ClientService } from "../stage-services/client/stage1-client-service";
import { SupportedGatewayImplementations } from "../types";
import { SATPHandler } from './SATPHandler'; // Assuming the interface is exported from this path
import { SupportedChain } from "../types";
import { SATPHandler, SATPHandlerOptions } from "../../types/satp-protocol";
import { Logger, LoggerProvider } from "@hyperledger/cactus-common";

export class Stage1SATPHandler implements SATPHandler {
constructor(
private session: SATPSession | undefined,
private serverService: Stage1ServerService,
private clientService: Stage1ClientService,
private supportedDLTs: SupportedGatewayImplementations[]
) {}
public static readonly CLASS_NAME = "Stage1SATPHandler";
private session: SATPSession;
private serverService: Stage1ServerService;
private clientService: Stage1ClientService;
private supportedDLTs: SupportedChain[];
private logger: Logger;

setupRouter(router: ConnectRouter): void {
router.service(SatpStage1Service, {
transferProposal: async (req: TransferProposalRequestMessage, context: HandlerContext) => {
try {
console.log("Received TransferProposalRequest", req, context);
const sessionData = await this.serverService.checkTransferProposalRequestMessage(req, this.session, this.supportedDLTs);
const message = await this.serverService.transferProposalResponse(req, this.session);
console.log("Returning response", message);
return message;
} catch (error) {
console.error("Error handling TransferProposalRequest:", error);
throw new Error("Failed to process TransferProposalRequest");
}
},
transferCommence: async (req: TransferCommenceRequestMessage, context: HandlerContext) => {
try {
console.log("Received TransferCommenceRequest", req, context);
const sessionData = await this.serverService.checkTransferCommenceRequestMessage(req, this.session);
const message = await this.serverService.transferCommenceResponse(req, this.session);
console.log("Returning response", message);
return message;
} catch (error) {
console.error("Error handling TransferCommenceRequest:", error);
throw new Error("Failed to process TransferCommenceRequest");
}
}
});
constructor(ops: SATPHandlerOptions) {
this.session = ops.session;
this.serverService = ops.serverService as Stage1ServerService;
this.clientService = ops.clientService as Stage1ClientService;
this.supportedDLTs = ops.supportedDLTs;
this.logger = LoggerProvider.getOrCreate(ops.loggerOptions);
this.logger.trace(`Initialized ${Stage1SATPHandler.CLASS_NAME}`);
}

getHandlerIdentifier(): string {
return "Stage1SATPHandler";
return Stage1SATPHandler.CLASS_NAME;
}

async TransferProposalImplementation(
req: TransferProposalRequestMessage,
): Promise<TransferProposalReceiptMessage> {
try {
console.log("Received TransferProposalRequest", req);
const sessionData =
await this.serverService.checkTransferProposalRequestMessage(
req,
this.session,
this.supportedDLTs,
);
const message = await this.serverService.transferProposalResponse(
req,
this.session,
);
console.log("message", message);
console.log("Returning response", sessionData);
const response = new TransferProposalReceiptMessage();
return response;
} catch (error) {
console.error("Error handling TransferProposalRequest:", error);
throw new Error("Failed to process TransferProposalRequest");
}
}

async TransferCommenceImplementation(
req: TransferCommenceRequestMessage,
): Promise<TransferCommenceResponseMessage> {
try {
console.log("Received TransferCommenceRequest", req);
const sessionData =
await this.serverService.checkTransferCommenceRequestMessage(
req,
this.session,
);
const message = await this.serverService.transferCommenceResponse(
req,
this.session,
);
console.log("Returning response", message);
console.log("Returning response", sessionData);
const response = new TransferProposalReceiptMessage();
return response;
} catch (error) {
console.error("Error handling TransferCommenceRequest:", error);
throw new Error("Failed to process TransferCommenceRequest");
}
}

setupRouter(router: ConnectRouter): void {
router.service(SatpStage1Service, {
transferProposal: this.TransferProposalImplementation,
transferCommence: this.TransferCommenceImplementation,
});
}
}
Loading

0 comments on commit ac5a55a

Please sign in to comment.