Robinyo commented on issue #12374:
URL: https://github.com/apache/apisix/issues/12374#issuecomment-3064620670
Success :)
Sample policy:
```
package organization
import rego.v1
import input.request
default allow := false
allow if {
request.method == "GET"
}
```
Sample input:
```
{
"request": {
"method": "GET"
}
}
```
Sample output:
```
{
"allow": true
}
```
Logs:
```
{
opa | "client_addr": "172.19.0.4:34652",
opa | "level": "info",
opa | "msg": "Received request.",
opa | "req_body":
"{\"input\":{\"request\":{\"headers\":{\"accept\":\"*/*\",\"user-agent\":\"curl/8.7.1\",\"content-type\":\"application/fhir+json\",\"host\":\"provider-directory.au.localhost\"},\"query\":{\"_id\":\"adv-hearing-care\"},\"port\":9443,\"path\":\"/fhir/Organization\",\"scheme\":\"https\",\"method\":\"GET\",\"host\":\"provider-directory.au.localhost\"},\"var\":{\"server_addr\":\"172.19.0.4\",\"remote_addr\":\"172.19.0.1\",\"server_port\":\"9443\",\"remote_port\":\"55502\",\"timestamp\":1752291648},\"type\":\"http\"}}",
opa | "req_id": 49,
opa | "req_method": "POST",
opa | "req_params": {},
opa | "req_path": "/v1/data/organization",
opa | "time": "2025-07-12T03:40:48Z"
opa | }
opa | {
opa | "decision_id":
"5c536793-05a6-4647-8894-2e94c9316a23",
opa | "input": {
opa | "request": {
opa | "headers": {
opa | "accept": "*/*",
opa | "content-type": "application/fhir+json",
opa | "host": "provider-directory.au.localhost",
opa | "user-agent": "curl/8.7.1"
opa | },
opa | "host": "provider-directory.au.localhost",
opa | "method": "GET",
opa | "path": "/fhir/Organization",
opa | "port": 9443,
opa | "query": {
opa | "_id": "adv-hearing-care"
opa | },
opa | "scheme": "https"
opa | },
opa | "type": "http",
opa | "var": {
opa | "remote_addr": "172.19.0.1",
opa | "remote_port": "55502",
opa | "server_addr": "172.19.0.4",
opa | "server_port": "9443",
opa | "timestamp": 1752291648
opa | }
opa | },
opa | "labels": {
opa | "id": "a64fad56-c5b3-40d6-b6be-99cd3d80ff06",
opa | "version": "1.5.1"
opa | },
opa | "level": "info",
opa | "metrics": {
opa | "counter_server_query_cache_hit": 1,
opa | "timer_rego_external_resolve_ns": 333,
opa | "timer_rego_input_parse_ns": 1707500,
opa | "timer_rego_query_eval_ns": 598667,
opa | "timer_server_handler_ns": 3228333
opa | },
opa | "msg": "Decision Log",
opa | "path": "organization",
opa | "req_id": 49,
opa | "requested_by": "172.19.0.4:34652",
opa | "result": {
opa | "allow": true,
opa | "request": {
opa | "method": "GET"
opa | }
opa | },
opa | "time": "2025-07-12T03:40:48Z",
opa | "timestamp": "2025-07-12T03:40:48.570314459Z",
opa | "type": "openpolicyagent.org/decision_logs"
opa | }
opa | {
opa | "client_addr": "172.19.0.4:34652",
opa | "level": "info",
opa | "msg": "Sent response.",
opa | "req_id": 49,
opa | "req_method": "POST",
opa | "req_path": "/v1/data/organization",
opa | "resp_body":
"{\"decision_id\":\"5c536793-05a6-4647-8894-2e94c9316a23\",\"result\":{\"allow\":true,\"request\":{\"method\":\"GET\"}}}\n",
opa | "resp_bytes": 106,
opa | "resp_duration": 9.179417,
opa | "resp_status": 200,
opa | "time": "2025-07-12T03:40:48Z"
opa | }
provider-directory | 2025-07-12T03:40:49.644Z INFO 1 ---
[nio-8080-exec-3] fhirtest.access : Path[/fhir]
Source[172.19.0.1] Operation[search-type Organization] UA[curl/8.7.1]
Params[?_id=adv-hearing-care] ResponseEncoding[JSON] Operation[search-type
Organization] UA[curl/8.7.1] Params[?_id=adv-hearing-care]
ResponseEncoding[JSON]
keycloak.au.localhost | 2025-07-12 03:40:52,312 TRACE
[io.vertx.ext.web.impl.RouterImpl] (vert.x-eventloop-thread-7) Router:
192775273 accepting request GET https://hapi-fhir.au.localhost:9000/health/ready
apisix | 172.19.0.1 - - [12/Jul/2025:03:40:49 +0000]
provider-directory.au.localhost "GET /fhir/Organization?_id=adv-hearing-care
HTTP/2.0" 200 1306 1.101 "-" "curl/8.7.1" 172.19.0.8:8080 200 1.067
"http://provider-directory.au.localhost"
```
Request:
```
curl -X GET
https://provider-directory.au.localhost/fhir/Organization\?_id\=adv-hearing-care
\
-H 'Content-Type: application/json'
```
Response:
```
{
"resourceType": "Bundle",
"id": "b8afd76e-a539-43d8-aed2-c8aff38171f9",
"meta": {
"lastUpdated": "2025-07-12T03:40:48.902+00:00"
},
"type": "searchset",
"total": 1,
"link": [ {
"relation": "self",
"url":
"https://provider-directory.au.localhost/fhir/Organization?_id=adv-hearing-care"
} ],
"entry": [ {
"fullUrl":
"https://provider-directory.au.localhost/fhir/Organization/adv-hearing-care",
"resource": {
"resourceType": "Organization",
"id": "adv-hearing-care",
"meta": {
"versionId": "1",
"lastUpdated": "2025-06-24T05:23:52.937+00:00",
"source": "#oBeaQFRaT1Y5sSyi",
"profile": [
"http://hl7.org.au/fhir/core/StructureDefinition/au-core-organization" ]
},
"identifier": [ {
"type": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "XX"
} ],
"text": "ABN"
},
"system": "http://hl7.org.au/id/abn",
"value": "12345678901"
} ],
"active": true,
"name": "Audiology Advanced Hearing Care",
"telecom": [ {
"system": "email",
"value": "[email protected]",
"use": "work"
} ]
},
"search": {
"mode": "match"
}
} ]
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]