From 68ab9b6d1d89b8d0e83367941cc75aeda303799a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 23 Jun 2023 01:07:54 -0700 Subject: [PATCH] always serialize RpcSecretKey as a ULID --- web3_proxy/src/frontend/authorization.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/frontend/authorization.rs b/web3_proxy/src/frontend/authorization.rs index a1fcba9e..d6270ab4 100644 --- a/web3_proxy/src/frontend/authorization.rs +++ b/web3_proxy/src/frontend/authorization.rs @@ -31,6 +31,7 @@ use rdkafka::producer::{FutureProducer, FutureRecord}; use rdkafka::util::Timeout as KafkaTimeout; use redis_rate_limiter::redis::AsyncCommands; use redis_rate_limiter::RedisRateLimitResult; +use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::fmt::Display; use std::hash::{Hash, Hasher}; @@ -46,12 +47,29 @@ use ulid::Ulid; use uuid::Uuid; /// This lets us use UUID and ULID while we transition to only ULIDs -#[derive(Copy, Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize)] pub enum RpcSecretKey { Ulid(Ulid), Uuid(Uuid), } +/// always serialize as a ULID. +impl Serialize for RpcSecretKey { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + Self::Ulid(x) => x.serialize(serializer), + Self::Uuid(x) => { + let x: Ulid = x.to_owned().into(); + + x.serialize(serializer) + } + } + } +} + /// TODO: should this have IpAddr and Origin or AuthorizationChecks? #[derive(Debug)] pub enum RateLimitResult {