Skip to main content

mz_catalog/durable/objects/serialization/
audit_log.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! This module is responsible for serializing objects from the
11//! [`mz_audit_log`] crate into protobuf.
12
13use mz_audit_log::{
14    AlterAddColumnV1, AlterApplyReplacementV1, AlterClusterReconfigurationV1,
15    AlterDefaultPrivilegeV1, AlterRetainHistoryV1, AlterSetClusterV1, AlterSourceSinkV1,
16    AlterSourceTimestampIntervalV1, BurstFinishCauseV1, ClusterHydrationBurstV1,
17    ClusterReplicaLoggingV1, CreateClusterReplicaV1, CreateClusterReplicaV2,
18    CreateClusterReplicaV3, CreateClusterReplicaV4, CreateIndexV1, CreateMaterializedViewV1,
19    CreateOrDropClusterReplicaReasonV1, CreateRoleV1, CreateSourceSinkV1, CreateSourceSinkV2,
20    CreateSourceSinkV3, CreateSourceSinkV4, DropClusterReplicaV1, DropClusterReplicaV2,
21    DropClusterReplicaV3, EventDetails, EventType, EventV1, FromPreviousIdV1, FullNameV1,
22    GrantRoleV1, GrantRoleV2, HydrationBurstLifecycleV1, IdFullNameV1, IdNameV1,
23    ReconfigurationLifecycleV1, RefreshDecisionWithReasonV1, RefreshDecisionWithReasonV2,
24    RenameClusterReplicaV1, RenameClusterV1, RenameItemV1, RenameSchemaV1, RevokeRoleV1,
25    RevokeRoleV2, RotateKeysV1, SchedulingDecisionV1, SchedulingDecisionsWithReasonsV1,
26    SchedulingDecisionsWithReasonsV2, SchemaV1, SchemaV2, SetV1, ToNewIdV1, UpdateItemV1,
27    UpdateOwnerV1, UpdatePrivilegeV1, VersionedEvent,
28};
29use mz_proto::TryFromProtoError;
30
31use crate::durable::objects::serialization::proto::Empty;
32use crate::durable::objects::serialization::{ProtoType, RustType, proto};
33
34impl RustType<proto::AuditLogEvent> for VersionedEvent {
35    fn into_proto(&self) -> proto::AuditLogEvent {
36        match self {
37            VersionedEvent::V1(event) => proto::AuditLogEvent::V1(event.into_proto()),
38        }
39    }
40
41    fn from_proto(proto: proto::AuditLogEvent) -> Result<Self, TryFromProtoError> {
42        match proto {
43            proto::AuditLogEvent::V1(event) => Ok(VersionedEvent::V1(event.into_rust()?)),
44        }
45    }
46}
47
48impl RustType<proto::audit_log_event_v1::EventType> for EventType {
49    fn into_proto(&self) -> proto::audit_log_event_v1::EventType {
50        match self {
51            EventType::Create => proto::audit_log_event_v1::EventType::Create,
52            EventType::Drop => proto::audit_log_event_v1::EventType::Drop,
53            EventType::Alter => proto::audit_log_event_v1::EventType::Alter,
54            EventType::Grant => proto::audit_log_event_v1::EventType::Grant,
55            EventType::Revoke => proto::audit_log_event_v1::EventType::Revoke,
56            EventType::Comment => proto::audit_log_event_v1::EventType::Comment,
57        }
58    }
59
60    fn from_proto(proto: proto::audit_log_event_v1::EventType) -> Result<Self, TryFromProtoError> {
61        match proto {
62            proto::audit_log_event_v1::EventType::Create => Ok(EventType::Create),
63            proto::audit_log_event_v1::EventType::Drop => Ok(EventType::Drop),
64            proto::audit_log_event_v1::EventType::Alter => Ok(EventType::Alter),
65            proto::audit_log_event_v1::EventType::Grant => Ok(EventType::Grant),
66            proto::audit_log_event_v1::EventType::Revoke => Ok(EventType::Revoke),
67            proto::audit_log_event_v1::EventType::Comment => Ok(EventType::Comment),
68            proto::audit_log_event_v1::EventType::Unknown => Err(
69                TryFromProtoError::unknown_enum_variant("EventType::Unknown"),
70            ),
71        }
72    }
73}
74
75impl RustType<proto::audit_log_event_v1::ObjectType> for mz_audit_log::ObjectType {
76    fn into_proto(&self) -> proto::audit_log_event_v1::ObjectType {
77        match self {
78            mz_audit_log::ObjectType::Cluster => proto::audit_log_event_v1::ObjectType::Cluster,
79            mz_audit_log::ObjectType::ClusterReplica => {
80                proto::audit_log_event_v1::ObjectType::ClusterReplica
81            }
82            mz_audit_log::ObjectType::Connection => {
83                proto::audit_log_event_v1::ObjectType::Connection
84            }
85            mz_audit_log::ObjectType::ContinualTask => {
86                proto::audit_log_event_v1::ObjectType::ContinualTask
87            }
88            mz_audit_log::ObjectType::Database => proto::audit_log_event_v1::ObjectType::Database,
89            mz_audit_log::ObjectType::Func => proto::audit_log_event_v1::ObjectType::Func,
90            mz_audit_log::ObjectType::Index => proto::audit_log_event_v1::ObjectType::Index,
91            mz_audit_log::ObjectType::MaterializedView => {
92                proto::audit_log_event_v1::ObjectType::MaterializedView
93            }
94            mz_audit_log::ObjectType::MetricSink => {
95                proto::audit_log_event_v1::ObjectType::MetricSink
96            }
97            mz_audit_log::ObjectType::NetworkPolicy => {
98                proto::audit_log_event_v1::ObjectType::NetworkPolicy
99            }
100            mz_audit_log::ObjectType::Role => proto::audit_log_event_v1::ObjectType::Role,
101            mz_audit_log::ObjectType::Secret => proto::audit_log_event_v1::ObjectType::Secret,
102            mz_audit_log::ObjectType::Schema => proto::audit_log_event_v1::ObjectType::Schema,
103            mz_audit_log::ObjectType::Sink => proto::audit_log_event_v1::ObjectType::Sink,
104            mz_audit_log::ObjectType::Source => proto::audit_log_event_v1::ObjectType::Source,
105            mz_audit_log::ObjectType::System => proto::audit_log_event_v1::ObjectType::System,
106            mz_audit_log::ObjectType::Table => proto::audit_log_event_v1::ObjectType::Table,
107            mz_audit_log::ObjectType::Type => proto::audit_log_event_v1::ObjectType::Type,
108            mz_audit_log::ObjectType::View => proto::audit_log_event_v1::ObjectType::View,
109        }
110    }
111
112    fn from_proto(proto: proto::audit_log_event_v1::ObjectType) -> Result<Self, TryFromProtoError> {
113        match proto {
114            proto::audit_log_event_v1::ObjectType::Cluster => Ok(mz_audit_log::ObjectType::Cluster),
115            proto::audit_log_event_v1::ObjectType::ClusterReplica => {
116                Ok(mz_audit_log::ObjectType::ClusterReplica)
117            }
118            proto::audit_log_event_v1::ObjectType::Connection => {
119                Ok(mz_audit_log::ObjectType::Connection)
120            }
121            proto::audit_log_event_v1::ObjectType::ContinualTask => {
122                Ok(mz_audit_log::ObjectType::ContinualTask)
123            }
124            proto::audit_log_event_v1::ObjectType::Database => {
125                Ok(mz_audit_log::ObjectType::Database)
126            }
127            proto::audit_log_event_v1::ObjectType::Func => Ok(mz_audit_log::ObjectType::Func),
128            proto::audit_log_event_v1::ObjectType::Index => Ok(mz_audit_log::ObjectType::Index),
129            proto::audit_log_event_v1::ObjectType::MaterializedView => {
130                Ok(mz_audit_log::ObjectType::MaterializedView)
131            }
132            proto::audit_log_event_v1::ObjectType::MetricSink => {
133                Ok(mz_audit_log::ObjectType::MetricSink)
134            }
135            proto::audit_log_event_v1::ObjectType::NetworkPolicy => {
136                Ok(mz_audit_log::ObjectType::NetworkPolicy)
137            }
138            proto::audit_log_event_v1::ObjectType::Role => Ok(mz_audit_log::ObjectType::Role),
139            proto::audit_log_event_v1::ObjectType::Secret => Ok(mz_audit_log::ObjectType::Secret),
140            proto::audit_log_event_v1::ObjectType::Schema => Ok(mz_audit_log::ObjectType::Schema),
141            proto::audit_log_event_v1::ObjectType::Sink => Ok(mz_audit_log::ObjectType::Sink),
142            proto::audit_log_event_v1::ObjectType::Source => Ok(mz_audit_log::ObjectType::Source),
143            proto::audit_log_event_v1::ObjectType::System => Ok(mz_audit_log::ObjectType::System),
144            proto::audit_log_event_v1::ObjectType::Table => Ok(mz_audit_log::ObjectType::Table),
145            proto::audit_log_event_v1::ObjectType::Type => Ok(mz_audit_log::ObjectType::Type),
146            proto::audit_log_event_v1::ObjectType::View => Ok(mz_audit_log::ObjectType::View),
147            proto::audit_log_event_v1::ObjectType::Unknown => Err(
148                TryFromProtoError::unknown_enum_variant("ObjectType::Unknown"),
149            ),
150        }
151    }
152}
153
154impl RustType<proto::audit_log_event_v1::IdFullNameV1> for IdFullNameV1 {
155    fn into_proto(&self) -> proto::audit_log_event_v1::IdFullNameV1 {
156        proto::audit_log_event_v1::IdFullNameV1 {
157            id: self.id.to_string(),
158            name: self.name.into_proto(),
159        }
160    }
161
162    fn from_proto(
163        proto: proto::audit_log_event_v1::IdFullNameV1,
164    ) -> Result<Self, TryFromProtoError> {
165        Ok(IdFullNameV1 {
166            id: proto.id,
167            name: proto.name.into_rust()?,
168        })
169    }
170}
171
172impl RustType<proto::audit_log_event_v1::FullNameV1> for FullNameV1 {
173    fn into_proto(&self) -> proto::audit_log_event_v1::FullNameV1 {
174        proto::audit_log_event_v1::FullNameV1 {
175            database: self.database.to_string(),
176            schema: self.schema.to_string(),
177            item: self.item.to_string(),
178        }
179    }
180
181    fn from_proto(proto: proto::audit_log_event_v1::FullNameV1) -> Result<Self, TryFromProtoError> {
182        Ok(FullNameV1 {
183            database: proto.database,
184            schema: proto.schema,
185            item: proto.item,
186        })
187    }
188}
189
190impl RustType<proto::audit_log_event_v1::IdNameV1> for IdNameV1 {
191    fn into_proto(&self) -> proto::audit_log_event_v1::IdNameV1 {
192        proto::audit_log_event_v1::IdNameV1 {
193            id: self.id.to_string(),
194            name: self.name.to_string(),
195        }
196    }
197
198    fn from_proto(proto: proto::audit_log_event_v1::IdNameV1) -> Result<Self, TryFromProtoError> {
199        Ok(IdNameV1 {
200            id: proto.id,
201            name: proto.name,
202        })
203    }
204}
205
206impl RustType<proto::audit_log_event_v1::RenameItemV1> for RenameItemV1 {
207    fn into_proto(&self) -> proto::audit_log_event_v1::RenameItemV1 {
208        proto::audit_log_event_v1::RenameItemV1 {
209            id: self.id.to_string(),
210            old_name: self.old_name.into_proto(),
211            new_name: self.new_name.into_proto(),
212        }
213    }
214
215    fn from_proto(
216        proto: proto::audit_log_event_v1::RenameItemV1,
217    ) -> Result<Self, TryFromProtoError> {
218        Ok(RenameItemV1 {
219            id: proto.id,
220            old_name: proto.old_name.into_rust()?,
221            new_name: proto.new_name.into_rust()?,
222        })
223    }
224}
225
226impl RustType<proto::audit_log_event_v1::RenameClusterV1> for RenameClusterV1 {
227    fn into_proto(&self) -> proto::audit_log_event_v1::RenameClusterV1 {
228        proto::audit_log_event_v1::RenameClusterV1 {
229            id: self.id.to_string(),
230            old_name: self.old_name.into_proto(),
231            new_name: self.new_name.into_proto(),
232        }
233    }
234
235    fn from_proto(
236        proto: proto::audit_log_event_v1::RenameClusterV1,
237    ) -> Result<Self, TryFromProtoError> {
238        Ok(RenameClusterV1 {
239            id: proto.id,
240            old_name: proto.old_name,
241            new_name: proto.new_name,
242        })
243    }
244}
245
246impl RustType<proto::audit_log_event_v1::RenameClusterReplicaV1> for RenameClusterReplicaV1 {
247    fn into_proto(&self) -> proto::audit_log_event_v1::RenameClusterReplicaV1 {
248        proto::audit_log_event_v1::RenameClusterReplicaV1 {
249            cluster_id: self.cluster_id.to_string(),
250            replica_id: self.replica_id.to_string(),
251            old_name: self.old_name.into_proto(),
252            new_name: self.new_name.into_proto(),
253        }
254    }
255
256    fn from_proto(
257        proto: proto::audit_log_event_v1::RenameClusterReplicaV1,
258    ) -> Result<Self, TryFromProtoError> {
259        Ok(RenameClusterReplicaV1 {
260            cluster_id: proto.cluster_id,
261            replica_id: proto.replica_id,
262            old_name: proto.old_name,
263            new_name: proto.new_name,
264        })
265    }
266}
267
268impl RustType<proto::audit_log_event_v1::ReconfigurationLifecycleV1>
269    for ReconfigurationLifecycleV1
270{
271    fn into_proto(&self) -> proto::audit_log_event_v1::ReconfigurationLifecycleV1 {
272        use proto::audit_log_event_v1::reconfiguration_lifecycle_v1::Transition;
273        let transition = match self {
274            ReconfigurationLifecycleV1::Started => Transition::Started(Empty {}),
275            ReconfigurationLifecycleV1::Finalized => Transition::Finalized(Empty {}),
276            ReconfigurationLifecycleV1::TimedOut => Transition::TimedOut(Empty {}),
277            ReconfigurationLifecycleV1::Cancelled => Transition::Cancelled(Empty {}),
278            ReconfigurationLifecycleV1::ResourceExhausted => {
279                Transition::ResourceExhausted(Empty {})
280            }
281        };
282        proto::audit_log_event_v1::ReconfigurationLifecycleV1 { transition }
283    }
284
285    fn from_proto(
286        proto: proto::audit_log_event_v1::ReconfigurationLifecycleV1,
287    ) -> Result<Self, TryFromProtoError> {
288        use proto::audit_log_event_v1::reconfiguration_lifecycle_v1::Transition;
289        Ok(match proto.transition {
290            Transition::Started(_) => ReconfigurationLifecycleV1::Started,
291            Transition::Finalized(_) => ReconfigurationLifecycleV1::Finalized,
292            Transition::TimedOut(_) => ReconfigurationLifecycleV1::TimedOut,
293            Transition::Cancelled(_) => ReconfigurationLifecycleV1::Cancelled,
294            Transition::ResourceExhausted(_) => ReconfigurationLifecycleV1::ResourceExhausted,
295        })
296    }
297}
298
299impl RustType<proto::audit_log_event_v1::AlterClusterReconfigurationV1>
300    for AlterClusterReconfigurationV1
301{
302    fn into_proto(&self) -> proto::audit_log_event_v1::AlterClusterReconfigurationV1 {
303        proto::audit_log_event_v1::AlterClusterReconfigurationV1 {
304            cluster_id: self.cluster_id.to_string(),
305            cluster_name: self.cluster_name.to_string(),
306            transition: self.transition.into_proto(),
307            forced: self.forced,
308            target_size: self.target_size.to_string(),
309            target_replication_factor: self.target_replication_factor,
310            target_availability_zones: self.target_availability_zones.clone(),
311            target_logging: self.target_logging.into_proto(),
312            deadline: self.deadline,
313        }
314    }
315
316    fn from_proto(
317        proto: proto::audit_log_event_v1::AlterClusterReconfigurationV1,
318    ) -> Result<Self, TryFromProtoError> {
319        Ok(AlterClusterReconfigurationV1 {
320            cluster_id: proto.cluster_id,
321            cluster_name: proto.cluster_name,
322            transition: proto.transition.into_rust()?,
323            forced: proto.forced,
324            target_size: proto.target_size,
325            target_replication_factor: proto.target_replication_factor,
326            target_availability_zones: proto.target_availability_zones,
327            target_logging: proto.target_logging.into_rust()?,
328            deadline: proto.deadline,
329        })
330    }
331}
332
333impl RustType<proto::audit_log_event_v1::ClusterReplicaLoggingV1> for ClusterReplicaLoggingV1 {
334    fn into_proto(&self) -> proto::audit_log_event_v1::ClusterReplicaLoggingV1 {
335        proto::audit_log_event_v1::ClusterReplicaLoggingV1 {
336            log_logging: self.log_logging,
337            interval: self.interval.into_proto(),
338        }
339    }
340
341    fn from_proto(
342        proto: proto::audit_log_event_v1::ClusterReplicaLoggingV1,
343    ) -> Result<Self, TryFromProtoError> {
344        Ok(ClusterReplicaLoggingV1 {
345            log_logging: proto.log_logging,
346            interval: proto.interval.into_rust()?,
347        })
348    }
349}
350
351impl RustType<proto::audit_log_event_v1::HydrationBurstLifecycleV1> for HydrationBurstLifecycleV1 {
352    fn into_proto(&self) -> proto::audit_log_event_v1::HydrationBurstLifecycleV1 {
353        use proto::audit_log_event_v1::hydration_burst_lifecycle_v1::Transition;
354        let transition = match self {
355            HydrationBurstLifecycleV1::Started => Transition::Started(Empty {}),
356            HydrationBurstLifecycleV1::Finished => Transition::Finished(Empty {}),
357        };
358        proto::audit_log_event_v1::HydrationBurstLifecycleV1 { transition }
359    }
360
361    fn from_proto(
362        proto: proto::audit_log_event_v1::HydrationBurstLifecycleV1,
363    ) -> Result<Self, TryFromProtoError> {
364        use proto::audit_log_event_v1::hydration_burst_lifecycle_v1::Transition;
365        Ok(match proto.transition {
366            Transition::Started(_) => HydrationBurstLifecycleV1::Started,
367            Transition::Finished(_) => HydrationBurstLifecycleV1::Finished,
368        })
369    }
370}
371
372impl RustType<proto::audit_log_event_v1::BurstFinishCauseV1> for BurstFinishCauseV1 {
373    fn into_proto(&self) -> proto::audit_log_event_v1::BurstFinishCauseV1 {
374        use proto::audit_log_event_v1::burst_finish_cause_v1::Cause;
375        let cause = match self {
376            BurstFinishCauseV1::LingerElapsed => Cause::LingerElapsed(Empty {}),
377            BurstFinishCauseV1::NoLongerWarranted => Cause::NoLongerWarranted(Empty {}),
378        };
379        proto::audit_log_event_v1::BurstFinishCauseV1 { cause }
380    }
381
382    fn from_proto(
383        proto: proto::audit_log_event_v1::BurstFinishCauseV1,
384    ) -> Result<Self, TryFromProtoError> {
385        use proto::audit_log_event_v1::burst_finish_cause_v1::Cause;
386        Ok(match proto.cause {
387            Cause::LingerElapsed(_) => BurstFinishCauseV1::LingerElapsed,
388            Cause::NoLongerWarranted(_) => BurstFinishCauseV1::NoLongerWarranted,
389        })
390    }
391}
392
393impl RustType<proto::audit_log_event_v1::ClusterHydrationBurstV1> for ClusterHydrationBurstV1 {
394    fn into_proto(&self) -> proto::audit_log_event_v1::ClusterHydrationBurstV1 {
395        proto::audit_log_event_v1::ClusterHydrationBurstV1 {
396            cluster_id: self.cluster_id.to_string(),
397            cluster_name: self.cluster_name.to_string(),
398            transition: self.transition.into_proto(),
399            finish_cause: self.finish_cause.map(|cause| cause.into_proto()),
400            burst_size: self.burst_size.to_string(),
401        }
402    }
403
404    fn from_proto(
405        proto: proto::audit_log_event_v1::ClusterHydrationBurstV1,
406    ) -> Result<Self, TryFromProtoError> {
407        Ok(ClusterHydrationBurstV1 {
408            cluster_id: proto.cluster_id,
409            cluster_name: proto.cluster_name,
410            transition: proto.transition.into_rust()?,
411            finish_cause: proto
412                .finish_cause
413                .map(|cause| cause.into_rust())
414                .transpose()?,
415            burst_size: proto.burst_size,
416        })
417    }
418}
419
420impl RustType<proto::audit_log_event_v1::DropClusterReplicaV1> for DropClusterReplicaV1 {
421    fn into_proto(&self) -> proto::audit_log_event_v1::DropClusterReplicaV1 {
422        proto::audit_log_event_v1::DropClusterReplicaV1 {
423            cluster_id: self.cluster_id.to_string(),
424            cluster_name: self.cluster_name.to_string(),
425            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
426                inner: id.to_string(),
427            }),
428            replica_name: self.replica_name.to_string(),
429        }
430    }
431
432    fn from_proto(
433        proto: proto::audit_log_event_v1::DropClusterReplicaV1,
434    ) -> Result<Self, TryFromProtoError> {
435        Ok(DropClusterReplicaV1 {
436            cluster_id: proto.cluster_id,
437            cluster_name: proto.cluster_name,
438            replica_id: proto.replica_id.map(|s| s.inner),
439            replica_name: proto.replica_name,
440        })
441    }
442}
443
444impl RustType<proto::audit_log_event_v1::DropClusterReplicaV2> for DropClusterReplicaV2 {
445    fn into_proto(&self) -> proto::audit_log_event_v1::DropClusterReplicaV2 {
446        proto::audit_log_event_v1::DropClusterReplicaV2 {
447            cluster_id: self.cluster_id.to_string(),
448            cluster_name: self.cluster_name.to_string(),
449            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
450                inner: id.to_string(),
451            }),
452            replica_name: self.replica_name.to_string(),
453            reason: self.reason.into_proto(),
454            scheduling_policies: self.scheduling_policies.into_proto(),
455        }
456    }
457
458    fn from_proto(
459        proto: proto::audit_log_event_v1::DropClusterReplicaV2,
460    ) -> Result<Self, TryFromProtoError> {
461        Ok(DropClusterReplicaV2 {
462            cluster_id: proto.cluster_id,
463            cluster_name: proto.cluster_name,
464            replica_id: proto.replica_id.map(|s| s.inner),
465            replica_name: proto.replica_name,
466            reason: proto.reason.into_rust()?,
467            scheduling_policies: proto.scheduling_policies.into_rust()?,
468        })
469    }
470}
471
472impl RustType<proto::audit_log_event_v1::DropClusterReplicaV3> for DropClusterReplicaV3 {
473    fn into_proto(&self) -> proto::audit_log_event_v1::DropClusterReplicaV3 {
474        proto::audit_log_event_v1::DropClusterReplicaV3 {
475            cluster_id: self.cluster_id.to_string(),
476            cluster_name: self.cluster_name.to_string(),
477            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
478                inner: id.to_string(),
479            }),
480            replica_name: self.replica_name.to_string(),
481            reason: self.reason.into_proto(),
482            scheduling_policies: self.scheduling_policies.into_proto(),
483        }
484    }
485
486    fn from_proto(
487        proto: proto::audit_log_event_v1::DropClusterReplicaV3,
488    ) -> Result<Self, TryFromProtoError> {
489        Ok(DropClusterReplicaV3 {
490            cluster_id: proto.cluster_id,
491            cluster_name: proto.cluster_name,
492            replica_id: proto.replica_id.map(|s| s.inner),
493            replica_name: proto.replica_name,
494            reason: proto.reason.into_rust()?,
495            scheduling_policies: proto.scheduling_policies.into_rust()?,
496        })
497    }
498}
499
500impl RustType<proto::audit_log_event_v1::CreateClusterReplicaV1> for CreateClusterReplicaV1 {
501    fn into_proto(&self) -> proto::audit_log_event_v1::CreateClusterReplicaV1 {
502        proto::audit_log_event_v1::CreateClusterReplicaV1 {
503            cluster_id: self.cluster_id.to_string(),
504            cluster_name: self.cluster_name.to_string(),
505            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
506                inner: id.to_string(),
507            }),
508            replica_name: self.replica_name.to_string(),
509            logical_size: self.logical_size.to_string(),
510            disk: self.disk,
511            billed_as: self.billed_as.clone(),
512            internal: self.internal,
513        }
514    }
515
516    fn from_proto(
517        proto: proto::audit_log_event_v1::CreateClusterReplicaV1,
518    ) -> Result<Self, TryFromProtoError> {
519        Ok(CreateClusterReplicaV1 {
520            cluster_id: proto.cluster_id,
521            cluster_name: proto.cluster_name,
522            replica_id: proto.replica_id.map(|id| id.inner),
523            replica_name: proto.replica_name,
524            logical_size: proto.logical_size,
525            disk: proto.disk,
526            billed_as: proto.billed_as,
527            internal: proto.internal,
528        })
529    }
530}
531
532impl RustType<proto::audit_log_event_v1::CreateClusterReplicaV2> for CreateClusterReplicaV2 {
533    fn into_proto(&self) -> proto::audit_log_event_v1::CreateClusterReplicaV2 {
534        proto::audit_log_event_v1::CreateClusterReplicaV2 {
535            cluster_id: self.cluster_id.to_string(),
536            cluster_name: self.cluster_name.to_string(),
537            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
538                inner: id.to_string(),
539            }),
540            replica_name: self.replica_name.to_string(),
541            logical_size: self.logical_size.to_string(),
542            disk: self.disk,
543            billed_as: self.billed_as.clone(),
544            internal: self.internal,
545            reason: self.reason.into_proto(),
546            scheduling_policies: self.scheduling_policies.into_proto(),
547        }
548    }
549
550    fn from_proto(
551        proto: proto::audit_log_event_v1::CreateClusterReplicaV2,
552    ) -> Result<Self, TryFromProtoError> {
553        Ok(CreateClusterReplicaV2 {
554            cluster_id: proto.cluster_id,
555            cluster_name: proto.cluster_name,
556            replica_id: proto.replica_id.map(|id| id.inner),
557            replica_name: proto.replica_name,
558            logical_size: proto.logical_size,
559            disk: proto.disk,
560            billed_as: proto.billed_as,
561            internal: proto.internal,
562            reason: proto.reason.into_rust()?,
563            scheduling_policies: proto.scheduling_policies.into_rust()?,
564        })
565    }
566}
567
568impl RustType<proto::audit_log_event_v1::CreateClusterReplicaV3> for CreateClusterReplicaV3 {
569    fn into_proto(&self) -> proto::audit_log_event_v1::CreateClusterReplicaV3 {
570        proto::audit_log_event_v1::CreateClusterReplicaV3 {
571            cluster_id: self.cluster_id.to_string(),
572            cluster_name: self.cluster_name.to_string(),
573            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
574                inner: id.to_string(),
575            }),
576            replica_name: self.replica_name.to_string(),
577            logical_size: self.logical_size.to_string(),
578            disk: self.disk,
579            billed_as: self.billed_as.clone(),
580            internal: self.internal,
581            reason: self.reason.into_proto(),
582            scheduling_policies: self.scheduling_policies.into_proto(),
583        }
584    }
585
586    fn from_proto(
587        proto: proto::audit_log_event_v1::CreateClusterReplicaV3,
588    ) -> Result<Self, TryFromProtoError> {
589        Ok(CreateClusterReplicaV3 {
590            cluster_id: proto.cluster_id,
591            cluster_name: proto.cluster_name,
592            replica_id: proto.replica_id.map(|id| id.inner),
593            replica_name: proto.replica_name,
594            logical_size: proto.logical_size,
595            disk: proto.disk,
596            billed_as: proto.billed_as,
597            internal: proto.internal,
598            reason: proto.reason.into_rust()?,
599            scheduling_policies: proto.scheduling_policies.into_rust()?,
600        })
601    }
602}
603
604impl RustType<proto::audit_log_event_v1::CreateClusterReplicaV4> for CreateClusterReplicaV4 {
605    fn into_proto(&self) -> proto::audit_log_event_v1::CreateClusterReplicaV4 {
606        proto::audit_log_event_v1::CreateClusterReplicaV4 {
607            cluster_id: self.cluster_id.to_string(),
608            cluster_name: self.cluster_name.to_string(),
609            replica_id: self.replica_id.as_ref().map(|id| proto::StringWrapper {
610                inner: id.to_string(),
611            }),
612            replica_name: self.replica_name.to_string(),
613            logical_size: self.logical_size.to_string(),
614            billed_as: self.billed_as.clone(),
615            internal: self.internal,
616            reason: self.reason.into_proto(),
617            scheduling_policies: self.scheduling_policies.into_proto(),
618        }
619    }
620
621    fn from_proto(
622        proto: proto::audit_log_event_v1::CreateClusterReplicaV4,
623    ) -> Result<Self, TryFromProtoError> {
624        Ok(CreateClusterReplicaV4 {
625            cluster_id: proto.cluster_id,
626            cluster_name: proto.cluster_name,
627            replica_id: proto.replica_id.map(|id| id.inner),
628            replica_name: proto.replica_name,
629            logical_size: proto.logical_size,
630            billed_as: proto.billed_as,
631            internal: proto.internal,
632            reason: proto.reason.into_rust()?,
633            scheduling_policies: proto.scheduling_policies.into_rust()?,
634        })
635    }
636}
637
638impl RustType<proto::audit_log_event_v1::CreateOrDropClusterReplicaReasonV1>
639    for CreateOrDropClusterReplicaReasonV1
640{
641    fn into_proto(&self) -> proto::audit_log_event_v1::CreateOrDropClusterReplicaReasonV1 {
642        match self {
643            CreateOrDropClusterReplicaReasonV1::Manual => {
644                use proto::audit_log_event_v1 as ev;
645                ev::CreateOrDropClusterReplicaReasonV1 {
646                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::Manual(Empty {}),
647                }
648            }
649            CreateOrDropClusterReplicaReasonV1::Schedule => {
650                use proto::audit_log_event_v1 as ev;
651                ev::CreateOrDropClusterReplicaReasonV1 {
652                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::Schedule(Empty {}),
653                }
654            }
655            CreateOrDropClusterReplicaReasonV1::System => {
656                use proto::audit_log_event_v1 as ev;
657                ev::CreateOrDropClusterReplicaReasonV1 {
658                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::System(Empty {}),
659                }
660            }
661            CreateOrDropClusterReplicaReasonV1::Reconfiguration => {
662                use proto::audit_log_event_v1 as ev;
663                ev::CreateOrDropClusterReplicaReasonV1 {
664                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::Reconfiguration(Empty {}),
665                }
666            }
667            CreateOrDropClusterReplicaReasonV1::HydrationBurst => {
668                use proto::audit_log_event_v1 as ev;
669                ev::CreateOrDropClusterReplicaReasonV1 {
670                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::HydrationBurst(Empty {}),
671                }
672            }
673            CreateOrDropClusterReplicaReasonV1::Retired => {
674                use proto::audit_log_event_v1 as ev;
675                ev::CreateOrDropClusterReplicaReasonV1 {
676                    reason: ev::CreateOrDropClusterReplicaReasonV1Reason::Retired(Empty {}),
677                }
678            }
679        }
680    }
681
682    fn from_proto(
683        proto: proto::audit_log_event_v1::CreateOrDropClusterReplicaReasonV1,
684    ) -> Result<Self, TryFromProtoError> {
685        use proto::audit_log_event_v1::CreateOrDropClusterReplicaReasonV1Reason as Reason;
686        match proto.reason {
687            Reason::Manual(Empty {}) => Ok(CreateOrDropClusterReplicaReasonV1::Manual),
688            Reason::Schedule(Empty {}) => Ok(CreateOrDropClusterReplicaReasonV1::Schedule),
689            Reason::System(Empty {}) => Ok(CreateOrDropClusterReplicaReasonV1::System),
690            Reason::Reconfiguration(Empty {}) => {
691                Ok(CreateOrDropClusterReplicaReasonV1::Reconfiguration)
692            }
693            Reason::HydrationBurst(Empty {}) => {
694                Ok(CreateOrDropClusterReplicaReasonV1::HydrationBurst)
695            }
696            Reason::Retired(Empty {}) => Ok(CreateOrDropClusterReplicaReasonV1::Retired),
697        }
698    }
699}
700
701impl RustType<proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV1>
702    for SchedulingDecisionsWithReasonsV1
703{
704    fn into_proto(&self) -> proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV1 {
705        proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV1 {
706            on_refresh: self.on_refresh.into_proto(),
707        }
708    }
709
710    fn from_proto(
711        proto: proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV1,
712    ) -> Result<Self, TryFromProtoError> {
713        Ok(SchedulingDecisionsWithReasonsV1 {
714            on_refresh: proto.on_refresh.into_rust()?,
715        })
716    }
717}
718
719impl RustType<proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV2>
720    for SchedulingDecisionsWithReasonsV2
721{
722    fn into_proto(&self) -> proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV2 {
723        proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV2 {
724            on_refresh: self.on_refresh.into_proto(),
725        }
726    }
727
728    fn from_proto(
729        proto: proto::audit_log_event_v1::SchedulingDecisionsWithReasonsV2,
730    ) -> Result<Self, TryFromProtoError> {
731        Ok(SchedulingDecisionsWithReasonsV2 {
732            on_refresh: proto.on_refresh.into_rust()?,
733        })
734    }
735}
736
737impl RustType<proto::audit_log_event_v1::RefreshDecisionWithReasonV1>
738    for RefreshDecisionWithReasonV1
739{
740    fn into_proto(&self) -> proto::audit_log_event_v1::RefreshDecisionWithReasonV1 {
741        let decision = match &self.decision {
742            SchedulingDecisionV1::On => proto::audit_log_event_v1::RefreshDecision::On(Empty {}),
743            SchedulingDecisionV1::Off => proto::audit_log_event_v1::RefreshDecision::Off(Empty {}),
744        };
745        proto::audit_log_event_v1::RefreshDecisionWithReasonV1 {
746            decision,
747            objects_needing_refresh: self.objects_needing_refresh.clone(),
748            rehydration_time_estimate: self.hydration_time_estimate.clone(),
749        }
750    }
751
752    fn from_proto(
753        proto: proto::audit_log_event_v1::RefreshDecisionWithReasonV1,
754    ) -> Result<Self, TryFromProtoError> {
755        let decision = match proto.decision {
756            proto::audit_log_event_v1::RefreshDecision::On(Empty {}) => SchedulingDecisionV1::On,
757            proto::audit_log_event_v1::RefreshDecision::Off(Empty {}) => SchedulingDecisionV1::Off,
758        };
759        Ok(RefreshDecisionWithReasonV1 {
760            decision,
761            objects_needing_refresh: proto.objects_needing_refresh,
762            hydration_time_estimate: proto.rehydration_time_estimate,
763        })
764    }
765}
766
767impl RustType<proto::audit_log_event_v1::RefreshDecisionWithReasonV2>
768    for RefreshDecisionWithReasonV2
769{
770    fn into_proto(&self) -> proto::audit_log_event_v1::RefreshDecisionWithReasonV2 {
771        let decision = match &self.decision {
772            SchedulingDecisionV1::On => proto::audit_log_event_v1::RefreshDecision::On(Empty {}),
773            SchedulingDecisionV1::Off => proto::audit_log_event_v1::RefreshDecision::Off(Empty {}),
774        };
775        proto::audit_log_event_v1::RefreshDecisionWithReasonV2 {
776            decision,
777            objects_needing_refresh: self.objects_needing_refresh.clone(),
778            objects_needing_compaction: self.objects_needing_compaction.clone(),
779            rehydration_time_estimate: self.hydration_time_estimate.clone(),
780        }
781    }
782
783    fn from_proto(
784        proto: proto::audit_log_event_v1::RefreshDecisionWithReasonV2,
785    ) -> Result<Self, TryFromProtoError> {
786        let decision = match proto.decision {
787            proto::audit_log_event_v1::RefreshDecision::On(Empty {}) => SchedulingDecisionV1::On,
788            proto::audit_log_event_v1::RefreshDecision::Off(Empty {}) => SchedulingDecisionV1::Off,
789        };
790        Ok(RefreshDecisionWithReasonV2 {
791            decision,
792            objects_needing_refresh: proto.objects_needing_refresh,
793            objects_needing_compaction: proto.objects_needing_compaction,
794            hydration_time_estimate: proto.rehydration_time_estimate,
795        })
796    }
797}
798
799impl RustType<proto::audit_log_event_v1::CreateSourceSinkV1> for CreateSourceSinkV1 {
800    fn into_proto(&self) -> proto::audit_log_event_v1::CreateSourceSinkV1 {
801        proto::audit_log_event_v1::CreateSourceSinkV1 {
802            id: self.id.to_string(),
803            name: self.name.into_proto(),
804            size: self.size.as_ref().map(|s| proto::StringWrapper {
805                inner: s.to_string(),
806            }),
807        }
808    }
809
810    fn from_proto(
811        proto: proto::audit_log_event_v1::CreateSourceSinkV1,
812    ) -> Result<Self, TryFromProtoError> {
813        Ok(CreateSourceSinkV1 {
814            id: proto.id,
815            name: proto.name.into_rust()?,
816            size: proto.size.map(|s| s.inner),
817        })
818    }
819}
820
821impl RustType<proto::audit_log_event_v1::CreateSourceSinkV2> for CreateSourceSinkV2 {
822    fn into_proto(&self) -> proto::audit_log_event_v1::CreateSourceSinkV2 {
823        proto::audit_log_event_v1::CreateSourceSinkV2 {
824            id: self.id.to_string(),
825            name: self.name.into_proto(),
826            size: self.size.as_ref().map(|s| proto::StringWrapper {
827                inner: s.to_string(),
828            }),
829            external_type: self.external_type.to_string(),
830        }
831    }
832
833    fn from_proto(
834        proto: proto::audit_log_event_v1::CreateSourceSinkV2,
835    ) -> Result<Self, TryFromProtoError> {
836        Ok(CreateSourceSinkV2 {
837            id: proto.id,
838            name: proto.name.into_rust()?,
839            size: proto.size.map(|s| s.inner),
840            external_type: proto.external_type,
841        })
842    }
843}
844
845impl RustType<proto::audit_log_event_v1::CreateSourceSinkV3> for CreateSourceSinkV3 {
846    fn into_proto(&self) -> proto::audit_log_event_v1::CreateSourceSinkV3 {
847        proto::audit_log_event_v1::CreateSourceSinkV3 {
848            id: self.id.to_string(),
849            name: self.name.into_proto(),
850            external_type: self.external_type.to_string(),
851        }
852    }
853
854    fn from_proto(
855        proto: proto::audit_log_event_v1::CreateSourceSinkV3,
856    ) -> Result<Self, TryFromProtoError> {
857        Ok(CreateSourceSinkV3 {
858            id: proto.id,
859            name: proto.name.into_rust()?,
860            external_type: proto.external_type,
861        })
862    }
863}
864
865impl RustType<proto::audit_log_event_v1::CreateSourceSinkV4> for CreateSourceSinkV4 {
866    fn into_proto(&self) -> proto::audit_log_event_v1::CreateSourceSinkV4 {
867        proto::audit_log_event_v1::CreateSourceSinkV4 {
868            id: self.id.to_string(),
869            cluster_id: self.cluster_id.as_ref().map(|id| proto::StringWrapper {
870                inner: id.to_string(),
871            }),
872            name: self.name.into_proto(),
873            external_type: self.external_type.to_string(),
874        }
875    }
876
877    fn from_proto(
878        proto: proto::audit_log_event_v1::CreateSourceSinkV4,
879    ) -> Result<Self, TryFromProtoError> {
880        Ok(CreateSourceSinkV4 {
881            id: proto.id,
882            cluster_id: proto.cluster_id.map(|s| s.inner),
883            name: proto.name.into_rust()?,
884            external_type: proto.external_type,
885        })
886    }
887}
888
889impl RustType<proto::audit_log_event_v1::CreateIndexV1> for CreateIndexV1 {
890    fn into_proto(&self) -> proto::audit_log_event_v1::CreateIndexV1 {
891        proto::audit_log_event_v1::CreateIndexV1 {
892            id: self.id.to_string(),
893            cluster_id: self.cluster_id.to_string(),
894            name: self.name.into_proto(),
895        }
896    }
897
898    fn from_proto(
899        proto: proto::audit_log_event_v1::CreateIndexV1,
900    ) -> Result<Self, TryFromProtoError> {
901        Ok(CreateIndexV1 {
902            id: proto.id,
903            cluster_id: proto.cluster_id,
904            name: proto.name.into_rust()?,
905        })
906    }
907}
908
909impl RustType<proto::audit_log_event_v1::CreateMaterializedViewV1> for CreateMaterializedViewV1 {
910    fn into_proto(&self) -> proto::audit_log_event_v1::CreateMaterializedViewV1 {
911        proto::audit_log_event_v1::CreateMaterializedViewV1 {
912            id: self.id.to_string(),
913            cluster_id: self.cluster_id.to_string(),
914            name: self.name.into_proto(),
915            replacement_target_id: self.replacement_target_id.into_proto(),
916        }
917    }
918
919    fn from_proto(
920        proto: proto::audit_log_event_v1::CreateMaterializedViewV1,
921    ) -> Result<Self, TryFromProtoError> {
922        Ok(CreateMaterializedViewV1 {
923            id: proto.id,
924            cluster_id: proto.cluster_id,
925            name: proto.name.into_rust()?,
926            replacement_target_id: proto.replacement_target_id,
927        })
928    }
929}
930
931impl RustType<proto::audit_log_event_v1::AlterApplyReplacementV1> for AlterApplyReplacementV1 {
932    fn into_proto(&self) -> proto::audit_log_event_v1::AlterApplyReplacementV1 {
933        proto::audit_log_event_v1::AlterApplyReplacementV1 {
934            target: self.target.into_proto(),
935            replacement: self.replacement.into_proto(),
936        }
937    }
938
939    fn from_proto(
940        proto: proto::audit_log_event_v1::AlterApplyReplacementV1,
941    ) -> Result<Self, TryFromProtoError> {
942        Ok(AlterApplyReplacementV1 {
943            target: proto.target.into_rust()?,
944            replacement: proto.replacement.into_rust()?,
945        })
946    }
947}
948
949impl RustType<proto::audit_log_event_v1::AlterSourceSinkV1> for AlterSourceSinkV1 {
950    fn into_proto(&self) -> proto::audit_log_event_v1::AlterSourceSinkV1 {
951        proto::audit_log_event_v1::AlterSourceSinkV1 {
952            id: self.id.to_string(),
953            name: self.name.into_proto(),
954            old_size: self.old_size.as_ref().map(|s| proto::StringWrapper {
955                inner: s.to_string(),
956            }),
957            new_size: self.new_size.as_ref().map(|s| proto::StringWrapper {
958                inner: s.to_string(),
959            }),
960        }
961    }
962
963    fn from_proto(
964        proto: proto::audit_log_event_v1::AlterSourceSinkV1,
965    ) -> Result<Self, TryFromProtoError> {
966        Ok(AlterSourceSinkV1 {
967            id: proto.id,
968            name: proto.name.into_rust()?,
969            old_size: proto.old_size.map(|s| s.inner),
970            new_size: proto.new_size.map(|s| s.inner),
971        })
972    }
973}
974
975impl RustType<proto::audit_log_event_v1::AlterSetClusterV1> for AlterSetClusterV1 {
976    fn into_proto(&self) -> proto::audit_log_event_v1::AlterSetClusterV1 {
977        proto::audit_log_event_v1::AlterSetClusterV1 {
978            id: self.id.to_string(),
979            name: self.name.into_proto(),
980            old_cluster_id: self.old_cluster_id.into_proto(),
981            new_cluster_id: self.new_cluster_id.into_proto(),
982        }
983    }
984
985    fn from_proto(
986        proto: proto::audit_log_event_v1::AlterSetClusterV1,
987    ) -> Result<Self, TryFromProtoError> {
988        Ok(Self {
989            id: proto.id,
990            name: proto.name.into_rust()?,
991            old_cluster_id: proto.old_cluster_id,
992            new_cluster_id: proto.new_cluster_id,
993        })
994    }
995}
996
997impl RustType<proto::audit_log_event_v1::GrantRoleV1> for GrantRoleV1 {
998    fn into_proto(&self) -> proto::audit_log_event_v1::GrantRoleV1 {
999        proto::audit_log_event_v1::GrantRoleV1 {
1000            role_id: self.role_id.to_string(),
1001            member_id: self.member_id.to_string(),
1002            grantor_id: self.grantor_id.to_string(),
1003        }
1004    }
1005
1006    fn from_proto(
1007        proto: proto::audit_log_event_v1::GrantRoleV1,
1008    ) -> Result<Self, TryFromProtoError> {
1009        Ok(GrantRoleV1 {
1010            role_id: proto.role_id,
1011            member_id: proto.member_id,
1012            grantor_id: proto.grantor_id,
1013        })
1014    }
1015}
1016
1017impl RustType<proto::audit_log_event_v1::GrantRoleV2> for GrantRoleV2 {
1018    fn into_proto(&self) -> proto::audit_log_event_v1::GrantRoleV2 {
1019        proto::audit_log_event_v1::GrantRoleV2 {
1020            role_id: self.role_id.to_string(),
1021            member_id: self.member_id.to_string(),
1022            grantor_id: self.grantor_id.to_string(),
1023            executed_by: self.executed_by.to_string(),
1024        }
1025    }
1026
1027    fn from_proto(
1028        proto: proto::audit_log_event_v1::GrantRoleV2,
1029    ) -> Result<Self, TryFromProtoError> {
1030        Ok(GrantRoleV2 {
1031            role_id: proto.role_id,
1032            member_id: proto.member_id,
1033            grantor_id: proto.grantor_id,
1034            executed_by: proto.executed_by,
1035        })
1036    }
1037}
1038
1039impl RustType<proto::audit_log_event_v1::RevokeRoleV1> for RevokeRoleV1 {
1040    fn into_proto(&self) -> proto::audit_log_event_v1::RevokeRoleV1 {
1041        proto::audit_log_event_v1::RevokeRoleV1 {
1042            role_id: self.role_id.to_string(),
1043            member_id: self.member_id.to_string(),
1044        }
1045    }
1046
1047    fn from_proto(
1048        proto: proto::audit_log_event_v1::RevokeRoleV1,
1049    ) -> Result<Self, TryFromProtoError> {
1050        Ok(RevokeRoleV1 {
1051            role_id: proto.role_id,
1052            member_id: proto.member_id,
1053        })
1054    }
1055}
1056
1057impl RustType<proto::audit_log_event_v1::RevokeRoleV2> for RevokeRoleV2 {
1058    fn into_proto(&self) -> proto::audit_log_event_v1::RevokeRoleV2 {
1059        proto::audit_log_event_v1::RevokeRoleV2 {
1060            role_id: self.role_id.to_string(),
1061            member_id: self.member_id.to_string(),
1062            grantor_id: self.grantor_id.to_string(),
1063            executed_by: self.executed_by.to_string(),
1064        }
1065    }
1066
1067    fn from_proto(
1068        proto: proto::audit_log_event_v1::RevokeRoleV2,
1069    ) -> Result<Self, TryFromProtoError> {
1070        Ok(RevokeRoleV2 {
1071            role_id: proto.role_id,
1072            member_id: proto.member_id,
1073            grantor_id: proto.grantor_id,
1074            executed_by: proto.executed_by,
1075        })
1076    }
1077}
1078
1079impl RustType<proto::audit_log_event_v1::UpdatePrivilegeV1> for UpdatePrivilegeV1 {
1080    fn into_proto(&self) -> proto::audit_log_event_v1::UpdatePrivilegeV1 {
1081        proto::audit_log_event_v1::UpdatePrivilegeV1 {
1082            object_id: self.object_id.to_string(),
1083            grantee_id: self.grantee_id.to_string(),
1084            grantor_id: self.grantor_id.to_string(),
1085            privileges: self.privileges.to_string(),
1086        }
1087    }
1088
1089    fn from_proto(
1090        proto: proto::audit_log_event_v1::UpdatePrivilegeV1,
1091    ) -> Result<Self, TryFromProtoError> {
1092        Ok(UpdatePrivilegeV1 {
1093            object_id: proto.object_id,
1094            grantee_id: proto.grantee_id,
1095            grantor_id: proto.grantor_id,
1096            privileges: proto.privileges,
1097        })
1098    }
1099}
1100
1101impl RustType<proto::audit_log_event_v1::AlterDefaultPrivilegeV1> for AlterDefaultPrivilegeV1 {
1102    fn into_proto(&self) -> proto::audit_log_event_v1::AlterDefaultPrivilegeV1 {
1103        proto::audit_log_event_v1::AlterDefaultPrivilegeV1 {
1104            role_id: self.role_id.to_string(),
1105            database_id: self.database_id.as_ref().map(|id| proto::StringWrapper {
1106                inner: id.to_string(),
1107            }),
1108            schema_id: self.schema_id.as_ref().map(|id| proto::StringWrapper {
1109                inner: id.to_string(),
1110            }),
1111            grantee_id: self.grantee_id.to_string(),
1112            privileges: self.privileges.to_string(),
1113        }
1114    }
1115
1116    fn from_proto(
1117        proto: proto::audit_log_event_v1::AlterDefaultPrivilegeV1,
1118    ) -> Result<Self, TryFromProtoError> {
1119        Ok(AlterDefaultPrivilegeV1 {
1120            role_id: proto.role_id,
1121            database_id: proto.database_id.map(|id| id.inner),
1122            schema_id: proto.schema_id.map(|id| id.inner),
1123            grantee_id: proto.grantee_id,
1124            privileges: proto.privileges,
1125        })
1126    }
1127}
1128
1129impl RustType<proto::audit_log_event_v1::UpdateOwnerV1> for UpdateOwnerV1 {
1130    fn into_proto(&self) -> proto::audit_log_event_v1::UpdateOwnerV1 {
1131        proto::audit_log_event_v1::UpdateOwnerV1 {
1132            object_id: self.object_id.to_string(),
1133            old_owner_id: self.old_owner_id.to_string(),
1134            new_owner_id: self.new_owner_id.to_string(),
1135        }
1136    }
1137
1138    fn from_proto(
1139        proto: proto::audit_log_event_v1::UpdateOwnerV1,
1140    ) -> Result<Self, TryFromProtoError> {
1141        Ok(UpdateOwnerV1 {
1142            object_id: proto.object_id,
1143            old_owner_id: proto.old_owner_id,
1144            new_owner_id: proto.new_owner_id,
1145        })
1146    }
1147}
1148
1149impl RustType<proto::audit_log_event_v1::SchemaV1> for SchemaV1 {
1150    fn into_proto(&self) -> proto::audit_log_event_v1::SchemaV1 {
1151        proto::audit_log_event_v1::SchemaV1 {
1152            id: self.id.to_string(),
1153            name: self.name.to_string(),
1154            database_name: self.database_name.to_string(),
1155        }
1156    }
1157
1158    fn from_proto(proto: proto::audit_log_event_v1::SchemaV1) -> Result<Self, TryFromProtoError> {
1159        Ok(SchemaV1 {
1160            id: proto.id,
1161            name: proto.name,
1162            database_name: proto.database_name,
1163        })
1164    }
1165}
1166
1167impl RustType<proto::audit_log_event_v1::SchemaV2> for SchemaV2 {
1168    fn into_proto(&self) -> proto::audit_log_event_v1::SchemaV2 {
1169        proto::audit_log_event_v1::SchemaV2 {
1170            id: self.id.to_string(),
1171            name: self.name.to_string(),
1172            database_name: self.database_name.as_ref().map(|d| proto::StringWrapper {
1173                inner: d.to_string(),
1174            }),
1175        }
1176    }
1177
1178    fn from_proto(proto: proto::audit_log_event_v1::SchemaV2) -> Result<Self, TryFromProtoError> {
1179        Ok(SchemaV2 {
1180            id: proto.id,
1181            name: proto.name,
1182            database_name: proto.database_name.map(|d| d.inner),
1183        })
1184    }
1185}
1186
1187impl RustType<proto::audit_log_event_v1::RenameSchemaV1> for RenameSchemaV1 {
1188    fn into_proto(&self) -> proto::audit_log_event_v1::RenameSchemaV1 {
1189        proto::audit_log_event_v1::RenameSchemaV1 {
1190            id: self.id.to_string(),
1191            database_name: self.database_name.clone(),
1192            old_name: self.old_name.clone(),
1193            new_name: self.new_name.clone(),
1194        }
1195    }
1196
1197    fn from_proto(
1198        proto: proto::audit_log_event_v1::RenameSchemaV1,
1199    ) -> Result<Self, TryFromProtoError> {
1200        Ok(RenameSchemaV1 {
1201            id: proto.id,
1202            database_name: proto.database_name,
1203            old_name: proto.old_name,
1204            new_name: proto.new_name,
1205        })
1206    }
1207}
1208
1209impl RustType<proto::audit_log_event_v1::UpdateItemV1> for UpdateItemV1 {
1210    fn into_proto(&self) -> proto::audit_log_event_v1::UpdateItemV1 {
1211        proto::audit_log_event_v1::UpdateItemV1 {
1212            id: self.id.to_string(),
1213            name: self.name.into_proto(),
1214        }
1215    }
1216
1217    fn from_proto(
1218        proto: proto::audit_log_event_v1::UpdateItemV1,
1219    ) -> Result<Self, TryFromProtoError> {
1220        Ok(UpdateItemV1 {
1221            id: proto.id,
1222            name: proto.name.into_rust()?,
1223        })
1224    }
1225}
1226
1227impl RustType<proto::audit_log_event_v1::AlterRetainHistoryV1> for AlterRetainHistoryV1 {
1228    fn into_proto(&self) -> proto::audit_log_event_v1::AlterRetainHistoryV1 {
1229        proto::audit_log_event_v1::AlterRetainHistoryV1 {
1230            id: self.id.to_string(),
1231            old_history: self.old_history.clone(),
1232            new_history: self.new_history.clone(),
1233        }
1234    }
1235
1236    fn from_proto(
1237        proto: proto::audit_log_event_v1::AlterRetainHistoryV1,
1238    ) -> Result<Self, TryFromProtoError> {
1239        Ok(AlterRetainHistoryV1 {
1240            id: proto.id,
1241            old_history: proto.old_history,
1242            new_history: proto.new_history,
1243        })
1244    }
1245}
1246
1247impl RustType<proto::audit_log_event_v1::AlterAddColumnV1> for AlterAddColumnV1 {
1248    fn into_proto(&self) -> proto::audit_log_event_v1::AlterAddColumnV1 {
1249        proto::audit_log_event_v1::AlterAddColumnV1 {
1250            id: self.id.to_string(),
1251            column: self.column.clone(),
1252            column_type: self.column_type.clone(),
1253            nullable: self.nullable,
1254        }
1255    }
1256
1257    fn from_proto(
1258        proto: proto::audit_log_event_v1::AlterAddColumnV1,
1259    ) -> Result<Self, TryFromProtoError> {
1260        Ok(AlterAddColumnV1 {
1261            id: proto.id,
1262            column: proto.column,
1263            column_type: proto.column_type,
1264            nullable: proto.nullable,
1265        })
1266    }
1267}
1268
1269impl RustType<proto::audit_log_event_v1::AlterSourceTimestampIntervalV1>
1270    for AlterSourceTimestampIntervalV1
1271{
1272    fn into_proto(&self) -> proto::audit_log_event_v1::AlterSourceTimestampIntervalV1 {
1273        proto::audit_log_event_v1::AlterSourceTimestampIntervalV1 {
1274            id: self.id.to_string(),
1275            old_interval: self.old_interval.clone(),
1276            new_interval: self.new_interval.clone(),
1277        }
1278    }
1279
1280    fn from_proto(
1281        proto: proto::audit_log_event_v1::AlterSourceTimestampIntervalV1,
1282    ) -> Result<Self, TryFromProtoError> {
1283        Ok(AlterSourceTimestampIntervalV1 {
1284            id: proto.id,
1285            old_interval: proto.old_interval,
1286            new_interval: proto.new_interval,
1287        })
1288    }
1289}
1290
1291impl RustType<proto::audit_log_event_v1::ToNewIdV1> for ToNewIdV1 {
1292    fn into_proto(&self) -> proto::audit_log_event_v1::ToNewIdV1 {
1293        proto::audit_log_event_v1::ToNewIdV1 {
1294            id: self.id.to_string(),
1295            new_id: self.new_id.to_string(),
1296        }
1297    }
1298
1299    fn from_proto(proto: proto::audit_log_event_v1::ToNewIdV1) -> Result<Self, TryFromProtoError> {
1300        Ok(ToNewIdV1 {
1301            id: proto.id,
1302            new_id: proto.new_id,
1303        })
1304    }
1305}
1306
1307impl RustType<proto::audit_log_event_v1::FromPreviousIdV1> for FromPreviousIdV1 {
1308    fn into_proto(&self) -> proto::audit_log_event_v1::FromPreviousIdV1 {
1309        proto::audit_log_event_v1::FromPreviousIdV1 {
1310            id: self.id.to_string(),
1311            previous_id: self.previous_id.to_string(),
1312        }
1313    }
1314
1315    fn from_proto(
1316        proto: proto::audit_log_event_v1::FromPreviousIdV1,
1317    ) -> Result<Self, TryFromProtoError> {
1318        Ok(FromPreviousIdV1 {
1319            id: proto.id,
1320            previous_id: proto.previous_id,
1321        })
1322    }
1323}
1324
1325impl RustType<proto::audit_log_event_v1::SetV1> for SetV1 {
1326    fn into_proto(&self) -> proto::audit_log_event_v1::SetV1 {
1327        proto::audit_log_event_v1::SetV1 {
1328            name: self.name.clone(),
1329            value: self.value.clone(),
1330        }
1331    }
1332
1333    fn from_proto(proto: proto::audit_log_event_v1::SetV1) -> Result<Self, TryFromProtoError> {
1334        Ok(SetV1 {
1335            name: proto.name,
1336            value: proto.value,
1337        })
1338    }
1339}
1340
1341impl RustType<proto::audit_log_event_v1::RotateKeysV1> for RotateKeysV1 {
1342    fn into_proto(&self) -> proto::audit_log_event_v1::RotateKeysV1 {
1343        proto::audit_log_event_v1::RotateKeysV1 {
1344            id: self.id.clone(),
1345            name: self.name.clone(),
1346        }
1347    }
1348
1349    fn from_proto(
1350        proto: proto::audit_log_event_v1::RotateKeysV1,
1351    ) -> Result<Self, TryFromProtoError> {
1352        Ok(RotateKeysV1 {
1353            id: proto.id,
1354            name: proto.name,
1355        })
1356    }
1357}
1358
1359impl RustType<proto::audit_log_event_v1::CreateRoleV1> for CreateRoleV1 {
1360    fn into_proto(&self) -> proto::audit_log_event_v1::CreateRoleV1 {
1361        proto::audit_log_event_v1::CreateRoleV1 {
1362            id: self.id.clone(),
1363            name: self.name.clone(),
1364            auto_provision_source: self.auto_provision_source.clone(),
1365        }
1366    }
1367
1368    fn from_proto(
1369        proto: proto::audit_log_event_v1::CreateRoleV1,
1370    ) -> Result<Self, TryFromProtoError> {
1371        Ok(CreateRoleV1 {
1372            id: proto.id,
1373            name: proto.name,
1374            auto_provision_source: proto.auto_provision_source,
1375        })
1376    }
1377}
1378
1379impl RustType<proto::audit_log_event_v1::Details> for EventDetails {
1380    fn into_proto(&self) -> proto::audit_log_event_v1::Details {
1381        use proto::audit_log_event_v1::Details::*;
1382
1383        match self {
1384            EventDetails::CreateClusterReplicaV1(details) => {
1385                CreateClusterReplicaV1(details.into_proto())
1386            }
1387            EventDetails::CreateClusterReplicaV2(details) => {
1388                CreateClusterReplicaV2(details.into_proto())
1389            }
1390            EventDetails::CreateClusterReplicaV3(details) => {
1391                CreateClusterReplicaV3(details.into_proto())
1392            }
1393            EventDetails::CreateClusterReplicaV4(details) => {
1394                CreateClusterReplicaV4(details.into_proto())
1395            }
1396            EventDetails::DropClusterReplicaV1(details) => {
1397                DropClusterReplicaV1(details.into_proto())
1398            }
1399            EventDetails::DropClusterReplicaV2(details) => {
1400                DropClusterReplicaV2(details.into_proto())
1401            }
1402            EventDetails::DropClusterReplicaV3(details) => {
1403                DropClusterReplicaV3(details.into_proto())
1404            }
1405            EventDetails::CreateSourceSinkV1(details) => CreateSourceSinkV1(details.into_proto()),
1406            EventDetails::CreateSourceSinkV2(details) => CreateSourceSinkV2(details.into_proto()),
1407            EventDetails::CreateSourceSinkV3(details) => CreateSourceSinkV3(details.into_proto()),
1408            EventDetails::CreateSourceSinkV4(details) => CreateSourceSinkV4(details.into_proto()),
1409            EventDetails::CreateIndexV1(details) => CreateIndexV1(details.into_proto()),
1410            EventDetails::CreateMaterializedViewV1(details) => {
1411                CreateMaterializedViewV1(details.into_proto())
1412            }
1413            EventDetails::AlterApplyReplacementV1(details) => {
1414                AlterApplyReplacementV1(details.into_proto())
1415            }
1416            EventDetails::AlterSourceSinkV1(details) => AlterSourceSinkV1(details.into_proto()),
1417            EventDetails::AlterSetClusterV1(details) => AlterSetClusterV1(details.into_proto()),
1418            EventDetails::GrantRoleV1(details) => GrantRoleV1(details.into_proto()),
1419            EventDetails::GrantRoleV2(details) => GrantRoleV2(details.into_proto()),
1420            EventDetails::RevokeRoleV1(details) => RevokeRoleV1(details.into_proto()),
1421            EventDetails::RevokeRoleV2(details) => RevokeRoleV2(details.into_proto()),
1422            EventDetails::UpdatePrivilegeV1(details) => UpdatePrivilegeV1(details.into_proto()),
1423            EventDetails::AlterDefaultPrivilegeV1(details) => {
1424                AlterDefaultPrivilegeV1(details.into_proto())
1425            }
1426            EventDetails::UpdateOwnerV1(details) => UpdateOwnerV1(details.into_proto()),
1427            EventDetails::IdFullNameV1(details) => IdFullNameV1(details.into_proto()),
1428            EventDetails::RenameClusterV1(details) => RenameClusterV1(details.into_proto()),
1429            EventDetails::RenameClusterReplicaV1(details) => {
1430                RenameClusterReplicaV1(details.into_proto())
1431            }
1432            EventDetails::RenameItemV1(details) => RenameItemV1(details.into_proto()),
1433            EventDetails::IdNameV1(details) => IdNameV1(details.into_proto()),
1434            EventDetails::SchemaV1(details) => SchemaV1(details.into_proto()),
1435            EventDetails::SchemaV2(details) => SchemaV2(details.into_proto()),
1436            EventDetails::RenameSchemaV1(details) => RenameSchemaV1(details.into_proto()),
1437            EventDetails::UpdateItemV1(details) => UpdateItemV1(details.into_proto()),
1438            EventDetails::AlterRetainHistoryV1(details) => {
1439                AlterRetainHistoryV1(details.into_proto())
1440            }
1441            EventDetails::AlterAddColumnV1(details) => AlterAddColumnV1(details.into_proto()),
1442            EventDetails::AlterSourceTimestampIntervalV1(details) => {
1443                AlterSourceTimestampIntervalV1(details.into_proto())
1444            }
1445            EventDetails::AlterClusterReconfigurationV1(details) => {
1446                AlterClusterReconfigurationV1(details.into_proto())
1447            }
1448            EventDetails::ClusterHydrationBurstV1(details) => {
1449                ClusterHydrationBurstV1(details.into_proto())
1450            }
1451            EventDetails::ToNewIdV1(details) => ToNewIdV1(details.into_proto()),
1452            EventDetails::FromPreviousIdV1(details) => FromPreviousIdV1(details.into_proto()),
1453            EventDetails::SetV1(details) => SetV1(details.into_proto()),
1454            EventDetails::ResetAllV1 => ResetAllV1(Empty {}),
1455            EventDetails::RotateKeysV1(details) => RotateKeysV1(details.into_proto()),
1456            EventDetails::CreateRoleV1(details) => CreateRoleV1(details.into_proto()),
1457        }
1458    }
1459
1460    fn from_proto(proto: proto::audit_log_event_v1::Details) -> Result<Self, TryFromProtoError> {
1461        use proto::audit_log_event_v1::Details::*;
1462
1463        match proto {
1464            CreateClusterReplicaV1(details) => {
1465                Ok(EventDetails::CreateClusterReplicaV1(details.into_rust()?))
1466            }
1467            CreateClusterReplicaV2(details) => {
1468                Ok(EventDetails::CreateClusterReplicaV2(details.into_rust()?))
1469            }
1470            CreateClusterReplicaV3(details) => {
1471                Ok(EventDetails::CreateClusterReplicaV3(details.into_rust()?))
1472            }
1473            CreateClusterReplicaV4(details) => {
1474                Ok(EventDetails::CreateClusterReplicaV4(details.into_rust()?))
1475            }
1476            DropClusterReplicaV1(details) => {
1477                Ok(EventDetails::DropClusterReplicaV1(details.into_rust()?))
1478            }
1479            DropClusterReplicaV2(details) => {
1480                Ok(EventDetails::DropClusterReplicaV2(details.into_rust()?))
1481            }
1482            DropClusterReplicaV3(details) => {
1483                Ok(EventDetails::DropClusterReplicaV3(details.into_rust()?))
1484            }
1485            CreateSourceSinkV1(details) => {
1486                Ok(EventDetails::CreateSourceSinkV1(details.into_rust()?))
1487            }
1488            CreateSourceSinkV2(details) => {
1489                Ok(EventDetails::CreateSourceSinkV2(details.into_rust()?))
1490            }
1491            CreateSourceSinkV3(details) => {
1492                Ok(EventDetails::CreateSourceSinkV3(details.into_rust()?))
1493            }
1494            CreateSourceSinkV4(details) => {
1495                Ok(EventDetails::CreateSourceSinkV4(details.into_rust()?))
1496            }
1497            CreateIndexV1(details) => Ok(EventDetails::CreateIndexV1(details.into_rust()?)),
1498            CreateMaterializedViewV1(details) => {
1499                Ok(EventDetails::CreateMaterializedViewV1(details.into_rust()?))
1500            }
1501            AlterApplyReplacementV1(details) => {
1502                Ok(EventDetails::AlterApplyReplacementV1(details.into_rust()?))
1503            }
1504            AlterSourceSinkV1(details) => Ok(EventDetails::AlterSourceSinkV1(details.into_rust()?)),
1505            AlterSetClusterV1(details) => Ok(EventDetails::AlterSetClusterV1(details.into_rust()?)),
1506            GrantRoleV1(details) => Ok(EventDetails::GrantRoleV1(details.into_rust()?)),
1507            GrantRoleV2(details) => Ok(EventDetails::GrantRoleV2(details.into_rust()?)),
1508            RevokeRoleV1(details) => Ok(EventDetails::RevokeRoleV1(details.into_rust()?)),
1509            RevokeRoleV2(details) => Ok(EventDetails::RevokeRoleV2(details.into_rust()?)),
1510            UpdatePrivilegeV1(details) => Ok(EventDetails::UpdatePrivilegeV1(details.into_rust()?)),
1511            AlterDefaultPrivilegeV1(details) => {
1512                Ok(EventDetails::AlterDefaultPrivilegeV1(details.into_rust()?))
1513            }
1514            UpdateOwnerV1(details) => Ok(EventDetails::UpdateOwnerV1(details.into_rust()?)),
1515            IdFullNameV1(details) => Ok(EventDetails::IdFullNameV1(details.into_rust()?)),
1516            RenameClusterV1(details) => Ok(EventDetails::RenameClusterV1(details.into_rust()?)),
1517            RenameClusterReplicaV1(details) => {
1518                Ok(EventDetails::RenameClusterReplicaV1(details.into_rust()?))
1519            }
1520            RenameItemV1(details) => Ok(EventDetails::RenameItemV1(details.into_rust()?)),
1521            IdNameV1(details) => Ok(EventDetails::IdNameV1(details.into_rust()?)),
1522            SchemaV1(details) => Ok(EventDetails::SchemaV1(details.into_rust()?)),
1523            SchemaV2(details) => Ok(EventDetails::SchemaV2(details.into_rust()?)),
1524            RenameSchemaV1(details) => Ok(EventDetails::RenameSchemaV1(details.into_rust()?)),
1525            UpdateItemV1(details) => Ok(EventDetails::UpdateItemV1(details.into_rust()?)),
1526            AlterRetainHistoryV1(details) => {
1527                Ok(EventDetails::AlterRetainHistoryV1(details.into_rust()?))
1528            }
1529            ToNewIdV1(details) => Ok(EventDetails::ToNewIdV1(details.into_rust()?)),
1530            FromPreviousIdV1(details) => Ok(EventDetails::FromPreviousIdV1(details.into_rust()?)),
1531            SetV1(details) => Ok(EventDetails::SetV1(details.into_rust()?)),
1532            ResetAllV1(Empty {}) => Ok(EventDetails::ResetAllV1),
1533            RotateKeysV1(details) => Ok(EventDetails::RotateKeysV1(details.into_rust()?)),
1534            CreateRoleV1(details) => Ok(EventDetails::CreateRoleV1(details.into_rust()?)),
1535            AlterAddColumnV1(details) => Ok(EventDetails::AlterAddColumnV1(details.into_rust()?)),
1536            AlterSourceTimestampIntervalV1(details) => Ok(
1537                EventDetails::AlterSourceTimestampIntervalV1(details.into_rust()?),
1538            ),
1539            AlterClusterReconfigurationV1(details) => Ok(
1540                EventDetails::AlterClusterReconfigurationV1(details.into_rust()?),
1541            ),
1542            ClusterHydrationBurstV1(details) => {
1543                Ok(EventDetails::ClusterHydrationBurstV1(details.into_rust()?))
1544            }
1545        }
1546    }
1547}
1548
1549impl RustType<proto::AuditLogEventV1> for EventV1 {
1550    fn into_proto(&self) -> proto::AuditLogEventV1 {
1551        proto::AuditLogEventV1 {
1552            id: self.id,
1553            event_type: self.event_type.into_proto(),
1554            object_type: self.object_type.into_proto(),
1555            user: self.user.as_ref().map(|u| proto::StringWrapper {
1556                inner: u.to_string(),
1557            }),
1558            occurred_at: proto::EpochMillis {
1559                millis: self.occurred_at,
1560            },
1561            details: self.details.into_proto(),
1562        }
1563    }
1564
1565    fn from_proto(proto: proto::AuditLogEventV1) -> Result<Self, TryFromProtoError> {
1566        Ok(EventV1 {
1567            id: proto.id,
1568            event_type: proto.event_type.into_rust()?,
1569            object_type: proto.object_type.into_rust()?,
1570            details: proto.details.into_rust()?,
1571            user: proto.user.map(|u| u.inner),
1572            occurred_at: proto.occurred_at.into_rust()?,
1573        })
1574    }
1575}