diff --git a/devops/dev/values.yaml b/devops/dev/values.yaml index 7bd2193c..d1cf35cb 100644 --- a/devops/dev/values.yaml +++ b/devops/dev/values.yaml @@ -103,6 +103,7 @@ iam-cache-server-helm: TYPEORM_LOGGING: error,warn TYPEORM_LOGGER: file DISABLE_GET_DIDS_BY_ROLE: true + IPFS_CLUSTER_PINNING_ENABLED: false opsValues: DB_NAME: ics diff --git a/devops/prod/values.yaml b/devops/prod/values.yaml index 462aac4f..5e771675 100644 --- a/devops/prod/values.yaml +++ b/devops/prod/values.yaml @@ -125,6 +125,7 @@ iam-cache-server-helm: TYPEORM_LOGGING: error,warn TYPEORM_LOGGER: file DISABLE_GET_DIDS_BY_ROLE: true + IPFS_CLUSTER_PINNING_ENABLED: false opsValues: DB_NAME: ics diff --git a/devops/staging/values.yaml b/devops/staging/values.yaml index 604d96e9..5cd52104 100644 --- a/devops/staging/values.yaml +++ b/devops/staging/values.yaml @@ -128,6 +128,7 @@ iam-cache-server-helm: TYPEORM_LOGGING: error,warn TYPEORM_LOGGER: file DISABLE_GET_DIDS_BY_ROLE: true + IPFS_CLUSTER_PINNING_ENABLED: false opsValues: DB_NAME: ics diff --git a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md index 5844f88e..570a77fa 100644 --- a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md +++ b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md @@ -14,19 +14,6 @@ - [constructor](modules_auth_login_strategy.AuthStrategy.md#constructor) -### Methods - -- [authenticate](modules_auth_login_strategy.AuthStrategy.md#authenticate) -- [decodeToken](modules_auth_login_strategy.AuthStrategy.md#decodetoken) -- [didUnification](modules_auth_login_strategy.AuthStrategy.md#didunification) -- [extractSiwe](modules_auth_login_strategy.AuthStrategy.md#extractsiwe) -- [extractToken](modules_auth_login_strategy.AuthStrategy.md#extracttoken) -- [getRoleDefinition](modules_auth_login_strategy.AuthStrategy.md#getroledefinition) -- [isEIP191TokenPayload](modules_auth_login_strategy.AuthStrategy.md#iseip191tokenpayload) -- [isSiweMessagePayload](modules_auth_login_strategy.AuthStrategy.md#issiwemessagepayload) -- [validate](modules_auth_login_strategy.AuthStrategy.md#validate) -- [verifyIssuer](modules_auth_login_strategy.AuthStrategy.md#verifyissuer) - ## Constructors ### constructor @@ -46,213 +33,3 @@ #### Overrides PassportStrategy(LoginStrategy, 'login').constructor - -## Methods - -### authenticate - -▸ **authenticate**(`req`): `void` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`void` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').authenticate - -___ - -### decodeToken - -▸ **decodeToken**<`T`\>(`token`, `options?`): `T` - -#### Type parameters - -| Name | -| :------ | -| `T` | - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `token` | `string` | -| `options?` | `DecodeOptions` | - -#### Returns - -`T` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').decodeToken - -___ - -### didUnification - -▸ **didUnification**(`did`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `did` | `string` | - -#### Returns - -`string` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').didUnification - -___ - -### extractSiwe - -▸ **extractSiwe**(`req`): `SiweReqPayload` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`SiweReqPayload` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').extractSiwe - -___ - -### extractToken - -▸ **extractToken**(`req`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`string` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').extractToken - -___ - -### getRoleDefinition - -▸ **getRoleDefinition**(`namespace`): `Promise`<`IRoleDefinitionV2`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `namespace` | `string` | - -#### Returns - -`Promise`<`IRoleDefinitionV2`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').getRoleDefinition - -___ - -### isEIP191TokenPayload - -▸ **isEIP191TokenPayload**(`payload`): payload is ITokenPayload - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `payload` | `unknown` | - -#### Returns - -payload is ITokenPayload - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').isEIP191TokenPayload - -___ - -### isSiweMessagePayload - -▸ **isSiweMessagePayload**(`payload`): payload is Partial - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `payload` | `unknown` | - -#### Returns - -payload is Partial - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').isSiweMessagePayload - -___ - -### validate - -▸ **validate**(`token`, `payload`, `done`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `token` | `string` | -| `payload` | `Partial`<`SiweMessage`\> \| `ITokenPayload` | -| `done` | (`err?`: `Error`, `user?`: `unknown`, `info?`: `unknown`) => `void` | - -#### Returns - -`Promise`<`void`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').validate - -___ - -### verifyIssuer - -▸ **verifyIssuer**(`issuer`, `role`): `Promise`<`VerificationResult`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `issuer` | `string` | -| `role` | `string` | - -#### Returns - -`Promise`<`VerificationResult`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').verifyIssuer diff --git a/docs/api/classes/modules_ipfs_ipfs_service.IPFSService.md b/docs/api/classes/modules_ipfs_ipfs_service.IPFSService.md index a1410f81..62456152 100644 --- a/docs/api/classes/modules_ipfs_ipfs_service.IPFSService.md +++ b/docs/api/classes/modules_ipfs_ipfs_service.IPFSService.md @@ -18,7 +18,7 @@ ### constructor -• **new IPFSService**(`didStoreCluster`, `didStoreInfura`, `pinsQueue`, `logger`) +• **new IPFSService**(`didStoreCluster`, `didStoreInfura`, `pinsQueue`, `logger`, `configService`) #### Parameters @@ -28,6 +28,7 @@ | `didStoreInfura` | `DidStore` | | `pinsQueue` | `Queue`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> | | `logger` | [`Logger`](modules_logger_logger_service.Logger.md) | +| `configService` | `ConfigService`<`Record`<`string`, `unknown`\>, ``false``\> | ## Methods diff --git a/e2e/ipfs/ipfs.testSuite.ts b/e2e/ipfs/ipfs.testSuite.ts index e0dd3cd2..f3b987b0 100644 --- a/e2e/ipfs/ipfs.testSuite.ts +++ b/e2e/ipfs/ipfs.testSuite.ts @@ -43,7 +43,8 @@ export const ipfsModuleTestSuite = () => { await queryRunner.release(); }); - it('save() should post claim in cluster', async () => { + // IPFS cluster support is disabled + it.skip('save() should post claim in cluster', async () => { const claimData = { claimType: 'claim type', claimTypeVersion: 1, @@ -90,7 +91,8 @@ export const ipfsModuleTestSuite = () => { .expect(HttpStatus.NOT_FOUND); }); - it('if claim is not found in cluster, get() should save claim in cluster', async () => { + // IPFS cluster support is disabled + it.skip('if claim is not found in cluster, get() should save claim in cluster', async () => { const didStoreClusterGet = jest.spyOn(didStoreCluster, 'get'); const didStoreInfuraGet = jest.spyOn(didStoreInfura, 'get'); diff --git a/src/modules/ipfs/ipfs.service.ts b/src/modules/ipfs/ipfs.service.ts index 1a377469..bb7dd007 100644 --- a/src/modules/ipfs/ipfs.service.ts +++ b/src/modules/ipfs/ipfs.service.ts @@ -11,6 +11,7 @@ import { } from './ipfs.types'; import { Logger } from '../logger/logger.service'; import { inspect } from 'util'; +import { ConfigService } from '@nestjs/config'; @Injectable() export class IPFSService { @@ -19,7 +20,8 @@ export class IPFSService { private didStoreInfura: DidStoreGateway, @InjectQueue(PIN_CLAIM_QUEUE_NAME) private readonly pinsQueue: Queue, - private readonly logger: Logger + private readonly logger: Logger, + private readonly configService: ConfigService ) { this.logger.setContext(IPFSService.name); } @@ -80,6 +82,13 @@ export class IPFSService { } this.logger.debug(`got ${cid}`); + if (!this.configService.get('IPFS_CLUSTER_PINNING_ENABLED')) { + this.logger.debug(`IPFS cluster pinning disabled. Skipping for ${cid}`); + return; + } + this.logger.debug( + `IPFS cluster pinning enabled. Pinning IPFS data for ${cid}` + ); try { await this.pinsQueue.add(PIN_CLAIM_JOB_NAME, { cid, claim }); } catch (e) { diff --git a/src/modules/ipfs/pin.processor.ts b/src/modules/ipfs/pin.processor.ts index 1186dc24..d81dd261 100644 --- a/src/modules/ipfs/pin.processor.ts +++ b/src/modules/ipfs/pin.processor.ts @@ -7,8 +7,8 @@ import { Processor, } from '@nestjs/bull'; import { Job } from 'bull'; -// import { DidStore as DidStoreInfura } from 'didStoreInfura'; -// import { DidStore as DidStoreCluster } from 'didStoreCluster'; +import { DidStore as DidStoreInfura } from 'didStoreInfura'; +import { DidStore as DidStoreCluster } from 'didStoreCluster'; import { Logger } from '../logger/logger.service'; import { PinClaimData, @@ -20,8 +20,8 @@ import { export class PinProcessor { constructor( private readonly logger: Logger, - // private didStoreCluster: DidStoreCluster, - // private didStoreInfura: DidStoreInfura + private didStoreCluster: DidStoreCluster, + private didStoreInfura: DidStoreInfura ) { this.logger.setContext(PinProcessor.name); } @@ -53,31 +53,31 @@ export class PinProcessor { @Process(PIN_CLAIM_JOB_NAME) async pin(job: Job) { return; - // const cid = job.data.cid; - // let claim = job.data.claim; - // this.logger.debug(`Pinning CID ${cid}`); - // try { - // await this.didStoreCluster.get(cid); - // } catch (_) { - // if (!claim) { - // try { - // claim = await this.didStoreInfura.get(cid); - // } catch (e) { - // this.logger.error( - // `Can not fetch claim from Infura IPFS. CID ${cid}: ${e}` - // ); - // return; - // } - // } - // try { - // const clusterCid = await this.didStoreCluster.save(claim); - // this.logger.debug(`CID ${cid} saved in cluster by CID ${clusterCid}`); - // } catch (e) { - // this.logger.error( - // `Can not save claim in IPFS cluster. CID ${cid}: ${e}` - // ); - // return; - // } - // } + const cid = job.data.cid; + let claim = job.data.claim; + this.logger.debug(`Pinning CID ${cid}`); + try { + await this.didStoreCluster.get(cid); + } catch (_) { + if (!claim) { + try { + claim = await this.didStoreInfura.get(cid); + } catch (e) { + this.logger.error( + `Can not fetch claim from Infura IPFS. CID ${cid}: ${e}` + ); + return; + } + } + try { + const clusterCid = await this.didStoreCluster.save(claim); + this.logger.debug(`CID ${cid} saved in cluster by CID ${clusterCid}`); + } catch (e) { + this.logger.error( + `Can not save claim in IPFS cluster. CID ${cid}: ${e}` + ); + return; + } + } } }