Skip to content

Commit

Permalink
feat: Add bearer token support using callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Dec 21, 2023
1 parent d1fdf11 commit 4528881
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 175 deletions.
13 changes: 2 additions & 11 deletions packages/data-store/src/__tests__/eventLogger.entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerEntities } from '../index'
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
import {
ActionType,
InitiatorType,
LogLevel,
PartyCorrelationType,
SubSystem,
System,
SystemCorrelationIdType
} from '@sphereon/ssi-sdk.core'
import { ActionType, InitiatorType, LogLevel, PartyCorrelationType, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-sdk.core'
import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
import { NonPersistedAuditLoggingEvent } from '../types'

Expand Down Expand Up @@ -52,7 +44,7 @@ describe('Database entities tests', (): void => {
partyAlias: 'test_alias',
description: 'test_description',
data: 'test_data_string',
diagnosticData: { data: 'test_data_string'}
diagnosticData: { data: 'test_data_string' },
}

const auditEventEntity: AuditEventEntity = auditEventEntityFrom(auditEvent)
Expand All @@ -78,5 +70,4 @@ describe('Database entities tests', (): void => {
expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
})

})
19 changes: 9 additions & 10 deletions packages/data-store/src/__tests__/eventLogger.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PartyCorrelationType,
SubSystem,
System,
SystemCorrelationIdType
SystemCorrelationIdType,
} from '@sphereon/ssi-sdk.core'
import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types'
Expand Down Expand Up @@ -55,10 +55,10 @@ describe('Database entities tests', (): void => {
partyAlias: 'test_alias',
description: 'test_description',
data: 'test_data_string',
diagnosticData: { data: 'test_data_string'}
diagnosticData: { data: 'test_data_string' },
}

const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
expect(savedAuditEvent).toBeDefined()
})

Expand All @@ -80,13 +80,13 @@ describe('Database entities tests', (): void => {
partyAlias: 'test_alias',
description: 'test_description',
data: 'test_data_string',
diagnosticData: { data: 'test_data_string'}
diagnosticData: { data: 'test_data_string' },
}

const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
expect(auditEvent1).toBeDefined()

const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
expect(auditEvent2).toBeDefined()

const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents()
Expand All @@ -111,10 +111,10 @@ describe('Database entities tests', (): void => {
partyAlias: 'test_alias',
description: 'test_description',
data: 'test_data_string',
diagnosticData: { data: 'test_data_string'}
diagnosticData: { data: 'test_data_string' },
}

const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
expect(savedAuditEvent).toBeDefined()

const args: GetAuditEventsArgs = {
Expand All @@ -127,11 +127,10 @@ describe('Database entities tests', (): void => {

it('should return no audit events if filter does not match', async (): Promise<void> => {
const args: GetAuditEventsArgs = {
filter: [{ correlationId: 'unknown_id'}],
filter: [{ correlationId: 'unknown_id' }],
}
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)

expect(result.length).toEqual(0)
})

})
29 changes: 11 additions & 18 deletions packages/data-store/src/entities/eventLogger/AuditEventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn
} from 'typeorm'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import {
ActionType,
InitiatorType,
Expand All @@ -14,7 +7,7 @@ import {
SubSystem,
System,
SystemCorrelationIdType,
ActionSubType
ActionSubType,
} from '@sphereon/ssi-sdk.core'
import { NonPersistedAuditLoggingEvent } from '../../types'

Expand All @@ -23,13 +16,13 @@ export class AuditEventEntity extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id!: string

@Column({ name: 'timestamp', nullable: false, unique: false})
@Column({ name: 'timestamp', nullable: false, unique: false })
timestamp!: Date

@Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false })
level!: LogLevel

@Column({ name: 'correlationId', nullable: false, unique: false})
@Column({ name: 'correlationId', nullable: false, unique: false })
correlationId!: string

