Skip to content

Commit

Permalink
license header
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjmartin committed Nov 1, 2024
1 parent 8e0a551 commit d5cc270
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
15 changes: 3 additions & 12 deletions crates/sui-edge-proxy/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, Context, Result};
// use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use url::Url;
Expand All @@ -19,24 +21,13 @@ pub struct PeerConfig {
pub address: Url,
}

impl PeerConfig {
/// Retrieve the SNI host from the URL, assuming it has been validated
pub fn sni_host(&self) -> Result<String> {
self.address
.host_str()
.map(|host| host.to_string())
.ok_or_else(|| anyhow!("URL does not contain a valid host"))
}
}

/// Load and validate configuration
pub fn load<P: AsRef<std::path::Path>>(path: P) -> Result<ProxyConfig> {
let path = path.as_ref();
let config: ProxyConfig = serde_yaml::from_reader(
std::fs::File::open(path).context(format!("cannot open {:?}", path))?,
)?;

// Validate URLs in the configuration
validate_peer_url(&config.read_peer)?;
validate_peer_url(&config.execution_peer)?;

Expand Down
3 changes: 3 additions & 0 deletions crates/sui-edge-proxy/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::config::PeerConfig;
use crate::metrics::AppMetrics;
use axum::{
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-edge-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

pub mod config;
pub mod handlers;
pub mod metrics;
3 changes: 3 additions & 0 deletions crates/sui-edge-proxy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use axum::{
routing::{any, get},
Router,
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-edge-proxy/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prometheus::{
register_gauge_vec_with_registry, register_histogram_vec_with_registry,
register_int_counter_vec_with_registry, GaugeVec, HistogramVec, IntCounterVec, Registry,
Expand Down

0 comments on commit d5cc270

Please sign in to comment.