diff --git a/.github/workflows/source-install.yml b/.github/workflows/source-install.yml index 60b27cfd11d9..b8c0dcb8e40b 100644 --- a/.github/workflows/source-install.yml +++ b/.github/workflows/source-install.yml @@ -88,17 +88,24 @@ jobs: - name: Test apisix run: | - curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' - { - "uri": "/get", - "upstream": { - "type": "roundrobin", - "nodes": { - "127.0.0.1:8088": 1 - } - } - }' + wget https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq + get_admin_key() { + local admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml) + echo "$admin_key" + } + export admin_key=$(get_admin_key); echo $admin_key + cat conf/config.yaml + curl -v http://127.0.0.1:9180/apisix/admin/routes/1 \ + -H "X-API-KEY: $admin_key" -X PUT -d ' + { + "uri": "/get", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:8088": 1 + } + } + }' result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/get` if [[ $result_code -ne 200 ]]; then printf "result_code: %s\n" "$result_code" diff --git a/Makefile b/Makefile index ff50ca881219..a7d601202364 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ ENV_DOCKER_COMPOSE ?= docker-compose --project-directory $(CURDIR) -p $(proj ENV_NGINX ?= $(ENV_NGINX_EXEC) -p $(CURDIR) -c $(CURDIR)/conf/nginx.conf ENV_NGINX_EXEC := $(shell command -v openresty 2>/dev/null || command -v nginx 2>/dev/null) ENV_OPENSSL_PREFIX ?= /usr/local/openresty/openssl3 +ENV_LIBYAML_INSTALL_PREFIX ?= /usr ENV_LUAROCKS ?= luarocks ## These variables can be injected by luarocks ENV_INST_PREFIX ?= /usr @@ -131,6 +132,7 @@ deps: install-runtime mkdir -p ~/.luarocks; \ $(ENV_LUAROCKS) config $(ENV_LUAROCKS_FLAG_LOCAL) variables.OPENSSL_LIBDIR $(addprefix $(ENV_OPENSSL_PREFIX), /lib); \ $(ENV_LUAROCKS) config $(ENV_LUAROCKS_FLAG_LOCAL) variables.OPENSSL_INCDIR $(addprefix $(ENV_OPENSSL_PREFIX), /include); \ + $(ENV_LUAROCKS) config $(ENV_LUAROCKS_FLAG_LOCAL) variables.YAML_DIR $(ENV_LIBYAML_INSTALL_PREFIX); \ $(ENV_LUAROCKS) install apisix-master-0.rockspec --tree deps --only-deps $(ENV_LUAROCKS_SERVER_OPT); \ else \ $(call func_echo_warn_status, "WARNING: You're not using LuaRocks 3.x; please remove the luarocks and reinstall it via https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh"); \ diff --git a/apisix-master-0.rockspec b/apisix-master-0.rockspec index 9a7b175a42b3..f94aed12749e 100644 --- a/apisix-master-0.rockspec +++ b/apisix-master-0.rockspec @@ -32,6 +32,7 @@ description = { dependencies = { "lua-resty-ctxdump = 0.1-0", + "lyaml = 6.2.8", "api7-lua-resty-dns-client = 7.0.1", "lua-resty-template = 2.0", "lua-resty-etcd = 1.10.5", diff --git a/apisix/admin/init.lua b/apisix/admin/init.lua index 50685af7ad36..4b4c7ec3add9 100644 --- a/apisix/admin/init.lua +++ b/apisix/admin/init.lua @@ -117,7 +117,7 @@ local function set_ctx_and_check_token() local ok, err = check_token(api_ctx) if not ok then core.log.warn("failed to check token: ", err) - core.response.exit(401, { error_msg = "failed to check token" }) + core.response.exit(401, { error_msg = "failed to check token", description = err }) end end diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 8b2b6a14efc0..1ee068d6bc9e 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -221,12 +221,9 @@ Please modify "admin_key" in conf/config.yaml . end if admin.key == "" then - util.die(help:format("ERROR: missing valid Admin API token."), "\n") - end - - if admin.key == "edd1c9f034335f136f87ad84b625c8f1" then stderr:write( - help:format([[WARNING: using fixed Admin API token has security risk.]]), + help:format([[WARNING: using empty Admin API. + This will trigger APISIX to automatically generate a random Admin API token.]]), "\n" ) end diff --git a/apisix/core/id.lua b/apisix/core/id.lua index 8f6f6a4e0f40..ef8f72783320 100644 --- a/apisix/core/id.lua +++ b/apisix/core/id.lua @@ -21,13 +21,19 @@ local fetch_local_conf = require("apisix.core.config_local").local_conf local try_read_attr = require("apisix.core.table").try_read_attr +local profile = require("apisix.core.profile") local log = require("apisix.core.log") -local uuid = require('resty.jit-uuid') +local uuid = require("resty.jit-uuid") +local lyaml = require("lyaml") local smatch = string.match local open = io.open - - -local prefix = ngx.config.prefix() +local type = type +local ipairs = ipairs +local string = string +local math = math +local prefix = ngx.config.prefix() +local pairs = pairs +local ngx_exit = ngx.exit local apisix_uid local _M = {version = 0.1} @@ -62,18 +68,77 @@ local function write_file(path, data) end +local function generate_yaml(table) + -- By default lyaml will parse null values as [] + -- The following logic is a workaround so that null values are parsed as null + local function replace_null(tbl) + for k, v in pairs(tbl) do + if type(v) == "table" then + replace_null(v) + elseif v == nil then + tbl[k] = "" + end + end + end + + -- Replace null values with "" + replace_null(table) + local yaml = lyaml.dump({ table }) + yaml = yaml:gsub("", "null"):gsub("%[%s*%]", "null") + return yaml +end + + _M.gen_uuid_v4 = uuid.generate_v4 +--- This will autogenerate the admin key if it's passed as an empty string in the configuration. +local function autogenerate_admin_key(default_conf) + local changed = false + -- Check if deployment.role is either traditional or control_plane + local deployment_role = default_conf.deployment and default_conf.deployment.role + if deployment_role and (deployment_role == "traditional" or + deployment_role == "control_plane") then + -- Check if deployment.admin.admin_key is not nil and it's an empty string + local admin_keys = try_read_attr(default_conf, "deployment", "admin", "admin_key") + if admin_keys and type(admin_keys) == "table" then + for i, admin_key in ipairs(admin_keys) do + if admin_key.role == "admin" and admin_key.key == "" then + changed = true + admin_keys[i].key = "" + for _ = 1, 32 do + admin_keys[i].key = admin_keys[i].key .. + string.char(math.random(65, 90) + math.random(0, 1) * 32) + end + end + end + end + end + return default_conf,changed +end + + function _M.init() + local local_conf = fetch_local_conf() + + local local_conf, changed = autogenerate_admin_key(local_conf) + if changed then + local yaml_conf = generate_yaml(local_conf) + local local_conf_path = profile:yaml_path("config") + local ok, err = write_file(local_conf_path, yaml_conf) + if not ok then + log.error("failed to write updated local configuration: ", err) + ngx_exit(-1) + end + end + + --allow user to specify a meaningful id as apisix instance id local uid_file_path = prefix .. "/conf/apisix.uid" apisix_uid = read_file(uid_file_path) if apisix_uid then return end - --allow user to specify a meaningful id as apisix instance id - local local_conf = fetch_local_conf() local id = try_read_attr(local_conf, "apisix", "id") if id then apisix_uid = local_conf.apisix.id @@ -89,6 +154,7 @@ function _M.init() end end + --- -- Returns the instance id of the running APISIX -- @@ -100,5 +166,4 @@ function _M.get() return apisix_uid end - return _M diff --git a/benchmark/run.sh b/benchmark/run.sh index fb185c93c9b4..44d0efafc660 100755 --- a/benchmark/run.sh +++ b/benchmark/run.sh @@ -74,8 +74,8 @@ sleep 3 ############################################# echo -e "\n\napisix: $worker_cnt worker + $upstream_cnt upstream + no plugin" - -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -100,8 +100,8 @@ sleep 1 ############################################# echo -e "\n\napisix: $worker_cnt worker + $upstream_cnt upstream + 2 plugins (limit-count + prometheus)" - -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { diff --git a/ci/centos7-ci.sh b/ci/centos7-ci.sh index 044c6239d3ce..cce816f74f48 100755 --- a/ci/centos7-ci.sh +++ b/ci/centos7-ci.sh @@ -29,6 +29,7 @@ install_dependencies() { cpanminus perl \ openssl-devel + yum install -y libyaml-devel # install newer curl yum makecache yum install -y libnghttp2-devel diff --git a/ci/common.sh b/ci/common.sh index 7e9f65e385b6..146b7aa5080a 100644 --- a/ci/common.sh +++ b/ci/common.sh @@ -23,6 +23,7 @@ export_version_info() { export_or_prefix() { export OPENRESTY_PREFIX="/usr/local/openresty" + export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH export OPENSSL_PREFIX=$OPENRESTY_PREFIX/openssl3 export OPENSSL_BIN=$OPENSSL_PREFIX/bin/openssl @@ -178,6 +179,8 @@ GRPC_SERVER_EXAMPLE_VER=20210819 linux_get_dependencies () { apt update apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl libpcre3 libpcre3-dev libldap2-dev + apt-get install -y libyaml-dev + wget https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq } function start_grpc_server_example() { diff --git a/ci/redhat-ci.sh b/ci/redhat-ci.sh index e6a50e2b6ebe..3cad10b5992b 100755 --- a/ci/redhat-ci.sh +++ b/ci/redhat-ci.sh @@ -26,7 +26,7 @@ install_dependencies() { wget tar gcc gcc-c++ automake autoconf libtool make unzip git sudo openldap-devel hostname patch \ which ca-certificates pcre pcre-devel xz \ openssl-devel - + yum install -y libyaml-devel yum install -y --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms cpanminus perl # install newer curl diff --git a/conf/config-default.yaml b/conf/config-default.yaml index d22dcdb24260..953fb1f098a3 100755 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -170,7 +170,8 @@ nginx_config: # Config for render the template to generate n stream: enable_access_log: false # Enable stream proxy access logging. access_log: logs/access_stream.log # Location of the stream access log. - access_log_format: "$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time" # Customize log format: http://nginx.org/en/docs/varindex.html + access_log_format: | + "$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time" # Customize log format: http://nginx.org/en/docs/varindex.html access_log_format_escape: default # Escape default or json characters in variables. lua_shared_dict: # Nginx Lua shared memory zone. Size units are m or k. etcd-cluster-health-check-stream: 10m @@ -208,7 +209,8 @@ nginx_config: # Config for render the template to generate n enable_access_log: true # Enable HTTP proxy access logging. access_log: logs/access.log # Location of the access log. access_log_buffer: 16384 # buffer size of access log. - access_log_format: "$remote_addr - $remote_user [$time_local] $http_host \"$request\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\"" + access_log_format: | + "$remote_addr - $remote_user [$time_local] $http_host \"$request\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\"" # Customize log format: http://nginx.org/en/docs/varindex.html access_log_format_escape: default # Escape default or json characters in variables. keepalive_timeout: 60s # Set the maximum time for which TCP connection keeps alive. @@ -643,7 +645,7 @@ deployment: # Deployment configurations admin_key: - name: admin # admin: write access to configurations. - key: edd1c9f034335f136f87ad84b625c8f1 # Set API key for the admin of Admin API. + key: '' # Set API key for the admin of Admin API. role: admin - name: viewer # viewer: read-only to configurations. diff --git a/conf/config.yaml b/conf/config.yaml index a77ce21e6238..6a3c43068f4a 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -59,5 +59,5 @@ deployment: admin: admin_key: - name: admin - key: edd1c9f034335f136f87ad84b625c8f1 # using fixed API token has security risk, please update it when you deploy to production environment + key: '' # using fixed API token has security risk, please update it when you deploy to production environment. If passed empty then will be autogenerated by APISIX and will be written back here. Recommended is to use external mechanism to generate and store the token. role: admin diff --git a/docs/en/latest/FAQ.md b/docs/en/latest/FAQ.md index 449abd882bf0..8a669b0f9c2d 100644 --- a/docs/en/latest/FAQ.md +++ b/docs/en/latest/FAQ.md @@ -120,10 +120,19 @@ Let's take an example query `foo.com/product/index.html?id=204&page=2` and consi There are two different ways to achieve this in Apache APISIX: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. Using the `vars` field in a [Route](terminology/route.md): ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "vars": [ @@ -136,7 +145,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335 } }' -curl -i http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "vars": [ @@ -163,7 +172,7 @@ Apache APISIX provides several different ways to achieve this: 1. Setting `http_to_https` to `true` in the [redirect](plugins/redirect.md) Plugin: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "host": "foo.com", @@ -178,7 +187,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1 2. Advanced routing with `vars` in the redirect Plugin: ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "host": "foo.com", @@ -201,7 +210,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f03433 3. Using the `serverless` Plugin: ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -392,7 +401,7 @@ deployment: 2. Add a proxy Route for the Apache APISIX dashboard: ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uris":[ "/*" ], "name":"apisix_proxy_dashboard", @@ -416,7 +425,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f03433 You can use the `vars` field in a Route for matching regular expressions: ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "vars": [ @@ -452,7 +461,7 @@ For more info on using `vars` refer to [lua-resty-expr](https://github.com/api7/ Yes. The example below shows configuring the FQDN `httpbin.default.svc.cluster.local` (a Kubernetes service): ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "upstream": { @@ -554,7 +563,7 @@ You can check [this post](https://juejin.cn/post/6965778290619449351) for a more To strip a prefix from a path in your route, like to take `/foo/get` and strip it to `/get`, you can use the [proxy-rewrite](plugins/proxy-rewrite.md) Plugin: ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/foo/*", "plugins": { diff --git a/docs/en/latest/admin-api.md b/docs/en/latest/admin-api.md index 722cdd57047d..158c8154335f 100644 --- a/docs/en/latest/admin-api.md +++ b/docs/en/latest/admin-api.md @@ -122,24 +122,33 @@ By default, the Admin API checks for references between resources and will refus You can make a force deletion by adding the request argument `force=true` to the delete request, for example: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash -$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ +$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H "X-API-KEY: $admin_key" -X PUT -d '{ "nodes": { "127.0.0.1:8080": 1 }, "type": "roundrobin" }' -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '{ "uri": "/*", "upstream_id": 1 }' {"value":{"priority":0,"upstream_id":1,"uri":"/*","create_time":1689038794,"id":"1","status":1,"update_time":1689038916},"key":"/apisix/routes/1"} -$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H "X-API-KEY: $admin_key" -X DELETE {"error_msg":"can not delete this upstream, route [1] is still using it now"} -$ curl "http://127.0.0.1:9180/apisix/admin/upstreams/1?force=anyvalue" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +$ curl "http://127.0.0.1:9180/apisix/admin/upstreams/1?force=anyvalue" -H "X-API-KEY: $admin_key" -X DELETE {"error_msg":"can not delete this upstream, route [1] is still using it now"} -$ curl "http://127.0.0.1:9180/apisix/admin/upstreams/1?force=true" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +$ curl "http://127.0.0.1:9180/apisix/admin/upstreams/1?force=true" -H "X-API-KEY: $admin_key" -X DELETE {"deleted":"1","key":"/apisix/upstreams/1"} ``` @@ -207,7 +216,7 @@ The example is as follows: ```shell curl "http://127.0.0.1:9180/apisix/admin/routes?page=1&page_size=10" \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X GET +-H "X-API-KEY: $admin_key" -X GET ``` ```json @@ -255,7 +264,7 @@ The following example will return a list of routes, and all routes in the list s ```shell curl 'http://127.0.0.1:9180/apisix/admin/routes?name=test&uri=foo&label=' \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X GET +-H "X-API-KEY: $admin_key" -X GET ``` ```json @@ -356,7 +365,7 @@ Example configuration: - Create a route ```shell - curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/index.html", "hosts": ["foo.com", "*.bar.com"], @@ -382,7 +391,7 @@ Example configuration: ```shell curl 'http://127.0.0.1:9180/apisix/admin/routes/2?ttl=60' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/aa/index.html", "upstream": { @@ -404,7 +413,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "upstream": { "nodes": { @@ -432,7 +441,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "upstream": { "nodes": { @@ -460,7 +469,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "upstream": { "nodes": { @@ -487,7 +496,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d '{ + -H "X-API-KEY: $admin_key" -X PATCH -i -d '{ "methods": ["GET", "POST"] }' ``` @@ -507,7 +516,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1/upstream/nodes \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "127.0.0.1:1982": 1 }' @@ -530,7 +539,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1/methods \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d'["POST", "DELETE", " PATCH"]' + -H "X-API-KEY: $admin_key" -X PATCH -i -d'["POST", "DELETE", " PATCH"]' ``` ```shell @@ -548,7 +557,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "status": 0 }' @@ -571,7 +580,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "status": 1 }' @@ -650,7 +659,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/services/201 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "plugins": { "limit-count": { @@ -679,7 +688,7 @@ Example configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/services/201 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "upstream": { "nodes": { @@ -828,7 +837,7 @@ When bound to a Route or Service, the Authentication Plugin infers the Consumer ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "username": "jack", "plugins": { @@ -969,7 +978,7 @@ Example Configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/100 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d ' + -H "X-API-KEY: $admin_key" -i -X PUT -d ' { "type":"roundrobin", "nodes":{ @@ -987,7 +996,7 @@ Example Configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/100 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "nodes": { "127.0.0.1:1981": 1 @@ -1039,7 +1048,7 @@ Example Configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/100 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "nodes": { "127.0.0.1:1980": null @@ -1064,7 +1073,7 @@ Example Configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/100/nodes \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -i -d ' + -H "X-API-KEY: $admin_key" -X PATCH -i -d ' { "127.0.0.1:1982": 1 }' @@ -1089,7 +1098,7 @@ Example Configuration: ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "upstream": { @@ -1320,7 +1329,7 @@ Example Configuration: ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/example-plugin \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d ' +-H "X-API-KEY: $admin_key" -i -X PUT -d ' { "skey": "val", "ikey": 1 @@ -1472,7 +1481,7 @@ Example API usage: ```shell curl -i http://127.0.0.1:9180/apisix/admin/secrets/vault/test2 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "http://xxx/get", "prefix" : "apisix", @@ -1542,7 +1551,7 @@ Example: ```bash curl http://127.0.0.1:9180/apisix/admin/schema/validate/routes \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X POST -i -d '{ + -H "X-API-KEY: $admin_key" -X POST -i -d '{ "uri": 1980, "upstream": { "scheme": "https", diff --git a/docs/en/latest/batch-processor.md b/docs/en/latest/batch-processor.md index 0e7020930447..48c1a9d39ac6 100644 --- a/docs/en/latest/batch-processor.md +++ b/docs/en/latest/batch-processor.md @@ -82,8 +82,17 @@ end The batch processor's configuration will be set inside the plugin's configuration. For example: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "http-logger": { diff --git a/docs/en/latest/benchmark.md b/docs/en/latest/benchmark.md index b8482603560c..bc86cf97d77d 100644 --- a/docs/en/latest/benchmark.md +++ b/docs/en/latest/benchmark.md @@ -52,8 +52,17 @@ The result of Flame Graph: And if you want to run the benchmark test in your machine, you should run another Nginx to listen 80 port. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -98,7 +107,7 @@ The result of Flame Graph: And if you want to run the benchmark test in your machine, you should run another Nginx to listen 80 port. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/certificate.md b/docs/en/latest/certificate.md index 1135506378d3..8916b667b3a7 100644 --- a/docs/en/latest/certificate.md +++ b/docs/en/latest/certificate.md @@ -35,9 +35,18 @@ The following is an example of configuring an SSL certificate with a single SNI Create an SSL object with the certificate and key valid for the SNI: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat t/certs/apisix.crt)"'", "key": "'"$(cat t/certs/apisix.key)"'", @@ -48,7 +57,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ Create a Router object: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/get", "hosts": ["test.com"], @@ -95,7 +104,7 @@ Create an SSL object with the certificate and key valid for the SNI: ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat t/certs/apisix.crt)"'", "key": "'"$(cat t/certs/apisix.key)"'", @@ -106,7 +115,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ Create a Router object: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/get", "hosts": ["*.test.com"], @@ -270,7 +279,7 @@ curl -vvv \ --cert /path/to/foo_client.crt \ --key /path/to/foo_client.key \ --cacert /path/to/apisix.ca-bundle \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/get", "upstream": { diff --git a/docs/en/latest/debug-function.md b/docs/en/latest/debug-function.md index 9b9883fb2be5..3d5728673639 100644 --- a/docs/en/latest/debug-function.md +++ b/docs/en/latest/debug-function.md @@ -31,10 +31,19 @@ In the response header of the request, through the response header of `X-APISIX- ## Example +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + >Example 1: `502` response status code comes from `Upstream` (IP address is not available) ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "upstream": { @@ -75,7 +84,7 @@ It has a response header of `X-APISIX-Upstream-Status: 502`. >Example 2: `502` response status code comes from `APISIX` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -109,7 +118,7 @@ There is no response header for `X-APISIX-Upstream-Status`. >Example 3: `Upstream` has multiple nodes, and all nodes are unavailable ```shell -$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "nodes": { "127.0.0.3:1": 1, @@ -122,7 +131,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034 ``` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream_id": "1" diff --git a/docs/en/latest/discovery.md b/docs/en/latest/discovery.md index e5ccada41fff..6844ede9f87a 100644 --- a/docs/en/latest/discovery.md +++ b/docs/en/latest/discovery.md @@ -186,8 +186,17 @@ discovery: Here is an example of routing a request with a URL of "/user/*" to a service which named "user-service" and use eureka discovery client in the registry : +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/user/*", "upstream": { @@ -210,7 +219,7 @@ Server: APISIX web server Because the upstream interface URL may have conflict, usually in the gateway by prefix to distinguish: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/a/*", "plugins": { @@ -225,7 +234,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f } }' -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/b/*", "plugins": { @@ -250,7 +259,7 @@ Suppose both A-SERVICE and B-SERVICE provide a `/test` API. The above configurat Eureka service discovery also supports use in L4, the configuration method is similar to L7. ```shell -$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "remote_addr": "127.0.0.1", "upstream": { diff --git a/docs/en/latest/discovery/consul.md b/docs/en/latest/discovery/consul.md index 1f230eddf37b..7b89494ca967 100644 --- a/docs/en/latest/discovery/consul.md +++ b/docs/en/latest/discovery/consul.md @@ -161,8 +161,17 @@ To avoid confusion, use the full consul key url path as service name in practice Here is an example of routing a request with a URL of "/*" to a service which named "service_a" and use consul discovery client in the registry : +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/*", "upstream": { @@ -204,7 +213,7 @@ You could find more usage in the `apisix/t/discovery/consul.t` file. Consul service discovery also supports use in L4, the configuration method is similar to L7. ```shell -$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "remote_addr": "127.0.0.1", "upstream": { diff --git a/docs/en/latest/discovery/consul_kv.md b/docs/en/latest/discovery/consul_kv.md index e0a2602c074b..3eb0f9d8b131 100644 --- a/docs/en/latest/discovery/consul_kv.md +++ b/docs/en/latest/discovery/consul_kv.md @@ -136,8 +136,17 @@ To avoid confusion, use the full consul key url path as service name in practice Here is an example of routing a request with a URL of "/*" to a service which named "http://127.0.0.1:8500/v1/kv/upstreams/webpages/" and use consul_kv discovery client in the registry : +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/*", "upstream": { @@ -180,7 +189,7 @@ You could find more usage in the `apisix/t/discovery/consul_kv.t` file. Consul_kv service discovery also supports use in L4, the configuration method is similar to L7. ```shell -$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "remote_addr": "127.0.0.1", "upstream": { diff --git a/docs/en/latest/discovery/nacos.md b/docs/en/latest/discovery/nacos.md index 9a7084577d30..5ebbcee46b49 100644 --- a/docs/en/latest/discovery/nacos.md +++ b/docs/en/latest/discovery/nacos.md @@ -62,8 +62,17 @@ discovery: Here is an example of routing a request with an URI of "/nacos/*" to a service which named "http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS" and use nacos discovery client in the registry: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/nacos/*", "upstream": { @@ -105,7 +114,7 @@ The formatted response as below: Nacos service discovery also supports use in L4, the configuration method is similar to L7. ```shell -$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "remote_addr": "127.0.0.1", "upstream": { @@ -129,7 +138,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f Example of routing a request with an URI of "/nacosWithNamespaceId/*" to a service with name, namespaceId "http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&namespaceId=test_ns" and use nacos discovery client in the registry: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/nacosWithNamespaceId/*", "upstream": { @@ -177,7 +186,7 @@ The formatted response as below: Example of routing a request with an URI of "/nacosWithGroupName/*" to a service with name, groupName "http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&groupName=test_group" and use nacos discovery client in the registry: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/3 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/3 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/nacosWithGroupName/*", "upstream": { @@ -225,7 +234,7 @@ The formatted response as below: Example of routing a request with an URI of "/nacosWithNamespaceIdAndGroupName/*" to a service with name, namespaceId, groupName "http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&namespaceId=test_ns&groupName=test_group" and use nacos discovery client in the registry: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/4 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/4 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/nacosWithNamespaceIdAndGroupName/*", "upstream": { diff --git a/docs/en/latest/grpc-proxy.md b/docs/en/latest/grpc-proxy.md index 20575d075938..dbe1a8cf363e 100644 --- a/docs/en/latest/grpc-proxy.md +++ b/docs/en/latest/grpc-proxy.md @@ -40,8 +40,17 @@ Here's an example, to proxying gRPC service by specified route: * attention: APISIX also support to expose gRPC service with plaintext HTTP/2, which does not rely on TLS, usually used to proxy gRPC service in intranet environment * the grpc server example:[grpc_server_example](https://github.com/api7/grpc_server_example) +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST", "GET"], "uri": "/helloworld.Greeter/SayHello", @@ -98,7 +107,7 @@ This means that the proxying is working. If your gRPC service encrypts with TLS by itself (so called `gPRCS`, gPRC + TLS), you need to change the `scheme` to `grpcs`. The example above runs gRPCS service on port 50052, to proxy gRPC request, we need to use the configuration below: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST", "GET"], "uri": "/helloworld.Greeter/SayHello", diff --git a/docs/en/latest/mtls.md b/docs/en/latest/mtls.md index 02e5e4b4550e..d6cfc0122919 100644 --- a/docs/en/latest/mtls.md +++ b/docs/en/latest/mtls.md @@ -65,8 +65,17 @@ Please replace the following certificate paths and domain name with your real on * Note: The same CA certificate as the server needs to be used * +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl --cacert /data/certs/mtls_ca.crt --key /data/certs/mtls_client.key --cert /data/certs/mtls_client.crt https://admin.apisix.dev:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' +curl --cacert /data/certs/mtls_ca.crt --key /data/certs/mtls_client.key --cert /data/certs/mtls_client.crt https://admin.apisix.dev:9180/apisix/admin/routes -H "X-API-KEY: $admin_key" ``` ## etcd with mTLS @@ -112,7 +121,7 @@ Here is an example shell script to create SSL with mTLS (id is `1`, changes admi ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert": "'"$(cat t/certs/mtls_server.crt)"'", "key": "'"$(cat t/certs/mtls_server.key)"'", @@ -191,7 +200,7 @@ Here is a similar shell script to patch a existed upstream with mTLS (changes ad ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -d ' +-H "X-API-KEY: $admin_key" -X PATCH -d ' { "tls": { "client_cert": "'"$(cat t/certs/mtls_client.crt)"'", diff --git a/docs/en/latest/plugin-develop.md b/docs/en/latest/plugin-develop.md index 014939a51270..406dce0e6e74 100644 --- a/docs/en/latest/plugin-develop.md +++ b/docs/en/latest/plugin-develop.md @@ -370,8 +370,17 @@ end Write the logic of the plugin in the corresponding phase. There are two parameters `conf` and `ctx` in the phase method, take the `limit-conn` plugin configuration as an example. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/api-breaker.md b/docs/en/latest/plugins/api-breaker.md index d0478b1c91da..c60070d42ea2 100644 --- a/docs/en/latest/plugins/api-breaker.md +++ b/docs/en/latest/plugins/api-breaker.md @@ -57,9 +57,18 @@ In an unhealthy state, if the Upstream service responds with a status code from The example below shows how you can configure the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl "http://127.0.0.1:9180/apisix/admin/routes/1" \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "api-breaker": { @@ -114,7 +123,7 @@ To remove the `api-breaker` Plugin, you can delete the corresponding JSON config ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/docs/en/latest/plugins/authz-casbin.md b/docs/en/latest/plugins/authz-casbin.md index b405cb4dd396..8f49fba039a9 100644 --- a/docs/en/latest/plugins/authz-casbin.md +++ b/docs/en/latest/plugins/authz-casbin.md @@ -65,8 +65,17 @@ You can enable the Plugin on a Route by either using the model/policy file paths The example below shows setting up Casbin authentication from your model/policy configuration file: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "authz-casbin": { @@ -90,7 +99,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 The example below shows setting up Casbin authentication from your model/policy text in your Plugin configuration: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "authz-casbin": { @@ -133,7 +142,7 @@ First, you need to send a `PUT` request to the Admin API to add the `model` and All Routes configured this way will use a single Casbin enforcer with the configured Plugin metadata. You can also update the model/policy in this way and the Plugin will automatically update to the new configuration. ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/authz-casbin -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/authz-casbin -H "X-API-KEY: $admin_key" -i -X PUT -d ' { "model": "[request_definition] r = sub, obj, act @@ -159,7 +168,7 @@ g, alice, admin" Once you have updated the Plugin metadata, you can add the Plugin to a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "authz-casbin": { @@ -239,7 +248,7 @@ curl -i http://127.0.0.1:9080/res -H 'user: alice' -X GET To remove the `authz-casbin` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/*", diff --git a/docs/en/latest/plugins/authz-casdoor.md b/docs/en/latest/plugins/authz-casdoor.md index 7a8985212f15..5f91c5f54e7c 100644 --- a/docs/en/latest/plugins/authz-casdoor.md +++ b/docs/en/latest/plugins/authz-casdoor.md @@ -93,8 +93,17 @@ Once this is done, the user is redirected to the original URL they wanted to vis To remove the `authz-casdoor` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/anything/*", diff --git a/docs/en/latest/plugins/authz-keycloak.md b/docs/en/latest/plugins/authz-keycloak.md index 8d900b726261..bb968e6f7d71 100644 --- a/docs/en/latest/plugins/authz-keycloak.md +++ b/docs/en/latest/plugins/authz-keycloak.md @@ -147,8 +147,17 @@ curl --location --request POST 'http://127.0.0.1:9080/api/token' \ The example below shows how you can enable the `authz-keycloak` Plugin on a specific Route. `${realm}` represents the realm name in Keycloak. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { @@ -211,7 +220,7 @@ The image below shows how the policies are configured in the Keycloak server: To remove the `authz-keycloak` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/en/latest/plugins/aws-lambda.md b/docs/en/latest/plugins/aws-lambda.md index 0281c8e3189d..1b80dc9da778 100644 --- a/docs/en/latest/plugins/aws-lambda.md +++ b/docs/en/latest/plugins/aws-lambda.md @@ -62,8 +62,17 @@ This Plugin supports authorization via AWS API key and AWS IAM secrets. The example below shows how you can configure the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "aws-lambda": { @@ -122,7 +131,7 @@ server: APISIX/2.10.2 Similarly, the function can be triggered via AWS API Gateway by using AWS IAM permissions for authorization. The Plugin includes authentication signatures in HTTP calls via AWS v4 request signing. The example below shows this method: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "aws-lambda": { @@ -159,7 +168,7 @@ The `uri` configured on a Route must end with `*` for this feature to work prope The example below configures this feature: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "aws-lambda": { @@ -199,7 +208,7 @@ Server: APISIX/2.11.0 To remove the `aws-lambda` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/aws", "plugins": {}, diff --git a/docs/en/latest/plugins/azure-functions.md b/docs/en/latest/plugins/azure-functions.md index 22f531ba0c65..f68b6f3b497f 100644 --- a/docs/en/latest/plugins/azure-functions.md +++ b/docs/en/latest/plugins/azure-functions.md @@ -64,8 +64,17 @@ The relative order priority is as follows: To add a new master API key, you can make a request to `/apisix/admin/plugin_metadata` with the required metadata as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/azure-functions -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/azure-functions -H "X-API-KEY: $admin_key" -X PUT -d ' { "master_apikey" : "" }' @@ -76,7 +85,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/azure-functions -H 'X-AP You can configure the Plugin on a specific Route as shown below assuming that you already have your Azure Functions up and running: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "azure-functions": { @@ -139,7 +148,7 @@ The `uri` configured on a Route must end with `*` for this feature to work prope The example below configures this feature: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "azure-functions": { @@ -176,7 +185,7 @@ Hello, APISIX To remove the `azure-functions` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/azure", "plugins": {}, diff --git a/docs/en/latest/plugins/basic-auth.md b/docs/en/latest/plugins/basic-auth.md index 997bc610a939..5073cff95cc5 100644 --- a/docs/en/latest/plugins/basic-auth.md +++ b/docs/en/latest/plugins/basic-auth.md @@ -55,8 +55,17 @@ For Route: To enable the Plugin, you have to create a Consumer object with the authentication configuration: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo", "plugins": { @@ -79,7 +88,7 @@ You can also use the [APISIX Dashboard](/docs/dashboard/USER_GUIDE) to complete Once you have created a Consumer object, you can then configure a Route or a Service to authenticate requests: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -130,7 +139,7 @@ HTTP/1.1 401 Unauthorized To remove the `jwt-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/batch-requests.md b/docs/en/latest/plugins/batch-requests.md index 9c7daba6ea8c..b9945f41048e 100644 --- a/docs/en/latest/plugins/batch-requests.md +++ b/docs/en/latest/plugins/batch-requests.md @@ -71,8 +71,17 @@ plugins: By default, the maximum body size that can be sent to `/apisix/batch-requests` can't be larger than 1 MiB. You can change this configuration of the Plugin through the endpoint `apisix/admin/plugin_metadata/batch-requests`: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/batch-requests -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/batch-requests -H "X-API-KEY: $admin_key" -X PUT -d ' { "max_body_size": 4194304 }' @@ -129,7 +138,7 @@ You can specify a custom URI with the [public-api](public-api.md) Plugin. You can set the URI you want when creating the Route and change the configuration of the public-api Plugin: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/br -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/batch-requests", "plugins": { @@ -145,7 +154,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f1 First, you need to setup a Route to the batch request API. We will use the [public-api](public-api.md) Plugin for this: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/br -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/batch-requests", "plugins": { diff --git a/docs/en/latest/plugins/body-transformer.md b/docs/en/latest/plugins/body-transformer.md index 2e2c171a039e..0d903496f709 100644 --- a/docs/en/latest/plugins/body-transformer.md +++ b/docs/en/latest/plugins/body-transformer.md @@ -55,9 +55,18 @@ Use cases: You can enable the Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/test_ws \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST"], "uri": "/ws", @@ -122,7 +131,7 @@ For example, you could use `base64` command to encode your template text file: ```bash curl http://127.0.0.1:9180/apisix/admin/routes/test_ws \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST"], "uri": "/ws", @@ -205,7 +214,7 @@ EOF ) curl http://127.0.0.1:9180/apisix/admin/routes/test_ws \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST"], "uri": "/ws", @@ -265,7 +274,7 @@ To remove the `body-transformer` Plugin, you can delete the corresponding JSON c ```shell curl http://127.0.0.1:9180/apisix/admin/routes/test_ws \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["POST"], "uri": "/ws", diff --git a/docs/en/latest/plugins/brotli.md b/docs/en/latest/plugins/brotli.md index 196fdb520234..3c7517a72177 100644 --- a/docs/en/latest/plugins/brotli.md +++ b/docs/en/latest/plugins/brotli.md @@ -70,8 +70,17 @@ If the upstream is returning a compressed response, then the Brotli plugin won't The example below enables the `brotli` Plugin on the specified Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/", "plugins": { @@ -116,7 +125,7 @@ Warning: " to save to a file. To remove the `brotli` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/", "upstream": { diff --git a/docs/en/latest/plugins/cas-auth.md b/docs/en/latest/plugins/cas-auth.md index 08173ac9716d..37d23b068a30 100644 --- a/docs/en/latest/plugins/cas-auth.md +++ b/docs/en/latest/plugins/cas-auth.md @@ -45,8 +45,17 @@ to do authentication, from the SP (service provider) perspective. You can enable the Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/cas1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/cas1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET", "POST"], "host" : "127.0.0.1", @@ -93,7 +102,7 @@ For example, if the `uri` of the current route is `/api/v1/*`, `cas_callback_uri To remove the `cas-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/cas1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/cas1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET", "POST"], "uri": "/anything/*", diff --git a/docs/en/latest/plugins/chaitin-waf.md b/docs/en/latest/plugins/chaitin-waf.md index 14966c4ea558..c34c40a69ea1 100644 --- a/docs/en/latest/plugins/chaitin-waf.md +++ b/docs/en/latest/plugins/chaitin-waf.md @@ -70,8 +70,17 @@ The response headers are listed below: An example configuration is as follows. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H "X-API-KEY: $admin_key" -X PUT -d ' { "nodes":[ { @@ -101,7 +110,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H 'X-API-KE A sample configuration is shown below, using `httpbun.org` as the example backend, which can be replaced as needed: ```bash -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "plugins": { @@ -242,7 +251,7 @@ To remove the `chaitin-waf` plugin, you can delete the corresponding JSON config APISIX will automatically reload and you do not have to restart for this to take effect: ```bash -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index f41a7aaec2e7..023f9e920bcd 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -113,8 +113,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/clickhouse-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/clickhouse-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -143,7 +152,7 @@ If multiple endpoints are configured, they will be written randomly. The example below shows how you can enable the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "clickhouse-logger": { @@ -184,7 +193,7 @@ curl 'http://localhost:8123/?query=select%20*%20from%20default.test' To remove the `clickhouse-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/client-control.md b/docs/en/latest/plugins/client-control.md index 03541066d517..eb702bf8afa6 100644 --- a/docs/en/latest/plugins/client-control.md +++ b/docs/en/latest/plugins/client-control.md @@ -46,9 +46,18 @@ This Plugin requires APISIX to run on APISIX-Runtime. See [apisix-build-tools](h The example below enables the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -91,7 +100,7 @@ To remove the `client-control` Plugin, you can delete the corresponding JSON con ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/consumer-restriction.md b/docs/en/latest/plugins/consumer-restriction.md index 1a20e59ba5f2..868675267ff7 100644 --- a/docs/en/latest/plugins/consumer-restriction.md +++ b/docs/en/latest/plugins/consumer-restriction.md @@ -62,8 +62,17 @@ The example below shows how you can use the `consumer-restriction` Plugin on a R You can first create two consumers `jack1` and `jack2`: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "username": "jack1", "plugins": { @@ -74,7 +83,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 } }' -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "username": "jack2", "plugins": { @@ -89,7 +98,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Next, you can configure the Plugin to the Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -136,7 +145,7 @@ HTTP/1.1 403 Forbidden The example below configures the Plugin to a Route to restrict `jack1` to only make `POST` requests: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -172,7 +181,7 @@ HTTP/1.1 403 Forbidden To also allow `GET` requests, you can update the Plugin configuration and it would be reloaded automatically: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -210,7 +219,7 @@ To restrict a Consumer from accessing a Service, you also need to use an Authent First, you can create two services: ```shell -curl http://127.0.0.1:9180/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/services/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -221,7 +230,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f "desc": "new service 001" }' -curl http://127.0.0.1:9180/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/services/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -236,7 +245,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f Then configure the `consumer-restriction` Plugin on the Consumer with the `key-auth` Plugin and the `service_id` to whitelist. ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "new_consumer", "plugins": { @@ -257,7 +266,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Finally, you can configure the `key-auth` Plugin and bind the service to the Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -288,7 +297,7 @@ HTTP/1.1 200 OK Now, if the Route is configured to the Service with `service_id` `2`: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -322,7 +331,7 @@ HTTP/1.1 403 Forbidden To remove the `consumer-restriction` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/cors.md b/docs/en/latest/plugins/cors.md index cf8d28064079..424bb59f6863 100644 --- a/docs/en/latest/plugins/cors.md +++ b/docs/en/latest/plugins/cors.md @@ -80,8 +80,17 @@ So, you have to set the CORS headers first, then access the `domain-B.com` URL, You can enable the Plugin on a specific Route or Service: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -120,7 +129,7 @@ curl http://127.0.0.1:9080/hello -v To remove the `cors` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/csrf.md b/docs/en/latest/plugins/csrf.md index 7211fcd99284..f5198272fbac 100644 --- a/docs/en/latest/plugins/csrf.md +++ b/docs/en/latest/plugins/csrf.md @@ -48,8 +48,17 @@ NOTE: `encrypt_fields = {"key"}` is also defined in the schema, which means that The example below shows how you can enable the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT-d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT-d ' { "uri": "/hello", "plugins": { @@ -132,7 +141,7 @@ HTTP/1.1 200 OK To remove the `csrf` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/docs/en/latest/plugins/datadog.md b/docs/en/latest/plugins/datadog.md index d5ca42ccf2c6..4b2d5b47c2ce 100644 --- a/docs/en/latest/plugins/datadog.md +++ b/docs/en/latest/plugins/datadog.md @@ -66,8 +66,17 @@ See [defining tags](https://docs.datadoghq.com/getting_started/tagging/#defining By default, the Plugin expects the DogStatsD service to be available at `127.0.0.1:8125`. If you want to change this, you can update the Plugin metadata as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H "X-API-KEY: $admin_key" -X PUT -d ' { "host": "172.168.45.29", "port": 8126, @@ -82,7 +91,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H 'X-API-KEY: e To reset to default configuration, make a PUT request with empty body: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{}' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H "X-API-KEY: $admin_key" -X PUT -d '{}' ``` ## Exported metrics @@ -118,7 +127,7 @@ If there are no suitable values for any particular tag, the tag will be omitted. Once you have your Datadog agent running, you can enable the Plugin as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "datadog": {} @@ -140,7 +149,7 @@ Now, requests to the endpoint `/hello` will generate metrics and push it to the To remove the `datadog` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/degraphql.md b/docs/en/latest/plugins/degraphql.md index 7407a435c531..6c375715e625 100644 --- a/docs/en/latest/plugins/degraphql.md +++ b/docs/en/latest/plugins/degraphql.md @@ -312,8 +312,17 @@ In the GET request, the variables are passed in the query string. To remove the `degraphql` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/graphql", diff --git a/docs/en/latest/plugins/dubbo-proxy.md b/docs/en/latest/plugins/dubbo-proxy.md index 7e09b0d599fc..eff2cebfcfa1 100644 --- a/docs/en/latest/plugins/dubbo-proxy.md +++ b/docs/en/latest/plugins/dubbo-proxy.md @@ -64,8 +64,17 @@ plugins: Now, when APISIX is reloaded, you can add it to a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "nodes": { "127.0.0.1:20880": 1 @@ -73,7 +82,7 @@ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f03433 "type": "roundrobin" }' -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uris": [ "/hello" @@ -161,7 +170,7 @@ body of the message To remove the `dubbo-proxy` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/en/latest/plugins/echo.md b/docs/en/latest/plugins/echo.md index f4babdfe4c71..da99f64bab09 100644 --- a/docs/en/latest/plugins/echo.md +++ b/docs/en/latest/plugins/echo.md @@ -54,8 +54,17 @@ At least one of `before_body`, `body`, and `after_body` must be specified. The example below shows how you can enable the `echo` Plugin for a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "echo": { @@ -92,7 +101,7 @@ To remove the `echo` Plugin, you can delete the corresponding JSON configuration ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/elasticsearch-logger.md b/docs/en/latest/plugins/elasticsearch-logger.md index 098dc27d335b..f959234eb776 100644 --- a/docs/en/latest/plugins/elasticsearch-logger.md +++ b/docs/en/latest/plugins/elasticsearch-logger.md @@ -103,9 +103,18 @@ This Plugin supports using batch processors to aggregate and process entries (lo The example below shows a complete configuration of the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "elasticsearch-logger":{ @@ -144,7 +153,7 @@ The example below shows a bare minimum configuration of the Plugin on a Route: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "elasticsearch-logger":{ @@ -251,7 +260,7 @@ The example below shows how you can configure through the Admin API: ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/elasticsearch-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -312,7 +321,7 @@ curl -X GET "http://127.0.0.1:9200/services/_search" | jq . ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/elasticsearch-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +-H "X-API-KEY: $admin_key" -X DELETE ``` ## Delete Plugin @@ -321,7 +330,7 @@ To remove the `elasticsearch-logger` Plugin, you can delete the corresponding JS ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{}, "upstream":{ diff --git a/docs/en/latest/plugins/error-log-logger.md b/docs/en/latest/plugins/error-log-logger.md index f63e89a9bd4f..039e429e5f4b 100644 --- a/docs/en/latest/plugins/error-log-logger.md +++ b/docs/en/latest/plugins/error-log-logger.md @@ -93,8 +93,17 @@ Once you have enabled the Plugin, you can configure it through the Plugin metada You can set the TCP server address by configuring the Plugin metadata as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "tcp": { "host": "127.0.0.1", @@ -109,7 +118,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H 'X-A You can configure the SkyWalking OAP server address as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "skywalking": { "endpoint_addr":"http://127.0.0.1:12800/v3/logs" @@ -125,7 +134,7 @@ The Plugin sends the error log as a string to the `data` field of a table in you You can configure it as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "clickhouse": { "user": "default", @@ -143,7 +152,7 @@ The Plugin sends the error log to Kafka, you can configure it as shown below: ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "kafka":{ "brokers":[ diff --git a/docs/en/latest/plugins/ext-plugin-post-resp.md b/docs/en/latest/plugins/ext-plugin-post-resp.md index 5a240c7fd5e2..ed51c6d81a2a 100644 --- a/docs/en/latest/plugins/ext-plugin-post-resp.md +++ b/docs/en/latest/plugins/ext-plugin-post-resp.md @@ -54,8 +54,17 @@ Execution of External Plugins will affect the response of the current request. The example below enables the `ext-plugin-post-resp` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -89,7 +98,7 @@ This will reach the configured Plugin Runner and the `ext-plugin-A` will be exec To remove the `ext-plugin-post-resp` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/ext-plugin-pre-req.md b/docs/en/latest/plugins/ext-plugin-pre-req.md index 766713ab33f4..ec15df697dab 100644 --- a/docs/en/latest/plugins/ext-plugin-pre-req.md +++ b/docs/en/latest/plugins/ext-plugin-pre-req.md @@ -50,8 +50,17 @@ Execution of External Plugins will affect the behavior of the current request. The example below enables the `ext-plugin-pre-req` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -85,7 +94,7 @@ This will reach the configured Plugin Runner and the `ext-plugin-A` will be exec To remove the `ext-plugin-pre-req` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/fault-injection.md b/docs/en/latest/plugins/fault-injection.md index 11edcb5afcf4..16d05b13aac7 100644 --- a/docs/en/latest/plugins/fault-injection.md +++ b/docs/en/latest/plugins/fault-injection.md @@ -79,8 +79,17 @@ This means that the relationship between the first two expressions is AND, and t You can enable the `fault-injection` Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -103,7 +112,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 Similarly, to enable a `delay` fault: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -125,7 +134,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 You can also enable the Plugin with both `abort` and `delay` which can have `vars` for matching: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -204,7 +213,7 @@ sys 0m0.010s You can enable the `fault-injection` Plugin with the `vars` attribute to set specific rules: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -270,7 +279,7 @@ Fault Injection! To remove the `fault-injection` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/file-logger.md b/docs/en/latest/plugins/file-logger.md index 61df441ee9ea..1d175258e9b0 100644 --- a/docs/en/latest/plugins/file-logger.md +++ b/docs/en/latest/plugins/file-logger.md @@ -107,8 +107,17 @@ You can also set the format of the logs by configuring the Plugin metadata. The The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/file-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/file-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -130,7 +139,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "file-logger": { @@ -161,7 +170,7 @@ You will be able to find the `file.log` file in the configured `logs` directory. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "file-logger": { @@ -202,7 +211,7 @@ Log records cannot be seen in `logs/file.log`. To remove the `file-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/forward-auth.md b/docs/en/latest/plugins/forward-auth.md index 4b8d138c93b8..b1aacc807c48 100644 --- a/docs/en/latest/plugins/forward-auth.md +++ b/docs/en/latest/plugins/forward-auth.md @@ -63,9 +63,18 @@ APISIX will generate and send the request headers listed below to the authorizat First, you need to setup your external authorization service. The example below uses Apache APISIX's [serverless](./serverless.md) Plugin to mock the service: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/auth' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H 'Content-Type: application/json' \ -d '{ "uri": "/auth", @@ -95,7 +104,7 @@ Now you can configure the `forward-auth` Plugin to a specific Route: ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/1' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -d '{ "uri": "/headers", "plugins": { @@ -162,7 +171,7 @@ Location: http://example.com/auth To remove the `forward-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/google-cloud-logging.md b/docs/en/latest/plugins/google-cloud-logging.md index 3ea60f4db447..4a8313bf87ad 100644 --- a/docs/en/latest/plugins/google-cloud-logging.md +++ b/docs/en/latest/plugins/google-cloud-logging.md @@ -99,8 +99,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/google-cloud-logging -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/google-cloud-logging -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -123,7 +132,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows a complete configuration of the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "google-cloud-logging": { @@ -163,7 +172,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 The example below shows a bare minimum configuration of the Plugin on a Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "google-cloud-logging": { @@ -199,7 +208,7 @@ You can then login and view the logs in [Google Cloud Logging Service](https://c To remove the `google-cloud-logging` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/grpc-transcode.md b/docs/en/latest/plugins/grpc-transcode.md index bf8d91e1fd60..46285a6cfcd9 100644 --- a/docs/en/latest/plugins/grpc-transcode.md +++ b/docs/en/latest/plugins/grpc-transcode.md @@ -63,8 +63,17 @@ Before enabling the Plugin, you have to add the content of your `.proto` or `.pb You can use the `/admin/protos/id` endpoint and add the contents of the file to the `content` field: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/protos/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/protos/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -106,7 +115,7 @@ As the content of the proto is binary, we encode it in `base64` and configure th ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "'"$(base64 -w0 /path/to/proto.pb)"'" }' @@ -121,7 +130,7 @@ You should see an `HTTP/1.1 201 Created` response with the following: Now, we can enable the `grpc-transcode` Plugin to a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/111 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -175,7 +184,7 @@ Proxy-Connection: keep-alive You can also configure the `pb_option` as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/23 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/23 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/zeebe/WorkflowInstanceCreate", @@ -226,7 +235,7 @@ Upload the proto file: ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -248,7 +257,7 @@ Enable the `grpc-transcode` plugin,and set the option `show_status_in_body` to ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -296,7 +305,7 @@ Note that there is an undecoded field in the return body. If you need to decode ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -323,7 +332,7 @@ Also configure the option `status_detail_type` to `helloworld.ErrorDetail`. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -367,7 +376,7 @@ Server: APISIX web server To remove the `grpc-transcode` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/111 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/grpctest", "plugins": {}, diff --git a/docs/en/latest/plugins/grpc-web.md b/docs/en/latest/plugins/grpc-web.md index a43ef64c10e8..87391453a170 100644 --- a/docs/en/latest/plugins/grpc-web.md +++ b/docs/en/latest/plugins/grpc-web.md @@ -42,8 +42,17 @@ The `grpc-web` Plugin is a proxy Plugin that can process [gRPC Web](https://gith You can enable the `grpc-web` Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/grpc/web/*", "plugins":{ @@ -86,7 +95,7 @@ The supported `Content-Type` includes `application/grpc-web`, `application/grpc- To remove the `grpc-web` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/grpc/web/*", "plugins":{}, diff --git a/docs/en/latest/plugins/gzip.md b/docs/en/latest/plugins/gzip.md index 05d3b62c1969..e8ff94162021 100644 --- a/docs/en/latest/plugins/gzip.md +++ b/docs/en/latest/plugins/gzip.md @@ -54,8 +54,17 @@ This Plugin requires APISIX to run on [APISIX-Runtime](../FAQ.md#how-do-i-build- The example below enables the `gzip` Plugin on the specified Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -101,7 +110,7 @@ Warning: " to save to a file. To remove the `gzip` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/hmac-auth.md b/docs/en/latest/plugins/hmac-auth.md index 5940a52df3da..9a7fadc8aa36 100644 --- a/docs/en/latest/plugins/hmac-auth.md +++ b/docs/en/latest/plugins/hmac-auth.md @@ -54,8 +54,17 @@ NOTE: `encrypt_fields = {"secret_key"}` is also defined in the schema, which mea First we enable the Plugin on a Consumer object as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -80,7 +89,7 @@ You can also use the [APISIX Dashboard](/docs/dashboard/USER_GUIDE) to complete Next, you can configure the Plugin to a Route or a Service: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -362,7 +371,7 @@ Accept-Ranges: bytes To remove the `hmac-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/http-logger.md b/docs/en/latest/plugins/http-logger.md index 4ad87acd07c4..d07375b0bcea 100644 --- a/docs/en/latest/plugins/http-logger.md +++ b/docs/en/latest/plugins/http-logger.md @@ -114,9 +114,18 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -139,7 +148,7 @@ The example below shows how you can enable the Plugin on a specific Route: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "http-logger": { @@ -171,7 +180,7 @@ curl -i http://127.0.0.1:9080/hello To disable this Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/inspect.md b/docs/en/latest/plugins/inspect.md index 8b891b82dc6c..cbd876ceb687 100644 --- a/docs/en/latest/plugins/inspect.md +++ b/docs/en/latest/plugins/inspect.md @@ -101,9 +101,18 @@ plugin_attr: ## Example usage +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash # create test route -curl http://127.0.0.1:9180/apisix/admin/routes/test_limit_req -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/test_limit_req -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/get", diff --git a/docs/en/latest/plugins/ip-restriction.md b/docs/en/latest/plugins/ip-restriction.md index 0f9e4769f3cf..93eeb5c34b1a 100644 --- a/docs/en/latest/plugins/ip-restriction.md +++ b/docs/en/latest/plugins/ip-restriction.md @@ -52,8 +52,17 @@ Either one of `whitelist` or `blacklist` attribute must be specified. They canno You can enable the Plugin on a Route or a Service as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -115,7 +124,7 @@ HTTP/1.1 403 Forbidden To change the whitelisted/blacklisted IPs, you can update the Plugin configuration. The changes are hot reloaded and there is no need to restart the service. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -140,7 +149,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 To remove the `ip-restriction` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/jwe-decrypt.md b/docs/en/latest/plugins/jwe-decrypt.md index 6da75d2bb83e..3e55a316fdd9 100644 --- a/docs/en/latest/plugins/jwe-decrypt.md +++ b/docs/en/latest/plugins/jwe-decrypt.md @@ -62,8 +62,17 @@ For Route: First, create a Consumer with `jwe-decrypt` and configure the decryption key: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -78,7 +87,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Next, create a Route with `jwe-decrypt` enabled to decrypt the authorization header: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/anything*", @@ -99,7 +108,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 The Plugin creates an internal endpoint `/apisix/plugin/jwe/encrypt` to encrypt data with JWE. To expose it publicly, create a Route with the [public-api](public-api.md) Plugin: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/jwenew -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/jwenew -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/jwe/encrypt", "plugins": { @@ -174,7 +183,7 @@ Apisix-Plugins: jwe-decrypt To remove the `jwe-decrypt` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/anything*", diff --git a/docs/en/latest/plugins/jwt-auth.md b/docs/en/latest/plugins/jwt-auth.md index 41919d4c11a5..e44fd58a5880 100644 --- a/docs/en/latest/plugins/jwt-auth.md +++ b/docs/en/latest/plugins/jwt-auth.md @@ -78,8 +78,17 @@ To enable the Plugin, you have to create a Consumer object with the JWT token an First, you can create a Consumer object through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -96,7 +105,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 The `jwt-auth` Plugin uses the HS256 algorithm by default. To use the RS256 algorithm, you can configure the public key and private key and specify the algorithm: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "kerouac", "plugins": { @@ -115,7 +124,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Once you have created a Consumer object, you can configure a Route to authenticate requests: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -142,7 +151,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 You need to first setup a Route for an API that signs the token using the [public-api](public-api.md) Plugin: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/jas -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/jas -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/jwt/sign", "plugins": { @@ -254,7 +263,7 @@ Accept-Ranges: bytes To remove the `jwt-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/kafka-logger.md b/docs/en/latest/plugins/kafka-logger.md index 476442e50cda..ecf087c17fa6 100644 --- a/docs/en/latest/plugins/kafka-logger.md +++ b/docs/en/latest/plugins/kafka-logger.md @@ -146,8 +146,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/kafka-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/kafka-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -169,7 +178,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the `kafka-logger` Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "kafka-logger": { @@ -223,7 +232,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `kafka-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/key-auth.md b/docs/en/latest/plugins/key-auth.md index f8dd177db47c..93705111d5bc 100644 --- a/docs/en/latest/plugins/key-auth.md +++ b/docs/en/latest/plugins/key-auth.md @@ -58,8 +58,17 @@ To enable the Plugin, you have to create a Consumer object with an authenticatio First you can create a Consumer object through the [Admin API](../admin-api.md) with a unique key: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -83,7 +92,7 @@ You can then add the `key-auth` Plugin: Once you have created a Consumer object, you can then configure a Route or a Service to authenticate requests: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -150,7 +159,7 @@ HTTP/1.1 401 Unauthorized To remove the `key-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/ldap-auth.md b/docs/en/latest/plugins/ldap-auth.md index dac081dc52fb..7e33fc977f6c 100644 --- a/docs/en/latest/plugins/ldap-auth.md +++ b/docs/en/latest/plugins/ldap-auth.md @@ -58,8 +58,17 @@ For Route: First, you have to create a Consumer and enable the `ldap-auth` Plugin on it: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo", "plugins": { @@ -73,7 +82,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Now you can enable the Plugin on a specific Route or a Service as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -144,7 +153,7 @@ HTTP/1.1 401 Unauthorized To remove the `ldap-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/limit-conn.md b/docs/en/latest/plugins/limit-conn.md index f95995530a5a..82751d02edb8 100644 --- a/docs/en/latest/plugins/limit-conn.md +++ b/docs/en/latest/plugins/limit-conn.md @@ -61,9 +61,18 @@ The `limit-conn` Plugin limits the number of concurrent requests to your service You can enable the Plugin on a Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -90,7 +99,7 @@ You can also configure the `key_type` to `var_combination` as shown: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -139,7 +148,7 @@ To remove the `limit-conn` Plugin, you can delete the corresponding JSON configu ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -165,7 +174,7 @@ Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ws", "enable_websocket": true, diff --git a/docs/en/latest/plugins/limit-count.md b/docs/en/latest/plugins/limit-count.md index 7fbec44d6a06..4c019332a899 100644 --- a/docs/en/latest/plugins/limit-count.md +++ b/docs/en/latest/plugins/limit-count.md @@ -61,9 +61,18 @@ The `limit-count` Plugin limits the number of requests to your service by a give You can enable the Plugin on a Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -88,7 +97,7 @@ You can also configure the `key_type` to `var_combination` as shown: ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -113,7 +122,7 @@ You can also create a group to share the same counter across multiple Routes: ```shell curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -137,7 +146,7 @@ Now every Route which belongs to group `services_1#1640140620` (or the service w ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "service_id": "1", "uri": "/hello" @@ -146,7 +155,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/2 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "service_id": "1", "uri": "/hello2" @@ -165,7 +174,7 @@ You can also share the same limit counter for all your requests by setting the ` ```shell curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -200,7 +209,7 @@ The example below shows how you can use the `redis` policy: ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -230,7 +239,7 @@ Similarly you can also configure the `redis-cluster` policy: ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -262,7 +271,7 @@ case you have environment variables `REDIS_HOST` and `REDIS_PASSWORD` set, you c ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -341,7 +350,7 @@ To remove the `limit-count` Plugin, you can delete the corresponding JSON config ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/limit-req.md b/docs/en/latest/plugins/limit-req.md index b9e1ce5b6d9d..9c5aafbb38aa 100644 --- a/docs/en/latest/plugins/limit-req.md +++ b/docs/en/latest/plugins/limit-req.md @@ -61,8 +61,17 @@ The `limit-req` Plugin limits the number of requests to your service using the [ You can enable the Plugin on a Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -113,7 +122,7 @@ You can also configure the Plugin on specific consumers to limit their requests. First, you can create a Consumer and enable the `limit-req` Plugin on it: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "consumer_jack", "plugins": { @@ -135,7 +144,7 @@ In this example, the [key-auth](./key-auth.md) Plugin is used to authenticate th Next, create a Route and enable the `key-auth` Plugin: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -204,7 +213,7 @@ Server: APISIX web server To remove the `limit-req` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -223,7 +232,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 Similarly for removing the Plugin from a Consumer: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "consumer_jack", "plugins": { diff --git a/docs/en/latest/plugins/loggly.md b/docs/en/latest/plugins/loggly.md index c7318ce76850..a1838c2366f1 100644 --- a/docs/en/latest/plugins/loggly.md +++ b/docs/en/latest/plugins/loggly.md @@ -77,8 +77,17 @@ We support [Syslog](https://documentation.solarwinds.com/en/success_center/loggl APISIX supports [Syslog](https://documentation.solarwinds.com/en/success_center/loggly/content/admin/streaming-syslog-without-using-files.htm) and [HTTP/S](https://documentation.solarwinds.com/en/success_center/loggly/content/admin/http-bulk-endpoint.htm) protocols to send data to Loggly. Syslog lets you send RFC5424 compliant syslog events with fine-grained control. But, HTTP/S bulk endpoint is better while sending large batches of logs at a fast transmission speed. You can configure the metadata to update the protocol as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loggly -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loggly -H "X-API-KEY: $admin_key" -X PUT -d ' { "protocol": "http" }' @@ -93,7 +102,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loggly -H 'X-API-KEY: ed The example below shows a complete configuration of the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "loggly":{ @@ -126,7 +135,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 The example below shows a bare minimum configuration of the Plugin on a Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "loggly":{ @@ -160,7 +169,7 @@ You can then view the logs on your Loggly Dashboard: To remove the `file-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/loki-logger.md b/docs/en/latest/plugins/loki-logger.md index 2a9e160b962b..69d101782ef0 100644 --- a/docs/en/latest/plugins/loki-logger.md +++ b/docs/en/latest/plugins/loki-logger.md @@ -113,8 +113,17 @@ Configuring the plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -136,7 +145,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the `loki-logger` plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "loki-logger": { @@ -166,7 +175,7 @@ curl -i http://127.0.0.1:9080/hello When you need to remove the `loki-logger` plugin, you can delete the corresponding JSON configuration with the following command and APISIX will automatically reload the relevant configuration without restarting the service: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/mocking.md b/docs/en/latest/plugins/mocking.md index eaadc0b45d63..71324a17a8dc 100644 --- a/docs/en/latest/plugins/mocking.md +++ b/docs/en/latest/plugins/mocking.md @@ -126,8 +126,17 @@ This is the response generated by the Plugin from this JSON schema: The example below configures the `mocking` Plugin for a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -227,7 +236,7 @@ x-mock-by: APISIX/2.10.0 To remove the `mocking` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/mqtt-proxy.md b/docs/en/latest/plugins/mqtt-proxy.md index 85cdcdfcfc06..07668d142839 100644 --- a/docs/en/latest/plugins/mqtt-proxy.md +++ b/docs/en/latest/plugins/mqtt-proxy.md @@ -60,8 +60,17 @@ You can now send the MQTT request to port `9100`. You can now create a stream Route and enable the `mqtt-proxy` Plugin: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -89,7 +98,7 @@ If you are using Docker in macOS, then `host.docker.internal` is the right param This Plugin exposes a variable `mqtt_client_id` which can be used for load balancing as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -131,7 +140,7 @@ Configure `ssl` providing the CA certificate and the server certificate, togethe Here is an example of how create a stream_route which is using the `mqtt-proxy` plugin, providing the CA certificate, the client certificate and the client key (for self-signed certificates which are not trusted by your host, use the `-k` flag): ```shell -curl 127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl 127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -156,5 +165,5 @@ The `sni` name must match one or more of the SNIs provided to the SSL object tha To remove the `mqtt-proxy` Plugin you can remove the corresponding configuration as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X DELETE ``` diff --git a/docs/en/latest/plugins/multi-auth.md b/docs/en/latest/plugins/multi-auth.md index e79914743957..824259fc80da 100644 --- a/docs/en/latest/plugins/multi-auth.md +++ b/docs/en/latest/plugins/multi-auth.md @@ -48,8 +48,17 @@ To enable the Plugin, you have to create two or more Consumer objects with diffe First create a Consumer using basic authentication: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo1", "plugins": { @@ -64,7 +73,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Then create a Consumer using key authentication: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo2", "plugins": { @@ -78,7 +87,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 Once you have created Consumer objects, you can then configure a Route or a Service to authenticate requests: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -140,7 +149,7 @@ If the request is not authorized, an `401 Unauthorized` error will be thrown: To remove the `multi-auth` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/node-status.md b/docs/en/latest/plugins/node-status.md index 7ad41f42aa40..91e184c026c4 100644 --- a/docs/en/latest/plugins/node-status.md +++ b/docs/en/latest/plugins/node-status.md @@ -56,8 +56,17 @@ plugins: You have to the setup the Route for the status API and expose it using the [public-api](public-api.md) Plugin. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/ns -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/status", "plugins": { @@ -115,5 +124,5 @@ plugins: You can also remove the Route on `/apisix/status`: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +curl http://127.0.0.1:9180/apisix/admin/routes/ns -H "X-API-KEY: $admin_key" -X DELETE ``` diff --git a/docs/en/latest/plugins/ocsp-stapling.md b/docs/en/latest/plugins/ocsp-stapling.md index fe85579de66b..1991ccf0b17d 100644 --- a/docs/en/latest/plugins/ocsp-stapling.md +++ b/docs/en/latest/plugins/ocsp-stapling.md @@ -42,8 +42,17 @@ plugins: After modifying the config file, reload APISIX or send an hot-loaded HTTP request through the Admin API to take effect: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` ## Attributes @@ -64,7 +73,7 @@ Create an SSL Resource as such: ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -95,7 +104,7 @@ To disable OCSP stapling feature, you can make a request as shown below: ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -112,7 +121,7 @@ Make sure all your SSL Resource doesn't contains `ocsp_stapling` field anymore. ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -d ' +-H "X-API-KEY: $admin_key" -X PATCH -d ' { "ocsp_stapling": null }' @@ -129,5 +138,5 @@ plugins: After modifying the config file, reload APISIX or send an hot-loaded HTTP request through the Admin API to take effect: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` diff --git a/docs/en/latest/plugins/opa.md b/docs/en/latest/plugins/opa.md index cddc9bb4f3e8..12d79a2e36da 100644 --- a/docs/en/latest/plugins/opa.md +++ b/docs/en/latest/plugins/opa.md @@ -302,8 +302,17 @@ curl -X GET 127.0.0.1:9080/get To remove the `opa` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/openfunction.md b/docs/en/latest/plugins/openfunction.md index 098cf238f114..12340ee1de0c 100644 --- a/docs/en/latest/plugins/openfunction.md +++ b/docs/en/latest/plugins/openfunction.md @@ -76,8 +76,17 @@ kubectl create secret docker-registry push-secret \ You can now configure the Plugin on a specific Route and point to this running OpenFunction service: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -118,7 +127,7 @@ The `uri` configured on a Route must end with `*` for this feature to work prope The example below configures this feature: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello/*", "plugins": { @@ -147,7 +156,7 @@ Hello, 123! To remove the `openfunction` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/openid-connect.md b/docs/en/latest/plugins/openid-connect.md index 231ca6eaf9dd..951e8b6d5ed5 100644 --- a/docs/en/latest/plugins/openid-connect.md +++ b/docs/en/latest/plugins/openid-connect.md @@ -118,8 +118,17 @@ The image below shows an example token introspection flow via a Gateway: The example below shows how you can enable the Plugin on Route. The Route below will protect the Upstream by introspecting the token provided in the request header: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins":{ @@ -162,7 +171,7 @@ You can also provide the public key of the JWT token for verification. If you ha The example below shows how you can add public key introspection to a Route: ```bash -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins":{ @@ -198,7 +207,7 @@ Once the user has authenticated with the identity provider, the Plugin will obta The example below adds the Plugin with this mode of operation to the Route: ```bash -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/en/latest/plugins/opentelemetry.md b/docs/en/latest/plugins/opentelemetry.md index 330bb0c90566..eeaaf7253f67 100644 --- a/docs/en/latest/plugins/opentelemetry.md +++ b/docs/en/latest/plugins/opentelemetry.md @@ -122,8 +122,17 @@ plugins: Now, you can enable the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ @@ -150,7 +159,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1 To remove the `opentelemetry` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/en/latest/plugins/openwhisk.md b/docs/en/latest/plugins/openwhisk.md index 333d0aea2592..e9a4ab2b0190 100644 --- a/docs/en/latest/plugins/openwhisk.md +++ b/docs/en/latest/plugins/openwhisk.md @@ -82,8 +82,17 @@ wsk action update test <(echo 'function main(){return {"ready":true}}') --kind n You can now configure the Plugin on a specific Route and point to this running OpenWhisk service: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -116,7 +125,7 @@ This will give back the response from the action: To remove the `openwhisk` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/prometheus.md b/docs/en/latest/plugins/prometheus.md index f1eb20d87f4d..2db3e1a84044 100644 --- a/docs/en/latest/plugins/prometheus.md +++ b/docs/en/latest/plugins/prometheus.md @@ -137,8 +137,17 @@ The `prometheus` Plugin can be enabled with an empty table. The example below shows how you can configure the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -364,7 +373,7 @@ apisix_upstream_status{name="/apisix/routes/1",ip="52.86.68.46",port="80"} 1 To remove the `prometheus` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, @@ -398,7 +407,7 @@ stream_plugins: Then you need to configure the `prometheus` plugin on the stream route: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "prometheus":{} diff --git a/docs/en/latest/plugins/proxy-cache.md b/docs/en/latest/plugins/proxy-cache.md index 2cd5ec5ca5b2..34a6751124df 100644 --- a/docs/en/latest/plugins/proxy-cache.md +++ b/docs/en/latest/plugins/proxy-cache.md @@ -82,9 +82,18 @@ apisix: You can enable the Plugin on a Route as shown below. The Plugin uses the disk-based `cache_strategy` and `disk_cache_one` as the `cache_zone` by default: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": { @@ -112,7 +121,7 @@ You can enable the Plugin on a Route with in-memory `cache_strategy` and a corre ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": { @@ -185,7 +194,7 @@ To remove the `proxy-cache` Plugin, you can delete the corresponding JSON config ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": {}, diff --git a/docs/en/latest/plugins/proxy-control.md b/docs/en/latest/plugins/proxy-control.md index 48c8ce4a73cf..b0f1cb93241b 100644 --- a/docs/en/latest/plugins/proxy-control.md +++ b/docs/en/latest/plugins/proxy-control.md @@ -46,9 +46,18 @@ This Plugin requires APISIX to run on [APISIX-Runtime](../FAQ.md#how-do-i-build- The example below enables the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/upload", "plugins": { @@ -81,7 +90,7 @@ To remove the `proxy-control` Plugin, you can delete the corresponding JSON conf ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/upload", "upstream": { diff --git a/docs/en/latest/plugins/proxy-mirror.md b/docs/en/latest/plugins/proxy-mirror.md index 73b65f8e19c5..d67afc4fd773 100644 --- a/docs/en/latest/plugins/proxy-mirror.md +++ b/docs/en/latest/plugins/proxy-mirror.md @@ -65,9 +65,18 @@ plugin_attr: You can enable the Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "proxy-mirror": { @@ -135,7 +144,7 @@ To remove the `proxy-mirror` Plugin, you can delete the corresponding JSON confi ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/proxy-rewrite.md b/docs/en/latest/plugins/proxy-rewrite.md index ffee1440acd3..dc22e1c478dc 100644 --- a/docs/en/latest/plugins/proxy-rewrite.md +++ b/docs/en/latest/plugins/proxy-rewrite.md @@ -56,8 +56,17 @@ Header configurations are executed according to the following priorities: The example below enables the `proxy-rewrite` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", @@ -108,7 +117,7 @@ Once you send the request, you can check the Upstream `access.log` for its outpu To remove the `proxy-rewrite` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md index 1c275ff23dda..d55131992f0d 100644 --- a/docs/en/latest/plugins/public-api.md +++ b/docs/en/latest/plugins/public-api.md @@ -138,8 +138,17 @@ HTTP/1.1 401 Unauthorized To remove the `public-api` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/docs/en/latest/plugins/real-ip.md b/docs/en/latest/plugins/real-ip.md index 519d502fdce1..0bd945675e8f 100644 --- a/docs/en/latest/plugins/real-ip.md +++ b/docs/en/latest/plugins/real-ip.md @@ -57,8 +57,17 @@ If the address specified in `source` is missing or invalid, the Plugin would not The example below enables the `real-ip` Plugin on the specified Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -101,7 +110,7 @@ remote-port: 9080 To remove the `real-ip` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/plugins/redirect.md b/docs/en/latest/plugins/redirect.md index 0b725451d918..3ec556ba808d 100644 --- a/docs/en/latest/plugins/redirect.md +++ b/docs/en/latest/plugins/redirect.md @@ -57,8 +57,17 @@ The `redirect` Plugin can be used to configure redirects. The example below shows how you can enable the `redirect` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test/index.html", "plugins": { @@ -79,7 +88,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1 You can also use any built-in Nginx variables in the new URI: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test", "plugins": { @@ -120,7 +129,7 @@ The response shows the response code and the `Location` header implying that the The example below shows how you can redirect HTTP to HTTPS: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -149,7 +158,7 @@ Location: https://127.0.0.1:9443/hello To remove the `redirect` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/referer-restriction.md b/docs/en/latest/plugins/referer-restriction.md index fb3d358a0201..24cb17b8f5a3 100644 --- a/docs/en/latest/plugins/referer-restriction.md +++ b/docs/en/latest/plugins/referer-restriction.md @@ -49,8 +49,17 @@ Only one of `whitelist` or `blacklist` attribute must be specified. They cannot You can enable the Plugin on a specific Route or a Service as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -112,7 +121,7 @@ HTTP/1.1 200 OK To remove the `referer-restriction` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/request-id.md b/docs/en/latest/plugins/request-id.md index 95dd565b1a55..bc7b4ee1bba1 100644 --- a/docs/en/latest/plugins/request-id.md +++ b/docs/en/latest/plugins/request-id.md @@ -52,9 +52,18 @@ The Plugin will not add a unique ID if the request already has a header with the The example below enables the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -90,7 +99,7 @@ To remove the `request-id` Plugin, you can delete the corresponding JSON configu ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/en/latest/plugins/request-validation.md b/docs/en/latest/plugins/request-validation.md index bd0d80b7f048..54f4eef491e6 100644 --- a/docs/en/latest/plugins/request-validation.md +++ b/docs/en/latest/plugins/request-validation.md @@ -49,9 +49,18 @@ At least one of `header_schema` or `body_schema` should be filled in. You can configure the Plugin on a specific Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { @@ -288,7 +297,7 @@ To remove the `request-validation` Plugin, you can delete the corresponding JSON ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/en/latest/plugins/response-rewrite.md b/docs/en/latest/plugins/response-rewrite.md index 9f1312e0bed1..467fc60ee474 100644 --- a/docs/en/latest/plugins/response-rewrite.md +++ b/docs/en/latest/plugins/response-rewrite.md @@ -71,8 +71,17 @@ Only one of `body` or `filters` can be configured. The example below enables the `response-rewrite` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", @@ -162,7 +171,7 @@ So, if you have configured the `response-rewrite` Plugin, it do a force overwrit The example below shows how you can replace a key in the response body. Here, the key X-Amzn-Trace-Id is replaced with X-Amzn-Trace-Id-Replace by configuring the filters attribute using regex: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "response-rewrite":{ @@ -231,7 +240,7 @@ X-Server-id: 3 To remove the `response-rewrite` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", diff --git a/docs/en/latest/plugins/rocketmq-logger.md b/docs/en/latest/plugins/rocketmq-logger.md index 324ecfe51d9b..ff09c668eb1c 100644 --- a/docs/en/latest/plugins/rocketmq-logger.md +++ b/docs/en/latest/plugins/rocketmq-logger.md @@ -191,8 +191,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/rocketmq-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/rocketmq-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -214,7 +223,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the `rocketmq-logger` Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "rocketmq-logger": { @@ -256,7 +265,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `rocketmq-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload, and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/serverless.md b/docs/en/latest/plugins/serverless.md index 11f3c7c6377a..b49ac8c036be 100644 --- a/docs/en/latest/plugins/serverless.md +++ b/docs/en/latest/plugins/serverless.md @@ -83,8 +83,17 @@ Prior to v2.12.0, the phase `before_proxy` was called `balancer`. This was updat The example below enables the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -121,7 +130,7 @@ You will find a message "serverless pre-function" and "match uri /index.html" in To remove the `serverless` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/plugins/skywalking-logger.md b/docs/en/latest/plugins/skywalking-logger.md index 7150c0bb2f24..d1890eb4dd94 100644 --- a/docs/en/latest/plugins/skywalking-logger.md +++ b/docs/en/latest/plugins/skywalking-logger.md @@ -123,8 +123,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/skywalking-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/skywalking-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -146,7 +155,7 @@ With this configuration, your logs would be formatted as shown below: Once you have set up your SkyWalking OAP server, you can enable the Plugin on a specific Route as shown below: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "skywalking-logger": { @@ -176,7 +185,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `skywalking-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/skywalking.md b/docs/en/latest/plugins/skywalking.md index c9d2920328fc..e73ac9552eb0 100644 --- a/docs/en/latest/plugins/skywalking.md +++ b/docs/en/latest/plugins/skywalking.md @@ -108,8 +108,17 @@ Once you do this, a background timer will be created to report data to the SkyWa Now, you can enable the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ @@ -202,7 +211,7 @@ You should also be able to see traces from all services: To remove the `skywalking` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/en/latest/plugins/sls-logger.md b/docs/en/latest/plugins/sls-logger.md index 94199a856730..d779386fa234 100644 --- a/docs/en/latest/plugins/sls-logger.md +++ b/docs/en/latest/plugins/sls-logger.md @@ -98,8 +98,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/sls-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/sls-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -121,7 +130,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can configure the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "sls-logger": { @@ -161,7 +170,7 @@ Now if you check your Ali Cloud log server, you will be able to see the logs: To remove the `sls-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/splunk-hec-logging.md b/docs/en/latest/plugins/splunk-hec-logging.md index acfa77468434..826f41e011f4 100644 --- a/docs/en/latest/plugins/splunk-hec-logging.md +++ b/docs/en/latest/plugins/splunk-hec-logging.md @@ -95,8 +95,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/splunk-hec-logging -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/splunk-hec-logging -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -119,7 +128,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows a complete configuration of the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "splunk-hec-logging":{ @@ -151,7 +160,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 The example below shows a bare minimum configuration of the Plugin on a Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "splunk-hec-logging":{ @@ -188,7 +197,7 @@ You should be able to login and search these logs from your Splunk dashboard: To remove the `splunk-hec-logging` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/syslog.md b/docs/en/latest/plugins/syslog.md index 11142807dd03..8cba65e0eccb 100644 --- a/docs/en/latest/plugins/syslog.md +++ b/docs/en/latest/plugins/syslog.md @@ -75,8 +75,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/syslog -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/syslog -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -98,7 +107,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the Plugin for a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "syslog": { @@ -130,7 +139,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `syslog` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/tcp-logger.md b/docs/en/latest/plugins/tcp-logger.md index b163029cd143..53fd43e6609f 100644 --- a/docs/en/latest/plugins/tcp-logger.md +++ b/docs/en/latest/plugins/tcp-logger.md @@ -109,8 +109,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tcp-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tcp-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -131,7 +140,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the `tcp-logger` Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "tcp-logger": { @@ -165,7 +174,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `tcp-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/tencent-cloud-cls.md b/docs/en/latest/plugins/tencent-cloud-cls.md index 9895dc564a81..f1ee4c43d7d9 100644 --- a/docs/en/latest/plugins/tencent-cloud-cls.md +++ b/docs/en/latest/plugins/tencent-cloud-cls.md @@ -108,9 +108,18 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tencent-cloud-cls \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -133,7 +142,7 @@ The example below shows how you can enable the Plugin on a specific Route: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "tencent-cloud-cls": { @@ -173,7 +182,7 @@ To disable this Plugin, you can delete the corresponding JSON configuration from ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/en/latest/plugins/traffic-split.md b/docs/en/latest/plugins/traffic-split.md index 7c45aa9e7b90..3a206a92405c 100644 --- a/docs/en/latest/plugins/traffic-split.md +++ b/docs/en/latest/plugins/traffic-split.md @@ -81,9 +81,18 @@ If only the `weight` attribute is configured, it corresponds to the weight of th You can configure the Plugin on a Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -127,7 +136,7 @@ Alternatively, you can configure `upstream_id` if you have already configured an ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -180,7 +189,7 @@ To set this up, you can configure the `weight` attribute of your `weighted_upstr ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -254,7 +263,7 @@ To set this up, you can configure `match` rules based on the request headers as ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -326,7 +335,7 @@ In the example below, only one `vars` rule is configured and the multiple expres ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -402,7 +411,7 @@ In the example below, multiple `vars` rules are configured and they have an OR r ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -526,7 +535,7 @@ For example, when the request header `x-api-id` is equal to `1` it should be dir ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -622,7 +631,7 @@ To remove the `traffic-split` Plugin, you can delete the corresponding JSON conf ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/ua-restriction.md b/docs/en/latest/plugins/ua-restriction.md index c55ba973d2ff..4eee1043639b 100644 --- a/docs/en/latest/plugins/ua-restriction.md +++ b/docs/en/latest/plugins/ua-restriction.md @@ -51,8 +51,17 @@ A common scenario is to set crawler rules. `User-Agent` is the identity of the c You can enable the Plugin on a Route or a Service as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -101,7 +110,7 @@ You should receive an `HTTP/1.1 403 Forbidden` response with the following messa To remove the `ua-restriction` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/en/latest/plugins/udp-logger.md b/docs/en/latest/plugins/udp-logger.md index 9af8c98dece1..503566a07fd5 100644 --- a/docs/en/latest/plugins/udp-logger.md +++ b/docs/en/latest/plugins/udp-logger.md @@ -107,8 +107,17 @@ Configuring the Plugin metadata is global in scope. This means that it will take The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/udp-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/udp-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -129,7 +138,7 @@ With this configuration, your logs would be formatted as shown below: The example below shows how you can enable the Plugin on a specific Route: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "udp-logger": { @@ -162,7 +171,7 @@ curl -i http://127.0.0.1:9080/hello To remove the `udp-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/en/latest/plugins/uri-blocker.md b/docs/en/latest/plugins/uri-blocker.md index 18be67c04797..07cb77446a42 100644 --- a/docs/en/latest/plugins/uri-blocker.md +++ b/docs/en/latest/plugins/uri-blocker.md @@ -43,8 +43,17 @@ The `uri-blocker` Plugin intercepts user requests with a set of `block_rules`. The example below enables the `uri-blocker` Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "plugins": { @@ -98,7 +107,7 @@ Server: APISIX web server To remove the `uri-blocker` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { diff --git a/docs/en/latest/plugins/wolf-rbac.md b/docs/en/latest/plugins/wolf-rbac.md index 954c894ebf10..9ee62459c577 100644 --- a/docs/en/latest/plugins/wolf-rbac.md +++ b/docs/en/latest/plugins/wolf-rbac.md @@ -64,8 +64,17 @@ Once you have done that you need to add `application`, `admin`, `normal user`, ` You need to first configure the Plugin on a Consumer: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username":"wolf_rbac", "plugins":{ @@ -87,7 +96,7 @@ The `appid` added in the configuration should already exist in wolf. You can now add the Plugin to a Route or a Service: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/*", @@ -116,7 +125,7 @@ You can also use the [APISIX Dashboard](/docs/dashboard/USER_GUIDE) to complete You can use the `public-api` Plugin to expose the API: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/wal -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/wal -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/wolf-rbac/login", "plugins": { @@ -271,7 +280,7 @@ HTTP/1.1 200 OK To remove the `wolf-rbac` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/*", diff --git a/docs/en/latest/plugins/workflow.md b/docs/en/latest/plugins/workflow.md index 48fa0963d92e..2e2fdace19b8 100644 --- a/docs/en/latest/plugins/workflow.md +++ b/docs/en/latest/plugins/workflow.md @@ -65,9 +65,18 @@ In `rules`, match `case` in order according to the index of the `rules`, and exe You can configure the `workflow` plugin on a Route as shown below: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/hello/*", "plugins":{ @@ -153,7 +162,7 @@ To remove the `workflow` plugin, you can delete the corresponding JSON configura ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/hello/*", "upstream": { diff --git a/docs/en/latest/plugins/zipkin.md b/docs/en/latest/plugins/zipkin.md index 16d89bec8e30..3a4ec06dbc45 100644 --- a/docs/en/latest/plugins/zipkin.md +++ b/docs/en/latest/plugins/zipkin.md @@ -110,8 +110,17 @@ func main(){ The example below enables the Plugin on a specific Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -178,7 +187,7 @@ docker run -d --name jaeger \ Similar to configuring for Zipkin, create a Route and enable the Plugin: ``` -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -221,7 +230,7 @@ You can access the Jaeger UI to view the traces in endpoint [http://127.0.0.1:16 To remove the `zipkin` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 7f6bf7f971ec..b6e42e665e44 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -77,8 +77,17 @@ Note: In the matching rules, the `priority` field takes precedence over other ru Create two routes with different `priority` values ​​(the larger the value, the higher the priority). +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -92,7 +101,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ``` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -119,7 +128,7 @@ All requests will only hit the route of port `1980` because it has a priority of To understand this, look at the example of setting host matching rules: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -133,7 +142,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ``` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -192,7 +201,7 @@ For more details, see https://github.com/api7/lua-resty-radixtree/#parameters-in Nginx provides a variety of built-in variables that can be used to filter routes based on certain criteria. Here is an example of how to filter routes by Nginx built-in variables: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/index.html", "vars": [ @@ -220,7 +229,7 @@ APISIX supports filtering route by POST form attributes with `Content-Type` = `a We can define the following route: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "methods": ["POST", "GET"], "uri": "/_post", @@ -270,7 +279,7 @@ Where We can filter such route with: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "methods": ["POST", "GET"], "uri": "/graphql", diff --git a/docs/en/latest/ssl-protocol.md b/docs/en/latest/ssl-protocol.md index 53dbcfbc752b..654eb00ed952 100644 --- a/docs/en/latest/ssl-protocol.md +++ b/docs/en/latest/ssl-protocol.md @@ -79,11 +79,20 @@ apisix: ssl_ciphers: ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA ``` +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 2. Specify the TLSv1.1 protocol version for the test.com domain. ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -98,7 +107,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server2.crt)"'", "key": "'"$(cat server2.key)"'", @@ -197,7 +206,7 @@ Sometimes, we may encounter a situation where a certificate is associated with m ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -212,7 +221,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/2 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index 937a1a5afefb..963c291152d4 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -57,8 +57,17 @@ If `apisix.stream_proxy` is undefined in `conf/config.yaml`, you will encounter You can create a stream route using the Admin API `/stream_routes` endpoint. For example: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "remote_addr": "192.168.5.3", "upstream": { @@ -85,7 +94,7 @@ Currently there are three attributes in stream routes that can be used for filte Here is an example: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "server_addr": "127.0.0.1", "server_port": 2000, @@ -128,7 +137,7 @@ Here is an example with MySQL: 3. Now we are going to create a stream route with server filtering: ```shell - curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "server_addr": "127.0.0.10", "server_port": 9101, @@ -186,7 +195,7 @@ mTLS is also supported, see [Protect Route](./mtls.md#protect-route) for how to Third, we need to configure a stream route to match and proxy it to the upstream: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -200,7 +209,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 When the connection is TLS over TCP, we can use the SNI to match a route, like: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "sni": "a.test.com", "upstream": { @@ -219,7 +228,7 @@ In this case, a connection handshaked with SNI `a.test.com` will be proxied to ` APISIX also supports proxying to TLS over TCP upstream. ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "scheme": "tls", diff --git a/docs/en/latest/terminology/consumer-group.md b/docs/en/latest/terminology/consumer-group.md index 2f91657805ee..88f437cae348 100644 --- a/docs/en/latest/terminology/consumer-group.md +++ b/docs/en/latest/terminology/consumer-group.md @@ -39,9 +39,18 @@ The example below illustrates how to create a Consumer Group and bind it to a Co Create a Consumer Group which shares the same rate limiting quota: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -58,7 +67,7 @@ Create a Consumer within the Consumer Group: ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { diff --git a/docs/en/latest/terminology/consumer.md b/docs/en/latest/terminology/consumer.md index c7f457d52132..17fc7d8f5010 100644 --- a/docs/en/latest/terminology/consumer.md +++ b/docs/en/latest/terminology/consumer.md @@ -74,11 +74,20 @@ For more information about the Consumer object, you can refer to the [Admin API The example below shows how you can enable a Plugin for a specific Consumer. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. Create a Consumer, specify the authentication plugin `key-auth`, and enable the specific plugin `limit-count`. ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -99,7 +108,7 @@ The example below shows how you can enable a Plugin for a specific Consumer. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {} @@ -133,7 +142,7 @@ We can use the [consumer-restriction](../plugins/consumer-restriction.md) Plugin ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {}, diff --git a/docs/en/latest/terminology/global-rule.md b/docs/en/latest/terminology/global-rule.md index 84726ed32155..1007f4b05ad2 100644 --- a/docs/en/latest/terminology/global-rule.md +++ b/docs/en/latest/terminology/global-rule.md @@ -36,11 +36,20 @@ Compared with the plugin configuration in Route, Service, Plugin Config, and Con The example below shows how you can use the `limit-count` Plugin on all requests: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -X PUT \ http://{apisix_listen_address}/apisix/admin/global_rules/1 \ -H 'Content-Type: application/json' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -d '{ "plugins": { "limit-count": { @@ -57,5 +66,5 @@ curl -X PUT \ You can also list all the Global rules by making this request with the Admin API: ```shell -curl http://{apisix_listen_address}/apisix/admin/global_rules -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' +curl http://{apisix_listen_address}/apisix/admin/global_rules -H "X-API-KEY: $admin_key" ``` diff --git a/docs/en/latest/terminology/plugin-config.md b/docs/en/latest/terminology/plugin-config.md index 4ed78e6d5776..88476d44a716 100644 --- a/docs/en/latest/terminology/plugin-config.md +++ b/docs/en/latest/terminology/plugin-config.md @@ -36,9 +36,18 @@ While configuring the same plugin, only one copy of the configuration is valid. The example below illustrates how to create a Plugin Config and bind it to a Route: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "desc": "blah", "plugins": { @@ -80,7 +89,7 @@ For example, if you configure a Plugin Config as shown below: ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "desc": "I am plugin_config 1", "plugins": { @@ -103,7 +112,7 @@ to a Route as shown below, ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uris": ["/index.html"], "plugin_config_id": 1, @@ -132,7 +141,7 @@ the effective configuration will be as the one shown below: ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uris": ["/index.html"], "upstream": { diff --git a/docs/en/latest/terminology/plugin-metadata.md b/docs/en/latest/terminology/plugin-metadata.md index 77aae9c94e4f..93ece32a6ccc 100644 --- a/docs/en/latest/terminology/plugin-metadata.md +++ b/docs/en/latest/terminology/plugin-metadata.md @@ -50,9 +50,18 @@ Plugin metadata objects should only be used for plugins that have metadata field The example below shows how you can configure through the Admin API: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", diff --git a/docs/en/latest/terminology/plugin.md b/docs/en/latest/terminology/plugin.md index 051fef32b07d..66fff7afdd3c 100644 --- a/docs/en/latest/terminology/plugin.md +++ b/docs/en/latest/terminology/plugin.md @@ -293,8 +293,17 @@ curl -v /dev/null http://127.0.0.1:9080/get?version=v2 -H"host:httpbin.org" APISIX Plugins are hot-loaded. This means that there is no need to restart the service if you add, delete, modify plugins, or even if you update the plugin code. To hot-reload, you can send an HTTP request through the [Admin API](../admin-api.md): +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` :::note diff --git a/docs/en/latest/terminology/route.md b/docs/en/latest/terminology/route.md index 896ee6fb5ba6..6300717dd058 100644 --- a/docs/en/latest/terminology/route.md +++ b/docs/en/latest/terminology/route.md @@ -50,9 +50,18 @@ These shortcomings are independently abstracted in APISIX by two concepts: [Serv The Route example shown below proxies the request with the URL `/index.html` to the Upstream service with the address `127.0.0.1:1980`. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/en/latest/terminology/secret.md b/docs/en/latest/terminology/secret.md index 8f0ec11a7a15..c38ffb68ca1b 100644 --- a/docs/en/latest/terminology/secret.md +++ b/docs/en/latest/terminology/secret.md @@ -99,9 +99,18 @@ export JACK_AUTH_KEY=abc Step 2: Reference the environment variable in the `key-auth` plugin +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -141,7 +150,7 @@ Step 2: Add APISIX Secrets resources through the Admin API, configure the Vault ```shell curl http://127.0.0.1:9180/apisix/admin/secrets/vault/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "https://127.0.0.1:8200", "prefix": "apisix", @@ -163,7 +172,7 @@ Step 3: Reference the APISIX Secrets resource in the `key-auth` plugin and fill ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { diff --git a/docs/en/latest/terminology/service.md b/docs/en/latest/terminology/service.md index 0e08b890c16e..69a0042823ab 100644 --- a/docs/en/latest/terminology/service.md +++ b/docs/en/latest/terminology/service.md @@ -37,11 +37,20 @@ For more information about Service, please refer to [Admin API Service object](. The following example creates a Service that enables the `limit-count` Plugin and then binds it to the Routes with the ids `100` and `101`. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. Create a Service. ```shell curl http://127.0.0.1:9180/apisix/admin/services/200 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -64,7 +73,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/200 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/100 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -74,7 +83,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/200 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/101 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/foo/index.html", @@ -86,7 +95,7 @@ We can also specify different Plugins or Upstream for the Routes than the ones d ```shell curl http://127.0.0.1:9180/apisix/admin/routes/102 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/bar/index.html", "id": "102", diff --git a/docs/en/latest/terminology/upstream.md b/docs/en/latest/terminology/upstream.md index c0cda0708689..4d8733ab197a 100644 --- a/docs/en/latest/terminology/upstream.md +++ b/docs/en/latest/terminology/upstream.md @@ -45,9 +45,18 @@ In addition to the equalization algorithm selections, Upstream also supports pas To create an Upstream object, you can use the Admin API as shown below. +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "type": "chash", "key": "remote_addr", @@ -62,7 +71,7 @@ After creating an Upstream object, it can be referenced by a specific Route or S ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream_id": 1 @@ -73,7 +82,7 @@ For convenience, you can directly bind the upstream address to a Route or Servic ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -99,7 +108,7 @@ The example below shows how you can configure a health check. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -144,7 +153,7 @@ Creating a Consumer object. ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -159,7 +168,7 @@ Creating a Route object and enabling the `key-auth` authentication Plugin. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {} @@ -188,7 +197,7 @@ Creating a Route and an upstream object. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hash_on_cookie", "upstream": { @@ -216,7 +225,7 @@ Creating a Route and an upstream object. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hash_on_header", "upstream": { @@ -235,6 +244,6 @@ The client can now send requests with a header. The example below shows using th ```shell curl http://127.0.0.1:9080/hash_on_header \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H "Content-Type: application/json" ``` diff --git a/docs/en/latest/tutorials/cache-api-responses.md b/docs/en/latest/tutorials/cache-api-responses.md index 92538cf7bcd7..9ee23f888593 100644 --- a/docs/en/latest/tutorials/cache-api-responses.md +++ b/docs/en/latest/tutorials/cache-api-responses.md @@ -100,8 +100,17 @@ proxy_cache: Next, we can directly run `apisix reload` command to reload the latest plugin code without restarting Apache APISIX. See the command to reload the newly added plugin: +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ``` shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` Then, we run two more curl commands to configure an Upstream and Route for the `/api/products` endpoint. The following command creates a sample upstream (that's our API Server): diff --git a/docs/en/latest/tutorials/client-to-apisix-mtls.md b/docs/en/latest/tutorials/client-to-apisix-mtls.md index 8c3b1c66c822..303bc00b638d 100644 --- a/docs/en/latest/tutorials/client-to-apisix-mtls.md +++ b/docs/en/latest/tutorials/client-to-apisix-mtls.md @@ -206,11 +206,20 @@ instead of alert error in the SSL handshake phase, if the client certificate is ### Example +:::note +You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. Configure route and ssl via admin API ```bash curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { @@ -221,7 +230,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ }' curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert": "'"$(" }' @@ -82,7 +92,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/azure-functions \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "azure-functions": { @@ -154,7 +164,7 @@ Hello, APISIX ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "azure-functions": { @@ -191,7 +201,7 @@ Hello, APISIX ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/azure", "plugins": {}, diff --git a/docs/zh/latest/plugins/basic-auth.md b/docs/zh/latest/plugins/basic-auth.md index eaded4128017..d0e212dcf2da 100644 --- a/docs/zh/latest/plugins/basic-auth.md +++ b/docs/zh/latest/plugins/basic-auth.md @@ -55,9 +55,19 @@ Route 端: 如果需要启用插件,就必须创建一个具有身份验证配置的 Consumer: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo", "plugins": { @@ -81,7 +91,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -135,7 +145,7 @@ HTTP/1.1 401 Unauthorized ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/batch-requests.md b/docs/zh/latest/plugins/batch-requests.md index 58a4b37c2760..045f3c288bf7 100644 --- a/docs/zh/latest/plugins/batch-requests.md +++ b/docs/zh/latest/plugins/batch-requests.md @@ -71,9 +71,19 @@ plugins: 默认情况下,可以发送到 `/apisix/batch-requests` 的最大请求体不能大于 1 MiB。你可以通过 `apisix/admin/plugin_metadata/batch-requests` 更改插件的此配置: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/batch-requests \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "max_body_size": 4194304 }' @@ -131,7 +141,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/batch-requests \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/br \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/batch-requests", "plugins": { @@ -148,7 +158,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/br \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/batch-requests", "plugins": { diff --git a/docs/zh/latest/plugins/brotli.md b/docs/zh/latest/plugins/brotli.md index 95f85a4e57f4..be13d1a95f80 100644 --- a/docs/zh/latest/plugins/brotli.md +++ b/docs/zh/latest/plugins/brotli.md @@ -64,8 +64,18 @@ sudo ldconfig 如下示例中,在指定的路由上启用 `brotli` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/", "plugins": { @@ -110,7 +120,7 @@ Warning: " to save to a file. 当您需要禁用 `brotli` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/", "upstream": { diff --git a/docs/zh/latest/plugins/chaitin-waf.md b/docs/zh/latest/plugins/chaitin-waf.md index 8d8331caac1d..e090c9213b69 100644 --- a/docs/zh/latest/plugins/chaitin-waf.md +++ b/docs/zh/latest/plugins/chaitin-waf.md @@ -69,8 +69,18 @@ description: 本文介绍了关于 Apache APISIX `chaitin-waf` 插件的基本 一个典型的示例配置如下: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H "X-API-KEY: $admin_key" -X PUT -d ' { "nodes":[ { @@ -100,7 +110,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf -H 'X-API-KE 一个典型的示例配置如下,这里使用 `httpbun.org` 作为示例后端,可以按需替换: ```bash -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "plugins": { @@ -240,7 +250,7 @@ Set-Cookie: sl-session=UdywdGL+uGS7q8xMfnJlbQ==; Domain=; Path=/; Max-Age=86400 当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```bash -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { diff --git a/docs/zh/latest/plugins/clickhouse-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md index f719a40e7848..f482f449d362 100644 --- a/docs/zh/latest/plugins/clickhouse-logger.md +++ b/docs/zh/latest/plugins/clickhouse-logger.md @@ -105,9 +105,19 @@ description: 本文介绍了 API 网关 Apache APISIX 如何使用 clickhouse-lo | ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ | | log_format | object | 否 | | | 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX](../apisix-variable.md) 或 [NGINX](http://nginx.org/en/docs/varindex.html) 变量。该配置全局生效。如果你指定了 `log_format`,该配置就会对所有绑定 `clickhouse-logger` 的路由或服务生效。| +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/clickhouse-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -136,7 +146,7 @@ curl -X POST 'http://localhost:8123/' \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "clickhouse-logger": { @@ -184,7 +194,7 @@ curl 'http://localhost:8123/?query=select%20*%20from%20default.test' ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/client-control.md b/docs/zh/latest/plugins/client-control.md index fa73680d0322..529c73de8c82 100644 --- a/docs/zh/latest/plugins/client-control.md +++ b/docs/zh/latest/plugins/client-control.md @@ -46,9 +46,19 @@ description: 本文介绍了 Apache APISIX proxy-control 插件的相关操作 以下示例展示了如何在指定路由上启用 `client-control` 插件,并设置 `max_body_size`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -93,7 +103,7 @@ HTTP/1.1 413 Request Entity Too Large ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/consumer-restriction.md b/docs/zh/latest/plugins/consumer-restriction.md index 15f96c78cfe2..bfca572cca23 100644 --- a/docs/zh/latest/plugins/consumer-restriction.md +++ b/docs/zh/latest/plugins/consumer-restriction.md @@ -60,8 +60,18 @@ description: Consumer Restriction 插件允许用户根据 Route、Service、Con 首先,创建两个 Consumer,分别为 `jack1` 和 `jack2`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "username": "jack1", "plugins": { @@ -72,7 +82,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 } }' -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "username": "jack2", "plugins": { @@ -87,7 +97,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 然后,在指定路由上启用并配置 `consumer-restriction` 插件,并通过将 `consumer_name` 加入 `whitelist` 来限制不同 Consumer 的访问: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -138,7 +148,7 @@ HTTP/1.1 403 Forbidden 然后,在指定路由上启用并配置 `consumer-restriction` 插件,并且仅允许 `jack1` 使用 `POST` 方法进行访问: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -176,7 +186,7 @@ HTTP/1.1 403 Forbidden 现在更新插件配置,增加 `jack1` 的 `GET` 访问能力: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -214,7 +224,7 @@ HTTP/1.1 200 OK 首先,创建两个 Service: ```shell -curl http://127.0.0.1:9180/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/services/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -225,7 +235,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f "desc": "new service 001" }' -curl http://127.0.0.1:9180/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/services/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -240,7 +250,7 @@ curl http://127.0.0.1:9180/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f 在指定 Consumer 上配置 `key-auth` 和 `consumer-restriction` 插件,并通过将 `service_id` 加入 `whitelist` 来限制 Consumer 对 Service 的访问: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "new_consumer", "plugins": { @@ -263,7 +273,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 在指定路由上启用并配置 `key-auth` 插件,并绑定 `service_id` 为 `1`: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -293,7 +303,7 @@ HTTP/1.1 200 OK 更新配置 `key-auth` 插件,并绑定 `service_id` 为 `2`: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -327,7 +337,7 @@ HTTP/1.1 403 Forbidden 当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/cors.md b/docs/zh/latest/plugins/cors.md index 0ced5a57dd45..be85cab211e7 100644 --- a/docs/zh/latest/plugins/cors.md +++ b/docs/zh/latest/plugins/cors.md @@ -62,8 +62,18 @@ description: 本文介绍了 Apache APISIX cors 插件的基本信息及使用 你可以通过如下命令在指定路由上启用 `cors` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -104,7 +114,7 @@ curl http://127.0.0.1:9080/hello -v 当你需要禁用 `cors` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/csrf.md b/docs/zh/latest/plugins/csrf.md index 555b0038ba39..49eb4bbb19cf 100644 --- a/docs/zh/latest/plugins/csrf.md +++ b/docs/zh/latest/plugins/csrf.md @@ -49,8 +49,18 @@ description: CSRF 插件基于 Double Submit Cookie 的方式,帮助用户阻 以下示例展示了如何在指定路由上启用并配置 `csrf` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -132,7 +142,7 @@ HTTP/1.1 200 OK 当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/docs/zh/latest/plugins/datadog.md b/docs/zh/latest/plugins/datadog.md index 76219dad55ff..7bb50d2b57d1 100644 --- a/docs/zh/latest/plugins/datadog.md +++ b/docs/zh/latest/plugins/datadog.md @@ -88,8 +88,18 @@ docker run -d --name dogstatsd-agent -e DD_API_KEY= -p 本小节介绍了如何在指定路由上启用 `datadog` 插件。进行以下操作之前请确认您的 Datadog Agent 已经启动并正常运行。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "datadog": {} @@ -112,7 +122,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 APISIX 插件是支持热加载的,所以不用重新启动 APISIX,配置就能生效。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -133,7 +143,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 向 `/apisix/admin/plugin_metadata/datadog` 发起请求,更改其元数据。操作示例如下: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H "X-API-KEY: $admin_key" -X PUT -d ' { "host": "172.168.45.29", "port": 8126, @@ -151,7 +161,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog -H 'X-API-KEY: e ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{}' +-H "X-API-KEY: $admin_key" -X PUT -d '{}' ``` ## 配置属性 diff --git a/docs/zh/latest/plugins/dubbo-proxy.md b/docs/zh/latest/plugins/dubbo-proxy.md index 48dc2cf83184..5d748e7bfd8d 100644 --- a/docs/zh/latest/plugins/dubbo-proxy.md +++ b/docs/zh/latest/plugins/dubbo-proxy.md @@ -58,8 +58,18 @@ plugins: 这里有个例子,在指定的路由中启用 `dubbo-proxy` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "nodes": { "127.0.0.1:20880": 1 @@ -67,7 +77,7 @@ curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f03433 "type": "roundrobin" }' -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uris": [ "/hello" @@ -119,7 +129,7 @@ blahblah # "body" will be the body 当你想在某个路由或服务中禁用 `dubbo-proxy` 插件,非常简单,你可以直接删除插件配置中的 `json` 配置,不需要重启服务就能立即生效: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/zh/latest/plugins/echo.md b/docs/zh/latest/plugins/echo.md index 4ce489f09ccc..e3920bbfaf60 100644 --- a/docs/zh/latest/plugins/echo.md +++ b/docs/zh/latest/plugins/echo.md @@ -59,9 +59,29 @@ description: 本文介绍了关于 Apache APISIX `echo` 插件的基本信息及 以下示例展示了如何在指定路由中启用 `echo` 插件。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "echo": { @@ -98,7 +118,7 @@ before the body modification hello world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/elasticsearch-logger.md b/docs/zh/latest/plugins/elasticsearch-logger.md index 7b0022e29ef0..06130f425155 100644 --- a/docs/zh/latest/plugins/elasticsearch-logger.md +++ b/docs/zh/latest/plugins/elasticsearch-logger.md @@ -104,9 +104,19 @@ description: 本文介绍了 API 网关 Apache APISIX 的 elasticsearch-logger ### 完整配置示例 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "elasticsearch-logger":{ @@ -143,7 +153,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "elasticsearch-logger":{ @@ -242,7 +252,7 @@ curl -X GET "http://127.0.0.1:9200/services/_search" | jq . ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/elasticsearch-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -303,7 +313,7 @@ curl -X GET "http://127.0.0.1:9200/services/_search" | jq . ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/elasticsearch-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +-H "X-API-KEY: $admin_key" -X DELETE ``` ## 删除插件 @@ -312,7 +322,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/elasticsearch-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{}, "upstream":{ diff --git a/docs/zh/latest/plugins/error-log-logger.md b/docs/zh/latest/plugins/error-log-logger.md index f8fab500600a..d9d559031fca 100644 --- a/docs/zh/latest/plugins/error-log-logger.md +++ b/docs/zh/latest/plugins/error-log-logger.md @@ -99,9 +99,19 @@ plugins: # plugin list 你可以通过配置插件元数据来设置 TCP 服务器地址,如下所示: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "tcp": { "host": "127.0.0.1", @@ -117,7 +127,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "skywalking": { "endpoint_addr": "http://127.0.0.1:12800/v3/logs" @@ -134,7 +144,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "clickhouse": { "user": "default", @@ -152,7 +162,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/error-log-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "kafka":{ "brokers":[ diff --git a/docs/zh/latest/plugins/ext-plugin-post-resp.md b/docs/zh/latest/plugins/ext-plugin-post-resp.md index 35fb72f7a0de..e4cacbe4cad8 100644 --- a/docs/zh/latest/plugins/ext-plugin-post-resp.md +++ b/docs/zh/latest/plugins/ext-plugin-post-resp.md @@ -59,9 +59,19 @@ External Plugin 执行的结果会影响当前请求的响应。 以下示例展示了如何在指定路由中启用 `ext-plugin-post-resp` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -96,7 +106,7 @@ curl -i http://127.0.0.1:9080/index.html ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/ext-plugin-pre-req.md b/docs/zh/latest/plugins/ext-plugin-pre-req.md index 3ad41500a749..4944501dc440 100644 --- a/docs/zh/latest/plugins/ext-plugin-pre-req.md +++ b/docs/zh/latest/plugins/ext-plugin-pre-req.md @@ -50,9 +50,19 @@ External Plugin 执行的结果会影响当前请求的行为。 以下示例展示了如何在指定路由中启用 `ext-plugin-pre-req` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -87,7 +97,7 @@ curl -i http://127.0.0.1:9080/index.html ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/fault-injection.md b/docs/zh/latest/plugins/fault-injection.md index 9ef8be668ac0..c0ae512cd3d3 100644 --- a/docs/zh/latest/plugins/fault-injection.md +++ b/docs/zh/latest/plugins/fault-injection.md @@ -79,9 +79,19 @@ description: 本文介绍了关于 Apache APISIX `fault-injection` 插件的基 你可以在指定路由启用 `fault-injection` 插件,并指定 `abort` 属性。如下所示: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -105,7 +115,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -128,7 +138,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -208,7 +218,7 @@ sys 0m0.010s ```Shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "fault-injection": { @@ -275,7 +285,7 @@ Fault Injection! ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/file-logger.md b/docs/zh/latest/plugins/file-logger.md index 87cd6e6ae041..bbd81c4581ff 100644 --- a/docs/zh/latest/plugins/file-logger.md +++ b/docs/zh/latest/plugins/file-logger.md @@ -113,9 +113,19 @@ description: API 网关 Apache APISIX file-logger 插件可用于将日志数据 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/file-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -138,7 +148,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/file-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "file-logger": { @@ -175,7 +185,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "file-logger": { @@ -217,7 +227,7 @@ curl -i http://127.0.0.1:9080/hello?name=rose ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/forward-auth.md b/docs/zh/latest/plugins/forward-auth.md index 82aa5f4c12ce..c5aa64241acc 100644 --- a/docs/zh/latest/plugins/forward-auth.md +++ b/docs/zh/latest/plugins/forward-auth.md @@ -62,9 +62,19 @@ APISIX 将生成并发送如下所示的请求头到认证服务: 首先,你需要设置一个外部认证服务。以下示例使用的是 Apache APISIX 无服务器插件模拟服务: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/auth' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H 'Content-Type: application/json' \ -d '{ "uri": "/auth", @@ -94,7 +104,7 @@ curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/auth' \ ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/1' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -d '{ "uri": "/headers", "plugins": { @@ -164,7 +174,7 @@ Location: http://example.com/auth ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/google-cloud-logging.md b/docs/zh/latest/plugins/google-cloud-logging.md index a0bf33a9f461..d0e0ba5c4a26 100644 --- a/docs/zh/latest/plugins/google-cloud-logging.md +++ b/docs/zh/latest/plugins/google-cloud-logging.md @@ -97,9 +97,19 @@ description: API 网关 Apache APISIX 的 google-cloud-logging 插件可用于 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/google-cloud-logging \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -123,7 +133,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/google-cloud-logging \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "google-cloud-logging": { @@ -163,7 +173,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "google-cloud-logging": { @@ -206,7 +216,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/grpc-transcode.md b/docs/zh/latest/plugins/grpc-transcode.md index aea2e3177941..10052d7d08c2 100644 --- a/docs/zh/latest/plugins/grpc-transcode.md +++ b/docs/zh/latest/plugins/grpc-transcode.md @@ -63,9 +63,19 @@ APISIX 接收 HTTP 请求后,首先对请求进行转码,并将转码后的 可以使用 `/admin/protos/id` 接口将文件的内容添加到 `content` 字段: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -107,7 +117,7 @@ protoc --include_imports --descriptor_set_out=proto.pb proto/helloworld.proto ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "'"$(base64 -w0 /path/to/proto.pb)"'" }' @@ -123,7 +133,7 @@ curl http://127.0.0.1:9180/apisix/admin/protos/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -179,7 +189,7 @@ Proxy-Connection: keep-alive 你也可以配置 `pb_option`,如下所示: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/23 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/23 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/zeebe/WorkflowInstanceCreate", @@ -230,7 +240,7 @@ Trailer: grpc-message ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -252,7 +262,7 @@ curl http://127.0.0.1:9180/apisix/admin/protos/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -300,7 +310,7 @@ Server: APISIX web server ```shell curl http://127.0.0.1:9180/apisix/admin/protos/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "content" : "syntax = \"proto3\"; package helloworld; @@ -327,7 +337,7 @@ curl http://127.0.0.1:9180/apisix/admin/protos/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/grpctest", @@ -371,7 +381,7 @@ Server: APISIX web server 当你需要禁用 `grpc-transcode` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/111 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/grpctest", "plugins": {}, diff --git a/docs/zh/latest/plugins/grpc-web.md b/docs/zh/latest/plugins/grpc-web.md index 76f4d3dcffb5..c8b901e089f0 100644 --- a/docs/zh/latest/plugins/grpc-web.md +++ b/docs/zh/latest/plugins/grpc-web.md @@ -42,9 +42,19 @@ description: 本文介绍了关于 Apache APISIX `grpc-web` 插件的基本信 你可以通过如下命令在指定路由上启用 `gRPC-web` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/grpc/web/*", "plugins":{ @@ -88,7 +98,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/grpc/web/*", "plugins":{}, diff --git a/docs/zh/latest/plugins/gzip.md b/docs/zh/latest/plugins/gzip.md index 39be90fc9f3e..a9546d7932cb 100644 --- a/docs/zh/latest/plugins/gzip.md +++ b/docs/zh/latest/plugins/gzip.md @@ -54,9 +54,19 @@ description: 本文介绍了关于 Apache APISIX `gzip` 插件的基本信息及 以下示例展示了如何在指定路由中启用 `gzip` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -103,7 +113,7 @@ Warning: " to save to a file. ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/hmac-auth.md b/docs/zh/latest/plugins/hmac-auth.md index c5a07f5f1efa..a0eb74a78081 100644 --- a/docs/zh/latest/plugins/hmac-auth.md +++ b/docs/zh/latest/plugins/hmac-auth.md @@ -54,9 +54,19 @@ description: 本文介绍了关于 Apache APISIX `hmac-auth` 插件的基本信 首先,我们需要在 Consumer 中启用该插件,如下所示: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -82,7 +92,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -387,7 +397,7 @@ Accept-Ranges: bytes ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/http-logger.md b/docs/zh/latest/plugins/http-logger.md index 7ea6e1242d86..1903ddd8b134 100644 --- a/docs/zh/latest/plugins/http-logger.md +++ b/docs/zh/latest/plugins/http-logger.md @@ -108,9 +108,19 @@ description: 本文介绍了 API 网关 Apache APISIX 的 http-logger 插件。 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -133,7 +143,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "http-logger": { @@ -166,7 +176,7 @@ curl -i http://127.0.0.1:9080/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/ip-restriction.md b/docs/zh/latest/plugins/ip-restriction.md index 66db9829ade5..95757f8a0129 100644 --- a/docs/zh/latest/plugins/ip-restriction.md +++ b/docs/zh/latest/plugins/ip-restriction.md @@ -52,8 +52,18 @@ description: 本文介绍了 Apache APISIX ip-restriction 插件的基本信息 以下示例展示了如何在特定路由上启用 `ip-restriction` 插件,并配置 `whitelist` 属性: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -119,7 +129,7 @@ HTTP/1.1 403 Forbidden 如果你需要更改白名单或黑名单的 IP 地址,你只需更新插件配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -144,7 +154,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 当你需要禁用 `ip-restriction` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/jwe-decrypt.md b/docs/zh/latest/plugins/jwe-decrypt.md index cf7363e27adb..b3bc92fb5432 100644 --- a/docs/zh/latest/plugins/jwe-decrypt.md +++ b/docs/zh/latest/plugins/jwe-decrypt.md @@ -62,8 +62,18 @@ Route 配置: 首先,基于 `jwe-decrypt` 插件创建一个 Consumer,并且配置解密密钥: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -78,7 +88,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 下一步,基于 `jwe-decrypt` 插件创建一个路由,用于解密 authorization 请求头: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/anything*", @@ -99,7 +109,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 该插件创建了一个内部的 API `/apisix/plugin/jwe/encrypt` 以使用 JWE 进行加密。要公开它,需要创建一个对应的路由,并启用 [public-api](public-api.md) 插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/jwenew -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/jwenew -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/jwe/encrypt", "plugins": { @@ -174,7 +184,7 @@ Apisix-Plugins: jwe-decrypt 要删除 `jwe-decrypt` 插件,您可以从插件配置中删除插件对应的 JSON 配置,APISIX 会自动加载,您不需要重新启动即可生效。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/anything*", diff --git a/docs/zh/latest/plugins/jwt-auth.md b/docs/zh/latest/plugins/jwt-auth.md index c06f9e59b557..eed13cf54df9 100644 --- a/docs/zh/latest/plugins/jwt-auth.md +++ b/docs/zh/latest/plugins/jwt-auth.md @@ -78,9 +78,19 @@ Route 端: 首先,你可以通过 Admin API 创建一个 Consumer: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -98,7 +108,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "kerouac", "plugins": { @@ -118,7 +128,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -140,7 +150,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/jas \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/jwt/sign", "plugins": { @@ -258,7 +268,7 @@ Accept-Ranges: bytes ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/plugins/kafka-logger.md b/docs/zh/latest/plugins/kafka-logger.md index de8d3096c9cd..1fdfe3b59a34 100644 --- a/docs/zh/latest/plugins/kafka-logger.md +++ b/docs/zh/latest/plugins/kafka-logger.md @@ -142,9 +142,19 @@ description: API 网关 Apache APISIX 的 kafka-logger 插件用于将日志作 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/kafka-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -167,7 +177,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/kafka-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "kafka-logger": { @@ -220,7 +230,7 @@ curl -i http://127.0.0.1:9080/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/key-auth.md b/docs/zh/latest/plugins/key-auth.md index f4a568ec8524..f45b514e30bd 100644 --- a/docs/zh/latest/plugins/key-auth.md +++ b/docs/zh/latest/plugins/key-auth.md @@ -58,9 +58,19 @@ Router 端: 首先,你可以通过 Admin API 创建一个具有唯一 key 的 Consumer: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -89,7 +99,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -157,7 +167,7 @@ HTTP/1.1 401 Unauthorized ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/plugins/ldap-auth.md b/docs/zh/latest/plugins/ldap-auth.md index 2a4af09bed53..0417879fd12a 100644 --- a/docs/zh/latest/plugins/ldap-auth.md +++ b/docs/zh/latest/plugins/ldap-auth.md @@ -56,8 +56,18 @@ Route 端: 首先,你需要创建一个 Consumer 并在其中配置该插件,具体代码如下: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo", "plugins": { @@ -71,7 +81,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 然后就可以在指定路由或服务中启用该插件,具体代码如下: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -142,7 +152,7 @@ HTTP/1.1 401 Unauthorized 当你需要禁用 `ldap-auth` 插件时,可以通过以下命令删除相应的 JSON 配置。APISIX 将自动重新加载,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/limit-conn.md b/docs/zh/latest/plugins/limit-conn.md index f91df1f5a027..51142e1ce2c7 100644 --- a/docs/zh/latest/plugins/limit-conn.md +++ b/docs/zh/latest/plugins/limit-conn.md @@ -61,9 +61,19 @@ description: 本文介绍了 Apache APISIX limit-conn 插件的相关操作, 以下示例展示了如何在指定路由上启用 `limit-conn` 插件,并设置 `key_type` 为 `"var"`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -91,7 +101,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -141,7 +151,7 @@ curl -i http://127.0.0.1:9080/index.html?sleep=20 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -164,7 +174,7 @@ Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ws", "enable_websocket": true, diff --git a/docs/zh/latest/plugins/limit-count.md b/docs/zh/latest/plugins/limit-count.md index 79b3ac4fe680..e65997929305 100644 --- a/docs/zh/latest/plugins/limit-count.md +++ b/docs/zh/latest/plugins/limit-count.md @@ -62,9 +62,19 @@ description: 本文介绍了 Apache APISIX limit-count 插件的相关操作, 以下示例展示了如何在指定路由上启用 `limit-count` 插件,并设置 `key_type` 为 `"var"`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -89,7 +99,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -114,7 +124,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -138,7 +148,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "service_id": "1", "uri": "/hello" @@ -147,7 +157,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/2 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "service_id": "1", "uri": "/hello2" @@ -158,7 +168,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/2 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -193,7 +203,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/services/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -223,7 +233,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -255,7 +265,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -336,7 +346,7 @@ Server: APISIX web server ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/plugins/limit-req.md b/docs/zh/latest/plugins/limit-req.md index dd6461d0edbd..7297491d637a 100644 --- a/docs/zh/latest/plugins/limit-req.md +++ b/docs/zh/latest/plugins/limit-req.md @@ -63,9 +63,19 @@ description: limit-req 插件使用漏桶算法限制对用户服务的请求速 以下示例展示了如何在指定路由上启用 `limit-req` 插件,并设置 `key_type` 的值为 `var`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -159,7 +169,7 @@ Server: APISIX web server ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "consumer_jack", "plugins": { @@ -180,7 +190,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -232,7 +242,7 @@ HTTP/1.1 403 Forbidden ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -248,7 +258,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ 你也可以通过以下命令移除 Consumer 上的 `limit-req` 插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "consumer_jack", "plugins": { diff --git a/docs/zh/latest/plugins/loggly.md b/docs/zh/latest/plugins/loggly.md index 5bf92cf5a9ae..e8b05af66d8f 100644 --- a/docs/zh/latest/plugins/loggly.md +++ b/docs/zh/latest/plugins/loggly.md @@ -75,9 +75,19 @@ APISIX 支持 [Syslog](https://documentation.solarwinds.com/en/success_center/lo Syslog 协议允许你发送符合 RFC5424 的 syslog 事件并进行细粒度控制。但是在以快速传输速度发送大量日志时,使用 HTTP/S 批量端点会更好。你可以通过以下方式更新元数据以更新使用的协议: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loggly \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "protocol": "http" }' @@ -93,7 +103,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loggly \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "loggly":{ @@ -125,7 +135,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "loggly":{ @@ -160,7 +170,7 @@ curl -i http://127.0.0.1:9080/index.html ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/loki-logger.md b/docs/zh/latest/plugins/loki-logger.md index c39be2cba8c6..5e0a5a41e31b 100644 --- a/docs/zh/latest/plugins/loki-logger.md +++ b/docs/zh/latest/plugins/loki-logger.md @@ -113,8 +113,18 @@ description: 本文件包含关于 Apache APISIX loki-logger 插件的信息。 以下示例展示了如何通过 Admin API 进行配置: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -136,7 +146,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H 'X-API-KE 以下示例展示了如何在特定的路由上启用 `loki-logger` 插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "loki-logger": { @@ -166,7 +176,7 @@ curl -i http://127.0.0.1:9080/hello 当您需要删除 `loki-logger` 插件时,您可以使用以下命令删除相应的 JSON 配置,APISIX 将自动重新加载相关配置,而无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/mocking.md b/docs/zh/latest/plugins/mocking.md index c6ea804c7599..17ca3a716580 100644 --- a/docs/zh/latest/plugins/mocking.md +++ b/docs/zh/latest/plugins/mocking.md @@ -126,9 +126,19 @@ JSON Schema 在其字段中支持以下类型: 你可以通过如下命令在指定路由上启用 `mocking` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -231,7 +241,7 @@ Server: APISIX/2.10.0 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/plugins/mqtt-proxy.md b/docs/zh/latest/plugins/mqtt-proxy.md index edee5b141062..30567c2b586e 100644 --- a/docs/zh/latest/plugins/mqtt-proxy.md +++ b/docs/zh/latest/plugins/mqtt-proxy.md @@ -60,9 +60,19 @@ description: 本文档介绍了 Apache APISIX mqtt-proxy 插件的信息,通 你可以创建一个 stream 路由并启用 `mqtt-proxy` 插件。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -87,7 +97,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -130,7 +140,7 @@ Stream 代理可以使用 TCP 连接并且支持 TLS。请参考 [如何通过 t ```shell curl 127.0.0.1:9180/apisix/admin/stream_routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "mqtt-proxy": { @@ -160,5 +170,5 @@ curl 127.0.0.1:9180/apisix/admin/stream_routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +-H "X-API-KEY: $admin_key" -X DELETE ``` diff --git a/docs/zh/latest/plugins/multi-auth.md b/docs/zh/latest/plugins/multi-auth.md index 852911d7e295..16ac84e0b834 100644 --- a/docs/zh/latest/plugins/multi-auth.md +++ b/docs/zh/latest/plugins/multi-auth.md @@ -48,8 +48,28 @@ For Route: 首先创建一个 Consumer 使用 basic-auth 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo1", "plugins": { @@ -64,7 +84,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 然后再创建一个 Consumer 使用 key-auth 插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "foo2", "plugins": { @@ -78,7 +98,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f1 创建 Consumer 之后,您可以配置一个路由或服务来验证请求: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", @@ -140,7 +160,7 @@ hello, world 要删除 `multi-auth` 插件,您可以从插件配置中删除插件对应的 JSON 配置,APISIX 会自动加载,您不需要重新启动即可生效。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/node-status.md b/docs/zh/latest/plugins/node-status.md index 34231f0d7a35..b210d78fd1b4 100644 --- a/docs/zh/latest/plugins/node-status.md +++ b/docs/zh/latest/plugins/node-status.md @@ -54,8 +54,18 @@ plugins: 你需要为 `/apisix/status` API 配置路由,并使用 [public-api](public-api.md) 插件暴露它。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/ns -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/status", "plugins": { @@ -111,5 +121,5 @@ Server: APISIX web server 你也可以移除暴露 `/apisix/status` 接口的路由。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE +curl http://127.0.0.1:9180/apisix/admin/routes/ns -H "X-API-KEY: $admin_key" -X DELETE ``` diff --git a/docs/zh/latest/plugins/ocsp-stapling.md b/docs/zh/latest/plugins/ocsp-stapling.md index d69862e946a3..025946f710f5 100644 --- a/docs/zh/latest/plugins/ocsp-stapling.md +++ b/docs/zh/latest/plugins/ocsp-stapling.md @@ -43,8 +43,18 @@ plugins: 修改配置文件之后,重启 APISIX 或者通过插件热加载接口来使配置生效: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` ## 属性 @@ -65,7 +75,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034 ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -96,7 +106,7 @@ OCSP Response Data: ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -113,7 +123,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PATCH -d ' +-H "X-API-KEY: $admin_key" -X PATCH -d ' { "ocsp_stapling": null }' @@ -130,5 +140,5 @@ plugins: 修改配置文件之后,重启 APISIX 或者通过插件热加载接口来使配置生效: ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` diff --git a/docs/zh/latest/plugins/opa.md b/docs/zh/latest/plugins/opa.md index 8ca473876dad..a72a2f1a9520 100644 --- a/docs/zh/latest/plugins/opa.md +++ b/docs/zh/latest/plugins/opa.md @@ -303,8 +303,18 @@ curl -X GET 127.0.0.1:9080/get 当你需要禁用 `opa` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/openfunction.md b/docs/zh/latest/plugins/openfunction.md index cc88feb6f527..e1797edb6587 100644 --- a/docs/zh/latest/plugins/openfunction.md +++ b/docs/zh/latest/plugins/openfunction.md @@ -76,8 +76,18 @@ kubectl create secret docker-registry push-secret \ 你可以通过以下命令在指定路由中启用该插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -118,7 +128,7 @@ hello, test! 下面的示例配置了此功能: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello/*", "plugins": { @@ -147,7 +157,7 @@ Hello, 123! 当你需要禁用 `openfunction` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/openid-connect.md b/docs/zh/latest/plugins/openid-connect.md index 2a6c21b5dfa7..c325ac4a2c6d 100644 --- a/docs/zh/latest/plugins/openid-connect.md +++ b/docs/zh/latest/plugins/openid-connect.md @@ -116,9 +116,19 @@ description: OpenID Connect(OIDC)是基于 OAuth 2.0 的身份认证协议 以下示例是在路由上启用插件。该路由将通过内省请求头中提供的令牌来保护上游: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins":{ @@ -162,7 +172,7 @@ curl -i -X GET http://127.0.0.1:9080/get -H "Authorization: Bearer {JWT_TOKEN}" ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins":{ @@ -197,7 +207,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/zh/latest/plugins/opentelemetry.md b/docs/zh/latest/plugins/opentelemetry.md index 7a95f302280a..94dd63a3d44a 100644 --- a/docs/zh/latest/plugins/opentelemetry.md +++ b/docs/zh/latest/plugins/opentelemetry.md @@ -123,9 +123,19 @@ plugins: 开启成功后,可以通过如下命令在指定路由上启用 `opentelemetry` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ @@ -153,7 +163,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/zh/latest/plugins/openwhisk.md b/docs/zh/latest/plugins/openwhisk.md index 061c2955bf00..d7dbc1af78b4 100644 --- a/docs/zh/latest/plugins/openwhisk.md +++ b/docs/zh/latest/plugins/openwhisk.md @@ -88,9 +88,19 @@ wsk action update test <(echo 'function main(){return {"ready":true}}') --kind n 你可以通过以下命令在指定路由中启用该插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -124,7 +134,7 @@ curl -i http://127.0.0.1:9080/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/prometheus.md b/docs/zh/latest/plugins/prometheus.md index fad3dd9eb7e7..f6809a26eb31 100644 --- a/docs/zh/latest/plugins/prometheus.md +++ b/docs/zh/latest/plugins/prometheus.md @@ -119,9 +119,19 @@ plugin_attr: 你可以通过如下命令在指定路由上启用 `prometheus` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -334,7 +344,7 @@ apisix_upstream_status{name="/apisix/routes/1",ip="52.86.68.46",port="80"} 1 当你需要禁用 `prometheus` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, @@ -368,7 +378,7 @@ stream_plugins: 接着你需要在 stream 路由中配置该插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "prometheus":{} diff --git a/docs/zh/latest/plugins/proxy-cache.md b/docs/zh/latest/plugins/proxy-cache.md index b39f3990fd8d..ff0decb18e70 100644 --- a/docs/zh/latest/plugins/proxy-cache.md +++ b/docs/zh/latest/plugins/proxy-cache.md @@ -80,9 +80,19 @@ apisix: 以下示例展示了如何在路由上启用 `proxy-cache` 插件。该插件默认使用基于磁盘的 `cache_strategy` 和默认使用`disk_cache_one` 为 `cache_zone`: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": { @@ -110,7 +120,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": { @@ -187,7 +197,7 @@ HTTP/1.1 200 OK ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/ip", "plugins": {}, diff --git a/docs/zh/latest/plugins/proxy-control.md b/docs/zh/latest/plugins/proxy-control.md index a9eafd238938..c268f3473da0 100644 --- a/docs/zh/latest/plugins/proxy-control.md +++ b/docs/zh/latest/plugins/proxy-control.md @@ -46,9 +46,19 @@ description: 本文介绍了 Apache APISIX proxy-control 插件的相关操作 以下示例展示了如何在指定路由上启用 `proxy-control` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/upload", "plugins": { @@ -81,7 +91,7 @@ curl -i http://127.0.0.1:9080/upload -d @very_big_file ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d + -H "X-API-KEY: $admin_key" -X PUT -d { "uri": "/upload", "upstream": { diff --git a/docs/zh/latest/plugins/proxy-mirror.md b/docs/zh/latest/plugins/proxy-mirror.md index 5b39a556f996..9a4b1fabb5d9 100644 --- a/docs/zh/latest/plugins/proxy-mirror.md +++ b/docs/zh/latest/plugins/proxy-mirror.md @@ -49,9 +49,19 @@ description: 本文介绍了 Apache APISIX proxy-mirror 插件的相关操作, 以下示例展示了如何在指定路由上启用 `proxy-mirror` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "proxy-mirror": { @@ -121,7 +131,7 @@ hello world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/proxy-rewrite.md b/docs/zh/latest/plugins/proxy-rewrite.md index 8d16466cefe0..d3204b9ed027 100644 --- a/docs/zh/latest/plugins/proxy-rewrite.md +++ b/docs/zh/latest/plugins/proxy-rewrite.md @@ -56,9 +56,19 @@ Header 头的相关配置,遵循如下优先级进行执行: 你可以通过如下命令在指定路由上启用 `proxy-rewrite` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", @@ -109,7 +119,7 @@ curl -X GET http://127.0.0.1:9080/test/index.html 当你需要禁用 `proxy-rewrite` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", diff --git a/docs/zh/latest/plugins/public-api.md b/docs/zh/latest/plugins/public-api.md index 303fd3c04260..0a50d0533c9d 100644 --- a/docs/zh/latest/plugins/public-api.md +++ b/docs/zh/latest/plugins/public-api.md @@ -54,9 +54,19 @@ description: 本文介绍了 public-api 的相关操作,你可以使用 public 然后,使用以下命令在指定路由上启用并配置 `public-api` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r1' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H 'Content-Type: application/json' \ -d '{ "uri": "/apisix/plugin/jwt/sign", @@ -86,7 +96,7 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTk0Mjg1MzIsImtleSI6InVzZXIta2V ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H 'Content-Type: application/json' \ -d '{ "uri": "/gen_token", @@ -116,7 +126,7 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTk0Mjg1NjIsImtleSI6InVzZXIta2V ```shell curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H 'Content-Type: application/json' \ -d '{ "uri": "/gen_token", @@ -161,7 +171,7 @@ HTTP/1.1 401 Unauthorized 当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/docs/zh/latest/plugins/real-ip.md b/docs/zh/latest/plugins/real-ip.md index 50514a1c46ff..1066c507ed86 100644 --- a/docs/zh/latest/plugins/real-ip.md +++ b/docs/zh/latest/plugins/real-ip.md @@ -57,9 +57,19 @@ description: 本文介绍了关于 Apache APISIX `real-ip` 插件的基本信息 以下示例展示了如何在指定路由中启用 `real-ip` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -103,7 +113,7 @@ remote-port: 9080 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/plugins/redirect.md b/docs/zh/latest/plugins/redirect.md index e700a36d59d4..351cf5b0656f 100644 --- a/docs/zh/latest/plugins/redirect.md +++ b/docs/zh/latest/plugins/redirect.md @@ -57,9 +57,19 @@ description: 本文介绍了关于 Apache APISIX `redirect` 插件的基本信 以下示例展示了如何在指定路由中启用 `redirect` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test/index.html", "plugins": { @@ -81,7 +91,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test", "plugins": { @@ -123,7 +133,7 @@ Location: /test/default.html ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -153,7 +163,7 @@ Location: https://127.0.0.1:9443/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/test/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/referer-restriction.md b/docs/zh/latest/plugins/referer-restriction.md index 73c60b1de5ba..a69d0dcf5cab 100644 --- a/docs/zh/latest/plugins/referer-restriction.md +++ b/docs/zh/latest/plugins/referer-restriction.md @@ -49,8 +49,18 @@ description: 本文介绍了 Apache APISIX referer-restriction 插件的使用 以下示例展示了如何在特定路由上启用 `referer-restriction` 插件,并配置 `whitelist` 和 `bypass_missing` 属性: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -118,7 +128,7 @@ HTTP/1.1 200 OK 当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/request-id.md b/docs/zh/latest/plugins/request-id.md index 01b49ee9f96a..28bb996beed5 100644 --- a/docs/zh/latest/plugins/request-id.md +++ b/docs/zh/latest/plugins/request-id.md @@ -50,9 +50,19 @@ description: 本文介绍了 Apache APISIX request-id 插件的相关操作, 以下示例展示了如何在指定路由上启用 `request-id` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -92,7 +102,7 @@ X-Request-Id: fe32076a-d0a5-49a6-a361-6c244c1df956 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/zh/latest/plugins/request-validation.md b/docs/zh/latest/plugins/request-validation.md index 9ea38161c0ae..5b491a419c61 100644 --- a/docs/zh/latest/plugins/request-validation.md +++ b/docs/zh/latest/plugins/request-validation.md @@ -49,9 +49,19 @@ description: 本文介绍了 Apache APISIX request-validation 插件的相关操 以下示例展示了如何在指定路由上启用 `request-validation` 插件,并设置 `body_schema` 字段: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { @@ -271,7 +281,7 @@ curl --header "Content-Type: application/json" \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/get", "plugins": { diff --git a/docs/zh/latest/plugins/response-rewrite.md b/docs/zh/latest/plugins/response-rewrite.md index be409411b346..936be773da8b 100644 --- a/docs/zh/latest/plugins/response-rewrite.md +++ b/docs/zh/latest/plugins/response-rewrite.md @@ -71,9 +71,19 @@ description: 本文介绍了关于 Apache APISIX `response-rewrite` 插件的基 你可以通过如下命令在指定路由上启用 `response-rewrite` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", @@ -161,7 +171,7 @@ X-Server-balancer-addr: 127.0.0.1:80 使用 `filters` 正则匹配将返回 body 的 X-Amzn-Trace-Id 替换为 X-Amzn-Trace-Id-Replace。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "response-rewrite":{ @@ -231,7 +241,7 @@ X-Server-id: 3 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/test/index.html", diff --git a/docs/zh/latest/plugins/rocketmq-logger.md b/docs/zh/latest/plugins/rocketmq-logger.md index faec6c48d3fc..21d8e42845e5 100644 --- a/docs/zh/latest/plugins/rocketmq-logger.md +++ b/docs/zh/latest/plugins/rocketmq-logger.md @@ -132,9 +132,19 @@ description: API 网关 Apache APISIX 的 rocketmq-logger 插件用于将日志 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/rocketmq-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -157,7 +167,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/rocketmq-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "rocketmq-logger": { @@ -200,7 +210,7 @@ curl -i http://127.0.0.1:9080/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/serverless.md b/docs/zh/latest/plugins/serverless.md index 97d6ee6a8a8f..6b9b847eb8e8 100644 --- a/docs/zh/latest/plugins/serverless.md +++ b/docs/zh/latest/plugins/serverless.md @@ -83,9 +83,19 @@ ngx.say(count) 你可以通过以下命令在指定路由中启用该插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -123,7 +133,7 @@ curl -i http://127.0.0.1:9080/index.html ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/plugins/skywalking-logger.md b/docs/zh/latest/plugins/skywalking-logger.md index 8ef7417582c4..1bc16bd03e13 100644 --- a/docs/zh/latest/plugins/skywalking-logger.md +++ b/docs/zh/latest/plugins/skywalking-logger.md @@ -125,9 +125,19 @@ description: 本文将介绍 API 网关 Apache APISIX 如何通过 skywalking-lo 以下示例展示了如何通过 Admin API 进行插件元数据配置: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/skywalking-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -150,7 +160,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/skywalking-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "skywalking-logger": { @@ -183,7 +193,7 @@ curl -i http://127.0.0.1:9080/hello ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/skywalking.md b/docs/zh/latest/plugins/skywalking.md index 324e108174c0..421cc0571f5a 100644 --- a/docs/zh/latest/plugins/skywalking.md +++ b/docs/zh/latest/plugins/skywalking.md @@ -118,8 +118,18 @@ plugins: 以下示例展示了如何在指定路由中启用 `skywalking` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ @@ -204,7 +214,7 @@ OK 当你需要禁用 `skywalking` 插件时,可通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uris": [ diff --git a/docs/zh/latest/plugins/sls-logger.md b/docs/zh/latest/plugins/sls-logger.md index 64613a34a66c..12f465386b29 100644 --- a/docs/zh/latest/plugins/sls-logger.md +++ b/docs/zh/latest/plugins/sls-logger.md @@ -87,8 +87,18 @@ title: sls-logger ### 设置日志格式示例 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/sls-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/sls-logger -H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -110,7 +120,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/sls-logger -H 'X-API-KEY 1. 下面例子展示了如何为指定路由开启 `sls-logger` 插件的。 ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "sls-logger": { @@ -156,7 +166,7 @@ hello, world 想要禁用“sls-logger”插件,是非常简单的,将对应的插件配置从 json 配置删除,就会立即生效,不需要重新启动服务: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/splunk-hec-logging.md b/docs/zh/latest/plugins/splunk-hec-logging.md index abaa12406116..ef22594096e1 100644 --- a/docs/zh/latest/plugins/splunk-hec-logging.md +++ b/docs/zh/latest/plugins/splunk-hec-logging.md @@ -93,9 +93,19 @@ description: API 网关 Apache APISIX 的 splunk-hec-logging 插件可用于将 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/splunk-hec-logging \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -119,7 +129,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/splunk-hec-logging \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "splunk-hec-logging":{ @@ -150,7 +160,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins":{ "splunk-hec-logging":{ @@ -194,7 +204,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": {}, diff --git a/docs/zh/latest/plugins/syslog.md b/docs/zh/latest/plugins/syslog.md index fd847f12211f..c4a351ee3791 100644 --- a/docs/zh/latest/plugins/syslog.md +++ b/docs/zh/latest/plugins/syslog.md @@ -78,9 +78,19 @@ description: API 网关 Apache APISIX syslog 插件可用于将日志推送到 S 你可以通过以下命令在指定路由中启用该插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "syslog": { @@ -119,7 +129,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/tcp-logger.md b/docs/zh/latest/plugins/tcp-logger.md index 17203a3e5ec0..158bb7cba293 100644 --- a/docs/zh/latest/plugins/tcp-logger.md +++ b/docs/zh/latest/plugins/tcp-logger.md @@ -104,9 +104,19 @@ description: 本文介绍了 API 网关 Apache APISIX 如何使用 tcp-logger 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tcp-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -128,7 +138,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tcp-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "tcp-logger": { @@ -169,7 +179,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/tencent-cloud-cls.md b/docs/zh/latest/plugins/tencent-cloud-cls.md index 0e45141d3d3f..a5c41bd72d62 100644 --- a/docs/zh/latest/plugins/tencent-cloud-cls.md +++ b/docs/zh/latest/plugins/tencent-cloud-cls.md @@ -106,9 +106,19 @@ description: API 网关 Apache APISIX tencent-cloud-cls 插件可用于将日志 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tencent-cloud-cls \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -131,7 +141,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/tencent-cloud-cls \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "tencent-cloud-cls": { @@ -177,7 +187,7 @@ hello, world ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/traffic-split.md b/docs/zh/latest/plugins/traffic-split.md index 68e52baac842..0cd3874d039b 100644 --- a/docs/zh/latest/plugins/traffic-split.md +++ b/docs/zh/latest/plugins/traffic-split.md @@ -77,9 +77,19 @@ description: 本文介绍了 Apache APISIX traffic-split 插件的相关操作 以下示例展示了如何在指定路由上启用 `traffic-split` 插件,并通过插件中的 `upstream` 属性配置上游信息: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -123,7 +133,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -174,7 +184,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -248,7 +258,7 @@ world 1981 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -324,7 +334,7 @@ hello 1980 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -413,7 +423,7 @@ hello 1980 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -531,7 +541,7 @@ hello 1980 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "plugins": { @@ -629,7 +639,7 @@ curl http://127.0.0.1:9080/hello -H 'x-api-id: 3' ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/ua-restriction.md b/docs/zh/latest/plugins/ua-restriction.md index eedcd015ae1c..f5ccc6514ef5 100644 --- a/docs/zh/latest/plugins/ua-restriction.md +++ b/docs/zh/latest/plugins/ua-restriction.md @@ -51,8 +51,18 @@ description: 本文介绍了 Apache APISIX ua-restriction 插件的使用方法 以下示例展示了如何在指定路由上启用并配置 `ua-restriction` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream": { @@ -101,7 +111,7 @@ curl http://127.0.0.1:9080/index.html --header 'User-Agent: Twitterspider/2.0' 当你需要禁用 `ua-restriction` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": {}, diff --git a/docs/zh/latest/plugins/udp-logger.md b/docs/zh/latest/plugins/udp-logger.md index a8ca60778551..45d0983ffbde 100644 --- a/docs/zh/latest/plugins/udp-logger.md +++ b/docs/zh/latest/plugins/udp-logger.md @@ -103,9 +103,19 @@ description: 本文介绍了 API 网关 Apache APISIX 如何使用 udp-logger 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/udp-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", @@ -127,7 +137,7 @@ curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/udp-logger \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/5 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "udp-logger": { @@ -166,7 +176,7 @@ hello, world 当你需要删除该插件时,可通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/hello", diff --git a/docs/zh/latest/plugins/uri-blocker.md b/docs/zh/latest/plugins/uri-blocker.md index 33c92dbf39a5..5595d3cb1fbe 100644 --- a/docs/zh/latest/plugins/uri-blocker.md +++ b/docs/zh/latest/plugins/uri-blocker.md @@ -43,8 +43,18 @@ description: 本文介绍了 Apache APISIX uri-blocker 插件的基本信息及 以下示例展示了如何在指定的路由上启用 `uri-blocker` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "plugins": { @@ -94,7 +104,7 @@ Server: APISIX web server 当你需要禁用 `uri-blocker` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { diff --git a/docs/zh/latest/plugins/wolf-rbac.md b/docs/zh/latest/plugins/wolf-rbac.md index dad4f26d13ff..058029ca3d51 100644 --- a/docs/zh/latest/plugins/wolf-rbac.md +++ b/docs/zh/latest/plugins/wolf-rbac.md @@ -64,9 +64,19 @@ description: 本文介绍了关于 Apache APISIX `wolf-rbac` 插件的基本信 首先需要创建一个 Consumer 并配置该插件,如下所示: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username":"wolf_rbac", "plugins":{ @@ -89,7 +99,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumers \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/*", @@ -119,7 +129,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl http://127.0.0.1:9180/apisix/admin/routes/wal \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/apisix/plugin/wolf-rbac/login", "plugins": { @@ -275,7 +285,7 @@ HTTP/1.1 200 OK ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/*", diff --git a/docs/zh/latest/plugins/workflow.md b/docs/zh/latest/plugins/workflow.md index 51ed1b32a7ba..7670bd219406 100644 --- a/docs/zh/latest/plugins/workflow.md +++ b/docs/zh/latest/plugins/workflow.md @@ -65,9 +65,19 @@ description: 本文介绍了关于 Apache APISIX `workflow` 插件的基本信 以下示例展示了如何在路由中启用 `workflow` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/hello/*", "plugins":{ @@ -153,7 +163,7 @@ HTTP/1.1 200 OK ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri":"/hello/*", "upstream": { diff --git a/docs/zh/latest/plugins/zipkin.md b/docs/zh/latest/plugins/zipkin.md index c43321f5f472..cca58374229b 100644 --- a/docs/zh/latest/plugins/zipkin.md +++ b/docs/zh/latest/plugins/zipkin.md @@ -110,8 +110,18 @@ func main(){ 以下示例展示了如何在指定路由中启用 `zipkin` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -178,7 +188,7 @@ docker run -d --name jaeger \ 通过以下命令创建路由并启用插件: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -221,7 +231,7 @@ HTTP/1.1 200 OK 当你需要禁用 `zipkin` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: ```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index bf6128d1f7e1..0631be23fbd2 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -82,8 +82,28 @@ title: 路由 RadixTree 创建两条 `priority` 值不同的路由(值越大,优先级越高)。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -97,7 +117,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ``` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -124,7 +144,7 @@ curl http://127.0.0.1:1980/hello 以下是设置主机匹配规则的示例: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -138,7 +158,7 @@ $ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ``` ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/2 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -197,7 +217,7 @@ apisix: 具体参数及使用方式请查看 [radixtree#new](https://github.com/api7/lua-resty-radixtree#new) 文档,下面是一个简单的示例: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/index.html", "vars": [ @@ -226,7 +246,7 @@ APISIX 支持通过 POST 表单属性过滤路由,其中需要您使用 `Conte 我们可以定义这样的路由: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "methods": ["POST"], "uri": "/_post", @@ -274,7 +294,7 @@ query getRepo { 我们可以用以下方法过滤掉这样的路由: ```shell -$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +$ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "methods": ["POST", "GET"], "uri": "/graphql", diff --git a/docs/zh/latest/ssl-protocol.md b/docs/zh/latest/ssl-protocol.md index 563b2095df90..d776e7ef8afd 100644 --- a/docs/zh/latest/ssl-protocol.md +++ b/docs/zh/latest/ssl-protocol.md @@ -81,9 +81,19 @@ apisix: 2. 为 test.com 域名指定 TLSv1.1 协议版本。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -98,7 +108,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server2.crt)"'", "key": "'"$(cat server2.key)"'", @@ -197,7 +207,7 @@ curl: (35) error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol vers ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", @@ -212,7 +222,7 @@ curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ ```bash curl http://127.0.0.1:9180/apisix/admin/ssls/2 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat server.crt)"'", "key": "'"$(cat server.key)"'", diff --git a/docs/zh/latest/stream-proxy.md b/docs/zh/latest/stream-proxy.md index 1c2a37c422ac..4aa6dd0213a3 100644 --- a/docs/zh/latest/stream-proxy.md +++ b/docs/zh/latest/stream-proxy.md @@ -44,8 +44,18 @@ apisix: 简例如下: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "remote_addr": "127.0.0.1", "upstream": { @@ -71,7 +81,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 例如 ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "server_addr": "127.0.0.1", "server_port": 2000, @@ -114,7 +124,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 3. 现在我们将创建一个带有服务器过滤的 stream 路由: ```shell - curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "server_addr": "127.0.0.10", "server_port": 9101, @@ -171,7 +181,7 @@ mTLS 也是支持的,参考 [保护路由](./mtls.md#保护路由)。 然后,我们需要配置一个 route,匹配连接并代理到上游: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -185,7 +195,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 当连接为 TLS over TCP 时,我们可以通过 SNI 来匹配路由,比如: ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "sni": "a.test.com", "upstream": { @@ -204,7 +214,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 APISIX 还支持代理到 TLS over TCP 上游。 ```shell -curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "scheme": "tls", diff --git a/docs/zh/latest/terminology/consumer-group.md b/docs/zh/latest/terminology/consumer-group.md index 94f870503c49..eaf4514e816e 100644 --- a/docs/zh/latest/terminology/consumer-group.md +++ b/docs/zh/latest/terminology/consumer-group.md @@ -36,9 +36,19 @@ description: 本文介绍了 Apache APISIX Consumer Group 对象的概念及使 创建一个共享相同限流配额的消费者组: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -55,7 +65,7 @@ curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a \ ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { diff --git a/docs/zh/latest/terminology/consumer.md b/docs/zh/latest/terminology/consumer.md index 7892b1b87bdf..22f4a0fd4211 100644 --- a/docs/zh/latest/terminology/consumer.md +++ b/docs/zh/latest/terminology/consumer.md @@ -72,11 +72,21 @@ Consumer 是某类服务的消费者,需要与用户认证配合才可以使 以下示例介绍了如何对某个 Consumer 开启指定插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. 创建 Consumer,指定认证插件 `key-auth`,并开启特定插件 `limit-count`。 ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -97,7 +107,7 @@ Consumer 是某类服务的消费者,需要与用户认证配合才可以使 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {} @@ -133,7 +143,7 @@ Consumer 是某类服务的消费者,需要与用户认证配合才可以使 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {}, diff --git a/docs/zh/latest/terminology/global-rule.md b/docs/zh/latest/terminology/global-rule.md index 5920b9efcdd0..8b3dc7ad4866 100644 --- a/docs/zh/latest/terminology/global-rule.md +++ b/docs/zh/latest/terminology/global-rule.md @@ -39,10 +39,20 @@ description: 本文介绍了全局规则的概念以及如何启用全局规则 以下示例展示了如何为所有请求启用 `limit-count` 插件: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/global_rules/1 -X PUT \ -H 'Content-Type: application/json' \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -d '{ "plugins": { "limit-count": { @@ -59,5 +69,5 @@ curl http://127.0.0.1:9180/apisix/admin/global_rules/1 -X PUT \ 你也可以通过以下命令查看所有的全局规则: ```shell -curl http://127.0.0.1:9180/apisix/admin/global_rules -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' +curl http://127.0.0.1:9180/apisix/admin/global_rules -H "X-API-KEY: $admin_key" ``` diff --git a/docs/zh/latest/terminology/plugin-config.md b/docs/zh/latest/terminology/plugin-config.md index 7603ee7165d9..7253890d9e04 100644 --- a/docs/zh/latest/terminology/plugin-config.md +++ b/docs/zh/latest/terminology/plugin-config.md @@ -39,11 +39,21 @@ description: Plugin Config 对象,可以用于创建一组通用的插件配 你可以参考如下步骤将 Plugin Config 绑定在路由上。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. 创建 Plugin config。 ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "desc": "enable limit-count plugin", "plugins": { @@ -60,7 +70,7 @@ description: Plugin Config 对象,可以用于创建一组通用的插件配 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uris": ["/index.html"], "plugin_config_id": 1, @@ -85,7 +95,7 @@ description: Plugin Config 对象,可以用于创建一组通用的插件配 ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "desc": "enable ip-restruction and limit-count plugin", "plugins": { @@ -108,7 +118,7 @@ description: Plugin Config 对象,可以用于创建一组通用的插件配 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uris": ["/index.html"], "plugin_config_id": 1, @@ -137,7 +147,7 @@ description: Plugin Config 对象,可以用于创建一组通用的插件配 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' + -H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uris": ["/index.html"], "upstream": { diff --git a/docs/zh/latest/terminology/plugin-metadata.md b/docs/zh/latest/terminology/plugin-metadata.md index 782b0a00f5df..3af77a08332f 100644 --- a/docs/zh/latest/terminology/plugin-metadata.md +++ b/docs/zh/latest/terminology/plugin-metadata.md @@ -51,9 +51,19 @@ description: APISIX 的插件元数据 以下示例展示了如何通过 Admin API 配置插件元数据: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "log_format": { "host": "$host", diff --git a/docs/zh/latest/terminology/plugin.md b/docs/zh/latest/terminology/plugin.md index bf76760f4529..b8a224233a97 100644 --- a/docs/zh/latest/terminology/plugin.md +++ b/docs/zh/latest/terminology/plugin.md @@ -294,8 +294,18 @@ APISIX 的插件是热加载的,不管你是新增、删除还是修改插件 只需要通过 Admin API 发送一个 HTTP 请求即可: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell -curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT +curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H "X-API-KEY: $admin_key" -X PUT ``` :::note 注意 diff --git a/docs/zh/latest/terminology/route.md b/docs/zh/latest/terminology/route.md index 097fa9f6d739..5c2270ab1b9f 100644 --- a/docs/zh/latest/terminology/route.md +++ b/docs/zh/latest/terminology/route.md @@ -45,9 +45,19 @@ Route(也称为路由)是 APISIX 中最基础和最核心的资源对象,A 你可以在路由中完成所有参数的配置,该方式设置容易设置,每个路由的相对独立自由度比较高。示例如下: +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -72,7 +82,7 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ ```shell curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugin_config_id": "123456789apacheapisix", @@ -98,7 +108,7 @@ APISIX 所有的资源对象的 ID,均使用字符串格式,如果使用的 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +-H "X-API-KEY: $admin_key" -X PUT -i -d ' { "uri": "/index.html", "upstream": { diff --git a/docs/zh/latest/terminology/secret.md b/docs/zh/latest/terminology/secret.md index 24a995f15f37..c59f0d4ceca4 100644 --- a/docs/zh/latest/terminology/secret.md +++ b/docs/zh/latest/terminology/secret.md @@ -99,9 +99,19 @@ export JACK_AUTH_KEY=abc 第二步:在 `key-auth` 插件中引用环境变量 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -141,7 +151,7 @@ vault kv put apisix/jack auth-key=value ```shell curl http://127.0.0.1:9180/apisix/admin/secrets/vault/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "https://127.0.0.1:8200", "prefix": "apisix", @@ -163,7 +173,7 @@ secrets: ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { diff --git a/docs/zh/latest/terminology/service.md b/docs/zh/latest/terminology/service.md index 0a78fcea90f9..aad15cee1e21 100644 --- a/docs/zh/latest/terminology/service.md +++ b/docs/zh/latest/terminology/service.md @@ -40,11 +40,21 @@ Service(也称之为服务)是某类 API 的抽象(也可以理解为一 以下示例创建了一个启用限流插件的服务,并且将该服务绑定到 ID 为 `100` 和 `101` 的路由上。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. 创建服务。 ```shell curl http://127.0.0.1:9180/apisix/admin/services/200 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "limit-count": { @@ -67,7 +77,7 @@ Service(也称之为服务)是某类 API 的抽象(也可以理解为一 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/100 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/index.html", @@ -79,7 +89,7 @@ Service(也称之为服务)是某类 API 的抽象(也可以理解为一 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/101 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "methods": ["GET"], "uri": "/foo/index.html", @@ -91,7 +101,7 @@ Service(也称之为服务)是某类 API 的抽象(也可以理解为一 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/102 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/bar/index.html", "id": "102", diff --git a/docs/zh/latest/terminology/upstream.md b/docs/zh/latest/terminology/upstream.md index dca9e56c25c9..5e7b15b73b74 100644 --- a/docs/zh/latest/terminology/upstream.md +++ b/docs/zh/latest/terminology/upstream.md @@ -43,11 +43,21 @@ Upstream(也称之为上游)是对虚拟主机抽象,即应用层服务或 APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上游做主被动健康检查、重试等逻辑。更多信息,请参考 [Admin API 中的 Upstream 资源](../admin-api.md#upstream)。 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + 1. 创建上游对象用例。 ```shell curl http://127.0.0.1:9180/apisix/admin/upstreams/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "type": "chash", "key": "remote_addr", @@ -64,7 +74,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "upstream_id": 1 @@ -77,7 +87,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -103,7 +113,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/index.html", "plugins": { @@ -148,7 +158,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/consumers \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "username": "jack", "plugins": { @@ -163,7 +173,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "plugins": { "key-auth": {} @@ -192,7 +202,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hash_on_cookie", "upstream": { @@ -211,7 +221,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9080/hash_on_cookie \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H "Cookie: sid=3c183a30cffcda1408daf1c61d47b274" ``` @@ -221,7 +231,7 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9180/apisix/admin/routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hash_on_header", "upstream": { @@ -240,6 +250,6 @@ APISIX 的 Upstream 对象除了基本的负载均衡算法外,还支持对上 ```shell curl http://127.0.0.1:9080/hash_on_header \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \ + -H "X-API-KEY: $admin_key" \ -H "Content-Type: application/json" ``` diff --git a/docs/zh/latest/tutorials/client-to-apisix-mtls.md b/docs/zh/latest/tutorials/client-to-apisix-mtls.md index 7d018089e0ef..a697c6d12abe 100644 --- a/docs/zh/latest/tutorials/client-to-apisix-mtls.md +++ b/docs/zh/latest/tutorials/client-to-apisix-mtls.md @@ -205,9 +205,19 @@ APISIX 允许配置 URI 白名单以便绕过 MTLS。如果请求的 URI 在白 1. 配置路由和证书 +:::note + +您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: + +```bash +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +``` + +::: + ```bash curl http://127.0.0.1:9180/apisix/admin/routes/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/*", "upstream": { @@ -218,7 +228,7 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \ }' curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert": "'"$( conf/config.yaml make init > output.log 2>&1 | true -grep -E "WARNING: using fixed Admin API token has security risk." output.log > /dev/null +grep -E "WARNING: using empty Admin API." output.log > /dev/null if [ ! $? -eq 0 ]; then echo "failed: need to show `WARNING: using fixed Admin API token has security risk`" exit 1 fi -echo "pass: show WARNING message if the user used default token and allow any IP to access" +echo "pass: show WARNING message if the user uses empty key" # admin_listen set echo ' @@ -280,7 +283,8 @@ rm logs/error.log make init make run -code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") make stop if [ ! $code -eq 200 ]; then @@ -323,6 +327,8 @@ apisix: rm logs/error.log make init make run +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') + make init @@ -352,9 +358,10 @@ rm logs/error.log make init make run +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') # initialize node-status public API routes #1 code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} -X PUT http://127.0.0.1:9180/apisix/admin/routes/node-status \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d "{ \"uri\": \"/apisix/status\", \"plugins\": { @@ -379,9 +386,10 @@ fi make init sleep 1 +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') # initialize node-status public API routes #2 code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} -X PUT http://127.0.0.1:9180/apisix/admin/routes/node-status \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d "{ \"uri\": \"/apisix/status\", \"plugins\": { @@ -420,6 +428,8 @@ stream_plugins: rm logs/error.log make init make run +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') + # first time check node status api code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/status) diff --git a/t/cli/test_admin_mtls.sh b/t/cli/test_admin_mtls.sh index 7bbad286e416..7f79b4edf2d8 100755 --- a/t/cli/test_admin_mtls.sh +++ b/t/cli/test_admin_mtls.sh @@ -20,7 +20,6 @@ . ./t/cli/common.sh # The 'admin.apisix.dev' is injected by ci/common.sh@set_coredns - echo ' deployment: admin: @@ -38,15 +37,16 @@ make run sleep 1 +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') # correct certs -code=$(curl -i -o /dev/null -s -w %{http_code} --cacert ./t/certs/mtls_ca.crt --key ./t/certs/mtls_client.key --cert ./t/certs/mtls_client.crt -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes) +code=$(curl -i -o /dev/null -s -w %{http_code} --cacert ./t/certs/mtls_ca.crt --key ./t/certs/mtls_client.key --cert ./t/certs/mtls_client.crt -H "X-API-KEY: $admin_key" https://admin.apisix.dev:9180/apisix/admin/routes) if [ ! "$code" -eq 200 ]; then echo "failed: failed to enabled mTLS for admin" exit 1 fi # skip -code=$(curl -i -o /dev/null -s -w %{http_code} -k -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes) +code=$(curl -i -o /dev/null -s -w %{http_code} -k -H "X-API-KEY: $admin_key" https://admin.apisix.dev:9180/apisix/admin/routes) if [ ! "$code" -eq 400 ]; then echo "failed: failed to enabled mTLS for admin" exit 1 diff --git a/t/cli/test_apisix_mirror.sh b/t/cli/test_apisix_mirror.sh index 5f685e77c781..65949d67f501 100755 --- a/t/cli/test_apisix_mirror.sh +++ b/t/cli/test_apisix_mirror.sh @@ -32,7 +32,8 @@ make init make run sleep 0.1 -curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { diff --git a/t/cli/test_cmd.sh b/t/cli/test_cmd.sh index fa93465a66e7..a5375dc24d13 100755 --- a/t/cli/test_cmd.sh +++ b/t/cli/test_cmd.sh @@ -80,6 +80,12 @@ deployment: admin_api_mtls: admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt' admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key' + admin_key_required: true # Enable Admin API authentication by default for security. + admin_key: + - + name: admin # admin: write access to configurations. + key: edd1c9f034335f136f87ad84b625c8f1 + role: admin " > conf/customized_config.yaml ./bin/apisix start -c conf/customized_config.yaml @@ -92,7 +98,7 @@ if [ ! -e conf/.customized_config_path ]; then fi # check if the custom config is used -code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1") if [ ! $code -eq 200 ]; then rm conf/customized_config.yaml echo "failed: customized config.yaml not be used" @@ -119,8 +125,10 @@ fi # check if apisix can be started use correctly default config. (https://github.com/apache/apisix/issues/9700) ./bin/apisix start - -code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +sleep 1 +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +echo "look here" $admin_key +code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ ! $code -eq 200 ]; then rm conf/customized_config.yaml echo "failed: should use default config" @@ -157,11 +165,17 @@ deployment: admin_api_mtls: admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt' admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key' + admin_key_required: true # Enable Admin API authentication by default for security. + admin_key: + - + name: admin # admin: write access to configurations. + key: edd1c9f034335f136f87ad84b625c8f1 + role: admin " > conf/customized_config.yaml ./bin/apisix start -c conf/customized_config.yaml -code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +code=$(curl -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1") if [ ! $code -eq 200 ]; then rm conf/customized_config.yaml echo "failed: should use default config" diff --git a/t/cli/test_deployment_control_plane.sh b/t/cli/test_deployment_control_plane.sh index ed3a062a8117..19e5152f138e 100755 --- a/t/cli/test_deployment_control_plane.sh +++ b/t/cli/test_deployment_control_plane.sh @@ -36,7 +36,8 @@ deployment: make run sleep 1 -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ ! $code -eq 200 ]; then echo "failed: control_plane should enable Admin API" @@ -45,7 +46,8 @@ fi echo "passed: control_plane should enable Admin API" -curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "upstream": { "nodes": { @@ -56,7 +58,8 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335 "uri": "/*" }' -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/c -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/c -H "X-API-KEY: $admin_key") make stop if [ ! $code -eq 404 ]; then echo "failed: should disable request proxy" diff --git a/t/cli/test_deployment_data_plane.sh b/t/cli/test_deployment_data_plane.sh index b7edb0e2411b..14b4cc26e321 100755 --- a/t/cli/test_deployment_data_plane.sh +++ b/t/cli/test_deployment_data_plane.sh @@ -50,7 +50,8 @@ fi echo "passed: data_plane does not write data to etcd" -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H "X-API-KEY: $admin_key") make stop if [ ! $code -eq 404 ]; then diff --git a/t/cli/test_deployment_traditional.sh b/t/cli/test_deployment_traditional.sh index 24996eb3b947..d4c209b3fa50 100755 --- a/t/cli/test_deployment_traditional.sh +++ b/t/cli/test_deployment_traditional.sh @@ -34,7 +34,8 @@ deployment: make run sleep 1 -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") make stop if [ ! $code -eq 200 ]; then @@ -63,7 +64,8 @@ deployment: make run sleep 1 -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") make stop if [ ! $code -eq 200 ]; then diff --git a/t/cli/test_dns.sh b/t/cli/test_dns.sh index 86dd9dbb1f19..f0e19a837597 100755 --- a/t/cli/test_dns.sh +++ b/t/cli/test_dns.sh @@ -144,9 +144,9 @@ nginx_config: make run sleep 0.5 - +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') curl -v -k -i -m 20 -o /dev/null -s -X PUT http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d '{ "upstream": { "type": "roundrobin", diff --git a/t/cli/test_etcd_healthcheck.sh b/t/cli/test_etcd_healthcheck.sh index 52b90bc908d2..e756653c1cca 100755 --- a/t/cli/test_etcd_healthcheck.sh +++ b/t/cli/test_etcd_healthcheck.sh @@ -49,7 +49,9 @@ docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml up -d make init && make run docker stop ${ETCD_NAME_0} -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') + +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ ! $code -eq 200 ]; then echo "failed: apisix got effect when one etcd node out of a cluster disconnected" exit 1 @@ -57,7 +59,9 @@ fi docker start ${ETCD_NAME_0} docker stop ${ETCD_NAME_1} -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') + +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ ! $code -eq 200 ]; then echo "failed: apisix got effect when one etcd node out of a cluster disconnected" exit 1 @@ -75,7 +79,8 @@ docker stop ${ETCD_NAME_0} && docker stop ${ETCD_NAME_1} && docker stop ${ETCD_N sleep_till=$(date +%s -d "$DATE + $HEALTH_CHECK_RETRY_TIMEOUT second") -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ $code -eq 200 ]; then echo "failed: apisix not got effect when all etcd nodes disconnected" exit 1 @@ -90,7 +95,8 @@ if [ "$sleep_seconds" -gt 0 ]; then sleep $sleep_seconds fi -code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H "X-API-KEY: $admin_key") if [ ! $code -eq 200 ]; then echo "failed: apisix could not recover when etcd node recover" docker ps diff --git a/t/cli/test_prometheus.sh b/t/cli/test_prometheus.sh index 2f2382980fb3..a613993d178e 100755 --- a/t/cli/test_prometheus.sh +++ b/t/cli/test_prometheus.sh @@ -78,9 +78,10 @@ plugin_attr: IP=127.0.0.1 PORT=9092 make run +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') # initialize prometheus metrics public API route #1 code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} -X PUT http://127.0.0.1:9180/apisix/admin/routes/metrics1 \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d "{ \"uri\": \"/prometheus/metrics\", \"plugins\": { @@ -153,9 +154,10 @@ plugin_attr: IP=127.0.0.1 PORT=9092 make run +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') # initialize prometheus metrics public API route #2 code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} -X PUT http://127.0.0.1:9180/apisix/admin/routes/metrics2 \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d "{ \"uri\": \"/apisix/prometheus/metrics\", \"plugins\": { diff --git a/t/cli/test_prometheus_stream.sh b/t/cli/test_prometheus_stream.sh index abf960e776a5..c326315c529d 100755 --- a/t/cli/test_prometheus_stream.sh +++ b/t/cli/test_prometheus_stream.sh @@ -35,8 +35,9 @@ stream_plugins: make run sleep 0.5 +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') curl -v -k -i -m 20 -o /dev/null -s -X PUT http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ - -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" \ + -H "X-API-KEY: $admin_key" \ -d '{ "plugins": { "prometheus": {} diff --git a/t/cli/test_tls_over_tcp.sh b/t/cli/test_tls_over_tcp.sh index 5f95f29db740..c4dbc67ee7e3 100755 --- a/t/cli/test_tls_over_tcp.sh +++ b/t/cli/test_tls_over_tcp.sh @@ -39,16 +39,18 @@ nginx_config: make run sleep 0.1 +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') curl http://127.0.0.1:9180/apisix/admin/ssls/1 \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +-H "X-API-KEY: $admin_key" -X PUT -d ' { "cert" : "'"$(cat t/certs/mtls_server.crt)"'", "key": "'"$(cat t/certs/mtls_server.key)"'", "snis": ["test.com"] }' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') curl -k -i http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ - -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d \ + -H "X-API-KEY: $admin_key" -X PUT -d \ '{"upstream":{"nodes":{"127.0.0.1:9101":1},"type":"roundrobin"}}' sleep 0.1 diff --git a/t/cli/test_upstream_mtls.sh b/t/cli/test_upstream_mtls.sh index 1245a01efd39..0318a4539a27 100755 --- a/t/cli/test_upstream_mtls.sh +++ b/t/cli/test_upstream_mtls.sh @@ -50,7 +50,8 @@ make init make run sleep 0.1 -curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { @@ -109,7 +110,8 @@ make init make run sleep 0.1 -curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') +curl -k -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' { "uri": "/hello", "upstream": { diff --git a/t/fuzzing/client_abort.py b/t/fuzzing/client_abort.py index 3a75442a32a5..80bf338eb338 100755 --- a/t/fuzzing/client_abort.py +++ b/t/fuzzing/client_abort.py @@ -22,9 +22,23 @@ import time import threading from public import check_leak, run_test +import yaml + +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None def create_route(): - command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return + command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY:{key}" -X PUT -d ' { "uri": "/client_abort", "upstream": { diff --git a/t/fuzzing/http_upstream.py b/t/fuzzing/http_upstream.py index 877f298cdd5e..6106602340a9 100755 --- a/t/fuzzing/http_upstream.py +++ b/t/fuzzing/http_upstream.py @@ -23,14 +23,25 @@ import random import threading from public import check_leak, run_test, connect_admin - +import yaml REQ_PER_THREAD = 50 THREADS_NUM = 4 TOTOL_ROUTES = 10 - +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None def create_route(): + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return for i in range(TOTOL_ROUTES): conn = connect_admin() scheme = "http" if i % 2 == 0 else "https" @@ -53,7 +64,7 @@ def create_route(): conn.request("PUT", "/apisix/admin/routes/" + i, conf, headers={ - "X-API-KEY":"edd1c9f034335f136f87ad84b625c8f1", + "X-API-KEY":key, }) response = conn.getresponse() assert response.status <= 300, response.read() diff --git a/t/fuzzing/requirements.txt b/t/fuzzing/requirements.txt index 785a5de912de..9c68d01c2934 100644 --- a/t/fuzzing/requirements.txt +++ b/t/fuzzing/requirements.txt @@ -1,3 +1,4 @@ psutil==5.8.0 typing==3.7.4.3 boofuzz==0.4.0 +PyYAML==5.4.1 diff --git a/t/fuzzing/serverless_route_test.py b/t/fuzzing/serverless_route_test.py index 564914734877..abdef56d7798 100644 --- a/t/fuzzing/serverless_route_test.py +++ b/t/fuzzing/serverless_route_test.py @@ -20,9 +20,23 @@ import subprocess from public import initfuzz, run_test from boofuzz import s_block, s_delim, s_get, s_group, s_initialize, s_size, s_static, s_string +import yaml + +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None def create_route(): - command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return + command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: {key}" -X PUT -d ' { "uri": "/post*", "methods": ["POST"], diff --git a/t/fuzzing/simple_http.py b/t/fuzzing/simple_http.py index b3db2027e3f2..e8c524758dd2 100755 --- a/t/fuzzing/simple_http.py +++ b/t/fuzzing/simple_http.py @@ -23,12 +23,20 @@ import random import threading from public import check_leak, LEAK_COUNT, run_test, connect_admin - +import yaml REQ_PER_THREAD = 50 THREADS_NUM = 10 TOTOL_ROUTES = 50 +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None def create_route(): conf = json.dumps({ @@ -41,10 +49,18 @@ def create_route(): } }) conn = connect_admin() + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return + key = key.replace('"', '') + print("the key is", key) + headers = { + "X-API-KEY": key, + } + print("Request headers:", headers) conn.request("PUT", "/apisix/admin/consumers", conf, - headers={ - "X-API-KEY":"edd1c9f034335f136f87ad84b625c8f1", - }) + headers=headers) response = conn.getresponse() assert response.status <= 300, response.read() @@ -80,11 +96,8 @@ def create_route(): "type": "roundrobin" }, }) - conn.request("PUT", "/apisix/admin/routes/" + i, conf, - headers={ - "X-API-KEY":"edd1c9f034335f136f87ad84b625c8f1", - }) + headers=headers) response = conn.getresponse() assert response.status <= 300, response.read() diff --git a/t/fuzzing/simpleroute_test.py b/t/fuzzing/simpleroute_test.py index 9ea56ce693b1..20d459eb54c4 100755 --- a/t/fuzzing/simpleroute_test.py +++ b/t/fuzzing/simpleroute_test.py @@ -20,19 +20,38 @@ import subprocess from public import initfuzz, run_test from boofuzz import s_block, s_delim, s_get, s_group, s_initialize, s_static, s_string +import yaml + + +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None + + + def create_route(): - command = '''curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' -{ + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return + # Construct curl command with the extracted key + command = f'''curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: {key}" -X PUT -d ' +{{ "uri": "/get*", "methods": ["GET"], - "upstream": { + "upstream": {{ "type": "roundrobin", - "nodes": { + "nodes": {{ "127.0.0.1:6666": 1 - } - } -}' + }} + }} +}}' ''' subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) diff --git a/t/fuzzing/vars_route_test.py b/t/fuzzing/vars_route_test.py index dc8325484c3c..3d382d239590 100644 --- a/t/fuzzing/vars_route_test.py +++ b/t/fuzzing/vars_route_test.py @@ -20,9 +20,22 @@ import subprocess from public import initfuzz, run_test from boofuzz import s_block, s_delim, s_get, s_group, s_initialize, s_static, s_string +import yaml +def get_admin_key_from_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + try: + admin_key = yaml_data['deployment']['admin']['admin_key'][0]['key'] + return admin_key + except KeyError: + return None def create_route(): - command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' + key = get_admin_key_from_yaml('conf/config.yaml') + if key is None: + print("Key not found in the YAML file.") + return + command = '''curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: {key}" -X PUT -d ' { "uri": "/parameter*", "vars": [ diff --git a/utils/install-dependencies.sh b/utils/install-dependencies.sh index 058a87eed1de..0a50fa9c33e5 100755 --- a/utils/install-dependencies.sh +++ b/utils/install-dependencies.sh @@ -54,7 +54,7 @@ function install_dependencies_with_yum() { set -eu fi sudo yum install -y \ - gcc gcc-c++ curl wget unzip xz gnupg perl-ExtUtils-Embed cpanminus patch \ + gcc gcc-c++ curl wget unzip xz gnupg perl-ExtUtils-Embed cpanminus patch libyaml-devel \ perl perl-devel pcre pcre-devel openldap-devel \ openresty-zlib-devel openresty-pcre-devel } diff --git a/utils/linux-install-luarocks.sh b/utils/linux-install-luarocks.sh index 50a2461d097b..fc7fc7be09b0 100755 --- a/utils/linux-install-luarocks.sh +++ b/utils/linux-install-luarocks.sh @@ -65,3 +65,4 @@ fi luarocks config variables.OPENSSL_LIBDIR ${OPENSSL_PREFIX}/lib luarocks config variables.OPENSSL_INCDIR ${OPENSSL_PREFIX}/include +luarocks config variables.YAML_DIR /usr