Skip to content

Commit

Permalink
Change config var names
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Nov 10, 2023
1 parent 2cda5a3 commit 0d0d078
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions env.default
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## You need to register at a broker for this
BROKER_ID=broker
PROXY_ID=proxy1.$BROKER_ID
PROXY_URL=http://localhost:8081
BEAM_PROXY_URL=http://localhost:8081
## You can change these as you want, because their local secrets
BEAM_APP_ID=app1.$PROXY_ID
BEAM_APP_SECRET=App1Secret
BEAM_SECRET=App1Secret
BIND_ADDR=0.0.0.0:8090
4 changes: 2 additions & 2 deletions src/beam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub fn create_beam_task(
target_sites: Vec<String>,
query: String,
) -> TaskRequest<RawString> {
let proxy_id = CONFIG.beam_app.proxy_id();
let proxy_id = CONFIG.beam_app_id.proxy_id();
let broker_id = proxy_id.as_ref().split_once('.').expect("Invalid beam id in config").1;
let to = target_sites.into_iter().map(|site| AppId::new_unchecked(format!("focus.{site}.{broker_id}"))).collect();
TaskRequest {
id,
from: CONFIG.beam_app.clone(),
from: CONFIG.beam_app_id.clone(),
to,
metadata: serde_json::Value::Null,
body: query.into(),
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ mod beam;
#[clap(author, version, about, long_about = None)]
struct Config {
/// URL of the Beam Proxy
#[clap(env)]
beam_url: Url,
#[clap(long, env)]
beam_proxy_url: Url,

/// Beam AppId of this application
#[clap(env, value_parser = |v: &str| Ok::<_, Infallible>(AppId::new_unchecked(v)))]
beam_app: AppId,
#[clap(long, env, value_parser = |v: &str| Ok::<_, Infallible>(AppId::new_unchecked(v)))]
beam_app_id: AppId,

/// Credentials to use on the Beam Proxy
#[clap(env)]
#[clap(long, env)]
beam_secret: String,

/// The socket address this server will bind to
#[clap(env, default_value = "0.0.0.0:8080")]
#[clap(long, env, default_value = "0.0.0.0:8080")]
bind_addr: SocketAddr,
}

static CONFIG: Lazy<Config> = Lazy::new(|| Config::parse());

static BEAM_CLIENT: Lazy<BeamClient> = Lazy::new(|| {
BeamClient::new(
&CONFIG.beam_app,
&CONFIG.beam_app_id,
&CONFIG.beam_secret,
CONFIG.beam_url.clone(),
CONFIG.beam_proxy_url.clone(),
)
});

Expand Down Expand Up @@ -122,7 +122,7 @@ async fn handle_listen_to_beam_tasks(
.send()
.await
.map_err(|err| {
println!("Failed request to {} with error: {}", CONFIG.beam_url, err);
println!("Failed request to {} with error: {}", CONFIG.beam_proxy_url, err);
(
StatusCode::BAD_GATEWAY,
format!("Error calling beam, check the server logs."),
Expand Down

0 comments on commit 0d0d078

Please sign in to comment.