Skip to content

Commit

Permalink
add ic-root-key
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Jun 11, 2024
1 parent edb3d62 commit 9cfae90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ env:

jobs:
test:
# runs-on: ubuntu-latest
runs-on: bazel-runner-small
container:
image: ghcr.io/catthehacker/ubuntu:full-22.04

steps:
- uses: actions/checkout@v4

#- run: rustup toolchain install stable --profile minimal

- uses: Swatinem/rust-cache@v2

- name: Run tests
Expand Down
6 changes: 5 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ pub struct Ic {
pub ic_url: Vec<Url>,

/// Whether to use static URLs or dynamically discovered URLs for routing.
/// For the dynamic routing case, provided argument ic-url: Vec<Url> is used as a seed list of API Nodes.
/// For the dynamic routing case, provided argument `ic-url` is used as a seed list of API Nodes.
#[clap(env, long)]
pub ic_use_discovery: bool,

/// Path to an IC root key. Must be DER-encoded. If not specified - hardcoded will be used.
#[clap(env, long)]
pub ic_root_key: Option<PathBuf>,
}

#[derive(Args)]
Expand Down
12 changes: 9 additions & 3 deletions src/routing/ic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod health_check;
pub mod route_provider;
pub mod transport;
use std::sync::Arc;
use std::{fs, sync::Arc};

use anyhow::Error;
use anyhow::{Context, Error};
use axum::{
body::Body,
response::{IntoResponse, Response},
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn convert_response(resp: Response<HttpGatewayResponseBody>) -> Response {
}

pub fn setup(
_cli: &Cli,
cli: &Cli,
http_client: Arc<dyn HttpClient>,
route_provider: Arc<dyn RouteProvider>,
) -> Result<HttpGatewayClient, Error> {
Expand All @@ -65,6 +65,12 @@ pub fn setup(
let agent = ic_agent::Agent::builder()
.with_transport(transport)
.build()?;

if let Some(v) = &cli.ic.ic_root_key {
let key = fs::read(v).context("unable to read IC root key")?;
agent.set_root_key(key);
}

let client = ic_http_gateway::HttpGatewayClientBuilder::new()
.with_agent(agent)
.build()?;
Expand Down

0 comments on commit 9cfae90

Please sign in to comment.