Skip to content

Commit f29a514

Browse files
lostmanpedronauck
andauthored
feat(data-stream): add nkey auth (#32)
Co-authored-by: Pedro Nauck <pedronauck@gmail.com>
1 parent 7ab4db6 commit f29a514

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/fuel-core-nats/nats.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
1+
authorization: {
2+
users: [
3+
{ nkey: UDMBGUBEOCJVCOXHSQGYRX4SGS3QEAEDIVNHDBD63YEKHSGPVO53I2NU }
4+
]
5+
}
26
jetstream = {
37
max_file_store = 21474836480
48
}

crates/fuel-core-nats/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@ pub struct Publisher {
4444
impl Publisher {
4545
pub async fn new(
4646
nats_url: &str,
47+
nats_nkey: Option<String>,
4748
chain_id: ChainId,
4849
base_asset_id: AssetId,
4950
fuel_database: CombinedDatabase,
5051
block_subscription: Receiver<Arc<dyn Deref<Target = ImportResult> + Send + Sync>>,
5152
) -> anyhow::Result<Self> {
5253
// Connect to the NATS server
53-
let client = async_nats::connect(nats_url)
54+
let client = match nats_nkey {
55+
Some(nkey) => async_nats::connect_with_options(
56+
nats_url,
57+
async_nats::ConnectOptions::with_nkey(nkey),
58+
)
5459
.await
55-
.context(format!("Connecting to {nats_url}"))?;
60+
.context(format!("Connecting to {nats_url}"))?,
61+
None => async_nats::connect(nats_url)
62+
.await
63+
.context(format!("Connecting to {nats_url}"))?,
64+
};
65+
5666
let max_payload_size = client.server_info().max_payload;
5767
info!("NATS Publisher: max_payload_size={max_payload_size}");
5868
// Create a JetStream context

crates/fuel-core-nats/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct Cli {
1212
default_value = "localhost:4222"
1313
)]
1414
nats_url: String,
15+
#[arg(long, value_name = "NKEY", env = "NATS_NKEY")]
16+
nats_nkey: Option<String>,
1517
#[command(flatten)]
1618
fuel_core_config: run::Command,
1719
}
@@ -31,6 +33,7 @@ async fn main() -> anyhow::Result<()> {
3133

3234
let publisher = fuel_core_nats::Publisher::new(
3335
&cli.nats_url,
36+
cli.nats_nkey,
3437
chain_id,
3538
*base_asset_id,
3639
service.shared.database.clone(),

0 commit comments

Comments
 (0)