This commit is contained in:
Conrad Ludgate
2025-03-27 12:39:00 +01:00
committed by Conrad Ludgate
parent 783260b88a
commit bdd68bb069
9 changed files with 25 additions and 57 deletions

4
Cargo.lock generated
View File

@@ -4614,9 +4614,9 @@ dependencies = [
[[package]]
name = "paracord"
version = "0.1.0-rc.5"
version = "0.1.0-rc.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe4d20c42ae2826a91463e015d3d76064b07b222d94d3646e854071aae25043b"
checksum = "965ee8b44c8a2556aa73279eab88d5aa63a2859336d8a61295104c8d8a4fb248"
dependencies = [
"boxcar",
"clashmap",

View File

@@ -114,7 +114,7 @@ ed25519-dalek = { version = "2", default-features = false, features = ["rand_cor
rsa = "0.9"
workspace_hack.workspace = true
paracord = { version = "0.1.0-rc.5", features = ["serde"] }
paracord = { version = "0.1.0-rc.6", features = ["serde"] }
[dev-dependencies]
assert-json-diff.workspace = true

View File

@@ -203,7 +203,7 @@ async fn authenticate(
let user: RoleName = db_info.user.into();
let user_info = ComputeUserInfo {
endpoint: db_info.aux.endpoint_id.resolve().into(),
endpoint: db_info.aux.endpoint_id.as_str().into(),
user: user.clone(),
options: NeonOptions::default(),
};

View File

@@ -87,7 +87,7 @@ impl JwkCacheEntry {
self.key_sets
.values()
// make sure our requested role has access to the key set
.filter(|key_set| key_set.role_names.iter().any(|role| *role.resolve() == **role_name))
.filter(|key_set| key_set.role_names.iter().any(|role| *role.as_str() == **role_name))
// try and find the requested key-id in the key set
.find_map(|key_set| {
key_set

View File

@@ -38,9 +38,9 @@ impl LocalBackend {
},
// TODO(conrad): make this better reflect compute info rather than endpoint info.
aux: MetricsAuxInfo {
endpoint_id: EndpointIdInt::get_or_intern("local"),
project_id: ProjectIdInt::get_or_intern("local"),
branch_id: BranchIdInt::get_or_intern("local"),
endpoint_id: EndpointIdInt::from_str_or_intern("local"),
project_id: ProjectIdInt::from_str_or_intern("local"),
branch_id: BranchIdInt::from_str_or_intern("local"),
compute_id: "local".into(),
cold_start_info: ColdStartInfo::WarmCached,
},

View File

@@ -194,7 +194,7 @@ impl ProjectInfoCacheImpl {
&self,
endpoint_id: &EndpointId,
) -> Option<Ref<'_, EndpointIdInt, EndpointInfo>> {
let endpoint_id = EndpointIdInt::get(endpoint_id)?;
let endpoint_id = EndpointIdInt::try_from_str(endpoint_id)?;
self.cache.get(&endpoint_id)
}
@@ -204,7 +204,7 @@ impl ProjectInfoCacheImpl {
role_name: &RoleName,
) -> Option<RoleAccessControl> {
let valid_since = self.get_cache_times();
let role_name = RoleNameInt::get(role_name)?;
let role_name = RoleNameInt::try_from_str(role_name)?;
let endpoint_info = self.get_endpoint_cache(endpoint_id)?;
endpoint_info.get_role_secret(role_name, valid_since)
}
@@ -297,10 +297,10 @@ impl ProjectInfoCacheImpl {
}
pub fn maybe_invalidate_role_secret(&self, endpoint_id: &EndpointId, role_name: &RoleName) {
let Some(endpoint_id) = EndpointIdInt::get(endpoint_id) else {
let Some(endpoint_id) = EndpointIdInt::try_from_str(endpoint_id) else {
return;
};
let Some(role_name) = RoleNameInt::get(role_name) else {
let Some(role_name) = RoleNameInt::try_from_str(role_name) else {
return;
};

View File

@@ -210,7 +210,7 @@ impl RequestContext {
pub(crate) fn set_project(&self, x: MetricsAuxInfo) {
let mut this = self.0.try_lock().expect("should not deadlock");
if this.endpoint_id.is_none() {
this.set_endpoint_id(x.endpoint_id.resolve().into());
this.set_endpoint_id(x.endpoint_id.as_str().into());
}
this.branch = Some(x.branch_id);
this.project = Some(x.project_id);

View File

@@ -1,5 +1,3 @@
use core::fmt;
use paracord::custom_key;
use crate::types::{AccountId, BranchId, EndpointId, ProjectId, RoleName};
@@ -12,92 +10,62 @@ custom_key!(pub struct AccountIdInt);
impl From<&RoleName> for RoleNameInt {
fn from(value: &RoleName) -> Self {
RoleNameInt::get_or_intern(value)
}
}
impl fmt::Display for RoleNameInt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.resolve())
RoleNameInt::from_str_or_intern(value)
}
}
impl From<&EndpointId> for EndpointIdInt {
fn from(value: &EndpointId) -> Self {
EndpointIdInt::get_or_intern(value)
EndpointIdInt::from_str_or_intern(value)
}
}
impl From<EndpointId> for EndpointIdInt {
fn from(value: EndpointId) -> Self {
EndpointIdInt::get_or_intern(&value)
}
}
impl fmt::Display for EndpointIdInt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.resolve())
EndpointIdInt::from_str_or_intern(&value)
}
}
impl From<&BranchId> for BranchIdInt {
fn from(value: &BranchId) -> Self {
BranchIdInt::get_or_intern(value)
BranchIdInt::from_str_or_intern(value)
}
}
impl From<BranchId> for BranchIdInt {
fn from(value: BranchId) -> Self {
BranchIdInt::get_or_intern(&value)
}
}
impl AsRef<str> for BranchIdInt {
fn as_ref(&self) -> &str {
self.resolve()
BranchIdInt::from_str_or_intern(&value)
}
}
impl std::ops::Deref for BranchIdInt {
type Target = str;
fn deref(&self) -> &str {
self.resolve()
self.as_str()
}
}
impl From<&ProjectId> for ProjectIdInt {
fn from(value: &ProjectId) -> Self {
ProjectIdInt::get_or_intern(value)
ProjectIdInt::from_str_or_intern(value)
}
}
impl From<ProjectId> for ProjectIdInt {
fn from(value: ProjectId) -> Self {
ProjectIdInt::get_or_intern(&value)
}
}
impl AsRef<str> for ProjectIdInt {
fn as_ref(&self) -> &str {
self.resolve()
ProjectIdInt::from_str_or_intern(&value)
}
}
impl std::ops::Deref for ProjectIdInt {
type Target = str;
fn deref(&self) -> &str {
self.resolve()
}
}
impl fmt::Display for ProjectIdInt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.resolve())
self.as_str()
}
}
impl From<&AccountId> for AccountIdInt {
fn from(value: &AccountId) -> Self {
AccountIdInt::get_or_intern(value)
AccountIdInt::from_str_or_intern(value)
}
}
impl From<AccountId> for AccountIdInt {
fn from(value: AccountId) -> Self {
AccountIdInt::get_or_intern(&value)
}
}
impl fmt::Display for AccountIdInt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.resolve())
AccountIdInt::from_str_or_intern(&value)
}
}

View File

@@ -85,7 +85,7 @@ impl EndpointId {
#[must_use]
pub fn normalize_intern(&self) -> EndpointIdInt {
EndpointIdInt::get_or_intern(self.normalize_str())
EndpointIdInt::from_str_or_intern(self.normalize_str())
}
}