-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cluster header + cluster prefixed keys for account updates (#51)
* feat: include cluster and include it in key generation * chore: extract key + buf account update create + add tests * publish: including cluster header with account updates * fix: add missing cluster module * nit: use cluster method to derive key * docs: document cluster config property
- Loading branch information
Showing
5 changed files
with
217 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::fmt::Display; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum Cluster { | ||
#[default] | ||
Mainnet, | ||
Devnet, | ||
Testnet, | ||
Custom(String), | ||
} | ||
|
||
impl From<&str> for Cluster { | ||
fn from(value: &str) -> Self { | ||
match value.to_lowercase().as_str() { | ||
"mainnet" => Self::Mainnet, | ||
"devnet" => Self::Devnet, | ||
"testnet" => Self::Testnet, | ||
_ => Self::Custom(value.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl Display for Cluster { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Mainnet => write!(f, "mainnet"), | ||
Self::Devnet => write!(f, "devnet"), | ||
Self::Testnet => write!(f, "testnet"), | ||
Self::Custom(value) => write!(f, "Custom({value})"), | ||
} | ||
} | ||
} | ||
|
||
impl Cluster { | ||
/// Derives a key to be used for Kafka events from the provided [cluster] and [program_id]. | ||
/// This schema to derive keys is concistently used across all Ironforge services when | ||
/// sending/receiving Kafka events. | ||
pub fn key(&self, program_id: &str) -> String { | ||
format!("{self}:{program_id}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters