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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ MODE_PS=1

PORT=3000

# OPA server URL returned by the getOpaServerUrl action.
#OPA_SERVER=https://opa.example.com

# Optional: if set, POST / requires X-API-Key to match this value.
#POLICY_SERVER_API_KEY=api_key_example`

Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ ENABLE_LOGS=1
MODE_PROXY=1
MODE_PS=1
PORT=3000
# OPA server URL returned by the getOpaServerUrl action
OPA_SERVER=https://opa.example.com
# Optional: enable HTTPS directly in policy-server when both cert and key are set.
HTTP_CERT_PATH=/usr/src/app/certs/cert.pem
HTTP_KEY_PATH=/usr/src/app/certs/key.pem
Expand Down Expand Up @@ -92,6 +94,7 @@ The reload endpoints rebuild the in-memory lists from the current env values plu
- `newDDO`
- `updateDDO`
- `validateDDO`
- `getOpaServerUrl`
- `passthrough`

## 1) initiate
Expand Down Expand Up @@ -1411,7 +1414,35 @@ Policy Server also replaces `response_uri` with `WALTID_VERIFY_RESPONSE_REDIRECT
}
```

## 12 passthrough
## 12 getOpaServerUrl

Returns the OPA server URL configured for this Policy Server, or `null` when
`OPA_SERVER` is not configured.

### PolicyServer Endpoint Example

**Endpoint**: `http://localhost:3000/`

### PolicyServer Expected Payload Example

```json
{
"action": "getOpaServerUrl",
"nodeAddress": "0x1111111111111111111111111111111111111111"
}
```

### PolicyServer Response Example

```json
{
"success": true,
"message": "https://opa.example.com",
"httpStatus": 200
}
```

## 13 passthrough

### PolicyServer Endpoint Example

Expand Down Expand Up @@ -1462,6 +1493,8 @@ LOCAL_PORT=8100
CONTAINER_PORT=8100

PORT=8100
# OPA server URL returned by the getOpaServerUrl action
OPA_SERVER=https://opa.example.com
# Optional direct HTTPS. Reverse proxy TLS offload remains supported without these.
HTTP_CERT_PATH=/usr/src/app/certs/cert.pem
HTTP_KEY_PATH=/usr/src/app/certs/key.pem
Expand Down
3 changes: 3 additions & 0 deletions docker-compose/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ MODE_PS=1

PORT=3000

# OPA server URL returned by the getOpaServerUrl action.
#OPA_SERVER=https://opa.example.com

# Optional: if set, POST / requires X-API-Key to match this value.
#POLICY_SERVER_API_KEY=api_key_example`

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "policy-server",
"version": "1.3.2",
"version": "1.3.3",
"description": "Policy Server implementation",
"type": "module",
"main": "index.js",
Expand Down
8 changes: 8 additions & 0 deletions src/policyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export class PolicyHandler {
// eslint-disable-next-line no-undef
[key: string]: any

public getOpaServerUrl(): PolicyRequestResponse {
return {
success: true,
message: process.env.OPA_SERVER ?? null,
httpStatus: 200
}
}

async execute(
policyRequestPayload: PolicyRequestPayload
): Promise<PolicyRequestResponse> {
Expand Down
37 changes: 37 additions & 0 deletions src/test/PolicyHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect } from 'chai'
import { PolicyHandler } from '../policyHandler.js'

describe('PolicyHandler', () => {
const originalOpaServer = process.env.OPA_SERVER

afterEach(() => {
if (originalOpaServer === undefined) delete process.env.OPA_SERVER
else process.env.OPA_SERVER = originalOpaServer
})

it('returns the configured OPA server URL', async () => {
process.env.OPA_SERVER = 'https://opa.example.com'
const handler = new PolicyHandler()

const response = await handler.execute({ action: 'getOpaServerUrl' })

expect(response).to.deep.equal({
success: true,
message: 'https://opa.example.com',
httpStatus: 200
})
})

it('returns null when the OPA server URL is not configured', async () => {
delete process.env.OPA_SERVER
const handler = new PolicyHandler()

const response = await handler.execute({ action: 'getOpaServerUrl' })

expect(response).to.deep.equal({
success: true,
message: null,
httpStatus: 200
})
})
})
8 changes: 8 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"newDDO",
"updateDDO",
"validateDDO",
"getOpaServerUrl",
"passthrough"
],
"description": "Type of policy action to perform"
Expand Down Expand Up @@ -1191,6 +1192,13 @@
"eventRaw": "raw event data"
}
},
"getOpaServerUrl": {
"summary": "Get the configured OPA server URL",
"value": {
"action": "getOpaServerUrl",
"nodeAddress": "0x1111111111111111111111111111111111111111"
}
},
"passthrough": {
"summary": "Passthrough action",
"value": {
Expand Down
Loading