feat: resolve auth profiles through secret ids
This commit is contained in:
@@ -43,6 +43,11 @@ pub enum RegistryError {
|
||||
},
|
||||
#[error("secret with name {name} already exists in workspace {workspace_id}")]
|
||||
SecretNameAlreadyExists { workspace_id: String, name: String },
|
||||
#[error("secret {secret_id} is referenced by auth profile {auth_profile_id}")]
|
||||
SecretReferencedByAuthProfile {
|
||||
secret_id: String,
|
||||
auth_profile_id: String,
|
||||
},
|
||||
#[error("invocation log {log_id} was not found")]
|
||||
InvocationLogNotFound { log_id: String },
|
||||
#[error("agent {agent_id} was not found")]
|
||||
|
||||
@@ -3258,6 +3258,25 @@ impl PostgresRegistry {
|
||||
rows.iter().map(map_auth_profile).collect()
|
||||
}
|
||||
|
||||
pub async fn list_auth_profiles_referencing_secret(
|
||||
&self,
|
||||
workspace_id: &WorkspaceId,
|
||||
secret_id: &SecretId,
|
||||
) -> Result<Vec<AuthProfile>, RegistryError> {
|
||||
let profiles = self.list_auth_profiles(workspace_id).await?;
|
||||
|
||||
Ok(profiles
|
||||
.into_iter()
|
||||
.filter(|profile| {
|
||||
profile
|
||||
.config
|
||||
.secret_ids()
|
||||
.into_iter()
|
||||
.any(|candidate| candidate == secret_id)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn save_sample_metadata(
|
||||
&self,
|
||||
request: SaveSampleMetadataRequest<'_>,
|
||||
@@ -4331,7 +4350,7 @@ mod tests {
|
||||
use crank_core::{
|
||||
ApiKeyHeaderAuthConfig, AsyncJobHandle, AuthConfig, AuthKind, AuthProfile, ConfigExport,
|
||||
ExecutionConfig, ExportMode, GeneratedDraft, GeneratedDraftStatus, HttpMethod, JobStatus,
|
||||
OperationId, OperationStatus, Protocol, RestTarget, RetryPolicy, Samples, SecretRef,
|
||||
OperationId, OperationStatus, Protocol, RestTarget, RetryPolicy, Samples, SecretId,
|
||||
StreamSession, StreamSessionId, StreamStatus, Target, ToolDescription, ToolExample,
|
||||
WorkspaceId,
|
||||
};
|
||||
@@ -4471,7 +4490,7 @@ mod tests {
|
||||
kind: AuthKind::ApiKeyHeader,
|
||||
config: AuthConfig::ApiKeyHeader(ApiKeyHeaderAuthConfig {
|
||||
header_name: "X-Api-Key".to_owned(),
|
||||
secret_ref: SecretRef::new("vault://crank/api-key"),
|
||||
secret_id: SecretId::new("secret_crank_api_key"),
|
||||
}),
|
||||
created_at: "2026-03-25T12:00:00Z".to_owned(),
|
||||
updated_at: "2026-03-25T12:00:00Z".to_owned(),
|
||||
@@ -4539,6 +4558,43 @@ mod tests {
|
||||
database.cleanup().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn lists_auth_profiles_referencing_secret() {
|
||||
let database = TestDatabase::new().await;
|
||||
let registry = database.registry().await;
|
||||
let primary_secret_id = SecretId::new("secret_primary");
|
||||
let secondary_secret_id = SecretId::new("secret_secondary");
|
||||
let profile = AuthProfile {
|
||||
id: "auth_crank".into(),
|
||||
workspace_id: test_workspace_id(),
|
||||
name: "Crank basic auth".to_owned(),
|
||||
kind: AuthKind::Basic,
|
||||
config: AuthConfig::Basic(crank_core::BasicAuthConfig {
|
||||
username_secret_id: primary_secret_id.clone(),
|
||||
password_secret_id: secondary_secret_id.clone(),
|
||||
}),
|
||||
created_at: "2026-03-25T12:00:00Z".to_owned(),
|
||||
updated_at: "2026-03-25T12:00:00Z".to_owned(),
|
||||
};
|
||||
|
||||
registry
|
||||
.save_auth_profile(SaveAuthProfileRequest {
|
||||
workspace_id: &test_workspace_id(),
|
||||
profile: &profile,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let profiles = registry
|
||||
.list_auth_profiles_referencing_secret(&test_workspace_id(), &primary_secret_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(profiles, vec![profile]);
|
||||
|
||||
database.cleanup().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stores_and_finishes_yaml_import_jobs() {
|
||||
let database = TestDatabase::new().await;
|
||||
|
||||
Reference in New Issue
Block a user