如何在 Rego 中发起 HTTP GET 请求
How to make HTTP GET request in Rego
我想在 rego 中向 url 发出获取请求。但它会引发 Invalid parameter: unallowed built-in function call in rego module: http.send 错误
这是我的代码。
package play
default hello = false
hello {
response := http.send({
"method" : "GET",
"url": "http://localhost:8181/v1/data/example"
})
}
我做错了什么?
该示例是正确的,但是 https://play.openpolicyagent.org 出于安全原因不允许 http.send
函数。在本地尝试。
$ opa run
REPL 内部:
> http.send({"method": "get", "url": "https://example.com"})
{
"body": null,
"raw_body": "\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n \u003ctitle\u003eExample Domain\u003c/title\u003e\n\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003cmeta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n \u003cstyle type=\"text/css\"\u003e\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n \u003c/style\u003e \n\u003c/head\u003e\n\n\u003cbody\u003e\n\u003cdiv\u003e\n \u003ch1\u003eExample Domain\u003c/h1\u003e\n \u003cp\u003eThis domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.\u003c/p\u003e\n \u003cp\u003e\u003ca href=\"https://www.iana.org/domains/example\"\u003eMore information...\u003c/a\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n",
"status": "200 OK",
"status_code": 200
}
我想在 rego 中向 url 发出获取请求。但它会引发 Invalid parameter: unallowed built-in function call in rego module: http.send 错误 这是我的代码。
package play
default hello = false
hello {
response := http.send({
"method" : "GET",
"url": "http://localhost:8181/v1/data/example"
})
}
我做错了什么?
该示例是正确的,但是 https://play.openpolicyagent.org 出于安全原因不允许 http.send
函数。在本地尝试。
$ opa run
REPL 内部:
> http.send({"method": "get", "url": "https://example.com"})
{
"body": null,
"raw_body": "\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n \u003ctitle\u003eExample Domain\u003c/title\u003e\n\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003cmeta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n \u003cstyle type=\"text/css\"\u003e\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n \u003c/style\u003e \n\u003c/head\u003e\n\n\u003cbody\u003e\n\u003cdiv\u003e\n \u003ch1\u003eExample Domain\u003c/h1\u003e\n \u003cp\u003eThis domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.\u003c/p\u003e\n \u003cp\u003e\u003ca href=\"https://www.iana.org/domains/example\"\u003eMore information...\u003c/a\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n",
"status": "200 OK",
"status_code": 200
}