├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .luacheckrc ├── LICENSE ├── MAINTAINING.md ├── Makefile ├── README.md ├── api_v3.md ├── health_check.md ├── lib └── resty │ ├── etcd.lua │ └── etcd │ ├── health_check.lua │ ├── proto.lua │ ├── serializers │ ├── json.lua │ └── raw.lua │ ├── utils.lua │ └── v3.lua ├── rockspec ├── lua-resty-etcd-0.5-0.rockspec ├── lua-resty-etcd-0.6-0.rockspec ├── lua-resty-etcd-0.7-0.rockspec ├── lua-resty-etcd-0.8-0.rockspec ├── lua-resty-etcd-0.9-0.rockspec ├── lua-resty-etcd-1.0-0.rockspec ├── lua-resty-etcd-1.1-0.rockspec ├── lua-resty-etcd-1.10.0-0.rockspec ├── lua-resty-etcd-1.10.1-0.rockspec ├── lua-resty-etcd-1.10.2-0.rockspec ├── lua-resty-etcd-1.10.3-0.rockspec ├── lua-resty-etcd-1.10.4-0.rockspec ├── lua-resty-etcd-1.10.5-0.rockspec ├── lua-resty-etcd-1.10.6-0.rockspec ├── lua-resty-etcd-1.2-0.rockspec ├── lua-resty-etcd-1.3-0.rockspec ├── lua-resty-etcd-1.4-0.rockspec ├── lua-resty-etcd-1.4.1-0.rockspec ├── lua-resty-etcd-1.4.2-0.rockspec ├── lua-resty-etcd-1.4.3-0.rockspec ├── lua-resty-etcd-1.4.4-0.rockspec ├── lua-resty-etcd-1.5.0-0.rockspec ├── lua-resty-etcd-1.5.1-0.rockspec ├── lua-resty-etcd-1.5.2-0.rockspec ├── lua-resty-etcd-1.5.3-0.rockspec ├── lua-resty-etcd-1.5.4-0.rockspec ├── lua-resty-etcd-1.5.5-0.rockspec ├── lua-resty-etcd-1.6.0-0.rockspec ├── lua-resty-etcd-1.6.1-0.rockspec ├── lua-resty-etcd-1.6.2-0.rockspec ├── lua-resty-etcd-1.7.0-0.rockspec ├── lua-resty-etcd-1.8.0-0.rockspec ├── lua-resty-etcd-1.8.1-0.rockspec ├── lua-resty-etcd-1.8.2-0.rockspec ├── lua-resty-etcd-1.8.3-0.rockspec ├── lua-resty-etcd-1.9.0-0.rockspec └── lua-resty-etcd-master-0.1-0.rockspec ├── t ├── Procfile-single ├── Procfile-single-enable-mtls ├── Procfile-single-enable-tls ├── certs │ ├── etcd.key │ ├── etcd.pem │ ├── mtls_ca.crt │ ├── mtls_client.crt │ ├── mtls_client.key │ ├── mtls_server.crt │ └── mtls_server.key ├── normalize.t └── v3 │ ├── add-auth.sh │ ├── auth.t │ ├── cluster.t │ ├── grpc │ ├── health_check.t │ ├── key.t │ ├── lease.t │ ├── misc.t │ ├── mtls.t │ ├── stats.t │ ├── tls.t │ └── txn.t │ ├── health_check.t │ ├── key.t │ ├── lease.t │ ├── lease3.4.t │ ├── mtls.t │ ├── opt.t │ ├── serializer.t │ ├── sni.t │ ├── stats.t │ ├── tls.t │ ├── txn.t │ └── unix_socket.t └── utils └── check-lua-code-style.sh /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | 10 | jobs: 11 | build: 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - version: 3.4.0 17 | conf: Procfile-single 18 | - version: 3.5.0 19 | conf: Procfile-single 20 | - version: 3.4.0 21 | conf: Procfile-single-enable-tls 22 | - version: 3.4.0 23 | conf: Procfile-single-enable-mtls 24 | 25 | runs-on: "ubuntu-20.04" 26 | env: 27 | OPENRESTY_PREFIX: "/usr/local/openresty" 28 | AUTH_ENDPOINT_V3: "127.0.0.1:12379" 29 | AUTH_USER: root 30 | AUTH_PWD: abc123 31 | ETCD_VER: "${{ matrix.version }}" 32 | GOREMAN_CONF: "${{ matrix.conf }}" 33 | 34 | steps: 35 | - uses: actions/checkout@v2 36 | 37 | - name: setup go 38 | uses: actions/setup-go@v2.1.3 39 | with: 40 | # goreman requires 1.17 41 | go-version: "1.17" 42 | 43 | - name: get dependencies 44 | run: sudo apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl 45 | 46 | - name: Setup Lua 47 | uses: leafo/gh-actions-lua@v8.0.0 48 | with: 49 | luaVersion: "5.1.5" 50 | 51 | - name: Install Luarocks 52 | uses: leafo/gh-actions-luarocks@v4 53 | 54 | - name: install 55 | run: | 56 | git clone https://github.com/openresty/test-nginx.git test-nginx 57 | cd test-nginx && (sudo cpanm --notest . > build.log 2>&1 || (cat build.log && exit 1)) && cd .. 58 | 59 | wget https://raw.githubusercontent.com/api7/apisix-build-tools/refs/tags/apisix-base/1.21.4.2.2/build-apisix-base.sh 60 | chmod +x build-apisix-base.sh 61 | OR_PREFIX=$OPENRESTY_PREFIX ./build-apisix-base.sh latest 62 | 63 | luarocks make rockspec/lua-resty-etcd-master-0.1-0.rockspec 64 | luarocks install luacheck > build.log 2>&1 || (cat build.log && exit 1) 65 | luarocks install dkjson > build.log 2>&1 || (cat build.log && exit 1) 66 | make utils 67 | wget https://github.com/etcd-io/etcd/releases/download/v$ETCD_VER/etcd-v$ETCD_VER-linux-amd64.tar.gz 68 | tar xf etcd-v$ETCD_VER-linux-amd64.tar.gz 69 | # run etcd local cluster, startup at localhost:2379, localhost:22379, and localhost:32379 70 | # see more https://github.com/etcd-io/etcd/blob/master/Documentation/dev-guide/local_cluster.md 71 | go get github.com/mattn/goreman 72 | 73 | - name: script 74 | if: matrix.conf != 'Procfile-single-enable-mtls' 75 | run: | 76 | if [[ "$GOREMAN_CONF" == "Procfile-single-enable-tls" ]]; then 77 | export ETCD_ENABLE_TLS=TRUE 78 | export ETCDCTL_EXTRA_OPTS="--insecure-transport=false --insecure-skip-tls-verify=true" 79 | fi 80 | export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$PWD/etcd-v$ETCD_VER-linux-amd64:$PATH 81 | etcd --version 82 | goreman -f ./t/$GOREMAN_CONF start > goreman.log 2>&1 & 83 | sleep 5 84 | chmod +x ./t/v3/add-auth.sh 85 | [[ $ETCD_ENABLE_TLS != TRUE ]] && ./t/v3/add-auth.sh || true 86 | cat goreman.log 87 | ps -ef | grep etcd 88 | luajit -v 89 | luajit -v | awk '{print$2}'| grep 2.1 90 | make lint || exit 1 91 | make test 92 | 93 | - name: script 94 | if: matrix.conf == 'Procfile-single-enable-mtls' 95 | run: | 96 | export ETCD_ENABLE_MTLS=TRUE 97 | export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$PWD/etcd-v$ETCD_VER-linux-amd64:$PATH 98 | etcd --version 99 | goreman -f ./t/$GOREMAN_CONF start > goreman.log 2>&1 & 100 | sleep 5 101 | prove -I../test-nginx/lib t/v3/mtls.t t/v3/grpc/mtls.t 102 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - "master" 7 | paths: 8 | - 'rockspec/**' 9 | 10 | jobs: 11 | release: 12 | name: Release 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout code 16 | uses: actions/checkout@v2 17 | 18 | - name: Install Lua 19 | uses: leafo/gh-actions-lua@v8 20 | 21 | - name: Install Luarocks 22 | uses: leafo/gh-actions-luarocks@v4 23 | 24 | - name: Extract release name 25 | id: release_env 26 | shell: bash 27 | run: | 28 | title="${{ github.event.head_commit.message }}" 29 | re="^feat: release v*(\S+)" 30 | if [[ $title =~ $re ]]; then 31 | v=v${BASH_REMATCH[1]} 32 | echo "##[set-output name=version;]${v}" 33 | echo "##[set-output name=version_withou_v;]${BASH_REMATCH[1]}" 34 | else 35 | echo "commit format is not correct" 36 | exit 1 37 | fi 38 | 39 | - name: Create Release 40 | uses: actions/create-release@v1 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | with: 44 | tag_name: ${{ steps.release_env.outputs.version }} 45 | release_name: ${{ steps.release_env.outputs.version }} 46 | draft: false 47 | prerelease: false 48 | 49 | - name: Upload to luarocks 50 | env: 51 | LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }} 52 | run: | 53 | luarocks install dkjson 54 | luarocks upload rockspec/lua-resty-etcd-${{ steps.release_env.outputs.version_withou_v }}-0.rockspec --api-key=${LUAROCKS_TOKEN} 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # dev 55 | go 56 | t/servroot 57 | utils/lj-releng 58 | [\.]* 59 | !.github/ 60 | *.etcd 61 | *.log 62 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | std = 'ngx_lua' 2 | 3 | ignore={ 4 | "542" 5 | } 6 | -- allow redefining err in the err handling 7 | redefined = false 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MAINTAINING.md: -------------------------------------------------------------------------------- 1 | ## Version Publish 2 | 3 | After [#137](https://github.com/api7/lua-resty-etcd/pull/137) got merged, we could publish new version of lua-resty-etcd easily. All you need to do is: 4 | 5 | - Create the release PR following the format `feat: release VERSION`, where `VERSION` should be the version used in the rockspec name, like `1.0` for `lua-resty-etcd-1.0-0.rockspec`. 6 | 7 | When the PR got merged, it would trigger Github Actions to upload to both github release and luarocks. 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local/openresty 2 | LUA_LIB_DIR ?= $(PREFIX)/lualib/$(LUA_VERSION) 3 | INSTALL ?= install 4 | 5 | ### install: Install the library to runtime 6 | .PHONY: install 7 | install: 8 | $(INSTALL) lib/resty/*.lua $(LUA_LIB_DIR)/resty/ 9 | 10 | ### dev: Create a development ENV 11 | .PHONY: dev 12 | dev: 13 | luarocks install rockspec/lua-resty-etcd-master-0.1-0.rockspec --only-deps --local 14 | 15 | ### help: Show Makefile rules 16 | .PHONY: help 17 | help: 18 | @echo Makefile rules: 19 | @echo 20 | @grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /' 21 | 22 | ### lint: Lint Lua source code 23 | .PHONY: lint 24 | lint: utils 25 | chmod a+x utils/check-lua-code-style.sh 26 | ./utils/check-lua-code-style.sh 27 | 28 | ### utils: Installation tools 29 | .PHONY: utils 30 | utils: 31 | ifeq ("$(wildcard utils/lj-releng)", "") 32 | wget -O utils/lj-releng https://raw.githubusercontent.com/iresty/openresty-devel-utils/master/lj-releng 33 | chmod a+x utils/lj-releng 34 | endif 35 | 36 | test: 37 | prove -I../test-nginx/lib -r -s t/ 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Name 2 | ==== 3 | 4 | [lua-resty-etcd](https://github.com/iresty/lua-resty-etcd) Nonblocking Lua etcd driver library for OpenResty, this module supports etcd API v3. 5 | 6 | [![Build Status](https://github.com/api7/lua-resty-etcd/actions/workflows/ci.yml/badge.svg)](https://github.com/api7/lua-resty-etcd/actions/workflows/ci.yml) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/iresty/lua-resty-etcd/blob/master/LICENSE) 8 | 9 | Table of Contents 10 | ================= 11 | * [Install](#install) 12 | * [API v3](api_v3.md) 13 | * **NOTE**: Requires ETCD version >= v3.4.0 14 | 15 | ## Install 16 | 17 | > Dependencies 18 | 19 | - api7-lua-resty-http: https://github.com/api7/lua-resty-http 20 | - lua-typeof: https://github.com/iresty/lua-typeof 21 | 22 | > install by luarocks 23 | 24 | ```shell 25 | luarocks install lua-resty-etcd 26 | ``` 27 | 28 | > install by source 29 | 30 | ```shell 31 | $ git clone https://github.com/iresty/lua-resty-etcd.git 32 | $ cd lua-resty-etcd 33 | $ make dev 34 | $ sudo make install 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /api_v3.md: -------------------------------------------------------------------------------- 1 | API V3 2 | ====== 3 | 4 | * [Methods](#methods) 5 | * [new](#new) 6 | * [get](#get) 7 | * [set](#set) 8 | * [setnx](#setnx) 9 | * [setx](#setx) 10 | * [delete](#delete) 11 | * [watch](#watch) 12 | * [watchcancel](#watchcancel) 13 | * [readdir](#readdir) 14 | * [watchdir](#watchdir) 15 | * [rmdir](#rmdir) 16 | * [txn](#txn) 17 | * [version](#version) 18 | * [grant](#grant) 19 | * [revoke](#revoke) 20 | * [keepalive](#keepalive) 21 | * [timetolive](#timetolive) 22 | * [leases](#leases) 23 | 24 | Method 25 | ====== 26 | 27 | ### new 28 | 29 | `syntax: cli, err = etcd.new([option:table])` 30 | 31 | - `option:table` 32 | - `protocol`: string - `v3`. 33 | - `http_host`: string - default `http://127.0.0.1:2379` 34 | - `ttl`: int - default `-1` 35 | default ttl for key operation. set -1 to disable ttl. 36 | - `key_prefix`: string 37 | append this prefix path string to key operation url. 38 | - `timeout`: int 39 | default request timeout seconds. 40 | - `api_prefix`: string 41 | to suit [etcd v3 api gateway](https://etcd.io/docs/v3.5/dev-guide/api_grpc_gateway/#notes). 42 | it will autofill by fetching etcd version if this option empty. 43 | - `ssl_verify`: boolean - whether to verify the etcd certificate when originating TLS connection with etcd (if you want to communicate to etcd with TLS connection, use `https` scheme in your `http_host`), default is `true`. 44 | - `ssl_cert_path`: string - path to the client certificate 45 | - `ssl_key_path`: string - path to the client key 46 | - `ssl_cert`: string - content of the client certificate 47 | - `ssl_key`: string - content of the client key 48 | - `serializer`: string - serializer type, default `json`, also support `raw` to keep origin string value. 49 | - `extra_headers`: table - adding custom headers for etcd requests. 50 | - `sni`: string - adding custom SNI fot etcd TLS requests. 51 | - `unix_socket_proxy`: string - the unix socket path which will be used to proxy the etcd request. 52 | 53 | The client method returns either a `etcd` object or an `error string`. 54 | 55 | ```lua 56 | local cli, err = require("resty.etcd").new({protocol = "v3"}) 57 | ``` 58 | 59 | Please refer to the **etcd API documentaion** at - https://github.com/coreos/etcd for more details. 60 | 61 | [Back to TOP](#api-v3) 62 | 63 | ### get 64 | 65 | `syntax: res, err = cli:get(key:string[, opts])` 66 | 67 | * `key`: string value. 68 | * `opts`: optional options. 69 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 70 | * `revision`: (int) revision is the point-in-time of the key-value store to use for the range. If revision is less than or equal to zero, the range is over the newest key-value store. If the revision has been compacted, ErrCompacted is returned as a response. 71 | 72 | To get the value for key. 73 | 74 | ```lua 75 | local res, err = cli:get('/path/to/key') 76 | ``` 77 | 78 | [Back to TOP](#api-v3) 79 | 80 | ### set 81 | 82 | `syntax: res, err = cli:set(key:string, val:JSON value [, opts:table])` 83 | 84 | * `key`: string value. 85 | * `val`: the value which can be encoded via JSON. 86 | * `opts`: optional options. 87 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 88 | * `lease`: (int) the lease ID to associate with the key in the key-value store. 89 | * `prev_kv`: (bool) If prev_kv is set, etcd gets the previous key-value pair before changing it. The previous key-value pair will be returned in the put response. 90 | * `ignore_value`: (bool) If ignore_value is set, etcd updates the key using its current value. Returns an error if the key does not exist. 91 | * `ignore_lease`: (bool) If ignore_lease is set, etcd updates the key using its current lease. Returns an error if the key does not exist. 92 | 93 | To set a key-value pair. 94 | 95 | ```lua 96 | local res, err = cli:set('/path/to/key', 'val', 10) 97 | ``` 98 | 99 | [Back to TOP](#api-v3) 100 | 101 | ### setnx 102 | 103 | `syntax: res, err = cli:setnx(key:string, val:JSON value [, opts:table])` 104 | 105 | * `key`: string value. 106 | * `val`: the value which can be encoded via JSON. 107 | * `opts`: optional options. 108 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 109 | 110 | To set a key-value pair if that key does not exist. 111 | 112 | ```lua 113 | local res, err = cli:setnx('/path/to/key', 'val', 10) 114 | ``` 115 | 116 | [Back to TOP](#api-v3) 117 | 118 | ### setx 119 | 120 | `syntax: res, err = cli:setx(key:string, val:JSON value [, opts:table])` 121 | 122 | * `key`: string value. 123 | * `val`: the value which can be encoded via JSON. 124 | * `opts`: optional options. 125 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 126 | 127 | To set a key-value pair when that key exists. 128 | 129 | ```lua 130 | local res, err = cli:setx('/path/to/key', 'val', 10) 131 | ``` 132 | 133 | [Back to TOP](#api-v3) 134 | 135 | ### delete 136 | 137 | `syntax: res, err = cli:delete(key:string [, opts:table])` 138 | 139 | * `key`: string value. 140 | * `opts`: optional options. 141 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 142 | * `prev_kv`: (bool) If prev_kv is set, etcd gets the previous key-value pairs before deleting it. The previous key-value pairs will be returned in the delete response. 143 | 144 | To delete a key-value pair. 145 | 146 | ```lua 147 | local res, err = cli:delete('/path/to/key') 148 | ``` 149 | 150 | [Back to TOP](#api-v3) 151 | 152 | 153 | ### watch 154 | 155 | `syntax: res, err = cli:watch(key:string [, opts:table]) ` 156 | 157 | * `key`: string value. 158 | * `opts`: optional options. 159 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 160 | * `start_revision`: (int) start_revision is an optional revision to watch from (inclusive). No start_revision is "now". 161 | * `progress_notify`: (bool) progress_notify is set so that the etcd server will periodically send a WatchResponse with no events to the new watcher if there are no recent events. 162 | * `filters`: (slice of (enum FilterType {NOPUT = 0;NODELETE = 1;})) filters filter the events at server side before it sends back to the watcher. 163 | * `prev_kv`: (bool) If prev_kv is set, created watcher gets the previous KV before the event happens. If the previous KV is already compacted, nothing will be returned. 164 | * `watch_id`: (int) If watch_id is provided and non-zero, it will be assigned to this watcher. Since creating a watcher in etcd is not a synchronous operation, this can be used to ensure that ordering is correct when creating multiple watchers on the same stream. Creating a watcher with an ID already in use on the stream will cause an error to be returned. 165 | * `fragment`: (bool) fragment enables splitting large revisions into multiple watch responses. 166 | * `need_cancel`: (bool) if watch need to be cancel, watch would return http_cli for further cancelation. See [watchcancel](#watchcancel) for detail. 167 | 168 | To watch the update of key. 169 | 170 | ```lua 171 | local res, err = cli:watch('/path/to/key') 172 | ``` 173 | 174 | [Back to TOP](#api-v3) 175 | 176 | ### watchcancel 177 | 178 | `syntax: res, err = cli:watchcancel(http_cli:table)` 179 | 180 | * `http_cli`: the http client needs to revoke. 181 | 182 | To cancel the watch before it get expired. Need to set `need_cancel` to get the http client for cancelation. 183 | 184 | ```lua 185 | local res, err, http_cli = cli:watch('/path/to/key', {need_cancel = true}) 186 | res = cli:watchcancel(http_cli) 187 | ``` 188 | 189 | [Back to TOP](#api-v3) 190 | 191 | ### readdir 192 | 193 | `syntax: res, err = cli:readdir(dir:string [, opts:table])` 194 | 195 | * `key`: string value. 196 | * `opts`: optional options. 197 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 198 | * `revision`: (int) revision is the point-in-time of the key-value store to use for the range. If revision is less than or equal to zero, the range is over the newest key-value store. If the revision has been compacted, ErrCompacted is returned as a response. 199 | * `limit`: (int) limit is a limit on the number of keys returned for the request. When limit is set to 0, it is treated as no limit. 200 | * `sort_order`: (int [SortNone:0, SortAscend:1, SortDescend:2]) sort_order is the order for returned sorted results. 201 | * `sort_target`: (int [SortByKey:0, SortByVersion:1, SortByCreateRevision:2, SortByModRevision:3, SortByValue:4]) sort_target is the key-value field to use for sorting. 202 | * `keys_only`: (bool) keys_only when set returns only the keys and not the values. 203 | * `count_only`: (bool) count_only when set returns only the count of the keys in the range. 204 | 205 | To read the directory. 206 | 207 | ```lua 208 | local res, err = cli:readdir('/path/to/dir') 209 | ``` 210 | 211 | [Back to TOP](#api-v3) 212 | 213 | 214 | ### watchdir 215 | 216 | `syntax: res, err = cli:watchdir(dir:string [, opts:table])` 217 | 218 | 219 | * `key`: string value. 220 | * `opts`: optional options. 221 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 222 | * `start_revision`: (int) start_revision is an optional revision to watch from (inclusive). No start_revision is "now". 223 | * `progress_notify`: (bool) progress_notify is set so that the etcd server will periodically send a WatchResponse with no events to the new watcher if there are no recent events. 224 | * `filters`: (slice of [enum FilterType {NOPUT = 0;NODELETE = 1;}]) filters filter the events at server side before it sends back to the watcher. 225 | * `prev_kv`: (bool) If prev_kv is set, created watcher gets the previous KV before the event happens. If the previous KV is already compacted, nothing will be returned. 226 | * `watch_id`: (int) If watch_id is provided and non-zero, it will be assigned to this watcher. Since creating a watcher in etcd is not a synchronous operation, this can be used to ensure that ordering is correct when creating multiple watchers on the same stream. Creating a watcher with an ID already in use on the stream will cause an error to be returned. 227 | * `fragment`: (bool) fragment enables splitting large revisions into multiple watch responses. 228 | 229 | To watch the update of directory. 230 | 231 | 232 | ```lua 233 | local res, err = cli:watchdir('/path/to/dir') 234 | ``` 235 | 236 | [Back to TOP](#api-v3) 237 | 238 | 239 | ### rmdir 240 | 241 | `syntax: res, err = cli:rmdir(dir:string [, opts:table])` 242 | 243 | * `key`: string value. 244 | * `opts`: optional options. 245 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 246 | * `prev_kv`: (bool) If prev_kv is set, etcd gets the previous key-value pairs before deleting it. The previous key-value pairs will be returned in the delete response. 247 | 248 | To remove the directory. 249 | 250 | ```lua 251 | local res, err = cli:rmdir('/path/to/dir') 252 | ``` 253 | 254 | [Back to TOP](#api-v3) 255 | 256 | 257 | ### txn 258 | 259 | `syntax: res, err = cli:txn(compare:array, success:array, failure:array [, opts:table])` 260 | 261 | * `compare`: array of [table](https://github.com/etcd-io/etcd/blob/master/Documentation/dev-guide/api_reference_v3.md#message-compare-etcdserveretcdserverpbrpcproto). 262 | * `success`: array of [table](https://github.com/etcd-io/etcd/blob/master/Documentation/dev-guide/api_reference_v3.md#message-requestop-etcdserveretcdserverpbrpcproto). 263 | * `failure`: array of [table](https://github.com/etcd-io/etcd/blob/master/Documentation/dev-guide/api_reference_v3.md#message-requestop-etcdserveretcdserverpbrpcproto). 264 | * `opts`: optional options. 265 | * `timeout`: (int) request timeout seconds. Set to 0 would use `lua_socket_connect_timeout` as timeout. 266 | 267 | Transaction. 268 | 269 | ```lua 270 | local compare = {} 271 | compare[1] = {} 272 | compare[1].target = "CREATE" 273 | compare[1].key = encode_base64("test") 274 | compare[1].createRevision = 0 275 | 276 | local success = {} 277 | success[1] = {} 278 | success[1].requestPut = {} 279 | success[1].requestPut.key = encode_base64("test") 280 | 281 | local res, err = cli:txn(compare, success, nil) 282 | ``` 283 | 284 | [Back to TOP](#api-v3) 285 | 286 | 287 | ### version 288 | 289 | `syntax: res, err = cli:version()` 290 | 291 | To get the etcd version info. 292 | 293 | [Back to TOP](#api-v3) 294 | 295 | ### grant 296 | 297 | `syntax: res, err = cli:grant(TTL:int [, ID:int])` 298 | 299 | - `TTL`: advisory time-to-live in seconds. 300 | - `ID`: the requested ID for the lease. If ID is set to 0, the lessor chooses an ID. 301 | 302 | To create a lease which expires if the server does not receive a keepalive within a given time to live period. All keys attached to the lease will get expired and be deleted if the lease expires. Each expired key generates a delete event in the event history. 303 | 304 | ```lua 305 | -- grant a lease with 5 second TTL 306 | local res, err = cli:grant(5) 307 | 308 | -- attach key to lease, whose ID would be contained in res 309 | local data, err = etcd:set('/path/to/key', 'val', {lease = res.body.ID}) 310 | ``` 311 | 312 | [Back to TOP](#api-v3) 313 | 314 | ### revoke 315 | 316 | `syntax: res, err = cli:revoke(ID:int)` 317 | 318 | - `ID`: the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. 319 | 320 | To revoke a lease. All keys attached to the lease will expire and be deleted. 321 | 322 | ```lua 323 | local res, err = cli:grant(5) 324 | local data, err = etcd:set('/path/to/key', 'val', {lease = res.body.ID}) 325 | 326 | local data, err = etcd:revoke(res.body.ID) 327 | local data, err = cli:get('/path/to/key') 328 | -- responce would contains no kvs 329 | ``` 330 | 331 | [Back to TOP](#api-v3) 332 | 333 | ### keepalive 334 | 335 | `syntax: res, err = cli:keepalive(ID:int)` 336 | 337 | - `ID`: the lease ID for the lease to keep alive. 338 | 339 | To keep the lease alive by streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client. 340 | 341 | [Back to TOP](#api-v3) 342 | 343 | ### timetolive 344 | 345 | `syntax: res, err = cli:timetolive(ID:int [, keys: bool])` 346 | 347 | - `ID`: the lease ID for the lease. 348 | - `keys`: if true, query all the keys attached to this lease. 349 | 350 | To retrieve lease information. 351 | 352 | [Back to TOP](#api-v3) 353 | 354 | ### leases 355 | 356 | `syntax: res, err = cli:leases()` 357 | 358 | To list all existing leases. 359 | 360 | [Back to TOP](#api-v3) 361 | -------------------------------------------------------------------------------- /health_check.md: -------------------------------------------------------------------------------- 1 | # Etcd Cluster Health Check 2 | 3 | ## Description 4 | 5 | Implement a passive health check mechanism, that when the connection/read/write fails, record it as an endpoint's failure. 6 | 7 | ## Methods 8 | 9 | * [init](#init) 10 | * [report_failure](#report_failure) 11 | * [get_target_status](#get_target_status) 12 | * [get_check_mode](#get_check_mode) 13 | 14 | ### init 15 | 16 | `syntax: health_check, err = health_check.init(params)` 17 | 18 | Initializes the health check object, overiding default params with the given ones. In case of failures, returns `nil` and a string describing the error. 19 | 20 | ### report_failure 21 | 22 | `syntax: health_check.report_failure(etcd_host)` 23 | 24 | Reports a health failure which will count against the number of occurrences required to make a target "fail". 25 | 26 | ### get_target_status 27 | 28 | `syntax: healthy, err = health_check.get_target_status(etcd_host)` 29 | 30 | Get the current status of the target. 31 | 32 | ### get_check_mode 33 | 34 | `syntax: mode = health_check.get_check_mode()` 35 | 36 | Get the current health check running mode. When `mode` is `round-robin`, it means running in [Round robin](#round-robin-based-health-check) mode, and `shared-dict` means running in [Policy](#policy-based-health-check) mode operation, `disabled` means the health check is disabled. 37 | 38 | When using this method to get the health check running mode, you can use `health_check.ROUND_ROBIN_MODE` and `health_check.SHARED_DICT_MODE`, `health_check.DISABLED_MODE` to judge and compare. 39 | 40 | ### disable 41 | 42 | `syntax: mode = health_check.disable()` 43 | 44 | Disable health check. 45 | 46 | ## Config 47 | 48 | | name | Type | Requirement | Default | Description | 49 | | ------------ | ------- | ----------- | ------- | ------------------------------------------------------------ | 50 | | shm_name | string | optional | | the declarative `lua_shared_dict` is used to store the health status of endpoints, if this option is not set, the health check will return to [round-robin](#round-robin-based-health-check) check mode. | 51 | | fail_timeout | integer | optional | 10s | sets the time during which the specified number of unsuccessful attempts to communicate with the endpoint should happen to marker the endpoint unavailable, and also sets the period of time the endpoint will be marked unavailable. | 52 | | max_fails | integer | optional | 1 | sets the number of failed attempts that must occur during the `fail_timeout` period for the endpoint to be marked unavailable. This configuration only takes effect in [policy](#policy-based-health-check) check mode | 53 | | retry | bool | optional | false | automatically retry another endpoint when operations failed. | 54 | 55 | ## Example 56 | 57 | ### Policy based health check 58 | 59 | ```lua 60 | local health_check, err = require("resty.etcd.health_check").init({ 61 | shm_name = "healthcheck_shm", 62 | fail_timeout = 10, 63 | max_fails = 1, 64 | retry = false, 65 | }) 66 | ``` 67 | 68 | In a `fail_timeout`, if there are `max_fails` consecutive failures, the endpoint is marked as unhealthy, the unhealthy endpoint will not be choosed to connect for a `fail_timeout` time in the future. 69 | 70 | Health check mechanism would switch endpoint only when the previously choosed endpoint is marked as unhealthy. 71 | 72 | The failure counter and health status of each etcd endpoint are shared across workers and by different etcd clients. 73 | 74 | PS: the `fail_timeout`, `max_fails` and `retry` of the health check After initialization, they will only be reset when the health check mode is switched. 75 | 76 | ### Round-robin based health check 77 | 78 | ```lua 79 | local health_check, err = require("resty.etcd.health_check").init({ 80 | fail_timeout = 10, 81 | retry = false, 82 | }) 83 | ``` 84 | 85 | Round-robin health check. When a endpoint fails, the endpoint will be marked as unhealthy, and will not be connected to the endpoint within the time set by `fail_timeout` (select the next healthy endpoint to connect). 86 | 87 | Unhealthy nodes will be released to the selection pool of healthy endpoints after the `fail_timeout` time is exceeded. 88 | 89 | The status of etcd unhealthy endpoints is only valid in the current worker 90 | 91 | ## Synopsis 92 | 93 | ```nginx 94 | http { 95 | # required declares a shared memory zone to store endpoints's health status 96 | # if you use the round-robin method for health check, you don’t need to set this 97 | lua_shared_dict healthcheck_shm 1m; 98 | 99 | server { 100 | location = /healthcheck { 101 | content_by_lua_block { 102 | # the health check feature is optional, and can be enabled with the following configuration. 103 | # if you use the round-robin method for health check, you don’t need to set this 104 | local health_check, err = require("resty.etcd.health_check").init({ 105 | shm_name = "healthcheck_shm", 106 | fail_timeout = 10, 107 | max_fails = 1, 108 | retry = false, 109 | }) 110 | 111 | local etcd, err = require("resty.etcd").new({ 112 | protocol = "v3", 113 | http_host = { 114 | "http://127.0.0.1:12379", 115 | "http://127.0.0.1:22379", 116 | "http://127.0.0.1:32379", 117 | }, 118 | user = 'root', 119 | password = 'abc123', 120 | }) 121 | } 122 | } 123 | } 124 | } 125 | ``` 126 | -------------------------------------------------------------------------------- /lib/resty/etcd.lua: -------------------------------------------------------------------------------- 1 | local etcdv3 = require("resty.etcd.v3") 2 | local typeof = require("typeof") 3 | local require = require 4 | local pcall = pcall 5 | 6 | local _M = {version = 0.9} 7 | 8 | 9 | local function require_serializer(serializer_name) 10 | if serializer_name then 11 | local ok, module = pcall(require, "resty.etcd.serializers." .. serializer_name) 12 | if ok then 13 | return module 14 | end 15 | end 16 | 17 | return require("resty.etcd.serializers.json") 18 | end 19 | 20 | function _M.new(opts) 21 | opts = opts or {} 22 | if not typeof.table(opts) then 23 | return nil, 'opts must be table' 24 | end 25 | 26 | local protocol = opts and opts.protocol or "v3" 27 | if protocol ~= "v3" then 28 | return nil, 'only support etcd v3 api' 29 | end 30 | 31 | opts.timeout = opts.timeout or 5 -- 5 sec 32 | opts.http_host = opts.http_host or "http://127.0.0.1:2379" 33 | opts.ttl = opts.ttl or -1 34 | 35 | local serializer_name = typeof.string(opts.serializer) and opts.serializer 36 | opts.serializer = require_serializer(serializer_name) 37 | opts.api_prefix = "/v3" 38 | 39 | return etcdv3.new(opts) 40 | end 41 | 42 | 43 | return _M 44 | -------------------------------------------------------------------------------- /lib/resty/etcd/health_check.lua: -------------------------------------------------------------------------------- 1 | local ngx_shared = ngx.shared 2 | local utils = require("resty.etcd.utils") 3 | local type = type 4 | local now = os.time 5 | local conf 6 | 7 | local HEALTH_CHECK_MODE_ROUND_ROBIN = "round-robin" 8 | local HEALTH_CHECK_MODE_SHARED_DICT = "shared-dict" 9 | local HEALTH_CHECK_MODE_DISABLED = "disabled" 10 | 11 | local _M = {} 12 | _M.ROUND_ROBIN_MODE = HEALTH_CHECK_MODE_ROUND_ROBIN 13 | _M.SHARED_DICT_MODE = HEALTH_CHECK_MODE_SHARED_DICT 14 | _M.DISABLED_MODE = HEALTH_CHECK_MODE_DISABLED 15 | 16 | local round_robin_unhealthy_target_hosts 17 | 18 | 19 | local function gen_unhealthy_key(etcd_host) 20 | return "unhealthy-" .. etcd_host 21 | end 22 | 23 | local function get_target_status(etcd_host) 24 | if not conf then 25 | return nil, "etcd health check uninitialized" 26 | end 27 | 28 | if conf.disabled then 29 | return true 30 | end 31 | 32 | if type(etcd_host) ~= "string" then 33 | return false, "etcd host invalid" 34 | end 35 | 36 | local unhealthy_key = gen_unhealthy_key(etcd_host) 37 | if conf.shm_name ~= nil then 38 | local unhealthy_endpoint, err = ngx_shared[conf.shm_name]:get(unhealthy_key) 39 | if err then 40 | utils.log_warn("failed to get unhealthy_key: ", 41 | unhealthy_key, " err: ", err) 42 | return 43 | end 44 | 45 | if not unhealthy_endpoint then 46 | return true 47 | end 48 | 49 | return false 50 | else 51 | if type(round_robin_unhealthy_target_hosts) ~= "table" then 52 | round_robin_unhealthy_target_hosts = {} 53 | end 54 | 55 | local target_fail_expired_time = round_robin_unhealthy_target_hosts[unhealthy_key] 56 | if target_fail_expired_time and target_fail_expired_time >= now() then 57 | return false, "endpoint: " .. etcd_host .. " is unhealthy" 58 | else 59 | return true 60 | end 61 | end 62 | end 63 | _M.get_target_status = get_target_status 64 | 65 | 66 | local function fault_count(key, shm_name, fail_timeout) 67 | local new_value, err, forcible = ngx_shared[shm_name]:incr(key, 1, 0, fail_timeout) 68 | if err then 69 | return nil, err 70 | end 71 | 72 | if forcible then 73 | utils.log_warn("shared dict: ", shm_name, " is full, valid items forcibly overwritten") 74 | end 75 | return new_value, nil 76 | end 77 | 78 | 79 | local function report_failure(etcd_host) 80 | if not conf then 81 | return nil, "etcd health check uninitialized" 82 | end 83 | 84 | if conf.disabled then 85 | return 86 | end 87 | 88 | if type(etcd_host) ~= "string" then 89 | return nil, "etcd host invalid" 90 | end 91 | 92 | if conf.shm_name ~= nil then 93 | local fails, err = fault_count(etcd_host, conf.shm_name, conf.fail_timeout) 94 | if err then 95 | utils.log_error("failed to incr etcd endpoint fail times: ", err) 96 | return nil, err 97 | end 98 | 99 | if fails >= conf.max_fails then 100 | local unhealthy_key = gen_unhealthy_key(etcd_host) 101 | local unhealthy_endpoint, _ = ngx_shared[conf.shm_name]:get(unhealthy_key) 102 | if unhealthy_endpoint == nil then 103 | ngx_shared[conf.shm_name]:set(unhealthy_key, etcd_host, 104 | conf.fail_timeout) 105 | utils.log_warn("update endpoint: ", etcd_host, " to unhealthy") 106 | end 107 | end 108 | else 109 | if type(round_robin_unhealthy_target_hosts) ~= "table" then 110 | round_robin_unhealthy_target_hosts = {} 111 | end 112 | local unhealthy_key = gen_unhealthy_key(etcd_host) 113 | round_robin_unhealthy_target_hosts[unhealthy_key] = now() + conf.fail_timeout 114 | utils.log_warn("update endpoint: ", etcd_host, " to unhealthy") 115 | end 116 | end 117 | _M.report_failure = report_failure 118 | 119 | 120 | local function get_check_mode() 121 | -- round-robin: nginx worker memory round-robin based health check 122 | -- shared-dict: nginx shared memory policy based health check 123 | if conf then 124 | if conf.disabled then 125 | return HEALTH_CHECK_MODE_DISABLED 126 | elseif conf.shm_name then 127 | return HEALTH_CHECK_MODE_SHARED_DICT 128 | end 129 | end 130 | 131 | return HEALTH_CHECK_MODE_ROUND_ROBIN 132 | end 133 | _M.get_check_mode = get_check_mode 134 | 135 | 136 | function _M.disable() 137 | if not conf then 138 | conf = {} 139 | end 140 | 141 | conf.disabled = true 142 | _M.conf = conf 143 | end 144 | 145 | 146 | function _M.init(opts) 147 | opts = opts or {} 148 | if not conf or opts.shm_name ~= conf.shm_name then 149 | conf = {} 150 | if opts.shm_name and type(opts.shm_name) == "string" then 151 | local shared_dict = ngx_shared[opts.shm_name] 152 | if not shared_dict then 153 | return nil, "failed to get ngx.shared dict: " .. opts.shm_name 154 | end 155 | conf.shm_name = opts.shm_name 156 | utils.log_info("healthy check use ngx.shared dict: ", opts.shm_name) 157 | else 158 | utils.log_info("healthy check use round robin") 159 | end 160 | conf.fail_timeout = opts.fail_timeout or 10 -- 10 sec 161 | conf.max_fails = opts.max_fails or 1 162 | conf.retry = opts.retry or false 163 | _M.conf = conf 164 | return _M, nil 165 | end 166 | end 167 | 168 | return _M 169 | -------------------------------------------------------------------------------- /lib/resty/etcd/serializers/json.lua: -------------------------------------------------------------------------------- 1 | local cjson = require("cjson.safe") 2 | 3 | 4 | return { 5 | serialize = cjson.encode, 6 | deserialize = cjson.decode 7 | } 8 | -------------------------------------------------------------------------------- /lib/resty/etcd/serializers/raw.lua: -------------------------------------------------------------------------------- 1 | local type = type 2 | 3 | 4 | local function raw_encode(v) 5 | local t = type(v) 6 | if t ~= 'string' then 7 | return nil, 'unsupported type for ' .. t 8 | end 9 | return v 10 | end 11 | 12 | local function raw_decode(v) 13 | return v 14 | end 15 | 16 | 17 | return { 18 | serialize = raw_encode, 19 | deserialize = raw_decode 20 | } 21 | -------------------------------------------------------------------------------- /lib/resty/etcd/utils.lua: -------------------------------------------------------------------------------- 1 | -- https://github.com/api7/lua-resty-http 2 | local http = require("resty.http") 3 | local clear_tab = require("table.clear") 4 | local split = require("ngx.re").split 5 | local find = ngx.re.find 6 | local concat_tab = table.concat 7 | local tostring = tostring 8 | local select = select 9 | local ipairs = ipairs 10 | local pairs = pairs 11 | local type = type 12 | 13 | 14 | if not http.tls_handshake then 15 | error("Bad http library. Should use api7-lua-resty-http instead") 16 | end 17 | 18 | 19 | local _M = {http = http} 20 | 21 | local normalize 22 | do 23 | local items = {} 24 | local function concat(sep, ...) 25 | local argc = select('#', ...) 26 | clear_tab(items) 27 | local len = 0 28 | 29 | for i = 1, argc do 30 | local v = select(i, ...) 31 | if v ~= nil then 32 | len = len + 1 33 | items[len] = tostring(v) 34 | end 35 | end 36 | 37 | return concat_tab(items, sep); 38 | end 39 | 40 | 41 | local segs = {} 42 | function normalize(...) 43 | local path = concat('/', ...) 44 | local names = {} 45 | local err 46 | 47 | segs, err = split(path, [[/]], "jo", nil, nil, segs) 48 | if not segs then 49 | return nil, err 50 | end 51 | 52 | local len = 0 53 | for _, seg in ipairs(segs) do 54 | if seg == '..' then 55 | if len > 0 then 56 | len = len - 1 57 | end 58 | 59 | elseif seg == '' or seg == '/' and names[len] == '/' then 60 | -- do nothing 61 | 62 | elseif seg ~= '.' then 63 | len = len + 1 64 | names[len] = seg 65 | end 66 | end 67 | 68 | return '/' .. concat_tab(names, '/', 1, len); 69 | end 70 | end 71 | _M.normalize = normalize 72 | 73 | 74 | function _M.get_real_key(prefix, key) 75 | return (type(prefix) == 'string' and prefix or "") .. key 76 | end 77 | 78 | 79 | function _M.has_value(arr, val) 80 | for key, value in pairs(arr) do 81 | if value == val then 82 | return key 83 | end 84 | end 85 | 86 | return false 87 | end 88 | 89 | function _M.starts_with(str, start) 90 | return str:sub(1, #start) == start 91 | end 92 | 93 | local ngx_log = ngx.log 94 | local ngx_ERR = ngx.ERR 95 | local ngx_INFO = ngx.INFO 96 | local ngx_WARN = ngx.WARN 97 | local function log_error(...) 98 | return ngx_log(ngx_ERR, ...) 99 | end 100 | _M.log_error = log_error 101 | 102 | 103 | local function log_info( ... ) 104 | return ngx_log(ngx_INFO, ...) 105 | end 106 | _M.log_info = log_info 107 | 108 | 109 | local function log_warn( ... ) 110 | return ngx_log(ngx_WARN, ...) 111 | end 112 | _M.log_warn = log_warn 113 | 114 | 115 | local function verify_key(key) 116 | if not key or #key == 0 then 117 | return false, "key should not be empty" 118 | end 119 | return true, nil 120 | end 121 | _M.verify_key = verify_key 122 | 123 | local function is_empty_str(input_str) 124 | return (find(input_str or '', [=[^\s*$]=], "jo")) 125 | end 126 | _M.is_empty_str = is_empty_str 127 | 128 | return _M 129 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-0.5-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "0.5-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v0.5" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/iresty/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.13", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-0.6-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "0.6-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v0.6" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/iresty/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.13", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-0.7-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "0.7-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v0.7" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/iresty/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-0.8-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "0.8-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v0.8" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/iresty/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.15", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua", 21 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 22 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 23 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 24 | } 25 | } -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-0.9-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "0.9-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v0.9" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/api7/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.15", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua", 21 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 22 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 23 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.0" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/api7/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.15", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua", 21 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 22 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 23 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.1" 6 | } 7 | description = { 8 | summary = "Nonblocking Lua etcd driver library for OpenResty", 9 | homepage = "https://github.com/api7/lua-resty-etcd", 10 | license = "Apache License 2.0", 11 | maintainer = "Yuansheng Wang " 12 | } 13 | dependencies = { 14 | "lua-resty-http = 0.15", 15 | "lua-typeof = 0.1" 16 | } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["resty.etcd"] = "lib/resty/etcd.lua", 21 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 22 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 23 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "api7-lua-protobuf = 0.1.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.1" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "api7-lua-protobuf = 0.1.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.2-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "api7-lua-protobuf = 0.1.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.3-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.3-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.3" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "lua-protobuf = 0.4.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.4-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.4-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.4" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "lua-protobuf = 0.4.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.5-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.5-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.5" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.2.2-0", 17 | "lua-protobuf = 0.4.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.10.6-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.10.6-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.10.6", 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.2.2-0", 17 | "lua-protobuf = 0.4.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.2-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v1.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.3-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.3-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v1.3" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.4-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.4-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v1.4" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.4.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.4.1-0" 3 | source = { 4 | url = "git://github.com/iresty/lua-resty-etcd", 5 | tag = "v1.4.1" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.4.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.4.2-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.4.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.4.3-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.4.3-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.4.3" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.4.4-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.4.4-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.4.4" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "lua-resty-http = 0.15", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.1" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "lua-typeof = 0.1" 18 | } 19 | 20 | build = { 21 | type = "builtin", 22 | modules = { 23 | ["resty.etcd"] = "lib/resty/etcd.lua", 24 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 25 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 26 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 27 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 28 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 29 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.2-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.1.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.3-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.3-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.3" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.1.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.4-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.4-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.4" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.5.5-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.5.5-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.5.5" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.6.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.6.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.6.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.6.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.6.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.6.1" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.6.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.6.2-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.6.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.7.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.7.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.7.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v2"] = "lib/resty/etcd/v2.lua", 24 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 25 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 26 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 27 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 28 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.8.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.8.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.8.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 24 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 25 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 26 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 27 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.8.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.8.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.8.1" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 24 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 25 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 26 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 27 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.8.2-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.8.2-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.8.2" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 24 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 25 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 26 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 27 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.8.3-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.8.3-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.8.3" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0" 12 | } 13 | 14 | dependencies = { 15 | "api7-lua-resty-http = 0.2.0", 16 | "lua-typeof = 0.1" 17 | } 18 | 19 | build = { 20 | type = "builtin", 21 | modules = { 22 | ["resty.etcd"] = "lib/resty/etcd.lua", 23 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 24 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 25 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 26 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 27 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-1.9.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd" 2 | version = "1.9.0-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | tag = "v1.9.0" 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.1.0", 17 | "luafilesystem = 1.7.0-2", 18 | "penlight = 1.9.2-1", 19 | "lua-typeof = 0.1" 20 | } 21 | 22 | build = { 23 | type = "builtin", 24 | modules = { 25 | ["resty.etcd"] = "lib/resty/etcd.lua", 26 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 27 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 28 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 29 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 30 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rockspec/lua-resty-etcd-master-0.1-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-resty-etcd-master" 2 | version = "0.1-0" 3 | source = { 4 | url = "git://github.com/api7/lua-resty-etcd", 5 | branch = "master", 6 | } 7 | 8 | description = { 9 | summary = "Nonblocking Lua etcd driver library for OpenResty", 10 | homepage = "https://github.com/api7/lua-resty-etcd", 11 | license = "Apache License 2.0", 12 | maintainer = "Yuansheng Wang " 13 | } 14 | 15 | dependencies = { 16 | "api7-lua-resty-http = 0.2.2-0", 17 | "lua-protobuf = 0.4.1", 18 | "luafilesystem = 1.7.0-2", 19 | "penlight = 1.9.2-1", 20 | "lua-typeof = 0.1" 21 | } 22 | 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["resty.etcd"] = "lib/resty/etcd.lua", 27 | ["resty.etcd.v3"] = "lib/resty/etcd/v3.lua", 28 | ["resty.etcd.proto"] = "lib/resty/etcd/proto.lua", 29 | ["resty.etcd.utils"] = "lib/resty/etcd/utils.lua", 30 | ["resty.etcd.serializers.json"] = "lib/resty/etcd/serializers/json.lua", 31 | ["resty.etcd.serializers.raw"] = "lib/resty/etcd/serializers/raw.lua", 32 | ["resty.etcd.health_check"] = "lib/resty/etcd/health_check.lua", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /t/Procfile-single: -------------------------------------------------------------------------------- 1 | # Use goreman to run `go get github.com/mattn/goreman` 2 | etcd0: etcd 3 | etcd1: etcd --name infra1 --listen-client-urls http://127.0.0.1:12379 --advertise-client-urls http://127.0.0.1:12379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new 4 | etcd2: etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new 5 | etcd3: etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new 6 | # A learner node can be started using Procfile.learner 7 | -------------------------------------------------------------------------------- /t/Procfile-single-enable-mtls: -------------------------------------------------------------------------------- 1 | # Use goreman to run `go get github.com/mattn/goreman` 2 | etcd0: etcd 3 | etcd1: etcd --name infra1 --listen-client-urls https://127.0.0.1:12379 --advertise-client-urls https://127.0.0.1:12379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/mtls_server.crt --key-file ./t/certs/mtls_server.key --client-cert-auth --trusted-ca-file ./t/certs/mtls_ca.crt 4 | etcd2: etcd --name infra2 --listen-client-urls https://127.0.0.1:22379 --advertise-client-urls https://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/mtls_server.crt --key-file ./t/certs/mtls_server.key --client-cert-auth --trusted-ca-file ./t/certs/mtls_ca.crt 5 | etcd3: etcd --name infra3 --listen-client-urls https://127.0.0.1:32379 --advertise-client-urls https://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/mtls_server.crt --key-file ./t/certs/mtls_server.key --client-cert-auth --trusted-ca-file ./t/certs/mtls_ca.crt 6 | # A learner node can be started using Procfile.learner 7 | -------------------------------------------------------------------------------- /t/Procfile-single-enable-tls: -------------------------------------------------------------------------------- 1 | # Use goreman to run `go get github.com/mattn/goreman` 2 | etcd0: etcd 3 | etcd1: etcd --name infra1 --listen-client-urls https://127.0.0.1:12379 --advertise-client-urls https://127.0.0.1:12379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/etcd.pem --key-file ./t/certs/etcd.key 4 | etcd2: etcd --name infra2 --listen-client-urls https://127.0.0.1:22379 --advertise-client-urls https://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/etcd.pem --key-file ./t/certs/etcd.key 5 | etcd3: etcd --name infra3 --listen-client-urls https://127.0.0.1:32379 --advertise-client-urls https://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --cert-file ./t/certs/etcd.pem --key-file ./t/certs/etcd.key 6 | # A learner node can be started using Procfile.learner 7 | -------------------------------------------------------------------------------- /t/certs/etcd.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCf6sMQke4OUrPf 3 | lZXqKZC4uaQLMxJB2DgacBf4Q3kXcVNCNHtc2U3U5cMD8tr3/Jt5MKKun5jQrbXV 4 | FF4eVr4Iv9jgPBwQc2kBUC9QL/alsMhEuXMeqdGQcCK3F0CLJdV3zUlKUDU0kg+O 5 | Exnbl1CHXrIbpD7zLy1i3s8p39v1pYFYf4WlrQxvfa/xo97gXY5dJv8RryryLzRc 6 | uhHYBvX5MHCGpbrY61JxpfZqBo8CmLuHl1tmbeXpdHdQB11LKiuL6HtKflNjc6rg 7 | 5r8bXl1nZbM/KOZEE+muA1LVoaTyHzY/aGXz0bNy4QRUO+De9JFcTDgnXnNZVG5x 8 | cyyDBpc9AgMBAAECggEAatcEtehZPJaCeClPPF/Cwbe9YoIfe4BCk186lHI3z7K1 9 | 5nB7zt+bwVY0AUpagv3wvXoB5lrYVOsJpa9y5iAb3GqYMc/XDCKfD/KLea5hwfcn 10 | BctEn0LjsPVKLDrLs2t2gBDWG2EU+udunwQh7XTdp2Nb6V3FdOGbGAg2LgrSwP1g 11 | 0r4z14F70oWGYyTQ5N8UGuyryVrzQH525OYl38Yt7R6zJ/44FVi/2TvdfHM5ss39 12 | SXWi00Q30fzaBEf4AdHVwVCRKctwSbrIOyM53kiScFDmBGRblCWOxXbiFV+d3bjX 13 | gf2zxs7QYZrFOzOO7kLtHGua4itEB02497v+1oKDwQKBgQDOBvCVGRe2WpItOLnj 14 | SF8iz7Sm+jJGQz0D9FhWyGPvrN7IXGrsXavA1kKRz22dsU8xdKk0yciOB13Wb5y6 15 | yLsr/fPBjAhPb4h543VHFjpAQcxpsH51DE0b2oYOWMmz+rXGB5Jy8EkP7Q4njIsc 16 | 2wLod1dps8OT8zFx1jX3Us6iUQKBgQDGtKkfsvWi3HkwjFTR+/Y0oMz7bSruE5Z8 17 | g0VOHPkSr4XiYgLpQxjbNjq8fwsa/jTt1B57+By4xLpZYD0BTFuf5po+igSZhH8s 18 | QS5XnUnbM7d6Xr/da7ZkhSmUbEaMeHONSIVpYNgtRo4bB9Mh0l1HWdoevw/w5Ryt 19 | L/OQiPhfLQKBgQCh1iG1fPh7bbnVe/HI71iL58xoPbCwMLEFIjMiOFcINirqCG6V 20 | LR91Ytj34JCihl1G4/TmWnsH1hGIGDRtJLCiZeHL70u32kzCMkI1jOhFAWqoutMa 21 | 7obDkmwraONIVW/kFp6bWtSJhhTQTD4adI9cPCKWDXdcCHSWj0Xk+U8HgQKBgBng 22 | t1HYhaLzIZlP/U/nh3XtJyTrX7bnuCZ5FhKJNWrYjxAfgY+NXHRYCKg5x2F5j70V 23 | be7pLhxmCnrPTMKZhik56AaTBOxVVBaYWoewhUjV4GRAaK5Wc8d9jB+3RizPFwVk 24 | V3OU2DJ1SNZ+W2HBOsKrEfwFF/dgby6i2w6MuAP1AoGBAIxvxUygeT/6P0fHN22P 25 | zAHFI4v2925wYdb7H//D8DIADyBwv18N6YH8uH7L+USZN7e4p2k8MGGyvTXeC6aX 26 | IeVtU6fH57Ddn59VPbF20m8RCSkmBvSdcbyBmqlZSBE+fKwCliKl6u/GH0BNAWKz 27 | r8yiEiskqRmy7P7MY9hDmEbG 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /t/certs/etcd.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDrzCCApegAwIBAgIJAI3Meu/gJVTLMA0GCSqGSIb3DQEBCwUAMG4xCzAJBgNV 3 | BAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3pob3UxDTAL 4 | BgNVBAoMBHRlc3QxDTALBgNVBAsMBHRlc3QxGzAZBgNVBAMMEmV0Y2QuY2x1c3Rl 5 | ci5sb2NhbDAeFw0yMDEwMjgwMzMzMDJaFw0yMTEwMjgwMzMzMDJaMG4xCzAJBgNV 6 | BAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3pob3UxDTAL 7 | BgNVBAoMBHRlc3QxDTALBgNVBAsMBHRlc3QxGzAZBgNVBAMMEmV0Y2QuY2x1c3Rl 8 | ci5sb2NhbDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ/qwxCR7g5S 9 | s9+VleopkLi5pAszEkHYOBpwF/hDeRdxU0I0e1zZTdTlwwPy2vf8m3kwoq6fmNCt 10 | tdUUXh5Wvgi/2OA8HBBzaQFQL1Av9qWwyES5cx6p0ZBwIrcXQIsl1XfNSUpQNTSS 11 | D44TGduXUIdeshukPvMvLWLezynf2/WlgVh/haWtDG99r/Gj3uBdjl0m/xGvKvIv 12 | NFy6EdgG9fkwcIalutjrUnGl9moGjwKYu4eXW2Zt5el0d1AHXUsqK4voe0p+U2Nz 13 | quDmvxteXWdlsz8o5kQT6a4DUtWhpPIfNj9oZfPRs3LhBFQ74N70kVxMOCdec1lU 14 | bnFzLIMGlz0CAwEAAaNQME4wHQYDVR0OBBYEFFHeljijrr+SPxlH5fjHRPcC7bv2 15 | MB8GA1UdIwQYMBaAFFHeljijrr+SPxlH5fjHRPcC7bv2MAwGA1UdEwQFMAMBAf8w 16 | DQYJKoZIhvcNAQELBQADggEBAG6NNTK7sl9nJxeewVuogCdMtkcdnx9onGtCOeiQ 17 | qvh5Xwn9akZtoLMVEdceU0ihO4wILlcom3OqHs9WOd6VbgW5a19Thh2toxKidHz5 18 | rAaBMyZsQbFb6+vFshZwoCtOLZI/eIZfUUMFqMXlEPrKru1nSddNdai2+zi5rEnM 19 | HCot43+3XYuqkvWlOjoi9cP+C4epFYrxpykVbcrtbd7TK+wZNiK3xtDPnVzjdNWL 20 | geAEl9xrrk0ss4nO/EreTQgS46gVU+tLC+b23m2dU7dcKZ7RDoiA9bdVc4a2IsaS 21 | 2MvLL4NZ2nUh8hAEHiLtGMAV3C6xNbEyM07hEpDW6vk6tqk= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /t/certs/mtls_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDSjCCAjICCQDmBdlKmGaJITANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJj 3 | bjESMBAGA1UECAwJR3VhbmdEb25nMQ8wDQYDVQQHDAZaaHVIYWkxDTALBgNVBAoM 4 | BGFwaTcxDDAKBgNVBAsMA29wczEWMBQGA1UEAwwNY2EuYXBpc2l4LmRldjAeFw0y 5 | MDA2MjAxMzEzNDFaFw0zMDA2MTgxMzEzNDFaMGcxCzAJBgNVBAYTAmNuMRIwEAYD 6 | VQQIDAlHdWFuZ0RvbmcxDzANBgNVBAcMBlpodUhhaTENMAsGA1UECgwEYXBpNzEM 7 | MAoGA1UECwwDb3BzMRYwFAYDVQQDDA1jYS5hcGlzaXguZGV2MIIBIjANBgkqhkiG 8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAun+Gq/bp7CcZ9i5ZdjuCvyZVXsiAaBELVi/Q 9 | QQtC90z5aQyWudTPB1Lcpk5HosbT73eHh03hFCRMFv6Miase1T59KJ4zGSFKoFEr 10 | j2cbNmWFJEhTGce1pn52zMzZrXERYhKBA0n4bwHK/IND0XeEZ2RQPtGnGBqj3vKL 11 | 3px+mOzIeMy4VMSkIkL2jlgo5jN0IjQIsvHRSrhIWzFhr6qtIJhuh0oI6gs+/yvA 12 | vspGeVFtIg/1PY3bOgFfhJg08/Aw7vgMjmADypEbBabLaWOZ8RZ3Ci2is6cL/1wX 13 | Sr8OIIBXTmTGmXEuSsMsBgC7BFwEY4XEsGx8QQJsrh1dSf2t0QIDAQABMA0GCSqG 14 | SIb3DQEBBQUAA4IBAQCKC98wWieC66NHAYb9ICOwr+XTmoFABpFNaM4bPXMD4IUq 15 | BaMGfBh92e4ANz2bm1D3J0ZNH3TVC7OhF2ymi6wSMde/Ygkh5xu2HgTEX2QTDQVd 16 | J27jwEIe45VLdvuu33jvE/iNNQHI6J6zP45gs/FS+CwMoYRnNcC+428YUf9XMcgM 17 | UkeMOnnkhw1OUzmoACY705hAEAPFbb7KkQ109lgbh6cucMy7Nw/N1t6Pyuxlqteg 18 | d8Wy6VFYPRRK43dYoA9B0yvsZCERvxgR1IrDjo0B2wIDzM4eM6ldLfnr8pPnBFfS 19 | g/Pdo6VZsXeSv3o00lBEY/25Vqxn3sPBK4E7a+mX 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /t/certs/mtls_client.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 1 (0x0) 4 | Serial Number: 64207 (0xfacf) 5 | Signature Algorithm: sha256WithRSAEncryption 6 | Issuer: C=cn, ST=GuangDong, L=ZhuHai, O=api7, OU=ops, CN=ca.apisix.dev 7 | Validity 8 | Not Before: Jun 20 13:15:00 2020 GMT 9 | Not After : Jul 8 13:15:00 2030 GMT 10 | Subject: C=cn, ST=GuangDong, O=api7, L=ZhuHai, CN=client.apisix.dev 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | Public-Key: (2048 bit) 14 | Modulus: 15 | 00:9f:28:8f:2e:88:41:ff:89:f6:62:91:29:d1:6b: 16 | 7f:c4:d8:1e:28:85:55:91:c2:3a:3f:23:1c:83:11: 17 | 6a:26:81:1e:2d:2e:4d:69:48:98:4f:ff:84:82:2d: 18 | 6b:8c:41:31:56:4d:b4:aa:b7:52:05:63:2e:19:6d: 19 | 54:87:1f:21:a8:34:f9:89:1a:b1:d1:24:21:84:fa: 20 | c8:29:7f:39:f4:1a:35:78:95:74:0f:24:3d:24:e8: 21 | 64:75:09:7d:8c:a3:54:d6:74:5a:92:27:f1:dc:e4: 22 | 04:30:71:01:67:3d:fa:0b:03:0b:01:cb:8c:aa:ae: 23 | 59:9f:f7:a6:40:53:2b:65:ff:b6:64:8d:fe:0f:ee: 24 | 62:64:24:7b:4c:fd:68:12:47:4a:46:86:36:53:00: 25 | 64:5f:e4:32:56:a0:ee:75:92:2d:e2:dc:92:3e:d7: 26 | 99:8e:86:69:e7:0a:99:e4:b2:71:95:3d:f9:7d:da: 27 | af:76:1f:3f:f8:bf:78:aa:13:e5:13:84:f6:11:a5: 28 | c1:9b:9d:d7:73:32:f3:da:09:78:9a:be:0f:01:fe: 29 | ed:8b:55:b9:f8:97:46:9d:6a:6a:90:19:ea:4e:02: 30 | 30:ff:d7:1a:da:39:53:f6:5b:6d:96:d0:fc:ed:0d: 31 | 72:78:ac:b7:be:71:aa:4d:4b:8a:06:b9:25:1f:90: 32 | 81:0d 33 | Exponent: 65537 (0x10001) 34 | Signature Algorithm: sha256WithRSAEncryption 35 | 72:a7:1f:15:21:ba:4f:e7:2f:64:a0:e5:40:7c:e0:ea:09:7b: 36 | 95:cf:80:d0:6f:54:c2:8d:d1:cf:cd:00:f2:95:20:f9:e2:9e: 37 | f5:1c:1b:f9:87:78:a7:b1:3f:31:34:b0:c8:1a:44:da:2c:ef: 38 | 93:76:d7:df:44:5f:27:6a:51:cb:09:f2:32:f4:70:db:50:da: 39 | 4e:49:41:75:e0:d2:7b:4d:0b:8b:6e:0a:02:0a:00:e9:ce:f3: 40 | bf:72:e6:14:86:df:a7:b9:ef:09:80:a1:52:a7:69:b8:23:7a: 41 | 3d:3d:cc:6d:64:91:7b:c0:9a:98:2a:a3:17:95:0a:ee:e1:ed: 42 | f2:be:02:ea:cb:6e:c1:82:4d:a1:e8:03:9a:46:d6:d7:07:0f: 43 | 12:50:7e:95:5c:6c:17:f0:40:34:81:5b:74:90:8e:24:6a:5f: 44 | 8e:77:ff:4d:67:c3:a9:1b:39:e2:ca:62:b6:89:ca:c6:86:f1: 45 | 95:36:2b:cf:96:a5:6e:89:0e:e6:dc:88:78:f0:7d:09:e9:53: 46 | 65:35:e9:72:a2:be:1c:5e:b8:a6:2b:57:f2:0d:2f:4b:31:8f: 47 | f7:d9:ad:a3:58:12:bb:c9:5b:38:79:96:5b:c8:74:d2:e6:79: 48 | 23:e6:bd:be:74:25:42:2c:fa:50:ea:9f:53:28:6d:35:f3:0e: 49 | 9b:82:15:70 50 | -----BEGIN CERTIFICATE----- 51 | MIIDOjCCAiICAwD6zzANBgkqhkiG9w0BAQsFADBnMQswCQYDVQQGEwJjbjESMBAG 52 | A1UECAwJR3VhbmdEb25nMQ8wDQYDVQQHDAZaaHVIYWkxDTALBgNVBAoMBGFwaTcx 53 | DDAKBgNVBAsMA29wczEWMBQGA1UEAwwNY2EuYXBpc2l4LmRldjAeFw0yMDA2MjAx 54 | MzE1MDBaFw0zMDA3MDgxMzE1MDBaMF0xCzAJBgNVBAYTAmNuMRIwEAYDVQQIDAlH 55 | dWFuZ0RvbmcxDTALBgNVBAoMBGFwaTcxDzANBgNVBAcMBlpodUhhaTEaMBgGA1UE 56 | AwwRY2xpZW50LmFwaXNpeC5kZXYwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 57 | AoIBAQCfKI8uiEH/ifZikSnRa3/E2B4ohVWRwjo/IxyDEWomgR4tLk1pSJhP/4SC 58 | LWuMQTFWTbSqt1IFYy4ZbVSHHyGoNPmJGrHRJCGE+sgpfzn0GjV4lXQPJD0k6GR1 59 | CX2Mo1TWdFqSJ/Hc5AQwcQFnPfoLAwsBy4yqrlmf96ZAUytl/7Zkjf4P7mJkJHtM 60 | /WgSR0pGhjZTAGRf5DJWoO51ki3i3JI+15mOhmnnCpnksnGVPfl92q92Hz/4v3iq 61 | E+UThPYRpcGbnddzMvPaCXiavg8B/u2LVbn4l0adamqQGepOAjD/1xraOVP2W22W 62 | 0PztDXJ4rLe+capNS4oGuSUfkIENAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHKn 63 | HxUhuk/nL2Sg5UB84OoJe5XPgNBvVMKN0c/NAPKVIPninvUcG/mHeKexPzE0sMga 64 | RNos75N2199EXydqUcsJ8jL0cNtQ2k5JQXXg0ntNC4tuCgIKAOnO879y5hSG36e5 65 | 7wmAoVKnabgjej09zG1kkXvAmpgqoxeVCu7h7fK+AurLbsGCTaHoA5pG1tcHDxJQ 66 | fpVcbBfwQDSBW3SQjiRqX453/01nw6kbOeLKYraJysaG8ZU2K8+WpW6JDubciHjw 67 | fQnpU2U16XKivhxeuKYrV/INL0sxj/fZraNYErvJWzh5llvIdNLmeSPmvb50JUIs 68 | +lDqn1MobTXzDpuCFXA= 69 | -----END CERTIFICATE----- 70 | -------------------------------------------------------------------------------- /t/certs/mtls_client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAnyiPLohB/4n2YpEp0Wt/xNgeKIVVkcI6PyMcgxFqJoEeLS5N 3 | aUiYT/+Egi1rjEExVk20qrdSBWMuGW1Uhx8hqDT5iRqx0SQhhPrIKX859Bo1eJV0 4 | DyQ9JOhkdQl9jKNU1nRakifx3OQEMHEBZz36CwMLAcuMqq5Zn/emQFMrZf+2ZI3+ 5 | D+5iZCR7TP1oEkdKRoY2UwBkX+QyVqDudZIt4tySPteZjoZp5wqZ5LJxlT35fdqv 6 | dh8/+L94qhPlE4T2EaXBm53XczLz2gl4mr4PAf7ti1W5+JdGnWpqkBnqTgIw/9ca 7 | 2jlT9lttltD87Q1yeKy3vnGqTUuKBrklH5CBDQIDAQABAoIBAHDe5bPdQ9jCcW3z 8 | fpGax/DER5b6//UvpfkSoGy/E+Wcmdb2yEVLC2FoVwOuzF+Z+DA5SU/sVAmoDZBQ 9 | vapZxJeygejeeo5ULkVNSFhNdr8LOzJ54uW+EHK1MFDj2xq61jaEK5sNIvRA7Eui 10 | SJl8FXBrxwmN3gNJRBwzF770fImHUfZt0YU3rWKw5Qin7QnlUzW2KPUltnSEq/xB 11 | kIzyWpuj7iAm9wTjH9Vy06sWCmxj1lzTTXlanjPb1jOTaOhbQMpyaAzRgQN8PZiE 12 | YKCarzVj7BJr7/vZYpnQtQDY12UL5n33BEqMP0VNHVqv+ZO3bktfvlwBru5ZJ7Cf 13 | URLsSc0CgYEAyz7FzV7cZYgjfUFD67MIS1HtVk7SX0UiYCsrGy8zA19tkhe3XVpc 14 | CZSwkjzjdEk0zEwiNAtawrDlR1m2kverbhhCHqXUOHwEpujMBjeJCNUVEh3OABr8 15 | vf2WJ6D1IRh8FA5CYLZP7aZ41fcxAnvIPAEThemLQL3C4H5H5NG2WFsCgYEAyHhP 16 | onpS/Eo/OXKYFLR/mvjizRVSomz1lVVL+GWMUYQsmgsPyBJgyAOX3Pqt9catgxhM 17 | DbEr7EWTxth3YeVzamiJPNVK0HvCax9gQ0KkOmtbrfN54zBHOJ+ieYhsieZLMgjx 18 | iu7Ieo6LDGV39HkvekzutZpypiCpKlMaFlCFiLcCgYEAmAgRsEj4Nh665VPvuZzH 19 | ZIgZMAlwBgHR7/v6l7AbybcVYEXLTNJtrGEEH6/aOL8V9ogwwZuIvb/TEidCkfcf 20 | zg/pTcGf2My0MiJLk47xO6EgzNdso9mMG5ZYPraBBsuo7NupvWxCp7NyCiOJDqGH 21 | K5NmhjInjzsjTghIQRq5+qcCgYEAxnm/NjjvslL8F69p/I3cDJ2/RpaG0sMXvbrO 22 | VWaMryQyWGz9OfNgGIbeMu2Jj90dar6ChcfUmb8lGOi2AZl/VGmc/jqaMKFnElHl 23 | J5JyMFicUzPMiG8DBH+gB71W4Iy+BBKwugHBQP2hkytewQ++PtKuP+RjADEz6vCN 24 | 0mv0WS8CgYBnbMRP8wIOLJPRMw/iL9BdMf606X4xbmNn9HWVp2mH9D3D51kDFvls 25 | 7y2vEaYkFv3XoYgVN9ZHDUbM/YTUozKjcAcvz0syLQb8wRwKeo+XSmo09+360r18 26 | zRugoE7bPl39WdGWaW3td0qf1r9z3sE2iWUTJPRQ3DYpsLOYIgyKmw== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /t/certs/mtls_server.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 1 (0x0) 4 | Serial Number: 64206 (0xface) 5 | Signature Algorithm: sha256WithRSAEncryption 6 | Issuer: C=cn, ST=GuangDong, L=ZhuHai, O=api7, OU=ops, CN=ca.apisix.dev 7 | Validity 8 | Not Before: Jun 20 13:14:34 2020 GMT 9 | Not After : Jun 18 13:14:34 2030 GMT 10 | Subject: C=cn, ST=GuangDong, O=api7, L=ZhuHai, CN=admin.apisix.dev 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | Public-Key: (2048 bit) 14 | Modulus: 15 | 00:9b:45:2a:e1:c9:6e:a7:af:af:bd:46:5c:5e:5f: 16 | 72:66:02:78:69:16:fd:f9:69:8e:47:68:0f:8d:35: 17 | 92:c4:14:40:5c:cf:57:3d:41:ea:13:7b:f4:de:c8: 18 | ab:e8:62:56:1e:60:61:f6:38:65:5f:30:b5:91:25: 19 | 79:07:12:45:ce:24:31:86:1f:2c:a6:cb:1d:8b:4b: 20 | 9e:5f:1f:c7:b6:f3:e8:98:ee:b3:70:c7:9e:5d:10: 21 | ce:29:e4:22:68:69:9e:df:ae:f6:bb:11:e8:b8:f1: 22 | 07:bf:2d:d5:57:f2:e4:07:8a:da:d2:7b:8a:53:d1: 23 | b4:f4:42:19:9a:14:98:01:3e:23:27:3a:0f:ad:d0: 24 | 1d:c5:31:9a:ee:ae:df:7f:fb:2e:34:0b:51:ca:b4: 25 | 8c:59:ae:86:5f:95:69:2b:4a:c6:2d:a5:ae:04:46: 26 | 7a:93:09:15:72:0a:78:ef:98:7d:00:b5:b4:b2:f2: 27 | e2:a9:2e:04:fb:de:84:ad:da:8e:a3:31:53:3a:d5: 28 | 91:cd:77:f5:b8:ea:eb:14:aa:d9:62:d1:12:79:87: 29 | 08:27:6d:c1:b9:e3:7d:f1:07:52:3c:a3:34:6a:c1: 30 | 96:cf:a2:84:cc:14:50:49:40:0b:38:3c:3b:1e:df: 31 | 57:6f:f2:05:35:92:9b:4f:b1:21:0b:f7:62:3a:2d: 32 | 83:c7 33 | Exponent: 65537 (0x10001) 34 | Signature Algorithm: sha256WithRSAEncryption 35 | 7a:1c:a3:d8:d4:97:5d:91:d2:c8:31:c4:40:ef:f1:38:ac:5c: 36 | b9:74:66:81:94:4f:71:02:38:49:5a:0d:7b:10:17:73:a5:96: 37 | 3e:de:0e:a4:75:8c:1b:c7:51:f9:f6:eb:9d:f4:bd:4c:1c:92: 38 | 41:d0:16:c6:73:c1:f9:7c:b6:71:7d:16:53:13:fa:70:90:c0: 39 | 95:e3:a3:51:30:96:02:f2:32:32:fe:a9:d1:ef:c5:7e:04:58: 40 | ca:20:ef:d0:43:8c:52:8d:52:3a:71:ed:0f:87:4e:8b:c6:28: 41 | 51:56:13:fd:71:81:10:cc:2f:2c:aa:8d:6a:93:d7:52:34:08: 42 | 23:7b:2b:a7:a4:3e:6b:8f:c3:af:59:b9:1c:b8:d8:6c:a3:88: 43 | c7:bd:b5:e1:eb:6b:6a:f2:7d:a3:89:c6:b0:21:f8:1b:9a:dc: 44 | bf:ef:d6:21:91:7f:65:99:4d:f4:49:24:ab:46:09:a0:c9:a1: 45 | 64:14:f4:56:73:ce:1b:22:dd:b7:1f:58:0f:29:ae:6a:6e:41: 46 | 6e:b4:5c:90:97:4e:59:4e:cf:e3:a1:89:d1:5a:65:a3:68:2f: 47 | b9:97:82:6f:4c:21:cb:f6:9b:7d:fd:d8:07:70:14:cd:10:fb: 48 | bf:03:70:fa:51:7c:56:4c:1b:a5:87:d3:1b:18:5c:22:87:6f: 49 | 04:08:59:53 50 | -----BEGIN CERTIFICATE----- 51 | MIIDOTCCAiECAwD6zjANBgkqhkiG9w0BAQsFADBnMQswCQYDVQQGEwJjbjESMBAG 52 | A1UECAwJR3VhbmdEb25nMQ8wDQYDVQQHDAZaaHVIYWkxDTALBgNVBAoMBGFwaTcx 53 | DDAKBgNVBAsMA29wczEWMBQGA1UEAwwNY2EuYXBpc2l4LmRldjAeFw0yMDA2MjAx 54 | MzE0MzRaFw0zMDA2MTgxMzE0MzRaMFwxCzAJBgNVBAYTAmNuMRIwEAYDVQQIDAlH 55 | dWFuZ0RvbmcxDTALBgNVBAoMBGFwaTcxDzANBgNVBAcMBlpodUhhaTEZMBcGA1UE 56 | AwwQYWRtaW4uYXBpc2l4LmRldjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 57 | ggEBAJtFKuHJbqevr71GXF5fcmYCeGkW/flpjkdoD401ksQUQFzPVz1B6hN79N7I 58 | q+hiVh5gYfY4ZV8wtZEleQcSRc4kMYYfLKbLHYtLnl8fx7bz6Jjus3DHnl0Qzink 59 | Imhpnt+u9rsR6LjxB78t1Vfy5AeK2tJ7ilPRtPRCGZoUmAE+Iyc6D63QHcUxmu6u 60 | 33/7LjQLUcq0jFmuhl+VaStKxi2lrgRGepMJFXIKeO+YfQC1tLLy4qkuBPvehK3a 61 | jqMxUzrVkc139bjq6xSq2WLREnmHCCdtwbnjffEHUjyjNGrBls+ihMwUUElACzg8 62 | Ox7fV2/yBTWSm0+xIQv3Yjotg8cCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAehyj 63 | 2NSXXZHSyDHEQO/xOKxcuXRmgZRPcQI4SVoNexAXc6WWPt4OpHWMG8dR+fbrnfS9 64 | TBySQdAWxnPB+Xy2cX0WUxP6cJDAleOjUTCWAvIyMv6p0e/FfgRYyiDv0EOMUo1S 65 | OnHtD4dOi8YoUVYT/XGBEMwvLKqNapPXUjQII3srp6Q+a4/Dr1m5HLjYbKOIx721 66 | 4etravJ9o4nGsCH4G5rcv+/WIZF/ZZlN9Ekkq0YJoMmhZBT0VnPOGyLdtx9YDymu 67 | am5BbrRckJdOWU7P46GJ0Vplo2gvuZeCb0why/abff3YB3AUzRD7vwNw+lF8Vkwb 68 | pYfTGxhcIodvBAhZUw== 69 | -----END CERTIFICATE----- 70 | -------------------------------------------------------------------------------- /t/certs/mtls_server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAm0Uq4clup6+vvUZcXl9yZgJ4aRb9+WmOR2gPjTWSxBRAXM9X 3 | PUHqE3v03sir6GJWHmBh9jhlXzC1kSV5BxJFziQxhh8spssdi0ueXx/HtvPomO6z 4 | cMeeXRDOKeQiaGme3672uxHouPEHvy3VV/LkB4ra0nuKU9G09EIZmhSYAT4jJzoP 5 | rdAdxTGa7q7ff/suNAtRyrSMWa6GX5VpK0rGLaWuBEZ6kwkVcgp475h9ALW0svLi 6 | qS4E+96ErdqOozFTOtWRzXf1uOrrFKrZYtESeYcIJ23BueN98QdSPKM0asGWz6KE 7 | zBRQSUALODw7Ht9Xb/IFNZKbT7EhC/diOi2DxwIDAQABAoIBAC3NJW0dAissw+ZN 8 | Twn3lcNJj0NQqPJdlL6zj4LT/ssgPiwibVWAkA/XTNA62ZrfBxBG1h7PW/fMYoLC 9 | TwUq+rRoMMOjhoRc/gYM9FaTBVKOeFpEb2IhQDGrt2TcCtpJ7beF4PolukRztRlL 10 | 59bdqy4eY5YbIx6+iWZT6UFuObiDqi7i4SLWEgK+/P4Uk8/SmhVqIWcj1m3SPK6I 11 | YbzsgXiT64fNd7/O06ISKia1UzvUCtH7tbxWxCvsqw+PqQT+YuEmNY1pOQGYp0dU 12 | 4ndzvrP0Ajuu3xH7aYP/Kilkz69PPMLygwNey4HRIAuUqw/HBfTR0/ccRSuhrYxb 13 | 9QaOP0ECgYEAyuqLo/tjWrFiJnDbhK3z2qcydktFS58da2QitSRYlQ6AQXjZ3+v7 14 | buL1QV59aXzIGTZz3gjO+omdpfIagBI47YnWIUtj+NylNROWv+aZXQwgC7ayQWTg 15 | eBu8L2YXBvAR9TgHhqj3Fl4YcuipVE3XFVjjvLjrbE1nssMmaJqi95kCgYEAw+O7 16 | Zdj/NedbI2GtnZv31YlLmrMdtmeAmU2x8eC5v30Kx3GCU9DdZzImsaYxxjfSL+6c 17 | eP/DF8JHWIGo9GQPcMSijHsaNMIwgv6+5rx+Lp/zsjwRApJsVQeoff2ZdWjnFsi3 18 | rRHE8QZfWMqcnOsr4io7xfVd3t4tV22BBrnt8l8CgYEAncU3xcxUN9PryI+/Xq4S 19 | CFQvvCJSQrX4neNByS31Yg/gUQex/5Tv7guxPZ5GTJqkylW4SU73/3y4gqp3SFTi 20 | xm6Be2mu1XRZT6dnctXNMLeYwwLOHmJc1YZbD0+FX/ORQuTJlT4Sv+VxhQa5gb70 21 | GLkAeWAeTBrzId7yIir5wyECgYAw2iJqC+vZrZD1Ce8aV0M/ZbYNJo5KZxWTJeUy 22 | xTCNqMl/Y7d036nXipJLy36uSE2K1p7/LgmhazoPwIY6LJoNLXy8PBcVATjH8m/5 23 | axis2AcWdBRp58pMilRi11PmC/tVm0jzSHMtCMHOivjzyVJwXMf7Xm3CnvX/z7dV 24 | zhihUQKBgHWtWfNk/svgLp6w8T6aMgyAb9ud5pX/CbNZhGNRqhPhJkss1tFr6/Mv 25 | bJiZoEP3C0sDdA1JRuMkXm5EE60xyhzCNmv5H0cQ3C2Y9Q9ly89ggwIXNiNfKWpP 26 | VrdvXQ3NkP/RaDy83B9dN2Jb6lUpcNQnB5Q5yAlsYaYgsGBedcvc 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /t/normalize.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua 'no_plan'; 2 | 3 | log_level('warn'); 4 | repeat_each(2); 5 | 6 | our $HttpConfig = <<'_EOC_'; 7 | lua_socket_log_errors off; 8 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 9 | _EOC_ 10 | 11 | run_tests(); 12 | 13 | __DATA__ 14 | 15 | === TEST 1: sanity 16 | --- http_config eval: $::HttpConfig 17 | --- config 18 | location /t { 19 | content_by_lua_block { 20 | local normalize = require("resty.etcd.utils").normalize 21 | 22 | local function ifNotEqual(l, r) 23 | if l ~= r then 24 | ngx.say("the left and right values were different.") 25 | end 26 | end 27 | 28 | ifNotEqual(normalize(), '/') 29 | ifNotEqual(normalize(nil, '/', 'test', nil, 'test'), '/test/test') 30 | 31 | ifNotEqual(normalize('/path/to/dir/file'), '/path/to/dir/file') 32 | ifNotEqual(normalize('path', 'to', 'dir', 'file'), '/path/to/dir/file') 33 | 34 | ifNotEqual(normalize('..//path/to/dir/file'), '/path/to/dir/file') 35 | ifNotEqual(normalize('..', '//path/to/dir/file'), '/path/to/dir/file') 36 | 37 | ifNotEqual(normalize('/path/to/dir/file/../../'), '/path/to') 38 | ifNotEqual(normalize('/path/to/dir/file/', '..', '..'), '/path/to') 39 | 40 | ifNotEqual(normalize('/path/../to/dir/file'), '/to/dir/file') 41 | ifNotEqual(normalize('path', '../to', '/dir/file'), '/to/dir/file') 42 | 43 | ifNotEqual(normalize('/path/../to/dir/../../../file'), '/file') 44 | ifNotEqual(normalize('path', '..', 'to', 'dir', '..', '..', '..', 'file'), '/file') 45 | 46 | local is_empty_str = require("resty.etcd.utils").is_empty_str 47 | ifNotEqual(not not is_empty_str("\n"), true) 48 | ifNotEqual(not not is_empty_str("\n\n"), true) 49 | ifNotEqual(not not is_empty_str("\r\n"), true) 50 | ifNotEqual(not not is_empty_str("\t\n"), true) 51 | ifNotEqual(not not is_empty_str("\t"), true) 52 | ifNotEqual(not not is_empty_str("\t\t"), true) 53 | ifNotEqual(not not is_empty_str("\r\t\n"), true) 54 | 55 | ngx.say("all done") 56 | } 57 | } 58 | --- request 59 | GET /t 60 | --- no_error_log 61 | [error] 62 | --- response_body 63 | all done 64 | -------------------------------------------------------------------------------- /t/v3/add-auth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export ETCDCTL_API=3 3 | etcdctl version 4 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" user add "${AUTH_USER}:${AUTH_PWD}" 5 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" role add root 6 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" user grant-role root root 7 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" role list 8 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" user list 9 | etcdctl ${ETCDCTL_EXTRA_OPTS} --endpoints="${AUTH_ENDPOINT_V3}" auth enable 10 | -------------------------------------------------------------------------------- /t/v3/auth.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.[123]./) { 9 | plan(skip_all => "etcd is too old"); 10 | } else { 11 | my $enable_tls = $ENV{ETCD_ENABLE_TLS}; 12 | if ((defined $enable_tls) && $enable_tls eq "TRUE") { 13 | plan(skip_all => "skip test cases with auth when TLS is enabled"); 14 | } else { 15 | plan 'no_plan'; 16 | } 17 | } 18 | 19 | our $HttpConfig = <<'_EOC_'; 20 | lua_socket_log_errors off; 21 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 22 | init_by_lua_block { 23 | local cjson = require("cjson.safe") 24 | 25 | function check_res(data, err, val, status) 26 | if err then 27 | ngx.log(ngx.ERR, "err: ", err) 28 | return 29 | end 30 | 31 | if val then 32 | if data.body.kvs==nil then 33 | ngx.exit(404) 34 | end 35 | if data.body.kvs and val ~= data.body.kvs[1].value then 36 | ngx.say("failed to check value") 37 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 38 | ", expect: ", val) 39 | ngx.exit(200) 40 | else 41 | ngx.say("checked val as expect: ", val) 42 | end 43 | end 44 | 45 | if status and status ~= data.status then 46 | ngx.exit(data.status) 47 | end 48 | end 49 | } 50 | _EOC_ 51 | 52 | run_tests(); 53 | 54 | __DATA__ 55 | 56 | === TEST 1: share same etcd auth token 57 | --- http_config eval: $::HttpConfig 58 | --- config 59 | location /t { 60 | content_by_lua_block { 61 | local etcd, err = require "resty.etcd" .new({ 62 | protocol = "v3", 63 | user = 'root', 64 | password = 'abc123', 65 | timeout = 3, 66 | http_host = { 67 | "http://127.0.0.1:12379", 68 | }, 69 | }) 70 | check_res(etcd, err) 71 | 72 | local t = {} 73 | for i = 1, 3 do 74 | local th = assert(ngx.thread.spawn(function(i) 75 | local res, err = etcd:set("/test", { a='abc'}) 76 | check_res(res, err) 77 | 78 | ngx.sleep(0.1) 79 | 80 | res, err = etcd:delete("/test") 81 | check_res(res, err) 82 | end)) 83 | table.insert(t, th) 84 | end 85 | for i, th in ipairs(t) do 86 | ngx.thread.wait(th) 87 | end 88 | ngx.say('ok') 89 | } 90 | } 91 | --- request 92 | GET /t 93 | --- no_error_log 94 | [error] 95 | --- response_body 96 | ok 97 | --- grep_error_log eval 98 | qr/uri: .+, timeout: \d+/ 99 | --- grep_error_log_out 100 | uri: /kv/put, timeout: 3 101 | uri: /auth/authenticate, timeout: 3 102 | uri: /kv/put, timeout: 3 103 | uri: /kv/put, timeout: 3 104 | uri: /kv/deleterange, timeout: 3 105 | uri: /kv/deleterange, timeout: 3 106 | uri: /kv/deleterange, timeout: 3 107 | 108 | 109 | 110 | === TEST 2: share same etcd auth token, auth failed 111 | --- http_config eval: $::HttpConfig 112 | --- config 113 | location /t { 114 | content_by_lua_block { 115 | local etcd, err = require "resty.etcd" .new({ 116 | protocol = "v3", 117 | user = 'root', 118 | password = '123', 119 | timeout = 3, 120 | http_host = { 121 | "http://127.0.0.1:12379", 122 | }, 123 | }) 124 | check_res(etcd, err) 125 | 126 | local t = {} 127 | for i = 1, 3 do 128 | local th = assert(ngx.thread.spawn(function(i) 129 | local res, err = etcd:set("/test", { a='abc'}) 130 | if not res then 131 | ngx.log(ngx.ERR, err) 132 | end 133 | end)) 134 | table.insert(t, th) 135 | end 136 | for i, th in ipairs(t) do 137 | ngx.thread.wait(th) 138 | end 139 | ngx.say('ok') 140 | } 141 | } 142 | --- request 143 | GET /t 144 | --- response_body 145 | ok 146 | --- grep_error_log eval 147 | qr/(uri: .+, timeout: \d+|v3 refresh jwt last err: [^,]+|authenticate refresh token fail)/ 148 | --- grep_error_log_out 149 | uri: /kv/put, timeout: 3 150 | uri: /auth/authenticate, timeout: 3 151 | uri: /kv/put, timeout: 3 152 | uri: /kv/put, timeout: 3 153 | authenticate refresh token fail 154 | v3 refresh jwt last err: authenticate refresh token fail 155 | authenticate refresh token fail 156 | v3 refresh jwt last err: authenticate refresh token fail 157 | authenticate refresh token fail 158 | 159 | 160 | 161 | === TEST 3: share same etcd auth token, failed to connect 162 | --- http_config eval: $::HttpConfig 163 | --- config 164 | location /t { 165 | content_by_lua_block { 166 | local etcd, err = require "resty.etcd" .new({ 167 | protocol = "v3", 168 | user = 'root', 169 | password = '123', 170 | timeout = 3, 171 | }) 172 | check_res(etcd, err) 173 | 174 | -- hack to inject 'connection refused' error 175 | etcd.endpoints = {{ 176 | full_prefix = "http://127.0.0.1:1997/v3", 177 | scheme = "http", 178 | host = "127.0.0.1", 179 | port = "1997", 180 | }} 181 | 182 | local t = {} 183 | for i = 1, 3 do 184 | local th = assert(ngx.thread.spawn(function(i) 185 | local res, err = etcd:set("/test", { a='abc'}) 186 | if not res then 187 | ngx.log(ngx.ERR, err) 188 | end 189 | end)) 190 | table.insert(t, th) 191 | end 192 | for i, th in ipairs(t) do 193 | ngx.thread.wait(th) 194 | end 195 | ngx.say('ok') 196 | } 197 | } 198 | --- request 199 | GET /t 200 | --- response_body 201 | ok 202 | --- grep_error_log eval 203 | qr/(uri: .+, timeout: \d+|has no healthy [^,]+)/ 204 | --- grep_error_log_out 205 | uri: /kv/put, timeout: 3 206 | uri: /auth/authenticate, timeout: 3 207 | has no healthy etcd endpoint available 208 | uri: /kv/put, timeout: 3 209 | uri: /auth/authenticate, timeout: 3 210 | has no healthy etcd endpoint available 211 | uri: /kv/put, timeout: 3 212 | uri: /auth/authenticate, timeout: 3 213 | has no healthy etcd endpoint available 214 | 215 | 216 | 217 | === TEST 4: Authorization header will not be overridden when etcd auth is enabled(request uri) 218 | --- http_config eval: $::HttpConfig 219 | --- config 220 | location /t { 221 | content_by_lua_block { 222 | local etcd, err = require "resty.etcd" .new({ 223 | protocol = "v3", 224 | user = 'root', 225 | password = 'abc123', 226 | timeout = 3, 227 | http_host = { 228 | "http://127.0.0.1:12379", 229 | }, 230 | extra_headers = { 231 | Authorization = "bar", 232 | }, 233 | }) 234 | check_res(etcd, err) 235 | local res, err = etcd:set("/test", { a='abc'}) 236 | check_res(res, err) 237 | ngx.say('ok') 238 | } 239 | } 240 | --- request 241 | GET /t 242 | --- no_error_log 243 | [error] 244 | --- response_body 245 | ok 246 | 247 | 248 | 249 | === TEST 5: Authorization header will not be overridden when etcd auth is enabled(request chunk) 250 | --- http_config eval: $::HttpConfig 251 | --- config 252 | location /t { 253 | content_by_lua_block { 254 | local etcd, err = require "resty.etcd" .new({ 255 | protocol = "v3", 256 | user = 'root', 257 | password = 'abc123', 258 | timeout = 3, 259 | http_host = { 260 | "http://127.0.0.1:12379", 261 | }, 262 | extra_headers = { 263 | Authorization = "bar", 264 | }, 265 | }) 266 | local res, err = etcd:set("/test", "abc") 267 | check_res(res, err) 268 | 269 | ngx.timer.at(0.1, function () 270 | etcd:set("/test", "bcd3") 271 | end) 272 | 273 | local cur_time = ngx.now() 274 | local body_chunk_fun, err = etcd:watch("/test", {timeout = 0.5}) 275 | if not body_chunk_fun then 276 | ngx.say("failed to watch: ", err) 277 | end 278 | 279 | local idx = 0 280 | while true do 281 | local chunk, err = body_chunk_fun() 282 | 283 | if not chunk then 284 | if err then 285 | ngx.say(err) 286 | end 287 | break 288 | end 289 | 290 | idx = idx + 1 291 | ngx.say(idx, ": ", require("cjson").encode(chunk.result)) 292 | end 293 | } 294 | } 295 | --- request 296 | GET /t 297 | --- no_error_log 298 | [error] 299 | --- response_body_like eval 300 | qr/1:.*"created":true.* 301 | 2:.*"value":"bcd3".* 302 | timeout/ 303 | --- timeout: 5 304 | -------------------------------------------------------------------------------- /t/v3/cluster.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./ || $etcd_version =~ /^etcd Version: 3.2./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | my $enable_tls = $ENV{ETCD_ENABLE_TLS}; 12 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 13 | plan(skip_all => "skip test cases with auth when TLS is enabled"); 14 | } else { 15 | plan 'no_plan'; 16 | } 17 | } 18 | 19 | our $HttpConfig = <<'_EOC_'; 20 | lua_socket_log_errors off; 21 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 22 | init_by_lua_block { 23 | local cjson = require("cjson.safe") 24 | 25 | function check_res(data, err, val, status) 26 | if err then 27 | ngx.say("err: ", err) 28 | ngx.exit(200) 29 | end 30 | 31 | if val then 32 | if data.body.kvs==nil then 33 | ngx.exit(404) 34 | end 35 | if data.body.kvs and val ~= data.body.kvs[1].value then 36 | ngx.say("failed to check value") 37 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 38 | ", expect: ", val) 39 | ngx.exit(200) 40 | else 41 | ngx.say("checked val as expect: ", val) 42 | end 43 | end 44 | 45 | if status and status ~= data.status then 46 | ngx.exit(data.status) 47 | end 48 | end 49 | } 50 | _EOC_ 51 | 52 | run_tests(); 53 | 54 | __DATA__ 55 | 56 | === TEST 1: cluster + auth 57 | --- http_config eval: $::HttpConfig 58 | --- config 59 | location /t { 60 | content_by_lua_block { 61 | local etcd, err = require "resty.etcd" .new({ 62 | protocol = "v3", 63 | http_host = { 64 | "http://127.0.0.1:12379", 65 | "http://127.0.0.1:22379", 66 | "http://127.0.0.1:32379", 67 | }, 68 | user = 'root', 69 | password = 'abc123', 70 | }) 71 | check_res(etcd, err) 72 | 73 | local res, err = etcd:set("/test", { a='abc'}) 74 | check_res(res, err) 75 | 76 | res, err = etcd:get("/test") 77 | check_res(res, err) 78 | 79 | assert(res.body.kvs[1].value) 80 | 81 | ngx.sleep(0.1) 82 | 83 | res, err = etcd:delete("/test") 84 | check_res(res, err) 85 | 86 | ngx.sleep(0.1) 87 | 88 | res, err = etcd:get("/test") 89 | assert(not res.body.kvs) 90 | 91 | etcd, err = require "resty.etcd" .new({ 92 | etcd_prefix = '/v3', 93 | protocol = "v3", 94 | http_host = { 95 | "http://127.0.0.1:12379", 96 | "http://127.0.0.1:22379", 97 | "http://127.0.0.1:32379", 98 | }, 99 | user = 'wrong_user_name', 100 | password = 'wrong_password', 101 | timeout= 10, 102 | }) 103 | res, err = etcd:get("/test") 104 | assert(err == "authenticate refresh token fail") 105 | 106 | ngx.sleep(0.1) 107 | ngx.say("all done") 108 | } 109 | } 110 | --- request 111 | GET /t 112 | --- no_error_log 113 | [error] 114 | --- response_body 115 | all done 116 | -------------------------------------------------------------------------------- /t/v3/grpc/health_check.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | workers(2); 7 | 8 | my $etcd_version = `etcd --version`; 9 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./ || $etcd_version =~ /^etcd Version: 3.2./) { 10 | plan(skip_all => "etcd is too old, skip v3 protocol"); 11 | } else { 12 | my $enable_tls = $ENV{ETCD_ENABLE_TLS}; 13 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 14 | plan(skip_all => "skip test cases with auth when TLS is enabled"); 15 | } else { 16 | plan 'no_plan'; 17 | } 18 | } 19 | 20 | add_block_preprocessor(sub { 21 | my ($block) = @_; 22 | 23 | if (!$block->main_config) { 24 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 25 | } 26 | 27 | if (!$block->request) { 28 | $block->set_value("request", "GET /t"); 29 | } 30 | 31 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 32 | $block->set_value("no_error_log", "[error]"); 33 | } 34 | 35 | }); 36 | 37 | our $HttpConfig = <<'_EOC_'; 38 | lua_socket_log_errors off; 39 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 40 | lua_shared_dict etcd_cluster_health_check 8m; 41 | init_by_lua_block { 42 | local cjson = require("cjson.safe") 43 | 44 | function check_res(data, err, val, status) 45 | if err then 46 | ngx.say("err: ", err) 47 | ngx.exit(200) 48 | end 49 | 50 | if val then 51 | if data.body.kvs==nil then 52 | ngx.exit(404) 53 | end 54 | if data.body.kvs and val ~= data.body.kvs[1].value then 55 | ngx.say("failed to check value") 56 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 57 | ", expect: ", val) 58 | ngx.exit(200) 59 | else 60 | ngx.say("checked val as expect: ", val) 61 | end 62 | end 63 | 64 | if status and status ~= data.status then 65 | ngx.exit(data.status) 66 | end 67 | end 68 | } 69 | _EOC_ 70 | 71 | run_tests(); 72 | 73 | __DATA__ 74 | 75 | === TEST 1: sanity 76 | --- http_config eval: $::HttpConfig 77 | --- config 78 | location /t { 79 | content_by_lua_block { 80 | local health_check, err = require "resty.etcd.health_check" .init({ 81 | shm_name = "etcd_cluster_health_check", 82 | fail_timeout = 5, 83 | max_fails = 3, 84 | }) 85 | assert( err == nil) 86 | assert( health_check.conf ~= nil) 87 | 88 | local etcd, err = require "resty.etcd" .new({ 89 | protocol = "v3", 90 | http_host = { 91 | "http://127.0.0.1:12379", 92 | "http://127.0.0.1:22379", 93 | "http://127.0.0.1:32379", 94 | }, 95 | use_grpc = true, 96 | user = 'root', 97 | password = 'abc123', 98 | }) 99 | check_res(etcd, err) 100 | 101 | ngx.say("done") 102 | } 103 | } 104 | --- response_body 105 | done 106 | 107 | 108 | 109 | === TEST 2: default configuration 110 | --- http_config eval: $::HttpConfig 111 | --- config 112 | location /t { 113 | content_by_lua_block { 114 | local health_check, err = require "resty.etcd.health_check" .init({ 115 | shm_name = "etcd_cluster_health_check", 116 | }) 117 | ngx.say(health_check.conf.max_fails) 118 | ngx.say(health_check.conf.fail_timeout) 119 | } 120 | } 121 | --- response_body 122 | 1 123 | 10 124 | 125 | 126 | 127 | === TEST 3: bad shm_name 128 | --- http_config eval: $::HttpConfig 129 | --- config 130 | location /t { 131 | content_by_lua_block { 132 | local health_check, err = require "resty.etcd.health_check" .init({ 133 | shm_name = "error_shm_name", 134 | }) 135 | ngx.say(err) 136 | } 137 | } 138 | --- response_body 139 | failed to get ngx.shared dict: error_shm_name 140 | 141 | 142 | 143 | === TEST 4: trigger unhealthy with set 144 | --- http_config eval: $::HttpConfig 145 | --- config 146 | location /t { 147 | content_by_lua_block { 148 | local health_check, err = require "resty.etcd.health_check" .init({ 149 | shm_name = "etcd_cluster_health_check", 150 | fail_timeout = 10, 151 | max_fails = 1, 152 | }) 153 | 154 | local etcd, err = require "resty.etcd" .new({ 155 | protocol = "v3", 156 | http_host = { 157 | "http://127.0.0.1:42379", 158 | "http://127.0.0.1:22379", 159 | "http://127.0.0.1:32379", 160 | }, 161 | use_grpc = true, 162 | user = 'root', 163 | password = 'abc123', 164 | init_count = -1, 165 | }) 166 | 167 | local res, err = etcd:set("/trigger_unhealthy", { a='abc'}) 168 | ngx.say(err) 169 | } 170 | } 171 | --- error_log eval 172 | qr/update endpoint: http:\/\/127.0.0.1:42379 to unhealthy/ 173 | --- response_body_like eval 174 | qr/.* dial tcp 127.0.0.1:42379: connect: connection refused/ 175 | 176 | 177 | 178 | === TEST 5: trigger unhealthy with watch 179 | --- http_config eval: $::HttpConfig 180 | --- config 181 | location /t { 182 | content_by_lua_block { 183 | local health_check, err = require "resty.etcd.health_check" .init({ 184 | shm_name = "etcd_cluster_health_check", 185 | fail_timeout = 10, 186 | max_fails = 1, 187 | }) 188 | 189 | local etcd, err = require "resty.etcd" .new({ 190 | protocol = "v3", 191 | http_host = { 192 | "http://127.0.0.1:42379", 193 | "http://127.0.0.1:22379", 194 | "http://127.0.0.1:32379", 195 | }, 196 | use_grpc = true, 197 | init_count = -1, 198 | }) 199 | 200 | local body_chunk_fun, err = etcd:create_grpc_watch_stream("/trigger_unhealthy", {}) 201 | if not body_chunk_fun then 202 | ngx.say(err) 203 | end 204 | } 205 | } 206 | --- error_log eval 207 | qr/update endpoint: http:\/\/127.0.0.1:42379 to unhealthy/ 208 | --- response_body_like eval 209 | qr/.* dial tcp 127.0.0.1:42379: connect: connection refused/ 210 | 211 | 212 | 213 | === TEST 6: fault count 214 | --- http_config eval: $::HttpConfig 215 | --- config 216 | location /t { 217 | content_by_lua_block { 218 | local health_check, err = require "resty.etcd.health_check" .init({ 219 | shm_name = "etcd_cluster_health_check", 220 | fail_timeout = 5, 221 | max_fails = 3, 222 | }) 223 | 224 | local etcd, err = require "resty.etcd" .new({ 225 | protocol = "v3", 226 | http_host = { 227 | "http://127.0.0.1:42379", 228 | "http://127.0.0.1:22379", 229 | "http://127.0.0.1:32379", 230 | }, 231 | use_grpc = true, 232 | user = 'root', 233 | password = 'abc123', 234 | init_count = -1, 235 | }) 236 | 237 | -- http://127.0.0.1:42379 will be selected only once 238 | for i = 1, 4 do 239 | etcd:set("/fault_count", { a='abc'}) 240 | end 241 | 242 | -- here have actually been 5 reads and writes to etcd, including one to /auth/authenticate 243 | 244 | local fails, err = ngx.shared["etcd_cluster_health_check"]:get("http://127.0.0.1:42379") 245 | if err then 246 | ngx.say(err) 247 | end 248 | ngx.say(fails) 249 | } 250 | } 251 | --- response_body 252 | 1 253 | 254 | 255 | 256 | === TEST 7: check endpoint is healthy 257 | --- http_config eval: $::HttpConfig 258 | --- config 259 | location /t { 260 | content_by_lua_block { 261 | local health_check, err = require "resty.etcd.health_check" .init({ 262 | shm_name = "etcd_cluster_health_check", 263 | fail_timeout = 3, 264 | max_fails = 1, 265 | }) 266 | 267 | local etcd, err = require "resty.etcd" .new({ 268 | protocol = "v3", 269 | http_host = { 270 | "http://127.0.0.1:42379", 271 | "http://127.0.0.1:22379", 272 | "http://127.0.0.1:32379", 273 | }, 274 | use_grpc = true, 275 | user = 'root', 276 | password = 'abc123', 277 | init_count = -1, 278 | }) 279 | 280 | etcd:set("/get_target_status", { a='abc'}) 281 | 282 | local healthy = health_check.get_target_status("http://127.0.0.1:42379") 283 | ngx.say(healthy) 284 | } 285 | } 286 | --- response_body 287 | false 288 | 289 | 290 | 291 | === TEST 8: make sure `fail_timeout` works 292 | --- http_config eval: $::HttpConfig 293 | --- config 294 | location /t { 295 | content_by_lua_block { 296 | local health_check, err = require "resty.etcd.health_check" .init({ 297 | shm_name = "etcd_cluster_health_check", 298 | fail_timeout = 2, 299 | max_fails = 1, 300 | }) 301 | 302 | local etcd, err = require "resty.etcd" .new({ 303 | protocol = "v3", 304 | http_host = { 305 | "http://127.0.0.1:42379", 306 | "http://127.0.0.1:22379", 307 | "http://127.0.0.1:32379", 308 | }, 309 | use_grpc = true, 310 | user = 'root', 311 | password = 'abc123', 312 | init_count = -1, 313 | }) 314 | 315 | local res, err 316 | 317 | -- make sure to select http://127.0.0.1:42379 once and trigger it to unhealthy 318 | for i = 1, 3 do 319 | res, err = etcd:set("/fail_timeout", "value") 320 | end 321 | 322 | -- ensure that unhealthy http://127.0.0.1:42379 are no longer selected 323 | for i = 1, 3 do 324 | res, err = etcd:get("/fail_timeout") 325 | assert(res, err) 326 | assert(res.body.kvs[1].value == "value") 327 | end 328 | 329 | ngx.say("done") 330 | } 331 | } 332 | --- timeout: 5 333 | --- response_body 334 | done 335 | --- error_log 336 | update endpoint: http://127.0.0.1:42379 to unhealthy 337 | 338 | 339 | 340 | === TEST 9: has no healthy etcd endpoint, directly return an error message 341 | --- http_config eval: $::HttpConfig 342 | --- config 343 | location /t { 344 | content_by_lua_block { 345 | local health_check, err = require "resty.etcd.health_check" .init({ 346 | shm_name = "etcd_cluster_health_check", 347 | fail_timeout = 3, 348 | max_fails = 1, 349 | }) 350 | 351 | health_check.report_failure("http://127.0.0.1:12379") 352 | health_check.report_failure("http://127.0.0.1:22379") 353 | health_check.report_failure("http://127.0.0.1:32379") 354 | 355 | local etcd, err = require "resty.etcd" .new({ 356 | protocol = "v3", 357 | http_host = { 358 | "http://127.0.0.1:12379", 359 | "http://127.0.0.1:22379", 360 | "http://127.0.0.1:32379", 361 | }, 362 | use_grpc = true, 363 | user = 'root', 364 | password = 'abc123', 365 | }) 366 | ngx.say(err) 367 | } 368 | } 369 | --- response_body 370 | has no healthy etcd endpoint available 371 | 372 | 373 | 374 | === TEST 10: test if retry works 375 | --- http_config eval: $::HttpConfig 376 | --- config 377 | location /t { 378 | content_by_lua_block { 379 | local health_check, err = require "resty.etcd.health_check" .init({ 380 | shm_name = "etcd_cluster_health_check", 381 | fail_timeout = 10, 382 | max_fails = 1, 383 | retry = true, 384 | }) 385 | 386 | local etcd, err = require "resty.etcd" .new({ 387 | protocol = "v3", 388 | http_host = { 389 | "http://127.0.0.1:42379", 390 | "http://127.0.0.1:52379", 391 | "http://127.0.0.1:22379", 392 | "http://127.0.0.1:32379", 393 | }, 394 | use_grpc = true, 395 | user = 'root', 396 | password = 'abc123', 397 | init_count = -1, 398 | }) 399 | 400 | local res, err 401 | for i = 1, 4 do 402 | res, err = etcd:set("/trigger_unhealthy", "abc") 403 | end 404 | check_res(res, err) 405 | local res, err = etcd:get("/trigger_unhealthy") 406 | check_res(res, err, "abc") 407 | -- unlike the retry in http version, we will use the same connection if the previous 408 | -- call is successful 409 | } 410 | } 411 | --- grep_error_log eval 412 | qr/update endpoint: http:\/\/127.0.0.1:\d+ to unhealthy/ 413 | --- grep_error_log_out 414 | update endpoint: http://127.0.0.1:42379 to unhealthy 415 | update endpoint: http://127.0.0.1:52379 to unhealthy 416 | --- response_body 417 | checked val as expect: abc 418 | 419 | 420 | 421 | === TEST 11: ring balancer with specific init_count 422 | --- http_config eval: $::HttpConfig 423 | --- config 424 | location /t { 425 | content_by_lua_block { 426 | local health_check = require("resty.etcd.health_check") 427 | health_check.disable() 428 | local etcd, err = require "resty.etcd" .new({ 429 | protocol = "v3", 430 | http_host = { 431 | "http://127.0.0.1:12379", 432 | "http://127.0.0.1:22379", 433 | "http://127.0.0.1:32379", 434 | }, 435 | use_grpc = true, 436 | init_count = 101, 437 | }) 438 | 439 | local res 440 | for i = 1, 3 do 441 | res, err = etcd:set("/ring_balancer", "abc") 442 | end 443 | 444 | ngx.say(etcd.init_count) 445 | } 446 | } 447 | --- response_body 448 | 105 449 | --- error_log 450 | choose endpoint: http://127.0.0.1:12379 451 | choose endpoint: http://127.0.0.1:22379 452 | 453 | 454 | 455 | === TEST 12: watch timeout should not be considered as unhealthy 456 | --- http_config eval: $::HttpConfig 457 | --- config 458 | location /t { 459 | content_by_lua_block { 460 | local health_check, err = require "resty.etcd.health_check" .init({ 461 | shm_name = "etcd_cluster_health_check", 462 | fail_timeout = 10, 463 | max_fails = 1, 464 | }) 465 | 466 | local etcd, err = require "resty.etcd" .new({ 467 | protocol = "v3", 468 | http_host = { 469 | "http://127.0.0.1:22379", 470 | }, 471 | use_grpc = true, 472 | init_count = -1, 473 | }) 474 | 475 | local body_chunk_fun, err = etcd:create_grpc_watch_stream("/trigger_unhealthy", {}, {timeout = 1}) 476 | if not body_chunk_fun then 477 | ngx.say(err) 478 | return 479 | end 480 | 481 | local _, err = etcd:read_grpc_watch_stream(body_chunk_fun) 482 | ngx.say(err) 483 | } 484 | } 485 | --- no_error_log eval 486 | qr/update endpoint: http:\/\/127.0.0.1:22379 to unhealthy/ 487 | --- response_body_like eval 488 | qr/failed to recv: / 489 | -------------------------------------------------------------------------------- /t/v3/grpc/key.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | add_block_preprocessor(sub { 15 | my ($block) = @_; 16 | 17 | if (!$block->main_config) { 18 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 19 | } 20 | 21 | if (!$block->request) { 22 | $block->set_value("request", "GET /t"); 23 | } 24 | 25 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 26 | $block->set_value("no_error_log", "[error]"); 27 | } 28 | }); 29 | 30 | our $HttpConfig = <<'_EOC_'; 31 | lua_socket_log_errors off; 32 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 33 | init_by_lua_block { 34 | local cjson = require("cjson.safe") 35 | 36 | function check_res(data, err, val, status) 37 | if err then 38 | ngx.say("err: ", err) 39 | ngx.exit(200) 40 | end 41 | 42 | if val then 43 | if data and data.body.kvs==nil then 44 | ngx.exit(400) 45 | end 46 | if data and data.body.kvs and #data.body.kvs ~= 0 and 47 | ((#val == 0) or (val ~= data.body.kvs[1].value)) then 48 | ngx.say("failed to check value") 49 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 50 | ", expect: ", val) 51 | ngx.exit(200) 52 | else 53 | ngx.say("checked val as expect: ", #val == 0 and "[]" or val) 54 | end 55 | end 56 | 57 | if status and status ~= data.status then 58 | ngx.exit(data.status) 59 | end 60 | end 61 | } 62 | _EOC_ 63 | 64 | run_tests(); 65 | 66 | __DATA__ 67 | 68 | === TEST 1: set(key, val) and get 69 | --- http_config eval: $::HttpConfig 70 | --- config 71 | location /t { 72 | content_by_lua_block { 73 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 74 | check_res(etcd, err) 75 | 76 | local res, err = etcd:set("/test", "abc", {prev_kv = true}) 77 | check_res(res, err) 78 | 79 | local data, err = etcd:get("/test") 80 | check_res(data, err, "abc") 81 | 82 | local data, err = etcd:get("") 83 | check_res(data, nil, err) 84 | 85 | local data, err = etcd:set("") 86 | check_res(data, nil, err) 87 | } 88 | } 89 | --- response_body 90 | checked val as expect: abc 91 | checked val as expect: failed to call: rpc error: code = InvalidArgument desc = etcdserver: key is not provided 92 | checked val as expect: failed to call: rpc error: code = InvalidArgument desc = etcdserver: key is not provided 93 | 94 | 95 | 96 | === TEST 2: readdir(key) 97 | --- http_config eval: $::HttpConfig 98 | --- config 99 | location /t { 100 | content_by_lua_block { 101 | local tab_nkeys = require "table.nkeys" 102 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 103 | check_res(etcd, err) 104 | 105 | local res, err = etcd:set("/dir", "abc") 106 | check_res(res, err) 107 | 108 | local res, err = etcd:set("/dir/a", "abca") 109 | check_res(res, err) 110 | 111 | local data, err = etcd:readdir("/dir") 112 | if tab_nkeys(data.body.kvs) == 2 then 113 | ngx.say("ok") 114 | ngx.exit(200) 115 | else 116 | ngx.say("failed") 117 | end 118 | 119 | } 120 | } 121 | --- response_body 122 | ok 123 | 124 | 125 | 126 | === TEST 3: set/del/get 127 | --- http_config eval: $::HttpConfig 128 | --- config 129 | location /t { 130 | content_by_lua_block { 131 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 132 | check_res(etcd, err) 133 | 134 | local res, err = etcd:set("/test", "abc", {prev_kv = true}) 135 | check_res(res, err) 136 | 137 | local data, err = etcd:get("/test") 138 | check_res(data, err, "abc") 139 | 140 | local data, err = etcd:delete("/test") 141 | assert(data.body.deleted == 1) 142 | 143 | local data, err = etcd:get("/test") 144 | check_res(data, nil) 145 | 146 | local data, err = etcd:delete("/test") 147 | assert(data.body.deleted == 0) 148 | assert(data.status == 404) 149 | local data, err = etcd:get("/test") 150 | check_res(data, nil) 151 | } 152 | } 153 | --- response_body 154 | checked val as expect: abc 155 | 156 | 157 | 158 | === TEST 4: watch dir 159 | --- http_config eval: $::HttpConfig 160 | --- config 161 | location /t { 162 | content_by_lua_block { 163 | local etcd, err = require("resty.etcd").new({protocol = "v3", use_grpc = true}) 164 | check_res(etcd, err) 165 | 166 | local res, err = etcd:set("/test/1", "abc") 167 | check_res(res, err) 168 | 169 | local opts = {} 170 | opts.timeout = 0.5 171 | 172 | local st, err = etcd:create_grpc_watch_stream("/test/", {}, opts) 173 | if not st then 174 | ngx.log(ngx.ERR, "create watch stream failed: ", err) 175 | return 176 | end 177 | 178 | ngx.timer.at(0.1, function () 179 | etcd:set("/test/1", "bcd3") 180 | end) 181 | 182 | local idx = 0 183 | while true do 184 | local chunk, err = etcd:read_grpc_watch_stream(st) 185 | 186 | if not chunk then 187 | if err then 188 | ngx.say(err) 189 | end 190 | break 191 | end 192 | 193 | idx = idx + 1 194 | ngx.say(idx, ": ", require("cjson").encode(chunk.result)) 195 | end 196 | } 197 | } 198 | --- response_body_like eval 199 | qr/1:.*"value":"bcd3".* 200 | .*context deadline exceeded/ 201 | --- timeout: 5 202 | -------------------------------------------------------------------------------- /t/v3/grpc/lease.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | add_block_preprocessor(sub { 15 | my ($block) = @_; 16 | 17 | if (!$block->main_config) { 18 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 19 | } 20 | 21 | if (!$block->request) { 22 | $block->set_value("request", "GET /t"); 23 | } 24 | 25 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 26 | $block->set_value("no_error_log", "[error]"); 27 | } 28 | }); 29 | 30 | our $HttpConfig = <<'_EOC_'; 31 | lua_socket_log_errors off; 32 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 33 | init_by_lua_block { 34 | function check_res(data, err, val, status) 35 | if err then 36 | ngx.say("err: ", err) 37 | ngx.exit(200) 38 | end 39 | 40 | if val then 41 | if data.body.kvs==nil then 42 | ngx.exit(404) 43 | end 44 | if data.body.kvs and val ~= data.body.kvs[1].value then 45 | ngx.say("failed to check value") 46 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 47 | ", expect: ", val) 48 | ngx.exit(200) 49 | else 50 | ngx.say("checked val as expect: ", val) 51 | end 52 | end 53 | 54 | if status and status ~= data.status then 55 | ngx.exit(data.status) 56 | end 57 | end 58 | } 59 | _EOC_ 60 | 61 | run_tests(); 62 | 63 | __DATA__ 64 | 65 | === TEST 1: lease grant, and wait for expiring 66 | --- http_config eval: $::HttpConfig 67 | --- config 68 | location /t { 69 | content_by_lua_block { 70 | local etcd, err = require "resty.etcd".new({protocol = "v3", use_grpc = true}) 71 | check_res(etcd, err) 72 | 73 | local res, err = etcd:grant(2) 74 | check_res(res, err) 75 | 76 | local data, err = etcd:set("/test", "abc", {prev_kv = true, lease = res.body.ID}) 77 | check_res(data, err) 78 | 79 | local data, err = etcd:get("/test") 80 | check_res(data, err, "abc") 81 | 82 | ngx.sleep(1) 83 | local data, err = etcd:get("/test") 84 | check_res(data, err, "abc") 85 | 86 | ngx.sleep(1.5) -- till lease expired 87 | local data, err = etcd:get("/test") 88 | if data.body.kvs == nil then 89 | ngx.say("key expired as expect") 90 | end 91 | } 92 | } 93 | --- response_body 94 | checked val as expect: abc 95 | checked val as expect: abc 96 | key expired as expect 97 | 98 | 99 | 100 | === TEST 2: lease grant and revoke 101 | --- http_config eval: $::HttpConfig 102 | --- config 103 | location /t { 104 | content_by_lua_block { 105 | local etcd, err = require "resty.etcd".new({protocol = "v3", use_grpc = true}) 106 | check_res(etcd, err) 107 | 108 | local res, err = etcd:grant(2) 109 | check_res(res, err) 110 | 111 | local data, err = etcd:set("/test1", "abc", {prev_kv = true, lease = res.body.ID}) 112 | check_res(data, err) 113 | 114 | local data, err = etcd:set("/test2", "bcd", {prev_kv = true, lease = res.body.ID}) 115 | check_res(data, err) 116 | 117 | local data, err = etcd:get("/test1") 118 | check_res(data, err, "abc") 119 | 120 | local data, err = etcd:get("/test2") 121 | check_res(data, err, "bcd") 122 | 123 | local data, err = etcd:revoke(res.body.ID) 124 | check_res(data, err) 125 | 126 | local data1, err1 = etcd:get("/test1") 127 | local data2, err2 = etcd:get("/test2") 128 | if data1.body.kvs == nil and data2.body.kvs == nil then 129 | ngx.say("deleted key as expect") 130 | else 131 | ngx.say("failed to delete key") 132 | ngx.exit(200) 133 | end 134 | } 135 | } 136 | --- response_body 137 | checked val as expect: abc 138 | checked val as expect: bcd 139 | deleted key as expect 140 | 141 | 142 | 143 | === TEST 3: lease grant and keealive 144 | --- http_config eval: $::HttpConfig 145 | --- config 146 | location /t { 147 | content_by_lua_block { 148 | local etcd, err = require "resty.etcd".new({protocol = "v3", use_grpc = true}) 149 | check_res(etcd, err) 150 | 151 | local res, err = etcd:grant(2, 123) 152 | check_res(res, err) 153 | 154 | local res, err = etcd:grant(2, 456) 155 | check_res(res, err) 156 | 157 | local data, err = etcd:set("/test1", "abc", {prev_kv = true, lease = 123}) 158 | check_res(data, err) 159 | 160 | local data, err = etcd:set("/test2", "bcd", {prev_kv = true, lease = 456}) 161 | check_res(data, err) 162 | 163 | local data, err = etcd:get("/test1") 164 | check_res(data, err, "abc") 165 | 166 | local data, err = etcd:get("/test2") 167 | check_res(data, err, "bcd") 168 | 169 | local data, err = etcd:timetolive(123, true) 170 | check_res(data, err) 171 | if data.body.keys then 172 | if data.body.keys[1] ~= "/test1" then 173 | ngx.say("lease attached keys are not as expected: ", data.body.keys) 174 | end 175 | end 176 | 177 | ngx.sleep(1) 178 | local data, err = etcd:keepalive(123) 179 | check_res(data, err) 180 | 181 | ngx.sleep(1.5) 182 | 183 | local data, err = etcd:get("/test1") 184 | if data.body.kvs == nil then 185 | ngx.say("Keepalive failed") 186 | end 187 | 188 | local data, err = etcd:get("/test2") 189 | if data.body.kvs ~= nil then 190 | ngx.say("Wrong lease got keepalived") 191 | end 192 | 193 | local data, err = etcd:revoke(123) 194 | check_res(data, err) 195 | 196 | ngx.say("all done") 197 | } 198 | } 199 | --- response_body 200 | checked val as expect: abc 201 | checked val as expect: bcd 202 | all done 203 | 204 | 205 | 206 | === TEST 4: lease grant, leases(), and wait for expiring 207 | --- http_config eval: $::HttpConfig 208 | --- config 209 | location /t { 210 | content_by_lua_block { 211 | local etcd, err = require "resty.etcd".new({protocol = "v3", use_grpc = true}) 212 | check_res(etcd, err) 213 | 214 | local res, err = etcd:grant(2) 215 | check_res(res, err) 216 | 217 | local data, err = etcd:leases() 218 | if data.body.leases[1].ID ~= res.body.ID then 219 | ngx.say("leases not working") 220 | ngx.say("result: ", require("cjson").encode(data.body)) 221 | end 222 | 223 | local data, err = etcd:set("/test", "abc", {prev_kv = true, lease = res.body.ID}) 224 | check_res(data, err) 225 | 226 | local data, err = etcd:get("/test") 227 | check_res(data, err, "abc") 228 | 229 | ngx.sleep(1) 230 | local data, err = etcd:get("/test") 231 | check_res(data, err, "abc") 232 | 233 | ngx.sleep(1.5) -- till lease expired 234 | local data, err = etcd:get("/test") 235 | if data.body.kvs == nil then 236 | ngx.say("key expired as expect") 237 | end 238 | } 239 | } 240 | --- response_body 241 | checked val as expect: abc 242 | checked val as expect: abc 243 | key expired as expect 244 | -------------------------------------------------------------------------------- /t/v3/grpc/misc.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | add_block_preprocessor(sub { 15 | my ($block) = @_; 16 | 17 | if (!$block->main_config) { 18 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 19 | } 20 | 21 | if (!$block->request) { 22 | $block->set_value("request", "GET /t"); 23 | } 24 | 25 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 26 | $block->set_value("no_error_log", "[error]"); 27 | } 28 | 29 | my $http_config = <<'_EOC_'; 30 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 31 | _EOC_ 32 | if (!$block->http_config) { 33 | $block->set_value("http_config", $http_config); 34 | } 35 | }); 36 | 37 | run_tests(); 38 | 39 | __DATA__ 40 | 41 | === TEST 1: load etcd module in init_by_lua 42 | --- http_config 43 | lua_package_path 'lib/?.lua;;'; 44 | init_by_lua_block { 45 | require("resty.etcd") 46 | } 47 | --- config 48 | location /t { 49 | content_by_lua_block { 50 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 51 | if etcd == nil then 52 | ngx.say(err) 53 | end 54 | } 55 | } 56 | --- response_body 57 | 58 | 59 | 60 | === TEST 2: close conn 61 | --- config 62 | location /t { 63 | content_by_lua_block { 64 | local etcd = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 65 | assert(etcd.conn ~= nil) 66 | etcd:close() 67 | assert(etcd.conn == nil) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /t/v3/grpc/mtls.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $enable_tls = $ENV{ETCD_ENABLE_MTLS}; 8 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 9 | plan 'no_plan'; 10 | } else { 11 | plan(skip_all => "etcd is not capable for mTLS connection"); 12 | } 13 | 14 | my $main_config = <<'_EOC_'; 15 | thread_pool grpc-client-nginx-module threads=1; 16 | _EOC_ 17 | 18 | my $http_config = <<'_EOC_'; 19 | lua_socket_log_errors off; 20 | lua_package_path 'lib/?.lua;/usr/share/lua/5.1/?.lua;;'; 21 | init_by_lua_block { 22 | local cjson = require("cjson.safe") 23 | 24 | function check_res(data, err, val, status) 25 | if err then 26 | ngx.say("err: ", err) 27 | ngx.exit(200) 28 | end 29 | 30 | if val then 31 | if data.body.kvs==nil then 32 | ngx.exit(404) 33 | end 34 | if data.body.kvs and val ~= data.body.kvs[1].value then 35 | ngx.say("failed to check value") 36 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 37 | ", expect: ", val) 38 | ngx.exit(200) 39 | else 40 | ngx.say("checked val as expect: ", val) 41 | end 42 | end 43 | 44 | if status and status ~= data.status then 45 | ngx.exit(data.status) 46 | end 47 | end 48 | 49 | function new_etcd(ssl_verify, ssl_cert_path, ssl_key_path, trusted_ca) 50 | return require "resty.etcd" .new({ 51 | protocol = "v3", 52 | api_prefix = "/v3", 53 | http_host = { 54 | "https://127.0.0.1:12379", 55 | }, 56 | use_grpc = true, 57 | ssl_verify = ssl_verify, 58 | ssl_cert_path = ssl_cert_path or "t/certs/mtls_client.crt", 59 | ssl_key_path = ssl_key_path or "t/certs/mtls_client.key", 60 | trusted_ca = trusted_ca, 61 | }) 62 | end 63 | } 64 | _EOC_ 65 | 66 | add_block_preprocessor(sub { 67 | my ($block) = @_; 68 | 69 | if (!$block->request) { 70 | $block->set_value("request", "GET /t"); 71 | } 72 | 73 | if (!$block->http_config) { 74 | $block->set_value("http_config", $http_config); 75 | } 76 | 77 | if (!$block->main_config) { 78 | $block->set_value("main_config", $main_config); 79 | } 80 | 81 | if (!$block->no_error_log && !$block->error_log) { 82 | $block->set_value("no_error_log", "[error]\n[alert]"); 83 | } 84 | }); 85 | 86 | run_tests(); 87 | 88 | __DATA__ 89 | 90 | === TEST 1: TLS no verify 91 | --- config 92 | location /t { 93 | content_by_lua_block { 94 | local etcd, err = new_etcd(false) 95 | check_res(etcd, err) 96 | 97 | local res, err = etcd:set("/test", { a='abc'}) 98 | check_res(res, err) 99 | ngx.say("done") 100 | } 101 | } 102 | --- response_body 103 | done 104 | 105 | 106 | 107 | === TEST 2: TLS verify 108 | --- config 109 | location /t { 110 | content_by_lua_block { 111 | local etcd, err = new_etcd(true) 112 | check_res(etcd, err) 113 | 114 | local res, err = etcd:set("/test", { a='abc'}) 115 | check_res(res, err) 116 | ngx.say("done") 117 | } 118 | } 119 | --- response_body_like eval 120 | qr/cannot validate certificate/ 121 | 122 | 123 | 124 | === TEST 3: bad client certificate 125 | --- config 126 | location /t { 127 | content_by_lua_block { 128 | local etcd, err = new_etcd(false, "t/certs/etcd.pem", "t/certs/etcd.key") 129 | check_res(etcd, err) 130 | 131 | local res, err = etcd:set("/test", { a='abc'}) 132 | check_res(res, err) 133 | ngx.say("done") 134 | } 135 | } 136 | --- response_body_like eval 137 | qr/bad certificate/ 138 | -------------------------------------------------------------------------------- /t/v3/grpc/stats.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua 'no_plan'; 2 | 3 | log_level('info'); 4 | repeat_each(1); 5 | 6 | my $lua_path = `lua -e 'print(package.path)'`; 7 | 8 | our $HttpConfig = <<_EOC_; 9 | lua_socket_log_errors off; 10 | lua_package_path 'lib/?.lua;$lua_path;;'; 11 | init_by_lua_block { 12 | function check_res(data, err) 13 | if err then 14 | ngx.say("err: ", err) 15 | ngx.exit(200) 16 | end 17 | end 18 | } 19 | _EOC_ 20 | 21 | add_block_preprocessor(sub { 22 | my ($block) = @_; 23 | 24 | if (!$block->main_config) { 25 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 26 | } 27 | 28 | if (!$block->request) { 29 | $block->set_value("request", "GET /t"); 30 | } 31 | 32 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 33 | $block->set_value("no_error_log", "[error]"); 34 | } 35 | }); 36 | 37 | run_tests(); 38 | 39 | __DATA__ 40 | 41 | === TEST 1: version 42 | --- http_config eval: $::HttpConfig 43 | --- config 44 | location /t { 45 | content_by_lua_block { 46 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 47 | check_res(etcd, err) 48 | 49 | local res, err = etcd:version() 50 | check_res(res, err) 51 | 52 | ngx.say(res.body.etcdserver) 53 | } 54 | } 55 | --- response_body_like eval 56 | qr{\d+.\d+.\d+} 57 | -------------------------------------------------------------------------------- /t/v3/grpc/tls.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $enable_tls = $ENV{ETCD_ENABLE_TLS}; 8 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 9 | plan 'no_plan'; 10 | } else { 11 | plan(skip_all => "etcd is not capable for TLS connection"); 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | local cjson = require("cjson.safe") 19 | 20 | function check_res(data, err, val, status) 21 | if err then 22 | ngx.say("err: ", err) 23 | ngx.exit(200) 24 | end 25 | 26 | if val then 27 | if data.body.kvs==nil then 28 | ngx.exit(404) 29 | end 30 | if data.body.kvs and val ~= data.body.kvs[1].value then 31 | ngx.say("failed to check value") 32 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 33 | ", expect: ", val) 34 | ngx.exit(200) 35 | else 36 | ngx.say("checked val as expect: ", val) 37 | end 38 | end 39 | 40 | if status and status ~= data.status then 41 | ngx.exit(data.status) 42 | end 43 | end 44 | } 45 | _EOC_ 46 | 47 | add_block_preprocessor(sub { 48 | my ($block) = @_; 49 | 50 | if (!$block->main_config) { 51 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 52 | } 53 | 54 | if (!$block->request) { 55 | $block->set_value("request", "GET /t"); 56 | } 57 | 58 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 59 | $block->set_value("no_error_log", "[error]"); 60 | } 61 | }); 62 | 63 | run_tests(); 64 | 65 | __DATA__ 66 | 67 | === TEST 1: TLS no verify 68 | --- http_config eval: $::HttpConfig 69 | --- config 70 | location /t { 71 | content_by_lua_block { 72 | local etcd, err = require "resty.etcd" .new({ 73 | protocol = "v3", 74 | http_host = { 75 | "https://127.0.0.1:12379", 76 | "https://127.0.0.1:22379", 77 | "https://127.0.0.1:32379", 78 | }, 79 | ssl_verify = false, 80 | use_grpc = true, 81 | }) 82 | check_res(etcd, err) 83 | 84 | local res, err = etcd:set("/test", { a='abc'}) 85 | check_res(res, err) 86 | ngx.say("done") 87 | } 88 | } 89 | --- response_body 90 | done 91 | 92 | 93 | 94 | === TEST 2: TLS verify 95 | --- http_config eval: $::HttpConfig 96 | --- config 97 | location /t { 98 | content_by_lua_block { 99 | local etcd, err = require "resty.etcd" .new({ 100 | protocol = "v3", 101 | http_host = { 102 | "https://127.0.0.1:12379", 103 | "https://127.0.0.1:22379", 104 | "https://127.0.0.1:32379", 105 | }, 106 | use_grpc = true, 107 | }) 108 | check_res(etcd, err) 109 | 110 | local res, err = etcd:set("/test", { a='abc'}) 111 | check_res(res, err) 112 | ngx.say("done") 113 | } 114 | } 115 | --- response_body eval 116 | qr/authentication handshake failed/ 117 | -------------------------------------------------------------------------------- /t/v3/grpc/txn.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | local cjson = require("cjson.safe") 19 | 20 | function check_res(data, err, val, status) 21 | if err then 22 | ngx.say("err: ", err) 23 | ngx.exit(200) 24 | end 25 | 26 | if val then 27 | if data.body.kvs==nil then 28 | ngx.exit(404) 29 | end 30 | if data.body.kvs and val ~= data.body.kvs[1].value then 31 | ngx.say("failed to check value") 32 | ngx.log(ngx.ERR, "failed to check value, got: ",data.body.kvs[1].value, 33 | ", expect: ", val) 34 | ngx.exit(200) 35 | else 36 | ngx.say("checked val as expect: ", val) 37 | end 38 | end 39 | 40 | if status and status ~= data.status then 41 | ngx.exit(data.status) 42 | end 43 | end 44 | } 45 | _EOC_ 46 | 47 | add_block_preprocessor(sub { 48 | my ($block) = @_; 49 | 50 | if (!$block->main_config) { 51 | $block->set_value("main_config", "thread_pool grpc-client-nginx-module threads=1;"); 52 | } 53 | 54 | if (!$block->request) { 55 | $block->set_value("request", "GET /t"); 56 | } 57 | 58 | if ((!defined $block->error_log) && (!defined $block->no_error_log)) { 59 | $block->set_value("no_error_log", "[error]"); 60 | } 61 | }); 62 | 63 | run_tests(); 64 | 65 | __DATA__ 66 | 67 | === TEST 1: txn("EQUAL") and get 68 | --- http_config eval: $::HttpConfig 69 | --- config 70 | location /t { 71 | content_by_lua_block { 72 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 73 | check_res(etcd, err) 74 | 75 | local res, err = etcd:set("/test", "abc") 76 | check_res(res, err) 77 | 78 | local data, err = etcd:get("/test") 79 | check_res(data, err, "abc") 80 | 81 | local data, err = etcd:txn( 82 | {{key = "/test", result = "EQUAL", value = "abc", target = "VALUE"}}, 83 | {{requestPut = {key = "/test", value = "ddd"}}} 84 | ) 85 | check_res(data, err) 86 | 87 | local data, err = etcd:get("/test") 88 | check_res(data, err, "ddd") 89 | } 90 | } 91 | --- response_body 92 | checked val as expect: abc 93 | checked val as expect: ddd 94 | 95 | 96 | 97 | === TEST 2: txn(not "EQUAL") and get 98 | --- http_config eval: $::HttpConfig 99 | --- config 100 | location /t { 101 | content_by_lua_block { 102 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 103 | check_res(etcd, err) 104 | 105 | local res, err = etcd:set("/test", "abc") 106 | check_res(res, err) 107 | 108 | local data, err = etcd:get("/test") 109 | check_res(data, err, "abc") 110 | 111 | local data, err = etcd:txn( 112 | {{key = "/test", result = "EQUAL", value = "not equal", target = "VALUE"}}, 113 | {{requestPut = {key = "/test", value = "ddd"}}} 114 | ) 115 | check_res(data, err) 116 | 117 | local data, err = etcd:get("/test") 118 | check_res(data, err, "abc") 119 | } 120 | } 121 | --- response_body 122 | checked val as expect: abc 123 | checked val as expect: abc 124 | 125 | 126 | 127 | === TEST 3: setnx(key, val) 128 | --- http_config eval: $::HttpConfig 129 | --- config 130 | location /t { 131 | content_by_lua_block { 132 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 133 | check_res(etcd, err) 134 | 135 | local res, err = etcd:delete("/setnx") 136 | check_res(res, err) 137 | 138 | local res, err = etcd:setnx("/setnx", "aaa") 139 | check_res(res, err, nil, 200) 140 | 141 | local res, err = etcd:setnx("/setnx", "bbb") 142 | check_res(res, err, nil, 200) 143 | 144 | local data, err = etcd:get("/setnx") 145 | check_res(data, err, "aaa", 200) 146 | } 147 | } 148 | --- response_body 149 | checked val as expect: aaa 150 | 151 | 152 | 153 | === TEST 4: txn with table 154 | --- http_config eval: $::HttpConfig 155 | --- config 156 | location /t { 157 | content_by_lua_block { 158 | local cjson = require("cjson.safe") 159 | local function check_res(data, err, val, status) 160 | if err then 161 | ngx.say("err: ", err) 162 | ngx.exit(200) 163 | end 164 | 165 | if val then 166 | if data.body.kvs==nil then 167 | ngx.exit(404) 168 | end 169 | if data.body.kvs and val ~= cjson.encode(data.body.kvs[1].value) then 170 | ngx.say("failed to check value") 171 | ngx.log(ngx.ERR, "failed to check value, got: ", 172 | cjson.encode(data.body.kvs[1].value), 173 | ", expect: ", val) 174 | ngx.exit(200) 175 | else 176 | ngx.say("checked val as expect: ", val) 177 | end 178 | end 179 | 180 | if status and status ~= data.status then 181 | ngx.exit(data.status) 182 | end 183 | end 184 | 185 | local etcd, err = require "resty.etcd" .new({protocol = "v3", use_grpc = true}) 186 | check_res(etcd, err) 187 | 188 | local res, err = etcd:set("/test", {k = "abc"}) 189 | check_res(res, err) 190 | 191 | local data, err = etcd:get("/test") 192 | check_res(data, err, '{"k":"abc"}') 193 | 194 | local data, err = etcd:txn( 195 | {{key = "/test", result = "EQUAL", value = {k = "abc"}, target = "VALUE"}}, 196 | {{requestPut = {key = "/test", value = {k = "ddd"}}}} 197 | ) 198 | check_res(data, err) 199 | 200 | local data, err = etcd:get("/test") 201 | check_res(data, err, '{"k":"ddd"}') 202 | } 203 | } 204 | --- response_body 205 | checked val as expect: {"k":"abc"} 206 | checked val as expect: {"k":"ddd"} 207 | -------------------------------------------------------------------------------- /t/v3/lease.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | function check_res(data, err, val, status) 19 | if err then 20 | ngx.say("err: ", err) 21 | ngx.exit(200) 22 | end 23 | 24 | if val then 25 | if data.body.kvs==nil then 26 | ngx.exit(404) 27 | end 28 | if data.body.kvs and val ~= data.body.kvs[1].value then 29 | ngx.say("failed to check value") 30 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 31 | ", expect: ", val) 32 | ngx.exit(200) 33 | else 34 | ngx.say("checked val as expect: ", val) 35 | end 36 | end 37 | 38 | if status and status ~= data.status then 39 | ngx.exit(data.status) 40 | end 41 | end 42 | } 43 | _EOC_ 44 | 45 | run_tests(); 46 | 47 | __DATA__ 48 | 49 | === TEST 1: lease grant, and wait for expiring 50 | --- http_config eval: $::HttpConfig 51 | --- config 52 | location /t { 53 | content_by_lua_block { 54 | local etcd, err = require "resty.etcd".new({protocol = "v3"}) 55 | check_res(etcd, err) 56 | 57 | local res, err = etcd:grant(2) 58 | check_res(res, err) 59 | 60 | local data, err = etcd:set("/test", "abc", {prev_kv = true, lease = res.body.ID}) 61 | check_res(data, err) 62 | 63 | local data, err = etcd:get("/test") 64 | check_res(data, err, "abc") 65 | 66 | ngx.sleep(1) 67 | local data, err = etcd:get("/test") 68 | check_res(data, err, "abc") 69 | 70 | ngx.sleep(1.5) -- till lease expired 71 | local data, err = etcd:get("/test") 72 | if data.body.kvs == nil then 73 | ngx.say("key expired as expect") 74 | end 75 | } 76 | } 77 | --- request 78 | GET /t 79 | --- no_error_log 80 | [error] 81 | --- response_body 82 | checked val as expect: abc 83 | checked val as expect: abc 84 | key expired as expect 85 | 86 | 87 | 88 | === TEST 2: lease grant and revoke 89 | --- http_config eval: $::HttpConfig 90 | --- config 91 | location /t { 92 | content_by_lua_block { 93 | local etcd, err = require "resty.etcd".new({protocol = "v3"}) 94 | check_res(etcd, err) 95 | 96 | local res, err = etcd:grant(2) 97 | check_res(res, err) 98 | 99 | local data, err = etcd:set("/test1", "abc", {prev_kv = true, lease = res.body.ID}) 100 | check_res(data, err) 101 | 102 | local data, err = etcd:set("/test2", "bcd", {prev_kv = true, lease = res.body.ID}) 103 | check_res(data, err) 104 | 105 | local data, err = etcd:get("/test1") 106 | check_res(data, err, "abc") 107 | 108 | local data, err = etcd:get("/test2") 109 | check_res(data, err, "bcd") 110 | 111 | local data, err = etcd:revoke(res.body.ID) 112 | check_res(data, err) 113 | 114 | local data1, err1 = etcd:get("/test1") 115 | local data2, err2 = etcd:get("/test2") 116 | if data1.body.kvs == nil and data2.body.kvs == nil then 117 | ngx.say("deleted key as expect") 118 | else 119 | ngx.say("failed to delete key") 120 | ngx.exit(200) 121 | end 122 | } 123 | } 124 | --- request 125 | GET /t 126 | --- no_error_log 127 | [error] 128 | --- response_body 129 | checked val as expect: abc 130 | checked val as expect: bcd 131 | deleted key as expect 132 | 133 | 134 | 135 | === TEST 3: lease grant and keealive 136 | --- http_config eval: $::HttpConfig 137 | --- config 138 | location /t { 139 | content_by_lua_block { 140 | local etcd, err = require "resty.etcd".new({protocol = "v3"}) 141 | check_res(etcd, err) 142 | 143 | local res, err = etcd:grant(2, 123) 144 | check_res(res, err) 145 | 146 | local res, err = etcd:grant(2, 456) 147 | check_res(res, err) 148 | 149 | local data, err = etcd:set("/test1", "abc", {prev_kv = true, lease = 123}) 150 | check_res(data, err) 151 | 152 | local data, err = etcd:set("/test2", "bcd", {prev_kv = true, lease = 456}) 153 | check_res(data, err) 154 | 155 | local data, err = etcd:get("/test1") 156 | check_res(data, err, "abc") 157 | 158 | local data, err = etcd:get("/test2") 159 | check_res(data, err, "bcd") 160 | 161 | local data, err = etcd:timetolive(123, true) 162 | check_res(data, err) 163 | if data.body.keys then 164 | if data.body.keys[1] ~= "/test1" then 165 | ngx.say("lease attached keys are not as expected: ", data.body.keys) 166 | end 167 | end 168 | 169 | ngx.sleep(1) 170 | local data, err = etcd:keepalive(123) 171 | check_res(data, err) 172 | 173 | ngx.sleep(1.5) 174 | 175 | local data, err = etcd:get("/test1") 176 | if data.body.kvs == nil then 177 | ngx.say("Keepalive failed") 178 | end 179 | 180 | local data, err = etcd:get("/test2") 181 | if data.body.kvs ~= nil then 182 | ngx.say("Wrong lease got keepalived") 183 | end 184 | 185 | local data, err = etcd:revoke(123) 186 | check_res(data, err) 187 | 188 | ngx.say("all done") 189 | } 190 | } 191 | --- request 192 | GET /t 193 | --- no_error_log 194 | [error] 195 | --- response_body 196 | checked val as expect: abc 197 | checked val as expect: bcd 198 | all done 199 | -------------------------------------------------------------------------------- /t/v3/lease3.4.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | #todo 8 | #test multi-leases 9 | #test multi-keys conbined to one lease 10 | #test the keys conbined to timetolive is the same to granted (some kind of decoding needed) 11 | 12 | my $etcd_version = `etcd --version`; 13 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./ || $etcd_version =~ /^etcd Version: 3.2./ || $etcd_version =~ /^etcd Version: 3.3./) { 14 | plan(skip_all => "test by another lease test"); 15 | } else { 16 | plan 'no_plan'; 17 | } 18 | 19 | our $HttpConfig = <<'_EOC_'; 20 | lua_socket_log_errors off; 21 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 22 | init_by_lua_block { 23 | function check_res(data, err, val, status) 24 | if err then 25 | ngx.say("err: ", err) 26 | ngx.exit(200) 27 | end 28 | 29 | if val then 30 | if data.body.kvs==nil then 31 | ngx.exit(404) 32 | end 33 | if data.body.kvs and val ~= data.body.kvs[1].value then 34 | ngx.say("failed to check value") 35 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 36 | ", expect: ", val) 37 | ngx.exit(200) 38 | else 39 | ngx.say("checked val as expect: ", val) 40 | end 41 | end 42 | 43 | if status and status ~= data.status then 44 | ngx.exit(data.status) 45 | end 46 | end 47 | } 48 | _EOC_ 49 | 50 | run_tests(); 51 | 52 | __DATA__ 53 | 54 | === TEST 1: lease grant, leases(), and wait for expiring 55 | --- http_config eval: $::HttpConfig 56 | --- config 57 | location /t { 58 | content_by_lua_block { 59 | local etcd, err = require "resty.etcd".new({protocol = "v3"}) 60 | check_res(etcd, err) 61 | 62 | local res, err = etcd:grant(2) 63 | check_res(res, err) 64 | 65 | local data, err = etcd:leases() 66 | if data.body.leases[1].ID ~= res.body.ID then 67 | ngx.say("leases not working") 68 | ngx.say("result: ", require("cjson").encode(data.body)) 69 | end 70 | 71 | local data, err = etcd:set("/test", "abc", {prev_kv = true, lease = res.body.ID}) 72 | check_res(data, err) 73 | 74 | local data, err = etcd:get("/test") 75 | check_res(data, err, "abc") 76 | 77 | ngx.sleep(1) 78 | local data, err = etcd:get("/test") 79 | check_res(data, err, "abc") 80 | 81 | ngx.sleep(1.5) -- till lease expired 82 | local data, err = etcd:get("/test") 83 | if data.body.kvs == nil then 84 | ngx.say("key expired as expect") 85 | end 86 | } 87 | } 88 | --- request 89 | GET /t 90 | --- no_error_log 91 | [error] 92 | --- response_body 93 | checked val as expect: abc 94 | checked val as expect: abc 95 | key expired as expect 96 | -------------------------------------------------------------------------------- /t/v3/opt.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | add_block_preprocessor(sub { 15 | my ($block) = @_; 16 | 17 | $block->set_value("request", "GET /t"); 18 | $block->set_value("no_error_log", "[error]"); 19 | 20 | my $http_config = <<_EOC_; 21 | lua_package_path 'lib/?.lua;;'; 22 | _EOC_ 23 | $block->set_value("http_config", $http_config); 24 | 25 | $block; 26 | }); 27 | 28 | run_tests(); 29 | 30 | __DATA__ 31 | 32 | === TEST 1: http_host 33 | --- config 34 | location /t { 35 | content_by_lua_block { 36 | local cases = { 37 | "http://127.0.0.1:2973", 38 | "http://127.0.0.1", 39 | "https://127.0.0.1:12000", 40 | "http://c.cn:9000", 41 | "http://c-a.cn:9000", 42 | "http://c_a.cn", 43 | "http://[ab::0]:2971", 44 | "http://[ab::0]", 45 | } 46 | for _, case in ipairs(cases) do 47 | local etcd, err = require "resty.etcd" .new({protocol = "v3", api_prefix = "/v3", 48 | http_host = case}) 49 | if not etcd then 50 | ngx.say(err) 51 | else 52 | ngx.say( 53 | etcd.endpoints[1].scheme, " ", 54 | etcd.endpoints[1].host, " ", 55 | etcd.endpoints[1].port) 56 | end 57 | end 58 | 59 | ngx.say('ok') 60 | } 61 | } 62 | --- response_body 63 | http 127.0.0.1 2973 64 | http 127.0.0.1 2379 65 | https 127.0.0.1 12000 66 | http c.cn 9000 67 | http c-a.cn 9000 68 | invalid http host: http://c_a.cn, err: not matched 69 | http [ab::0] 2971 70 | http [ab::0] 2379 71 | ok 72 | -------------------------------------------------------------------------------- /t/v3/serializer.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | local cjson = require("cjson.safe") 19 | 20 | function check_res(data, err, val, status) 21 | if err then 22 | ngx.say("err: ", err) 23 | ngx.exit(200) 24 | end 25 | 26 | if val then 27 | if data and data.body.kvs==nil then 28 | ngx.exit(404) 29 | end 30 | if data and data.body.kvs and val ~= data.body.kvs[1].value then 31 | ngx.say("failed to check value") 32 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 33 | ", expect: ", val) 34 | ngx.exit(200) 35 | else 36 | ngx.say("checked val as expect: ", val) 37 | end 38 | end 39 | 40 | if status and status ~= data.status then 41 | ngx.exit(data.status) 42 | end 43 | end 44 | } 45 | _EOC_ 46 | 47 | run_tests(); 48 | 49 | __DATA__ 50 | 51 | === TEST 1: raw string serializer 52 | --- http_config eval: $::HttpConfig 53 | --- config 54 | location /t { 55 | content_by_lua_block { 56 | local cjson = require("cjson.safe") 57 | 58 | local etcd, err = require("resty.etcd").new({ 59 | protocol = "v3", 60 | serializer = "raw" 61 | }) 62 | check_res(etcd, err) 63 | 64 | local res 65 | res, err = etcd:rmdir("/dir") 66 | check_res(res, err, nil, 200) 67 | 68 | res, err = etcd:set("/dir/v3/a", '"foo"') 69 | check_res(res, err) 70 | 71 | res, err = etcd:get("/dir/v3/a") 72 | check_res(res, err, '"foo"') 73 | 74 | local s = cjson.encode({a = 1}) 75 | res, err = etcd:setx("/dir/v3/a", s) 76 | check_res(res, err, nil, 200) 77 | 78 | res, err = etcd:get("/dir/v3/a") 79 | check_res(res, err, s, 200) 80 | 81 | res, err = etcd:setnx("/dir/v3/not_exist", "") 82 | check_res(res, err, nil, 200) 83 | 84 | res, err = etcd:get("/dir/v3/not_exist") 85 | check_res(res, err, "", 200) 86 | 87 | res, err = etcd:rmdir("/dir") 88 | check_res(res, err, nil, 200) 89 | 90 | res, err = etcd:set("/dir/v3/b", 111) 91 | check_res(res, err) 92 | } 93 | } 94 | --- request 95 | GET /t 96 | --- no_error_log 97 | [error] 98 | --- response_body 99 | checked val as expect: "foo" 100 | checked val as expect: {"a":1} 101 | checked val as expect: 102 | err: unsupported type for number 103 | 104 | 105 | === TEST 2: json serializer 106 | --- http_config eval: $::HttpConfig 107 | --- config 108 | location /t { 109 | content_by_lua_block { 110 | local cjson = require("cjson.safe") 111 | 112 | local etcd, err = require("resty.etcd").new({ 113 | protocol = "v3", 114 | serializer = "json" 115 | }) 116 | check_res(etcd, err) 117 | 118 | local res 119 | res, err = etcd:rmdir("/dir") 120 | check_res(res, err, nil, 200) 121 | 122 | res, err = etcd:set("/dir/v3/a", 111) 123 | check_res(res, err) 124 | 125 | res, err = etcd:get("/dir/v3/a") 126 | check_res(res, err, 111) 127 | 128 | res, err = etcd:set("/dir/v3/a", '"foo"') 129 | check_res(res, err) 130 | 131 | res, err = etcd:get("/dir/v3/a") 132 | check_res(res, err, '"foo"') 133 | 134 | local s = cjson.encode({a = 1}) 135 | res, err = etcd:setx("/dir/v3/a", s) 136 | check_res(res, err, nil, 200) 137 | 138 | res, err = etcd:get("/dir/v3/a") 139 | check_res(res, err, s, 200) 140 | 141 | res, err = etcd:setnx("/dir/v3/not_exist", "") 142 | check_res(res, err, nil, 200) 143 | 144 | res, err = etcd:get("/dir/v3/not_exist") 145 | check_res(res, err, "", 200) 146 | 147 | res, err = etcd:rmdir("/dir") 148 | check_res(res, err, nil, 200) 149 | } 150 | } 151 | --- request 152 | GET /t 153 | --- no_error_log 154 | [error] 155 | --- response_body 156 | checked val as expect: 111 157 | checked val as expect: "foo" 158 | checked val as expect: {"a":1} 159 | checked val as expect: 160 | 161 | === TEST 3: default serializer 162 | --- http_config eval: $::HttpConfig 163 | --- config 164 | location /t { 165 | content_by_lua_block { 166 | local cjson = require("cjson.safe") 167 | 168 | local etcd, err = require("resty.etcd").new({ 169 | protocol = "v3", 170 | }) 171 | check_res(etcd, err) 172 | 173 | local res 174 | res, err = etcd:rmdir("/dir") 175 | check_res(res, err, nil, 200) 176 | 177 | res, err = etcd:set("/dir/v3/a", 111) 178 | check_res(res, err) 179 | 180 | res, err = etcd:get("/dir/v3/a") 181 | check_res(res, err, 111) 182 | 183 | res, err = etcd:set("/dir/v3/a", '"foo"') 184 | check_res(res, err) 185 | 186 | res, err = etcd:get("/dir/v3/a") 187 | check_res(res, err, '"foo"') 188 | 189 | local s = cjson.encode({a = 1}) 190 | res, err = etcd:setx("/dir/v3/a", s) 191 | check_res(res, err, nil, 200) 192 | 193 | res, err = etcd:get("/dir/v3/a") 194 | check_res(res, err, s, 200) 195 | 196 | res, err = etcd:setnx("/dir/v3/not_exist", "") 197 | check_res(res, err, nil, 200) 198 | 199 | res, err = etcd:get("/dir/v3/not_exist") 200 | check_res(res, err, "", 200) 201 | 202 | res, err = etcd:rmdir("/dir") 203 | check_res(res, err, nil, 200) 204 | } 205 | } 206 | --- request 207 | GET /t 208 | --- no_error_log 209 | [error] 210 | --- response_body 211 | checked val as expect: 111 212 | checked val as expect: "foo" 213 | checked val as expect: {"a":1} 214 | checked val as expect: 215 | -------------------------------------------------------------------------------- /t/v3/sni.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $enable_tls = $ENV{ETCD_ENABLE_MTLS}; 8 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 9 | plan 'no_plan'; 10 | } else { 11 | plan(skip_all => "etcd is not capable for mTLS connection"); 12 | } 13 | 14 | my $http_config = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | lua_ssl_trusted_certificate ../../../t/certs/mtls_ca.crt; 18 | init_by_lua_block { 19 | local cjson = require("cjson.safe") 20 | 21 | function check_res(data, err, val, status) 22 | if err then 23 | ngx.say("err: ", err) 24 | ngx.exit(200) 25 | end 26 | 27 | if val then 28 | if data.body.kvs==nil then 29 | ngx.exit(404) 30 | end 31 | if data.body.kvs and val ~= data.body.kvs[1].value then 32 | ngx.say("failed to check value") 33 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 34 | ", expect: ", val) 35 | ngx.exit(200) 36 | else 37 | ngx.say("checked val as expect: ", val) 38 | end 39 | end 40 | 41 | if status and status ~= data.status then 42 | ngx.exit(data.status) 43 | end 44 | end 45 | 46 | function new_etcd(ssl_verify, ssl_cert_path, ssl_key_path, sni) 47 | return require "resty.etcd" .new({ 48 | protocol = "v3", 49 | api_prefix = "/v3", 50 | http_host = { 51 | "https://127.0.0.1:12379", 52 | "https://127.0.0.1:22379", 53 | "https://127.0.0.1:32379", 54 | }, 55 | ssl_verify = ssl_verify, 56 | ssl_cert_path = ssl_cert_path or "t/certs/mtls_client.crt", 57 | ssl_key_path = ssl_key_path or "t/certs/mtls_client.key", 58 | sni = sni, 59 | }) 60 | end 61 | } 62 | _EOC_ 63 | 64 | add_block_preprocessor(sub { 65 | my ($block) = @_; 66 | 67 | if (!$block->request) { 68 | $block->set_value("request", "GET /t"); 69 | } 70 | 71 | if (!$block->http_config) { 72 | $block->set_value("http_config", $http_config); 73 | } 74 | 75 | if (!$block->no_error_log && !$block->error_log) { 76 | $block->set_value("no_error_log", "[error]\n[alert]"); 77 | } 78 | }); 79 | 80 | run_tests(); 81 | 82 | __DATA__ 83 | 84 | === TEST 1: without sni, use host(127.0.0.1) as sni by default 85 | --- config 86 | location /t { 87 | content_by_lua_block { 88 | local etcd, err = new_etcd(true) 89 | local res, err = etcd:set("/test", { a='abc'}) 90 | if err then 91 | ngx.say(err) 92 | else 93 | ngx.say("done") 94 | end 95 | } 96 | } 97 | --- response_body 98 | certificate host mismatch 99 | 100 | 101 | 102 | === TEST 2: certificate host mismatch (requesy uri) 103 | --- config 104 | location /t { 105 | content_by_lua_block { 106 | local etcd, err = new_etcd(true, nil, nil, "wrong.sni") 107 | local res, err = etcd:set("/test", { a='abc'}) 108 | if err then 109 | ngx.say(err) 110 | else 111 | ngx.say("done") 112 | end 113 | } 114 | } 115 | --- response_body 116 | certificate host mismatch 117 | 118 | 119 | 120 | === TEST 3: sni match server cert common name (requesy uri) 121 | --- config 122 | location /t { 123 | content_by_lua_block { 124 | local etcd, err = new_etcd(true, nil, nil, "admin.apisix.dev") 125 | local res, err = etcd:set("/test", { a='abc'}) 126 | if err then 127 | ngx.say(err) 128 | else 129 | ngx.say("done") 130 | end 131 | } 132 | } 133 | --- response_body 134 | done 135 | 136 | 137 | 138 | === TEST 4: certificate host mismatch (requesy chunk) 139 | --- config 140 | location /t { 141 | content_by_lua_block { 142 | local etcd, err = new_etcd(true, nil, nil, "127.0.0.1") 143 | local cur_time = ngx.now() 144 | local body_chunk_fun, err = etcd:watch("/test", {timeout = 0.5}) 145 | if not body_chunk_fun then 146 | ngx.say("failed to watch: ", err) 147 | else 148 | ngx.say("done") 149 | end 150 | 151 | } 152 | } 153 | --- response_body 154 | failed to watch: https://127.0.0.1:12379: certificate host mismatch 155 | 156 | 157 | 158 | === TEST 5: sni match server cert common name (requesy chunk) 159 | --- config 160 | location /t { 161 | content_by_lua_block { 162 | local etcd, err = new_etcd(true, nil, nil, "admin.apisix.dev") 163 | local cur_time = ngx.now() 164 | local body_chunk_fun, err = etcd:watch("/test", {timeout = 0.5}) 165 | if not body_chunk_fun then 166 | ngx.say("failed to watch: ", err) 167 | else 168 | ngx.say("done") 169 | end 170 | } 171 | } 172 | --- response_body 173 | done 174 | -------------------------------------------------------------------------------- /t/v3/stats.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua 'no_plan'; 2 | 3 | log_level('info'); 4 | repeat_each(1); 5 | 6 | my $lua_path = `lua -e 'print(package.path)'`; 7 | 8 | our $HttpConfig = <<_EOC_; 9 | lua_socket_log_errors off; 10 | lua_package_path 'lib/?.lua;$lua_path;;'; 11 | init_by_lua_block { 12 | function check_res(data, err) 13 | if err then 14 | ngx.say("err: ", err) 15 | ngx.exit(200) 16 | end 17 | end 18 | } 19 | _EOC_ 20 | 21 | run_tests(); 22 | 23 | __DATA__ 24 | 25 | === TEST 1: version 26 | --- http_config eval: $::HttpConfig 27 | --- config 28 | location /t { 29 | content_by_lua_block { 30 | local etcd, err = require "resty.etcd" .new({protocol = "v3"}) 31 | check_res(etcd, err) 32 | 33 | local res, err = etcd:version() 34 | check_res(res, err) 35 | 36 | ngx.say(res.body.etcdserver) 37 | } 38 | } 39 | --- request 40 | GET /t 41 | --- no_error_log 42 | [error] 43 | --- response_body_like eval 44 | qr{\d+.\d+.\d+} 45 | -------------------------------------------------------------------------------- /t/v3/tls.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $enable_tls = $ENV{ETCD_ENABLE_TLS}; 8 | if (defined($enable_tls) && $enable_tls eq "TRUE") { 9 | plan 'no_plan'; 10 | } else { 11 | plan(skip_all => "etcd is not capable for TLS connection"); 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | local cjson = require("cjson.safe") 19 | 20 | function check_res(data, err, val, status) 21 | if err then 22 | ngx.say("err: ", err) 23 | ngx.exit(200) 24 | end 25 | 26 | if val then 27 | if data.body.kvs==nil then 28 | ngx.exit(404) 29 | end 30 | if data.body.kvs and val ~= data.body.kvs[1].value then 31 | ngx.say("failed to check value") 32 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 33 | ", expect: ", val) 34 | ngx.exit(200) 35 | else 36 | ngx.say("checked val as expect: ", val) 37 | end 38 | end 39 | 40 | if status and status ~= data.status then 41 | ngx.exit(data.status) 42 | end 43 | end 44 | } 45 | _EOC_ 46 | 47 | run_tests(); 48 | 49 | __DATA__ 50 | 51 | === TEST 1: TLS no verify 52 | --- http_config eval: $::HttpConfig 53 | --- config 54 | location /t { 55 | content_by_lua_block { 56 | local etcd, err = require "resty.etcd" .new({ 57 | protocol = "v3", 58 | http_host = { 59 | "https://127.0.0.1:12379", 60 | "https://127.0.0.1:22379", 61 | "https://127.0.0.1:32379", 62 | }, 63 | ssl_verify = false, 64 | }) 65 | check_res(etcd, err) 66 | 67 | local res, err = etcd:set("/test", { a='abc'}) 68 | check_res(res, err) 69 | ngx.say("done") 70 | } 71 | } 72 | --- request 73 | GET /t 74 | --- no_error_log 75 | [error] 76 | --- response_body 77 | done 78 | 79 | 80 | 81 | === TEST 2: TLS verify 82 | --- http_config eval: $::HttpConfig 83 | --- config 84 | location /t { 85 | content_by_lua_block { 86 | local etcd, err = require "resty.etcd" .new({ 87 | protocol = "v3", 88 | http_host = { 89 | "https://127.0.0.1:12379", 90 | "https://127.0.0.1:22379", 91 | "https://127.0.0.1:32379", 92 | }, 93 | }) 94 | check_res(etcd, err) 95 | 96 | local res, err = etcd:set("/test", { a='abc'}) 97 | check_res(res, err) 98 | ngx.say("done") 99 | } 100 | } 101 | --- request 102 | GET /t 103 | --- no_error_log 104 | [error] 105 | --- response_body eval 106 | qr/18: self signed certificate/ 107 | 108 | 109 | 110 | === TEST 3: watch(key) 111 | --- http_config eval: $::HttpConfig 112 | --- config 113 | location /t { 114 | content_by_lua_block { 115 | local etcd, err = require("resty.etcd").new({ 116 | protocol = "v3", 117 | ssl_verify = false, 118 | http_host = { 119 | "https://127.0.0.1:12379", 120 | "https://127.0.0.1:22379", 121 | "https://127.0.0.1:32379", 122 | } 123 | }) 124 | 125 | check_res(etcd, err) 126 | 127 | local res, err = etcd:set("/test", "abc") 128 | check_res(res, err) 129 | 130 | ngx.timer.at(0.1, function () 131 | etcd:set("/test", "bcd3") 132 | end) 133 | 134 | local cur_time = ngx.now() 135 | local body_chunk_fun, err = etcd:watch("/test", {timeout = 0.5}) 136 | if not body_chunk_fun then 137 | ngx.say("failed to watch: ", err) 138 | end 139 | 140 | local idx = 0 141 | while true do 142 | local chunk, err = body_chunk_fun() 143 | 144 | if not chunk then 145 | if err then 146 | ngx.say(err) 147 | end 148 | break 149 | end 150 | 151 | idx = idx + 1 152 | ngx.say(idx, ": ", require("cjson").encode(chunk.result)) 153 | end 154 | } 155 | } 156 | --- request 157 | GET /t 158 | --- no_error_log 159 | [error] 160 | --- response_body_like eval 161 | qr/1:.*"created":true.* 162 | 2:.*"value":"bcd3".* 163 | timeout/ 164 | --- timeout: 5 165 | -------------------------------------------------------------------------------- /t/v3/txn.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $etcd_version = `etcd --version`; 8 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 9 | plan(skip_all => "etcd is too old, skip v3 protocol"); 10 | } else { 11 | plan 'no_plan'; 12 | } 13 | 14 | our $HttpConfig = <<'_EOC_'; 15 | lua_socket_log_errors off; 16 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;'; 17 | init_by_lua_block { 18 | local cjson = require("cjson.safe") 19 | 20 | function check_res(data, err, val, status) 21 | if err then 22 | ngx.say("err: ", err) 23 | ngx.exit(200) 24 | end 25 | 26 | if val then 27 | if data.body.kvs==nil then 28 | ngx.exit(404) 29 | end 30 | if data.body.kvs and val ~= data.body.kvs[1].value then 31 | ngx.say("failed to check value") 32 | ngx.log(ngx.ERR, "failed to check value, got: ",data.body.kvs[1].value, 33 | ", expect: ", val) 34 | ngx.exit(200) 35 | else 36 | ngx.say("checked val as expect: ", val) 37 | end 38 | end 39 | 40 | if status and status ~= data.status then 41 | ngx.exit(data.status) 42 | end 43 | end 44 | } 45 | _EOC_ 46 | 47 | run_tests(); 48 | 49 | __DATA__ 50 | 51 | === TEST 1: txn("EQUAL") and get 52 | --- http_config eval: $::HttpConfig 53 | --- config 54 | location /t { 55 | content_by_lua_block { 56 | local etcd, err = require "resty.etcd" .new({protocol = "v3"}) 57 | check_res(etcd, err) 58 | 59 | local res, err = etcd:set("/test", "abc") 60 | check_res(res, err) 61 | 62 | local data, err = etcd:get("/test") 63 | check_res(data, err, "abc") 64 | 65 | local data, err = etcd:txn( 66 | {{key = "/test", result = "EQUAL", value = "abc", target = "VALUE"}}, 67 | {{requestPut = {key = "/test", value = "ddd"}}} 68 | ) 69 | check_res(data, err) 70 | 71 | local data, err = etcd:get("/test") 72 | check_res(data, err, "ddd") 73 | } 74 | } 75 | --- request 76 | GET /t 77 | --- no_error_log 78 | [error] 79 | --- response_body 80 | checked val as expect: abc 81 | checked val as expect: ddd 82 | 83 | 84 | 85 | === TEST 2: txn(not "EQUAL") and get 86 | --- http_config eval: $::HttpConfig 87 | --- config 88 | location /t { 89 | content_by_lua_block { 90 | local etcd, err = require "resty.etcd" .new({protocol = "v3"}) 91 | check_res(etcd, err) 92 | 93 | local res, err = etcd:set("/test", "abc") 94 | check_res(res, err) 95 | 96 | local data, err = etcd:get("/test") 97 | check_res(data, err, "abc") 98 | 99 | local data, err = etcd:txn( 100 | {{key = "/test", result = "EQUAL", value = "not equal", target = "VALUE"}}, 101 | {{requestPut = {key = "/test", value = "ddd"}}} 102 | ) 103 | check_res(data, err) 104 | 105 | local data, err = etcd:get("/test") 106 | check_res(data, err, "abc") 107 | } 108 | } 109 | --- request 110 | GET /t 111 | --- no_error_log 112 | [error] 113 | --- response_body 114 | checked val as expect: abc 115 | checked val as expect: abc 116 | -------------------------------------------------------------------------------- /t/v3/unix_socket.t: -------------------------------------------------------------------------------- 1 | use Test::Nginx::Socket::Lua; 2 | 3 | log_level('info'); 4 | no_long_string(); 5 | repeat_each(1); 6 | 7 | my $test_dir = html_dir(); 8 | $ENV{TEST_NGINX_HTML_DIR} ||= $test_dir; 9 | 10 | my $etcd_version = `etcd --version`; 11 | if ($etcd_version =~ /^etcd Version: 2/ || $etcd_version =~ /^etcd Version: 3.1./) { 12 | plan(skip_all => "etcd is too old, skip v3 protocol"); 13 | } else { 14 | plan 'no_plan'; 15 | } 16 | 17 | our $HttpConfig = <<"_EOC_"; 18 | lua_socket_log_errors off; 19 | lua_package_path 'lib/?.lua;/usr/local/share/lua/5.1/?.lua;;'; 20 | init_by_lua_block { 21 | local cjson = require("cjson.safe") 22 | 23 | function check_res(data, err, val, status) 24 | if err then 25 | ngx.say("err: ", err) 26 | ngx.exit(200) 27 | end 28 | 29 | if val then 30 | if data and data.body.kvs==nil then 31 | ngx.exit(404) 32 | end 33 | if data and data.body.kvs and val ~= data.body.kvs[1].value then 34 | ngx.say("failed to check value") 35 | ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value, 36 | ", expect: ", val) 37 | ngx.exit(200) 38 | else 39 | ngx.say("checked val as expect: ", val) 40 | end 41 | end 42 | 43 | if status and status ~= data.status then 44 | ngx.exit(data.status) 45 | end 46 | end 47 | } 48 | 49 | server { 50 | listen unix:$test_dir/lua-resty-etcd.sock; 51 | location / { 52 | access_by_lua_block { 53 | ngx.log(ngx.WARN, "hit with host ", ngx.var.http_host) 54 | } 55 | proxy_pass http://127.0.0.1:2379; 56 | proxy_http_version 1.1; 57 | proxy_set_header Connection ""; 58 | proxy_set_header Host \$http_host; 59 | } 60 | } 61 | _EOC_ 62 | 63 | run_tests(); 64 | 65 | __DATA__ 66 | 67 | === TEST 1: request over unix socket 68 | --- http_config eval: $::HttpConfig 69 | --- config 70 | location /t { 71 | content_by_lua_block { 72 | local etcd, err = require("resty.etcd").new({protocol = "v3", unix_socket_proxy = "unix:$TEST_NGINX_HTML_DIR/lua-resty-etcd.sock"}) 73 | check_res(etcd, err) 74 | 75 | local res, err = etcd:set("/test", "abc") 76 | check_res(res, err) 77 | 78 | ngx.timer.at(0.1, function () 79 | etcd:set("/test", "bcd3") 80 | end) 81 | 82 | ngx.timer.at(0.2, function () 83 | etcd:set("/test", "bcd4") 84 | end) 85 | 86 | local cur_time = ngx.now() 87 | local body_chunk_fun, err, http_cli = etcd:watch("/test", {timeout = 0.5, need_cancel = true}) 88 | 89 | if type(http_cli) ~= "table" then 90 | ngx.say("need_cancel failed") 91 | end 92 | 93 | if not body_chunk_fun then 94 | ngx.say("failed to watch: ", err) 95 | end 96 | 97 | local chunk, err = body_chunk_fun() 98 | ngx.say("created: ", chunk.result.created) 99 | local chunk, err = body_chunk_fun() 100 | ngx.say("value: ", chunk.result.events[1].kv.value) 101 | 102 | local res, err = etcd:watchcancel(http_cli) 103 | if not res then 104 | ngx.say("failed to cancel: ", err) 105 | end 106 | 107 | local chunk, err = body_chunk_fun() 108 | ngx.say(err) 109 | 110 | ngx.say("ok") 111 | } 112 | } 113 | --- request 114 | GET /t 115 | --- no_error_log 116 | [error] 117 | --- grep_error_log eval 118 | qr/hit with host 127.0.0.1/ 119 | --- grep_error_log_out 120 | hit with host 127.0.0.1 121 | hit with host 127.0.0.1 122 | hit with host 127.0.0.1 123 | --- response_body 124 | created: true 125 | value: bcd3 126 | closed 127 | ok 128 | --- timeout: 5 129 | 130 | 131 | 132 | === TEST 2: request over unix socket, unix socket doesn't exist 133 | --- http_config eval: $::HttpConfig 134 | --- config 135 | location /t { 136 | content_by_lua_block { 137 | local etcd, err = require("resty.etcd").new({protocol = "v3", http_host = "http://127.0.0.1:2379", 138 | unix_socket_proxy = "unix:$TEST_NGINX_HTML_DIR/bad.sock"}) 139 | check_res(etcd, err) 140 | 141 | local res, err = etcd:set("/test", "abc") 142 | check_res(res, err) 143 | 144 | ngx.timer.at(0.1, function () 145 | etcd:set("/test", "bcd3") 146 | end) 147 | 148 | ngx.timer.at(0.2, function () 149 | etcd:set("/test", "bcd4") 150 | end) 151 | 152 | local cur_time = ngx.now() 153 | local body_chunk_fun, err, http_cli = etcd:watch("/test", {timeout = 0.5, need_cancel = true}) 154 | 155 | if type(http_cli) ~= "table" then 156 | ngx.say("need_cancel failed") 157 | end 158 | 159 | if not body_chunk_fun then 160 | ngx.say("failed to watch: ", err) 161 | end 162 | 163 | local chunk, err = body_chunk_fun() 164 | ngx.say("created: ", chunk.result.created) 165 | local chunk, err = body_chunk_fun() 166 | ngx.say("value: ", chunk.result.events[1].kv.value) 167 | 168 | local res, err = etcd:watchcancel(http_cli) 169 | if not res then 170 | ngx.say("failed to cancel: ", err) 171 | end 172 | 173 | local chunk, err = body_chunk_fun() 174 | ngx.say(err) 175 | 176 | ngx.say("ok") 177 | } 178 | } 179 | --- request 180 | GET /t 181 | --- no_error_log 182 | [error] 183 | --- grep_error_log eval 184 | qr/hit with host 127.0.0.1/ 185 | --- grep_error_log_out 186 | --- response_body 187 | created: true 188 | value: bcd3 189 | closed 190 | ok 191 | --- timeout: 5 192 | -------------------------------------------------------------------------------- /utils/check-lua-code-style.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | luacheck -q lib 6 | 7 | find lib -name '*.lua' -exec ./utils/lj-releng {} + > \ 8 | /tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1) 9 | 10 | grep -E "ERROR.*.lua:" /tmp/check.log > /tmp/error.log | true 11 | if [ -s /tmp/error.log ]; then 12 | echo "=====bad style=====" 13 | cat /tmp/check.log 14 | exit 1 15 | fi 16 | --------------------------------------------------------------------------------