From f75e45500cc74baac6c3de184b6be50908da4b2d Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 16 Sep 2020 06:28:08 -0700 Subject: [PATCH] allow customProvider on publish --- src/ocean/Assets.ts | 5 +++-- src/ocean/Compute.ts | 5 +++-- src/provider/Provider.ts | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index 27332382..aee93a4c 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -379,12 +379,13 @@ export class Assets extends Instantiable { creator: Account, cost: string, datePublished: string, - timeout = 0 + timeout = 0, + customProvider?: string ): Promise { return { type: 'access', index: 2, - serviceEndpoint: this.ocean.provider.getConsumeEndpoint(), + serviceEndpoint: customProvider || this.ocean.provider.getConsumeEndpoint(), attributes: { main: { creator: creator.getId(), diff --git a/src/ocean/Compute.ts b/src/ocean/Compute.ts index 597bc454..416b9a47 100644 --- a/src/ocean/Compute.ts +++ b/src/ocean/Compute.ts @@ -279,14 +279,15 @@ export class Compute extends Instantiable { datePublished: string, providerAttributes: any, computePrivacy?: ServiceComputePrivacy, - timeout?: number + timeout?: number, + customProvider?: string ): ServiceCompute { const name = 'dataAssetComputingService' if (!timeout) timeout = 3600 const service = { type: 'compute', index: 3, - serviceEndpoint: this.ocean.provider.getComputeEndpoint(), + serviceEndpoint: customProvider || this.ocean.provider.getComputeEndpoint(), attributes: { main: { name, diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index 6502f2a8..877e1be5 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -283,4 +283,22 @@ export class Provider extends Instantiable { public getDownloadEndpoint(): string { return `${this.url}${apiPath}/download` } + + public async isValidProvider(url: string): Promise { + const fetch = this.ocean.utils.fetch.get(url) + await fetch + .then((response: Response) => { + if (response.ok) { + const params = response.json() + if (params) return true + } + return false + }) + .catch((error: Error) => { + this.logger.error('Error validating provider') + this.logger.error(error.message) + return false + }) + return false + } }