Skip to content
Snippets Groups Projects
Unverified Commit 93d4bef2 authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

MR cleanup

parent 62300a0a
No related branches found
No related tags found
1 merge request!38feat: rest agent support for connection and proof change state events
Pipeline #65556 passed with stage
in 1 minute and 29 seconds
......@@ -150,7 +150,7 @@ export const getAskarAnonCredsIndyModules = (networks: any) => {
export const svdxProofStateChangeHandler = async (
ev: ProofStateChangedEvent,
agent: Agent,
config: IConfAgent,
config?: IConfAgent,
) => {
if (ProofState.Done !== ev.payload.proofRecord.state) {
return;
......@@ -182,17 +182,22 @@ export const svdxProofStateChangeHandler = async (
"email"
].raw;
if (!config?.agentSVDXWebHook) {
console.log("Agent SVDX web hook not set");
return;
}
try {
await axios.post(
config.agentSVDXWebHook,
config?.agentSVDXWebHook,
{
email,
connectionId: ev.payload.proofRecord.connectionId,
},
{
auth: {
username: config.agentSVDXBasicUser,
password: config.agentSVDXBasicPass,
username: config?.agentSVDXBasicUser,
password: config?.agentSVDXBasicPass,
},
},
);
......@@ -204,7 +209,7 @@ export const svdxProofStateChangeHandler = async (
export const svdxConnectionStateChangeHandler = async (
ev: ConnectionStateChangedEvent,
agent: Agent,
config: IConfAgent,
config?: IConfAgent,
) => {
if (
ev.payload.connectionRecord.role === DidExchangeRole.Responder &&
......@@ -253,8 +258,8 @@ export const svdxConnectionStateChangeHandler = async (
name: "email",
restrictions: [
{
schema_id: config.agentSVDXSchemaId,
cred_def_id: config.agentSVDXCredDefId,
schema_id: config?.agentSVDXSchemaId,
cred_def_id: config?.agentSVDXCredDefId,
},
],
},
......
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common";
import { Injectable } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
/**
* Basic guard is NOT currently used, it is left for the time when we implement jwt auth for the rest of the routes
*/
@Injectable()
export class BasicGuard extends AuthGuard("basic") {}
// basic.strategy.ts
import { ConfigService } from "@nestjs/config";
import { IConfAgent } from "@ocm-engine/config";
import { BasicStrategy as Strategy } from "passport-http";
import { PassportStrategy } from "@nestjs/passport";
import { Injectable, UnauthorizedException } from "@nestjs/common";
/**
* Basic strategy is NOT currently used, it is left for the time when we implement jwt auth for the rest of the routes
*/
@Injectable()
export class BasicStrategy extends PassportStrategy(Strategy, "basic") {
constructor(private readonly configService: ConfigService) {
......@@ -13,12 +15,12 @@ export class BasicStrategy extends PassportStrategy(Strategy, "basic") {
async validate(username: string, password: string): Promise<boolean> {
console.log(username, password);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const config: IConfAgent = this.configService.get<IConfAgent>("agent")!;
const config: IConfAgent | undefined =
this.configService.get<IConfAgent>("agent");
if (
config.agentSVDXBasicUser === username &&
config.agentSVDXBasicPass === password
config?.agentSVDXBasicUser === username &&
config?.agentSVDXBasicPass === password
) {
return true;
}
......
......@@ -24,22 +24,20 @@ import {
@Injectable()
export class AgentEventListenerServce implements OnModuleInit {
private agentConfig: IConfAgent;
private agentConfig: IConfAgent | undefined;
private readonly logger: Logger = new Logger(AgentEventListenerServce.name);
constructor(
private readonly gatewayClient: GatewayClient,
//TODO: can I replace with agent service ??
private readonly askar: AskarService,
private readonly configService: ConfigService,
) {}
onModuleInit(): void {
this.logger.debug("Agent is listening for AFJ events");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.agentConfig = this.configService.get<IConfAgent>("agent")!;
this.agentConfig = this.configService.get<IConfAgent>("agent");
if (this.agentConfig.agentIsSVDX && this.agentConfig.agentIsRest) {
if (this.agentConfig?.agentIsSVDX && this.agentConfig?.agentIsRest) {
this.askar.agent.events.on(
ConnectionEventTypes.ConnectionStateChanged,
async (ev: ConnectionStateChangedEvent) => {
......@@ -84,7 +82,7 @@ export class AgentEventListenerServce implements OnModuleInit {
dto.connectionId = ev.payload.basicMessageRecord.connectionId;
dto.from = connectionInfo?.theirLabel;
if (this.agentConfig.agentIsRest) {
if (this.agentConfig?.agentIsRest) {
this.logger.debug(
"agent is configured as rest, webhook still not implemented",
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment