Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Support etcd storage backend #63

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ jobs:
- ubuntu-latest
- macos-latest
runs-on: ${{matrix.os}}
services:
etcd:
image: quay.io/coreos/etcd:v3.5.0
options: >-
--entrypoint etcd
--publish 2379:2379
--publish 2380:2380

steps:
- uses: actions/checkout@v3
- name: Setup protoc
run: |
if [ ${{ runner.os }} = 'ubuntu-latest' ]; then
sudo apt-get update
sudo apt-get install -y protobuf-compiler
elif [ ${{ runner.os }} = 'macos-latest' ]; then
brew install protobuf
fi
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down Expand Up @@ -60,10 +75,19 @@ jobs:
os:
- windows-latest
runs-on: ${{matrix.os}}
services:
etcd:
image: quay.io/coreos/etcd:v3.5.0
options: >-
--entrypoint etcd
--publish 2379:2379
--publish 2380:2380

steps:
- uses: actions/checkout@v3
- run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Setup protoc
run: vcpkg install protobuf protobuf:x64-windows
- name: install openssl
run: vcpkg install openssl:x64-windows-static-md
- name: Setup Rust
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ Cargo.lock

# VIM temp file
*.swp

# IDE files
.idea
.vscode

# OS files
.DS_Store
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ ureq = "2.9"
glob = "0.3"
serde_asn1_der = "0.8"
base64 = "0.22"
etcd-client = { version = "0.12.4", features = ["tls"] }
tokio = "1.37.0"
ipnetwork = "0.20"

[patch.crates-io]
Expand Down
24 changes: 24 additions & 0 deletions examples/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"listener": {
"tcp": {
"ltype": "tcp",
"address": "0.0.0.0:8080",
"tls_disable": true
}
},
"storage": {
"etcd": {
"stype": "etcd",
"address": "http://127.0.0.1:2379",
"path": "rustyvault"
}
},
"api_addr": "http://localhost:8080",
"log_format": "json",
"log_level": "info",
"pid_file": "/tmp/rustyvault/vault.pid",
"work_dir": "/tmp/rustyvault",
"daemon": true,
"daemon_user": "vault",
"daemon_group": "vault"
}
2 changes: 1 addition & 1 deletion src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ where
let storage: HashMap<String, Storage> = Deserialize::deserialize(deserializer)?;

for key in storage.keys() {
if key != "file" {
if key != "file" && key != "etcd" {
return Err(serde::de::Error::custom("Invalid storage key"));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ pub enum RvError {
#[error("RwLock was poisoned (writing)")]
ErrRwLockWritePoison,

#[error("Some backend error happened, {:?}", .source)]
BackendError {
#[from]
source: crate::storage::physical::error::BackendError,
},
#[error("Some net addr parse error happened, {:?}", .source)]
AddrParseError {
#[from]
Expand Down
7 changes: 7 additions & 0 deletions src/storage/physical/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum BackendError {
#[error("Backend etcd error: {0}!")]
EtcdError(String),
}
Loading
Loading