Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit a45467f

Browse files
clnv0x0177b11f
andauthored
rewrite API and add tests (#66)
* rewrite API and add tests * add v3 api proto file, fix test code warring Co-authored-by: 0x0177b11f <[email protected]>
1 parent b031bfb commit a45467f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2158
-2017
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
[package]
22
name = "etcd-rs"
3-
version = "0.6.0"
4-
authors = ["luncj <[email protected]>"]
3+
version = "1.0.0-alpha.0"
4+
authors = ["lodrem <[email protected]>"]
55
edition = "2021"
66
keywords = ["etcd", "future", "async"]
7-
repository = "https://github.com/luncj/etcd-rs"
8-
homepage = "https://github.com/luncj/etcd-rs"
7+
repository = "https://github.com/lodrem/etcd-rs"
8+
homepage = "https://github.com/lodrem/etcd-rs"
99
description = "etcd client for rust"
1010
documentation = "https://docs.rs/etcd-rs"
1111
license = "MIT"
1212

1313
[dependencies]
1414
tonic = { version = "0.6", features = ["tls"] }
1515
prost = "0.9"
16-
tokio = "1.15"
16+
tokio = "1.17"
1717
tokio-stream = "0.1"
1818
async-trait = "0.1"
1919
futures = "0.3"
2020
thiserror = "1.0"
2121
http = "0.2"
2222

2323
[dev-dependencies]
24-
tokio = { version = "1.15", features = ["full"] }
24+
tokio = { version = "1.17", features = ["full"] }
2525
rand = "0.8"
2626

2727
[build-dependencies]

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ ETCD_CLUSTER_WITH_TLS ?= false
33
ETCD_NODE ?= etcd-1
44
ETCD_VERSION ?= v3.5.2
55

6+
TEST_CASE ?= test_basic
7+
68
.PHONY: build
79
build:
810
cargo build
911

1012
.PHONY: test
1113
test:
12-
RUST_BACKTRACE=full cargo test -- --test-threads=1 --nocapture;
14+
RUST_BACKTRACE=full cargo test -- --test-threads=1 --show-output;
1315
cargo check --no-default-features
1416

17+
.PHONY: test-one
18+
test-one:
19+
RUST_BACKTRACE=full cargo test ${TEST_CASE} -- --test-threads=1 --show-output;
20+
1521
.PHONY: publish
1622
publish:
1723
cargo package && cargo publish

README.md

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
1-
etcd for Rust
1+
etcd client for Rust
22
====
33

4-
[![CI Status][ci-badge]][ci-url]
5-
[![Crates.io][crates-badge]][crates-url]
6-
[![License][license-badge]][license-url]
4+
[<img alt="github" height="20" src="https://img.shields.io/badge/github-lodrem/etcd--rs-8da0cb?style=for-the-badge&labelColor=555555&logo=github">](https://github.com/lodrem/etcd-rs)
5+
[<img alt="crates.io" height="20" src="https://img.shields.io/crates/v/etcd-rs.svg?style=for-the-badge&color=fc8d62&logo=rust">](https://crates.io/crates/etcd-rs)
6+
[<img alt="docs.rs" height="20" src="https://img.shields.io/badge/docs.rs-etcd--rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K">](https://docs.rs/etcd-rs)
7+
[<img alt="build status" height="20" src="https://img.shields.io/github/workflow/status/lodrem/etcd-rs/CI/master?style=for-the-badge">](https://github.com/luncj/etcd-rs/actions?query%3Amaster)
78

8-
[ci-badge]: https://img.shields.io/github/workflow/status/luncj/etcd-rs/CI?style=flat-square
9-
[ci-url]: https://github.com/luncj/etcd-rs/actions
10-
[crates-badge]: https://img.shields.io/crates/v/etcd-rs.svg?style=flat-square
11-
[crates-url]: https://crates.io/crates/etcd-rs
12-
[license-badge]: https://img.shields.io/github/license/luncj/etcd-rs.svg?style=flat-square
13-
[license-url]: https://github.com/luncj/etcd-rs/blob/master/LICENSE
9+
An [etcd](https://github.com/etcd-io/etcd) (API v3) client for Rust backed by [tokio](https://github.com/tokio-rs/tokio) and [tonic](https://github.com/hyperium/tonic).
1410

15-
16-
An [etcd](https://github.com/etcd-io/etcd) (API v3) client for Rust, and it provides `async/await` APIs backed by [tokio](https://github.com/tokio-rs/tokio) and [tonic](https://github.com/hyperium/tonic).
17-
18-
Documentation on the library can be found at [docs.rs/etcd-rs](https://docs.rs/etcd-rs).
19-
20-
Features
21-
----
22-
23-
- Asynchronous
24-
- Etcd APIv3
25-
26-
Examples
11+
Supported APIs
2712
----
2813

29-
[./examples](./examples)
14+
- KV
15+
- [x] Put
16+
- [x] Range
17+
- [x] Delete
18+
- [x] Transaction
19+
- [x] Compact
20+
- Lease
21+
- [x] Grant
22+
- [x] Revoke
23+
- [x] KeepAlive
24+
- [x] TimeToLive
25+
- Watch
26+
- [x] WatchCreate
27+
- [x] WatchCancel
28+
- Auth
29+
- [x] Authenticate
30+
- [ ] RoleAdd
31+
- [ ] RoleGrantPermission
32+
- [ ] UserAdd
33+
- [ ] UserGrantRole
34+
- [ ] AuthEnable
35+
- [ ] AuthDisable
36+
- Cluster
37+
- [x] MemberAdd
38+
- [x] MemberRemove
39+
- [x] MemberUpdate
40+
- [x] MemberList
41+
- Maintenance
42+
- [ ] Alarm
43+
- [ ] Status
44+
- [ ] Defragment
45+
- [ ] Hash
46+
- [ ] Snapshot
47+
- [ ] MoveLeader
3048

3149
Usage
3250
----
@@ -35,66 +53,61 @@ Add following dependencies in your project `cargo.toml`:
3553

3654
```toml
3755
[dependencies]
38-
etcd-rs = "0.6"
56+
etcd-rs = "1.0.0-alpha.0"
3957
```
4058

41-
#### Setup Client
42-
4359
```rust
44-
fn foo() {
45-
let endpoints = vec!["http://127.0.0.1:2379".to_owned()];
46-
47-
let client = Client::connect(ClientConfig {
48-
endpoints,
60+
use etcd_rs::Client;
61+
62+
#[tokio::main]
63+
async fn main() {
64+
let cli = Client::connect(ClientConfig {
65+
endpoints: [
66+
"http://127.0.0.1:12379",
67+
"http://127.0.0.1:22379",
68+
"http://127.0.0.1:32379",
69+
],
4970
..Default::default()
50-
}).await;
71+
}).await;
72+
73+
cli.put(("foo", "bar")).await.expect("put kv");
74+
75+
let kvs = cli.get("foo").await.expect("get kv").take_kvs();
76+
assert_eq!(kvs.len(), 1);
5177
}
5278
```
5379

54-
if authenticate enabled
80+
Development
81+
----
5582

56-
```rust
57-
fn foo() {
58-
let endpoints = vec!["http://127.0.0.1:2379".to_owned()];
5983

60-
let client = Client::connect(ClientConfig {
61-
endpoints,
62-
auth: Some(("user".to_owned(), "password".to_owned())),
63-
..Default::default()
64-
}).await;
65-
}
66-
```
84+
requirements:
85+
- Makefile
86+
- docker
87+
- docker-compose
6788

68-
with tls
89+
### Start local etcd cluster
6990

70-
```rust
71-
fn foo() {
72-
let endpoints = vec!["https://127.0.0.1:2379".to_owned()];
73-
let tls = ClientTlsConfig::new();
74-
75-
let client = Client::connect(ClientConfig {
76-
endpoints,
77-
auth: Some(("user".to_owned(), "password".to_owned())),
78-
tls: Some(tls),
79-
..Default::default()
80-
}).await;
81-
}
91+
```shell
92+
make setup-etcd-cluster
8293
```
8394

84-
Developemnt
85-
----
95+
stop cluster
96+
```shell
97+
make teardown-etcd-cluster
98+
```
8699

87100
### Run tests
88101

89-
requirements:
90-
- Makefile
91-
- docker
92-
- docker-compose
93-
94102
```shell
95103
make test
96104
```
97105

106+
for specified case:
107+
```shell
108+
TEST_CASE=test_put_error make test-one
109+
```
110+
98111
License
99112
----
100113

build.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fn main() -> Result<(), Box<dyn std::error::Error>> {
2-
// NOTE: compile v3lockpb before rpc for disabling generate duplicated client in v3lockpb
3-
tonic_build::configure()
4-
.build_server(false)
5-
.build_client(false)
6-
.compile(&["proto/lock.proto"], &["proto"])?;
7-
82
tonic_build::configure().build_server(false).compile(
9-
&["proto/auth.proto", "proto/kv.proto", "proto/rpc.proto"],
3+
&[
4+
"proto/auth.proto",
5+
"proto/kv.proto",
6+
"proto/rpc.proto",
7+
"proto/v3lock.proto",
8+
"proto/v3election.proto",
9+
],
1010
&["proto"],
1111
)?;
1212

0 commit comments

Comments
 (0)