-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Lachstec/dev
merge dev into main
- Loading branch information
Showing
9 changed files
with
174 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,46 @@ | ||
name: Rust | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
branches: [ "main", "dev" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
branches: [ "main", "dev" ] | ||
|
||
jobs: | ||
build: | ||
test: | ||
|
||
name: Test `cargo check/test/build` on ${{ matrix.os }} | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Protoc | ||
uses: arduino/setup-protoc@v2 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
components: rustfmt, clippy | ||
|
||
- name: Setup Cargo Cache | ||
uses: actions/cache@v3 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Setup Protobuf Compiler | ||
uses: arduino/setup-protoc@v2 | ||
|
||
- name: Run Unit Tests | ||
run: cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
fn main() { | ||
let proto_dir = "proto"; | ||
println!("cargo:rerun-if-changed={}", proto_dir); | ||
|
||
tonic_build::configure() | ||
.build_server(false) | ||
.compile_well_known_types(true) | ||
.compile( | ||
&["proto/gnmi/gnmi.proto", | ||
&[ | ||
"proto/gnmi/gnmi.proto", | ||
"proto/gnmi_ext/gnmi_ext.proto", | ||
"proto/target/target.proto", | ||
"proto/collector/collector.proto", | ||
"proto/google.proto" | ||
"proto/google.proto", | ||
], | ||
&["proto"] | ||
)?; | ||
Ok(()) | ||
} | ||
&[proto_dir], | ||
).expect("Failed to compile protobuf files"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use http::{HeaderValue, Request}; | ||
use std::error::Error; | ||
use std::sync::Arc; | ||
use std::task::{Context, Poll}; | ||
use tonic::codegen::Body; | ||
use tower_service::Service; | ||
|
||
/// Service that injects username and password into the request metadata | ||
#[derive(Debug, Clone)] | ||
pub struct AuthService<S> { | ||
inner: S, | ||
username: Option<Arc<HeaderValue>>, | ||
password: Option<Arc<HeaderValue>>, | ||
} | ||
|
||
impl<S> AuthService<S> { | ||
#[inline] | ||
pub fn new( | ||
inner: S, | ||
username: Option<Arc<HeaderValue>>, | ||
password: Option<Arc<HeaderValue>>, | ||
) -> Self { | ||
Self { | ||
inner, | ||
username, | ||
password, | ||
} | ||
} | ||
} | ||
|
||
/// Implementation of Service so that it plays nicely with tonic. | ||
/// Trait bounds have to match those specified on [`tonic::client::GrpcService`] | ||
impl<S, ReqBody, ResBody> Service<Request<ReqBody>> for AuthService<S> | ||
where | ||
S: Service<Request<ReqBody>, Response = ResBody>, | ||
S::Error:, | ||
ResBody: Body, | ||
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync>>, | ||
{ | ||
type Response = S::Response; | ||
type Error = S::Error; | ||
type Future = S::Future; | ||
|
||
#[inline] | ||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.inner.poll_ready(cx) | ||
} | ||
|
||
#[inline] | ||
fn call(&mut self, mut request: Request<ReqBody>) -> Self::Future { | ||
if let Some(user) = &self.username { | ||
if let Some(pass) = &self.password { | ||
request | ||
.headers_mut() | ||
.insert("username", user.as_ref().clone()); | ||
request | ||
.headers_mut() | ||
.insert("password", pass.as_ref().clone()); | ||
} | ||
} | ||
|
||
self.inner.call(request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
mod client; | ||
|
||
pub use client::{ | ||
Client, | ||
ClientBuilder | ||
}; | ||
pub use client::{Client, ClientBuilder}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.