feat: resolve auth profiles through secret ids

This commit is contained in:
a.tolmachev
2026-04-07 00:43:35 +03:00
parent a6388e4353
commit 191e749b14
10 changed files with 237 additions and 40 deletions
+17 -19
View File
@@ -1,45 +1,32 @@
use serde::{Deserialize, Serialize};
use crate::{
ids::{AuthProfileId, WorkspaceId},
ids::{AuthProfileId, SecretId, WorkspaceId},
protocol::AuthKind,
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct SecretRef(pub String);
impl SecretRef {
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BearerAuthConfig {
pub header_name: String,
pub secret_ref: SecretRef,
pub secret_id: SecretId,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BasicAuthConfig {
pub username_secret_ref: SecretRef,
pub password_secret_ref: SecretRef,
pub username_secret_id: SecretId,
pub password_secret_id: SecretId,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiKeyHeaderAuthConfig {
pub header_name: String,
pub secret_ref: SecretRef,
pub secret_id: SecretId,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiKeyQueryAuthConfig {
pub param_name: String,
pub secret_ref: SecretRef,
pub secret_id: SecretId,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -51,6 +38,17 @@ pub enum AuthConfig {
ApiKeyQuery(ApiKeyQueryAuthConfig),
}
impl AuthConfig {
pub fn secret_ids(&self) -> Vec<&SecretId> {
match self {
Self::Bearer(config) => vec![&config.secret_id],
Self::Basic(config) => vec![&config.username_secret_id, &config.password_secret_id],
Self::ApiKeyHeader(config) => vec![&config.secret_id],
Self::ApiKeyQuery(config) => vec![&config.secret_id],
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct AuthProfile {
pub id: AuthProfileId,
+1 -1
View File
@@ -18,7 +18,7 @@ pub use access::{
pub use agent::{Agent, AgentOperationBinding, AgentStatus, AgentVersion};
pub use auth::{
ApiKeyHeaderAuthConfig, ApiKeyQueryAuthConfig, AuthConfig, AuthProfile, BasicAuthConfig,
BearerAuthConfig, SecretRef,
BearerAuthConfig,
};
pub use ids::{
AgentId, AsyncJobId, AuthProfileId, DescriptorId, InvitationId, InvocationLogId, OperationId,
+5 -5
View File
@@ -266,7 +266,7 @@ mod tests {
use serde_json::json;
use crate::{
auth::{AuthConfig, AuthProfile, BearerAuthConfig, SecretRef},
auth::{AuthConfig, AuthProfile, BearerAuthConfig},
ids::{AuthProfileId, OperationId, SampleId},
operation::{
ConfigExport, ExecutionConfig, GraphqlTarget, Operation, OperationStatus,
@@ -430,7 +430,7 @@ mod tests {
}
#[test]
fn auth_profile_serializes_secret_refs_without_secret_values() {
fn auth_profile_serializes_secret_ids_without_secret_values() {
let profile = AuthProfile {
id: AuthProfileId::new("auth_01"),
workspace_id: crate::ids::WorkspaceId::new("ws_01"),
@@ -438,7 +438,7 @@ mod tests {
kind: AuthKind::Bearer,
config: AuthConfig::Bearer(BearerAuthConfig {
header_name: "Authorization".to_owned(),
secret_ref: SecretRef::new("secret://auth/crm-prod-token"),
secret_id: crate::ids::SecretId::new("secret_crm_prod_token"),
}),
created_at: "2026-03-25T08:00:00Z".to_owned(),
updated_at: "2026-03-25T08:00:00Z".to_owned(),
@@ -448,8 +448,8 @@ mod tests {
assert_eq!(value["kind"], "bearer");
assert_eq!(
value["config"]["bearer"]["secret_ref"],
"secret://auth/crm-prod-token"
value["config"]["bearer"]["secret_id"],
"secret_crm_prod_token"
);
}