Skip to content

Commit

Permalink
Merge pull request #2597 from jarhodes314/2591-refactor-the-c8y-remot…
Browse files Browse the repository at this point in the history
…e-access-plugin-to-use-the-c8y-auth-proxy

Refactor the c8y remote access plugin to use the c8y auth proxy
  • Loading branch information
jarhodes314 authored Jan 26, 2024
2 parents 037c0bf + 845480e commit 9c4bad9
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 78 deletions.
45 changes: 44 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ thiserror = "1.0"
time = "0.3"
tokio = { version = "1.23", default-features = false }
tokio-rustls = "0.24.1"
tokio-tungstenite = { version = "0.20.0" }
tokio-util = { version = "0.7", features = ["codec"] }
toml = "0.7"
tower = "0.4"
Expand Down
4 changes: 3 additions & 1 deletion crates/extensions/c8y_auth_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = { workspace = true }

[dependencies]
anyhow = { workspace = true }
axum = { workspace = true, features = ["macros"] }
axum = { workspace = true, features = ["macros", "ws", "headers"] }
axum-server = { workspace = true }
axum_tls = { workspace = true }
c8y_http_proxy = { workspace = true }
Expand All @@ -29,13 +29,15 @@ tokio = { workspace = true, features = [
"process",
"io-util",
] }
tokio-tungstenite = { workspace = true, features = ["rustls-tls-native-roots"] }
tracing = { workspace = true }
url = { workspace = true }

[dev-dependencies]
env_logger = { workspace = true }
mockito = { workspace = true }
rcgen = { workspace = true }
rustls = { workspace = true, features = ["dangerous_configuration"] }
tedge_http_ext = { workspace = true, features = ["test_helpers"] }

[lints]
Expand Down
17 changes: 9 additions & 8 deletions crates/extensions/c8y_auth_proxy/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use tedge_config::TEdgeConfig;
use tedge_config_macros::OptionalConfig;
use tracing::info;

use crate::server::AppState;
use crate::server::AppData;
use crate::server::Server;
use crate::tokens::TokenManager;

type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;

pub struct C8yAuthProxyBuilder {
app_state: AppState,
app_data: AppData,
bind_address: IpAddr,
bind_port: u16,
signal_sender: mpsc::Sender<RuntimeRequest>,
Expand All @@ -41,8 +41,9 @@ impl C8yAuthProxyBuilder {
config: &TEdgeConfig,
jwt: &mut ServerActorBuilder<C8YJwtRetriever, Sequential>,
) -> anyhow::Result<Self> {
let app_state = AppState {
target_host: format!("https://{}", config.c8y.http.or_config_not_set()?).into(),
let app_data = AppData {
is_https: true,
host: config.c8y.http.or_config_not_set()?.to_string(),
token_manager: TokenManager::new(JwtRetriever::new("C8Y-PROXY => JWT", jwt)).shared(),
};
let bind = &config.c8y.proxy.bind;
Expand All @@ -52,7 +53,7 @@ impl C8yAuthProxyBuilder {
let ca_path = config.c8y.proxy.ca_path.clone();

Ok(Self {
app_state,
app_data,
bind_address: bind.address,
bind_port: bind.port,
signal_sender,
Expand All @@ -69,7 +70,7 @@ impl Builder<C8yAuthProxy> for C8yAuthProxyBuilder {

fn try_build(self) -> Result<C8yAuthProxy, Self::Error> {
Ok(C8yAuthProxy {
app_state: self.app_state,
app_data: self.app_data,
bind_address: self.bind_address,
bind_port: self.bind_port,
signal_receiver: self.signal_receiver,
Expand All @@ -87,7 +88,7 @@ impl RuntimeRequestSink for C8yAuthProxyBuilder {
}

pub struct C8yAuthProxy {
app_state: AppState,
app_data: AppData,
bind_address: IpAddr,
bind_port: u16,
signal_receiver: mpsc::Receiver<RuntimeRequest>,
Expand All @@ -104,7 +105,7 @@ impl Actor for C8yAuthProxy {

async fn run(mut self) -> Result<(), RuntimeError> {
let server = Server::try_init(
self.app_state,
self.app_data,
self.bind_address,
self.bind_port,
self.cert_path,
Expand Down
Loading

1 comment on commit 9c4bad9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
381 0 3 381 100 52m36.961s

Please sign in to comment.