Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/core/handler/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export class ValidateDDOHandler extends CommandHandler {
task.publisherAddress,
task.policyServer
)
if (!response) {
if (!response.success) {
CORE_LOGGER.logMessage(
`Error: Validation for ${task.publisherAddress} was denied`,
true
Expand Down
4 changes: 2 additions & 2 deletions src/components/core/handler/encryptHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class EncryptHandler extends CommandHandler {
task.consumerAddress,
task.policyServer
)
if (!response) {
if (!response.success) {
CORE_LOGGER.logMessage(
`Error: Encrypt for ${task.consumerAddress} was denied`,
true
Expand Down Expand Up @@ -163,7 +163,7 @@ export class EncryptFileHandler extends CommandHandler {
task.policyServer,
task.files
)
if (!response) {
if (!response.success) {
CORE_LOGGER.logMessage(
`Error: EncryptFile for ${task.consumerAddress} was denied`,
true
Expand Down
18 changes: 13 additions & 5 deletions src/components/policyServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@ import { BaseFileObject } from '../../@types/fileObject.js'

export class PolicyServer {
serverUrl: string
private apikey: string

public constructor() {
this.serverUrl = process.env.POLICY_SERVER_URL
this.apikey = process.env.POLICY_SERVER_API_KEY
}

private async askServer(command: any): Promise<PolicyServerResult> {
if (!this.serverUrl) return { success: true, message: '', httpStatus: 404 }
let response
const headers: Record<string, string> = {
'Content-Type': 'application/json'
}
if (this.apikey) {
headers['X-API-Key'] = this.apikey
}
try {
response = await fetch(this.serverUrl, {
headers: {
'Content-Type': 'application/json'
},
headers,
method: 'POST',
body: JSON.stringify(command)
})
} catch (e) {
const errorText =
e instanceof Error ? e.message : typeof e === 'string' ? e : JSON.stringify(e)
return {
success: true,
message: '',
success: false,
message: errorText || 'Policy server request failed',
httpStatus: 400
}
}
Expand Down
Loading