@Column('simple-enum', { name: 'system', enum: System, nullable: false, unique: false })
Expand All @@ -50,28 +43,28 @@ export class AuditEventEntity extends BaseEntity {
@Column('simple-enum', { name: 'systemCorrelationIdType', enum: SystemCorrelationIdType, nullable: true, unique: false })
systemCorrelationIdType?: SystemCorrelationIdType

@Column({ name: 'systemCorrelationId', nullable: true, unique: false})
@Column({ name: 'systemCorrelationId', nullable: true, unique: false })
systemCorrelationId?: string

@Column({ name: 'systemAlias', nullable: false, unique: false})
@Column({ name: 'systemAlias', nullable: false, unique: false })
systemAlias?: string

@Column('simple-enum', { name: 'partyCorrelationType', enum: PartyCorrelationType, nullable: true, unique: false })
partyCorrelationType?: PartyCorrelationType

@Column({ name: 'partyCorrelationId', nullable: true, unique: false})
@Column({ name: 'partyCorrelationId', nullable: true, unique: false })
partyCorrelationId?: string

@Column({ name: 'partyAlias', nullable: true, unique: false})
@Column({ name: 'partyAlias', nullable: true, unique: false })
partyAlias?: string

@Column({ name: 'description', nullable: false, unique: false})
@Column({ name: 'description', nullable: false, unique: false })
description!: string

@Column({ name: 'data', nullable: true, unique: false})
@Column({ name: 'data', nullable: true, unique: false })
data?: string

@Column({ name: 'diagnosticData', nullable: true, unique: false})
@Column({ name: 'diagnosticData', nullable: true, unique: false })
diagnosticData?: string

@CreateDateColumn({ name: 'created_at', nullable: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export abstract class AbstractEventLoggerStore {
abstract getAuditEvents(args: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>>
abstract storeAuditEvent(args: StoreAuditEventArgs): Promise<AuditLoggingEvent>
}

18 changes: 9 additions & 9 deletions packages/data-store/src/eventLogger/EventLoggerStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Debug, {Debugger} from 'debug'
import {DataSource} from 'typeorm'
import {AuditLoggingEvent} from '@sphereon/ssi-sdk.core'
import {OrPromise} from '@sphereon/ssi-types'
import {AbstractEventLoggerStore} from './AbstractEventLoggerStore'
import {AuditEventEntity, auditEventEntityFrom} from '../entities/eventLogger/AuditEventEntity'
import {GetAuditEventsArgs, StoreAuditEventArgs} from '../types'
import Debug, { Debugger } from 'debug'
import { DataSource } from 'typeorm'
import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
import { OrPromise } from '@sphereon/ssi-types'
import { AbstractEventLoggerStore } from './AbstractEventLoggerStore'
import { AuditEventEntity, auditEventEntityFrom } from '../entities/eventLogger/AuditEventEntity'
import { GetAuditEventsArgs, StoreAuditEventArgs } from '../types'

const debug: Debugger = Debug('sphereon:ssi-sdk:event-store')

Expand Down Expand Up @@ -55,8 +55,8 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
systemAlias: event.systemAlias,
systemCorrelationId: event.systemCorrelationId,
systemCorrelationIdType: event.systemCorrelationIdType,
...(event.data && {data: JSON.parse(event.data)}),
...(event.diagnosticData && {diagnosticData: JSON.parse(event.diagnosticData)}),
...(event.data && { data: JSON.parse(event.data) }),
...(event.diagnosticData && { diagnosticData: JSON.parse(event.diagnosticData) }),
}
}
}
9 changes: 3 additions & 6 deletions packages/data-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,14 @@ export const DataStoreIssuanceBrandingEntities = [

export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEntity]

export const DataStoreEventLoggerEntities = [
AuditEventEntity
]

export const DataStoreEventLoggerEntities = [AuditEventEntity]

// All entities combined if a party wants to enable them all at once
export const DataStoreEntities = [
...DataStoreContactEntities,
...DataStoreIssuanceBrandingEntities,
...DataStoreStatusListEntities,
...DataStoreEventLoggerEntities
...DataStoreEventLoggerEntities,
]

export {
Expand Down Expand Up @@ -112,5 +109,5 @@ export {
StatusListEntity,
StatusListEntryEntity,
AuditEventEntity,
auditEventEntityFrom
auditEventEntityFrom,
}
4 changes: 2 additions & 2 deletions packages/data-store/src/migrations/generic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents'
export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318]
export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429]
export const DataStoreStatusListMigrations = [CreateStatusList1693866470000]
export const DataStoreEventLoggerMigrations= [CreateAuditEvents1701635835330]
export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330]

// All migrations together
export const DataStoreMigrations = [
...DataStoreContactMigrations,
...DataStoreIssuanceBrandingMigrations,
...DataStoreStatusListMigrations,
...DataStoreEventLoggerMigrations
...DataStoreEventLoggerMigrations,
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ export class CreateAuditEvents1701634812183 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3')`)
await queryRunner.query(`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`)
await queryRunner.query(`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`)
await queryRunner.query(
`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`
)
await queryRunner.query(
`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`
)
await queryRunner.query(`CREATE TYPE "public"."Action_type_enum" AS ENUM('create', 'read', 'update', 'delete', 'execute')`)
await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`)
await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`)
await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'email', 'hostname', 'phone')`)
await queryRunner.query(`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT NOT NULL, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`)
await queryRunner.query(
`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT NOT NULL, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export class CreateAuditEvents1701634819487 implements MigrationInterface {
name = 'CreateAuditEvents1701634819487'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "AuditEvents" ("id" varchar PRIMARY KEY NOT NULL, "timestamp" datetime NOT NULL, "level" varchar CHECK( "level" IN ('0','1','2','3') ) NOT NULL, "correlationId" varchar NOT NULL, "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','credentials','web3','profile','contact') ) NOT NULL, "subSystemType" varchar CHECK( "subSystemType" IN ('key','did_provider','did_resolver','oid4vp_op','oid4vci_client','siopv2_op','contact_manager','vc_issuer','vc_verifier','vc_persistence','transport','profile') ) NOT NULL, "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL, "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL, "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ), "systemCorrelationId" varchar, "systemAlias" varchar NOT NULL, "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ), "partyCorrelationId" varchar, "partyAlias" varchar, "description" varchar NOT NULL, "data" varchar, "diagnosticData" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`)
await queryRunner.query(
`CREATE TABLE "AuditEvents" ("id" varchar PRIMARY KEY NOT NULL, "timestamp" datetime NOT NULL, "level" varchar CHECK( "level" IN ('0','1','2','3') ) NOT NULL, "correlationId" varchar NOT NULL, "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','credentials','web3','profile','contact') ) NOT NULL, "subSystemType" varchar CHECK( "subSystemType" IN ('key','did_provider','did_resolver','oid4vp_op','oid4vci_client','siopv2_op','contact_manager','vc_issuer','vc_verifier','vc_persistence','transport','profile') ) NOT NULL, "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL, "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL, "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ), "systemCorrelationId" varchar, "systemAlias" varchar NOT NULL, "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ), "partyCorrelationId" varchar, "partyAlias" varchar, "description" varchar NOT NULL, "data" varchar, "diagnosticData" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
Expand Down
Loading

0 comments on commit 4528881

Please sign in to comment.