Skip to content
4 changes: 4 additions & 0 deletions src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FeeStrategy } from './Fees'
import { Schema } from '../components/database'
import { KeyProviderType } from './KeyManager'
import type { PersistentStorageConfig } from './PersistentStorage.js'
import type { AccessList } from './AccessList'

export interface OceanNodeDBConfig {
url: string | null
Expand Down Expand Up @@ -194,6 +195,9 @@ export interface OceanNodeStatus {
// detailed information
c2dClusters?: any[]
supportedSchemas?: Schema[]
persistentStorage?: {
accessLists?: AccessList[]
}
}

export interface FindDDOResponse {
Expand Down
24 changes: 15 additions & 9 deletions src/components/core/handler/persistentStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ export class PersistentStorageCreateBucketHandler extends CommandHandler {
const storage = requirePersistentStorage(this)
const node = this.getOceanNode()
const config = node.getConfig()
const isAllowedCreate = await checkAddressOnAccessList(
task.consumerAddress,
config.persistentStorage?.accessLists,
node
)
if (!isAllowedCreate) {
return {
stream: null,
status: { httpStatus: 403, error: 'You are not allowed to create new buckets' }
// if we have access lists,check them.
if (config.persistentStorage?.accessLists) {
const isAllowedCreate = await checkAddressOnAccessList(
task.consumerAddress,
config.persistentStorage?.accessLists,
node
)
if (!isAllowedCreate) {
return {
stream: null,
status: {
httpStatus: 403,
error: 'You are not allowed to create new buckets'
}
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/core/utils/statusHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
StorageTypes,
OceanNodeConfig
} from '../../../@types/OceanNode.js'
import { getConfiguration } from '../../../utils/index.js'

Check failure on line 10 in src/components/core/utils/statusHandler.ts

View workflow job for this annotation

GitHub Actions / lint

'getConfiguration' is defined but never used
import { CORE_LOGGER } from '../../../utils/logging/common.js'
import { OceanNode } from '../../../OceanNode.js'
import { typesenseSchemas } from '../../database/TypesenseSchemas.js'
Expand Down Expand Up @@ -112,7 +112,7 @@
)
return
}
const config = await getConfiguration()
const config = oceanNode.getConfig()

// no previous status?
if (!nodeStatus) {
Expand Down Expand Up @@ -173,5 +173,11 @@
}
nodeStatus.supportedSchemas = typesenseSchemas.ddoSchemas
}

if (config.persistentStorage) {
nodeStatus.persistentStorage = {}
if (config.persistentStorage.accessLists)
nodeStatus.persistentStorage.accessLists = config.persistentStorage.accessLists
}
return nodeStatus
}
19 changes: 17 additions & 2 deletions src/test/integration/persistentStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
PersistentStorageListFilesHandler,
PersistentStorageUploadFileHandler
} from '../../components/core/handler/persistentStorage.js'
import { StatusHandler } from '../../components/core/handler/statusHandler.js'
import { OceanNode } from '../../OceanNode.js'
import type { AccessList } from '../../@types/AccessList.js'
import { ENVIRONMENT_VARIABLES, PROTOCOL_COMMANDS } from '../../utils/constants.js'
import { getConfiguration } from '../../utils/config.js'
import { streamToObject } from '../../utils/util.js'
import { streamToObject, streamToString } from '../../utils/util.js'
import {
DEFAULT_TEST_TIMEOUT,
OverrideEnvConfig,
Expand All @@ -35,7 +36,7 @@ import { Blockchain } from '../../utils/blockchain.js'
import { RPCS, SupportedNetwork } from '../../@types/blockchain.js'
import { DEVELOPMENT_CHAIN_ID } from '../../utils/address.js'
import { deployAndGetAccessListConfig } from '../utils/contracts.js'
import { OceanNodeConfig } from '../../@types/OceanNode.js'
import { OceanNodeConfig, OceanNodeStatus } from '../../@types/OceanNode.js'
import { KeyManager } from '../../components/KeyManager/index.js'

describe('Persistent storage handlers (integration)', function () {
Expand Down Expand Up @@ -119,6 +120,20 @@ describe('Persistent storage handlers (integration)', function () {
// await fsp.rm(psRoot, { recursive: true, force: true })
})

it('should expose persistent storage access lists on node status', async () => {
const statusCommand = {
command: PROTOCOL_COMMANDS.STATUS,
node: oceanNode.getKeyManager().getPeerId().toString()
}
const response = await new StatusHandler(oceanNode).handle(statusCommand)
expect(response.status.httpStatus).to.equal(200)
const body = await streamToString(response.stream as Readable)
const nodeStatus = JSON.parse(body) as OceanNodeStatus
expect(nodeStatus.persistentStorage).to.be.an('object')
expect(nodeStatus.persistentStorage?.accessLists).to.be.an('array').with.lengthOf(1)
expect(nodeStatus.persistentStorage.accessLists).to.equal(bucketAllowList)
})

it('create bucket → upload → list → delete (happy path)', async () => {
const consumerAddress = await consumer.getAddress()
let nonce = Date.now().toString()
Expand Down
Loading