Skip to content

Commit

Permalink
[faucet-fix] Correctly unwrap stuff (#20901)
Browse files Browse the repository at this point in the history
## Description 

The previous code will panic when starting localnet with the faucet
needed for running local tests as the two envs are not set!

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
stefan-mysten authored and ebmifa committed Jan 16, 2025
1 parent 7b25a59 commit f7ab83f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/sui-faucet/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,18 @@ pub async fn start_faucet(
concurrency_limit: usize,
prometheus_registry: &Registry,
) -> Result<(), anyhow::Error> {
if app_state.config.authenticated {
let (cloudflare_turnstile_url, turnstile_secret_key) = if app_state.config.authenticated {
ensure!(TURNSTILE_SECRET_KEY.is_some() && CLOUDFLARE_TURNSTILE_URL.is_some(),
"Both CLOUDFLARE_TURNSTILE_URL and TURNSTILE_SECRET_KEY env vars must be set for testnet deployment (--authenticated flag was set)");
}

(
CLOUDFLARE_TURNSTILE_URL.as_ref().unwrap().to_string(),
TURNSTILE_SECRET_KEY.as_ref().unwrap().to_string(),
)
} else {
("".to_string(), "".to_string())
};

// TODO: restrict access if needed
let cors = CorsLayer::new()
.allow_methods(vec![Method::GET, Method::POST])
Expand All @@ -229,8 +237,8 @@ pub async fn start_faucet(
let token_manager = Arc::new(RequestsManager::new(
max_requests_per_ip,
Duration::from_secs(reset_time_interval_secs),
CLOUDFLARE_TURNSTILE_URL.as_ref().unwrap().to_string(),
TURNSTILE_SECRET_KEY.as_ref().unwrap().to_string(),
cloudflare_turnstile_url,
turnstile_secret_key,
));

let governor_cfg = Arc::new(
Expand Down

0 comments on commit f7ab83f

Please sign in to comment.