Skip to content

Commit ecbfddc

Browse files
committed
Move audit log deserialization into helper function
Signed-off-by: Joanna Lau <118241363+joannalauu@users.noreply.github.com>
1 parent efca0ad commit ecbfddc

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

common/persistence/sql/sql_domain_audit_store.go

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,32 +146,7 @@ func (m *sqlDomainAuditStore) GetDomainAuditLogs(
146146

147147
var auditLogs []*persistence.InternalDomainAuditLog
148148
for _, row := range rows {
149-
auditLog := &persistence.InternalDomainAuditLog{
150-
EventID: row.EventID,
151-
DomainID: row.DomainID,
152-
OperationType: row.OperationType,
153-
CreatedTime: row.CreatedTime,
154-
LastUpdatedTime: row.LastUpdatedTime,
155-
Identity: row.Identity,
156-
IdentityType: row.IdentityType,
157-
Comment: row.Comment,
158-
}
159-
160-
if len(row.StateBefore) > 0 {
161-
auditLog.StateBefore = &persistence.DataBlob{
162-
Encoding: row.StateBeforeEncoding,
163-
Data: row.StateBefore,
164-
}
165-
}
166-
167-
if len(row.StateAfter) > 0 {
168-
auditLog.StateAfter = &persistence.DataBlob{
169-
Encoding: row.StateAfterEncoding,
170-
Data: row.StateAfter,
171-
}
172-
}
173-
174-
auditLogs = append(auditLogs, auditLog)
149+
auditLogs = append(auditLogs, deseralizeDomainAuditLogRow(row))
175150
}
176151

177152
return &persistence.InternalGetDomainAuditLogsResponse{
@@ -193,3 +168,33 @@ func getDataBlobEncoding(blob *persistence.DataBlob) constants.EncodingType {
193168
}
194169
return blob.Encoding
195170
}
171+
172+
173+
func deseralizeDomainAuditLogRow(row *sqlplugin.DomainAuditLogRow) *persistence.InternalDomainAuditLog {
174+
auditLog := &persistence.InternalDomainAuditLog{
175+
EventID: row.EventID,
176+
DomainID: row.DomainID,
177+
OperationType: row.OperationType,
178+
CreatedTime: row.CreatedTime,
179+
LastUpdatedTime: row.LastUpdatedTime,
180+
Identity: row.Identity,
181+
IdentityType: row.IdentityType,
182+
Comment: row.Comment,
183+
}
184+
185+
if len(row.StateBefore) > 0 {
186+
auditLog.StateBefore = &persistence.DataBlob{
187+
Encoding: row.StateBeforeEncoding,
188+
Data: row.StateBefore,
189+
}
190+
}
191+
192+
if len(row.StateAfter) > 0 {
193+
auditLog.StateAfter = &persistence.DataBlob{
194+
Encoding: row.StateAfterEncoding,
195+
Data: row.StateAfter,
196+
}
197+
}
198+
199+
return auditLog
200+
}

0 commit comments

Comments
 (0)