mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
using a SecretStore with custom config
This commit is contained in:
parent
407aba7450
commit
a6d2ce8fde
@ -15,6 +15,7 @@ import IdGenerator from "./IdGenerator"
|
|||||||
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
||||||
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
|
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
|
||||||
import Access from "./ServiceAgreements/Templates/Access"
|
import Access from "./ServiceAgreements/Templates/Access"
|
||||||
|
import ConfigProvider from "../ConfigProvider"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assets submodule of Ocean Protocol.
|
* Assets submodule of Ocean Protocol.
|
||||||
@ -56,6 +57,7 @@ export default class OceanAssets {
|
|||||||
* @return {Promise<DDO>}
|
* @return {Promise<DDO>}
|
||||||
*/
|
*/
|
||||||
public async create(metadata: MetaData, publisher: Account, services: Service[] = []): Promise<DDO> {
|
public async create(metadata: MetaData, publisher: Account, services: Service[] = []): Promise<DDO> {
|
||||||
|
const {secretStoreUri} = ConfigProvider.getConfig()
|
||||||
const {didRegistry} = await Keeper.getInstance()
|
const {didRegistry} = await Keeper.getInstance()
|
||||||
const aquarius = AquariusProvider.getAquarius()
|
const aquarius = AquariusProvider.getAquarius()
|
||||||
const brizo = BrizoProvider.getBrizo()
|
const brizo = BrizoProvider.getBrizo()
|
||||||
@ -64,8 +66,11 @@ export default class OceanAssets {
|
|||||||
|
|
||||||
const authorizationService = (services.find(({type}) => type === "Authorization") || {}) as ServiceAuthorization
|
const authorizationService = (services.find(({type}) => type === "Authorization") || {}) as ServiceAuthorization
|
||||||
const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint
|
const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint
|
||||||
|
const secretStoreConfig = {
|
||||||
|
secretStoreUri: secretStoreUrl,
|
||||||
|
}
|
||||||
|
|
||||||
const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreUrl).encryptDocument(did.getId(), metadata.base.files)
|
const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreConfig).encryptDocument(did.getId(), metadata.base.files)
|
||||||
|
|
||||||
const template = new Access()
|
const template = new Access()
|
||||||
const serviceAgreementTemplate = new ServiceAgreementTemplate(template)
|
const serviceAgreementTemplate = new ServiceAgreementTemplate(template)
|
||||||
@ -121,6 +126,12 @@ export default class OceanAssets {
|
|||||||
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), String(serviceDefinitionIdCount), "xxx", "xxx"),
|
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), String(serviceDefinitionIdCount), "xxx", "xxx"),
|
||||||
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "Authorization",
|
||||||
|
services: 'SecretStore',
|
||||||
|
serviceEndpoint: secretStoreUri,
|
||||||
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "Metadata",
|
type: "Metadata",
|
||||||
serviceEndpoint,
|
serviceEndpoint,
|
||||||
@ -148,7 +159,11 @@ export default class OceanAssets {
|
|||||||
},
|
},
|
||||||
...services
|
...services
|
||||||
.map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})),
|
.map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})),
|
||||||
] as Service[],
|
]
|
||||||
|
// Remove duplications
|
||||||
|
.reverse()
|
||||||
|
.filter(({type}, i, list) => list.findIndex(({type: t}) => t === type) === i)
|
||||||
|
.reverse() as Service[],
|
||||||
})
|
})
|
||||||
|
|
||||||
ddo.addChecksum()
|
ddo.addChecksum()
|
||||||
@ -156,8 +171,6 @@ export default class OceanAssets {
|
|||||||
|
|
||||||
const storedDdo = await aquarius.storeDDO(ddo)
|
const storedDdo = await aquarius.storeDDO(ddo)
|
||||||
|
|
||||||
// Logger.log(JSON.stringify(storedDdo, null, 2))
|
|
||||||
|
|
||||||
await didRegistry.registerAttribute(
|
await didRegistry.registerAttribute(
|
||||||
did.getId(),
|
did.getId(),
|
||||||
ddo.getChecksum(),
|
ddo.getChecksum(),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import SecretStore from "@oceanprotocol/secret-store-client"
|
import SecretStore from "@oceanprotocol/secret-store-client"
|
||||||
|
import SecretStoreConfig from "@oceanprotocol/secret-store-client/dist/models/SecretStoreConfig"
|
||||||
import ConfigProvider from "../ConfigProvider"
|
import ConfigProvider from "../ConfigProvider"
|
||||||
|
|
||||||
export default class SecretStoreProvider {
|
export default class SecretStoreProvider {
|
||||||
@ -8,24 +9,30 @@ export default class SecretStoreProvider {
|
|||||||
SecretStoreProvider.secretStore = secretStore
|
SecretStoreProvider.secretStore = secretStore
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getSecretStore(url?: string): SecretStore {
|
public static getSecretStore(config?: Partial<SecretStoreConfig>): SecretStore {
|
||||||
if (!url) {
|
config = {...config}
|
||||||
|
// Cleaning undefined parameters
|
||||||
|
Object.keys(config)
|
||||||
|
.forEach(key => config[key] || delete config[key])
|
||||||
|
|
||||||
|
if (!Object.keys(config).length) {
|
||||||
if (!SecretStoreProvider.secretStore) {
|
if (!SecretStoreProvider.secretStore) {
|
||||||
SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig())
|
SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
return SecretStoreProvider.secretStore
|
return SecretStoreProvider.secretStore
|
||||||
} else {
|
} else {
|
||||||
if (!SecretStoreProvider.secretStoreByUrl.get(url)) {
|
const configRef = JSON.stringify(config)
|
||||||
SecretStoreProvider.secretStoreByUrl.set(url,
|
if (!SecretStoreProvider.secretStoreByUrl.get(configRef)) {
|
||||||
|
SecretStoreProvider.secretStoreByUrl.set(configRef,
|
||||||
new SecretStore({
|
new SecretStore({
|
||||||
...ConfigProvider.getConfig(),
|
...ConfigProvider.getConfig(),
|
||||||
secretStoreUri: url,
|
...config,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return SecretStoreProvider.secretStoreByUrl.get(url)
|
return SecretStoreProvider.secretStoreByUrl.get(configRef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ describe("DDO", () => {
|
|||||||
|
|
||||||
it("should create an predefined ddo", async () => {
|
it("should create an predefined ddo", async () => {
|
||||||
|
|
||||||
const service: Partial<Service> = {
|
const service: Partial<Service> & any = {
|
||||||
serviceEndpoint: "http://",
|
serviceEndpoint: "http://",
|
||||||
description: "nice service",
|
description: "nice service",
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ describe("DDO", () => {
|
|||||||
assert(ddo)
|
assert(ddo)
|
||||||
|
|
||||||
assert(ddo.service.length === 1)
|
assert(ddo.service.length === 1)
|
||||||
assert(ddo.service[0].description === service.description)
|
assert((ddo.service[0] as any).description === service.description)
|
||||||
|
|
||||||
assert(ddo.authentication.length === 0)
|
assert(ddo.authentication.length === 0)
|
||||||
assert(ddo.publicKey.length === 0)
|
assert(ddo.publicKey.length === 0)
|
||||||
|
@ -21,7 +21,7 @@ let accounts: Account[]
|
|||||||
let publisherAccount: Account
|
let publisherAccount: Account
|
||||||
let consumerAccount: Account
|
let consumerAccount: Account
|
||||||
|
|
||||||
let accessService: Service
|
let accessService: Service<"Access">
|
||||||
let metaDataService: Service<"Metadata">
|
let metaDataService: Service<"Metadata">
|
||||||
|
|
||||||
const did: DID = DID.generate()
|
const did: DID = DID.generate()
|
||||||
|
Loading…
Reference in New Issue
Block a user