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