@@ -38,7 +38,7 @@ pub struct AuditLogEntryInitParams {
3838 pub source_ip : IpAddr ,
3939 pub user_agent : Option < String > ,
4040 pub actor : AuditLogActor ,
41- pub auth_method : Option < String > ,
41+ pub auth_method : Option < AuditLogAuthMethod > ,
4242}
4343
4444impl_enum_type ! (
@@ -86,6 +86,54 @@ impl_enum_type!(
8686 Timeout => b"timeout"
8787) ;
8888
89+ impl_enum_type ! (
90+ AuditLogAuthMethodEnum :
91+
92+ #[ derive(
93+ Clone ,
94+ Copy ,
95+ Debug ,
96+ AsExpression ,
97+ FromSqlRow ,
98+ Serialize ,
99+ Deserialize ,
100+ PartialEq ,
101+ Eq ,
102+ ) ]
103+ pub enum AuditLogAuthMethod ;
104+
105+ // Enum values
106+ SessionCookie => b"session_cookie"
107+ AccessToken => b"access_token"
108+ ScimToken => b"scim_token"
109+ Spoof => b"spoof"
110+ ) ;
111+
112+ impl From < AuditLogAuthMethod > for views:: AuthMethod {
113+ fn from ( m : AuditLogAuthMethod ) -> Self {
114+ match m {
115+ AuditLogAuthMethod :: SessionCookie => {
116+ views:: AuthMethod :: SessionCookie
117+ }
118+ AuditLogAuthMethod :: AccessToken => views:: AuthMethod :: AccessToken ,
119+ AuditLogAuthMethod :: ScimToken => views:: AuthMethod :: ScimToken ,
120+ AuditLogAuthMethod :: Spoof => views:: AuthMethod :: Spoof ,
121+ }
122+ }
123+ }
124+
125+ impl From < & nexus_types:: authn:: SchemeName > for AuditLogAuthMethod {
126+ fn from ( s : & nexus_types:: authn:: SchemeName ) -> Self {
127+ use nexus_types:: authn:: SchemeName ;
128+ match s {
129+ SchemeName :: SessionCookie => AuditLogAuthMethod :: SessionCookie ,
130+ SchemeName :: AccessToken => AuditLogAuthMethod :: AccessToken ,
131+ SchemeName :: ScimToken => AuditLogAuthMethod :: ScimToken ,
132+ SchemeName :: Spoof => AuditLogAuthMethod :: Spoof ,
133+ }
134+ }
135+ }
136+
89137#[ derive( Queryable , Insertable , Selectable , Clone , Debug ) ]
90138#[ diesel( table_name = audit_log) ]
91139pub struct AuditLogEntryInit {
@@ -115,7 +163,7 @@ pub struct AuditLogEntryInit {
115163
116164 /// API token or session cookie. Optional because it will not be defined
117165 /// on unauthenticated requests like login attempts.
118- pub auth_method : Option < String > ,
166+ pub auth_method : Option < AuditLogAuthMethod > ,
119167}
120168
121169impl From < AuditLogEntryInitParams > for AuditLogEntryInit {
@@ -182,20 +230,20 @@ pub struct AuditLogEntry {
182230 /// Actor kind indicating builtin user, silo user, or unauthenticated
183231 pub actor_kind : AuditLogActorKind ,
184232
185- /// The name of the authn scheme used. None if unauthenticated.
186- pub auth_method : Option < String > ,
187-
188233 // Fields that are not present on init
189234 /// Time log entry was completed with info about result of operation
190235 pub time_completed : DateTime < Utc > ,
191- /// Result kind indicating success, error, or timeout
192- pub result_kind : AuditLogResultKind ,
193236 /// Optional because not present for timeout result
194237 pub http_status_code : Option < SqlU16 > ,
195238 /// Optional even if result is an error
196239 pub error_code : Option < String > ,
197240 /// Always present if result is an error
198241 pub error_message : Option < String > ,
242+ /// Result kind indicating success, error, or timeout
243+ pub result_kind : AuditLogResultKind ,
244+
245+ /// The authn scheme used. None if unauthenticated.
246+ pub auth_method : Option < AuditLogAuthMethod > ,
199247}
200248
201249/// Struct that we can use as a kind of constructor arg for our actual audit
@@ -320,7 +368,7 @@ impl TryFrom<AuditLogEntry> for views::AuditLogEntry {
320368 views:: AuditLogEntryActor :: Unauthenticated
321369 }
322370 } ,
323- auth_method : entry. auth_method ,
371+ auth_method : entry. auth_method . map ( Into :: into ) ,
324372 time_completed : entry. time_completed ,
325373 result : match entry. result_kind {
326374 AuditLogResultKind :: Success => {
0 commit comments