Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
fb21bb97
Commit
fb21bb97
authored
3 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Patches
Plain Diff
Deeper object changes for audit events
parent
b9faf8ef
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
audit/audit.go
+32
-21
32 additions, 21 deletions
audit/audit.go
with
32 additions
and
21 deletions
audit/audit.go
+
32
−
21
View file @
fb21bb97
...
@@ -38,27 +38,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -38,27 +38,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
// 0 = Object
// 0 = Object
// 1 = field
// 1 = field
objectKey
:=
ToSnakeCase
(
change
.
Path
[
0
])
ChildObjectChanges
(
changes
,
change
.
Path
[
0
],
change
.
Path
[
1
],
change
.
From
,
change
.
To
)
field
:=
ToSnakeCase
(
change
.
Path
[
1
])
existingObject
,
present
:=
changes
[
objectKey
]
if
present
{
if
object
,
ok
:=
existingObject
.
(
map
[
string
]
interface
{});
ok
{
object
[
field
]
=
FieldChange
{
From
:
change
.
From
,
To
:
change
.
To
,
}
changes
[
objectKey
]
=
object
}
}
else
{
fieldChange
:=
map
[
string
]
interface
{}{
field
:
FieldChange
{
From
:
change
.
From
,
To
:
change
.
To
,
},
}
changes
[
objectKey
]
=
fieldChange
}
}
else
if
len
(
change
.
Path
)
==
3
{
}
else
if
len
(
change
.
Path
)
==
3
{
// Array of objects
// Array of objects
...
@@ -69,6 +49,13 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -69,6 +49,13 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
objectKey
:=
ToSnakeCase
(
change
.
Path
[
0
])
objectKey
:=
ToSnakeCase
(
change
.
Path
[
0
])
indexString
:=
change
.
Path
[
1
]
indexString
:=
change
.
Path
[
1
]
if
!
string_utils
.
IsNumericString
(
indexString
)
{
// Not an array, but an deeper nested object
ChildObjectChanges
(
changes
,
change
.
Path
[
len
(
change
.
Path
)
-
2
],
change
.
Path
[
len
(
change
.
Path
)
-
1
],
change
.
From
,
change
.
To
)
continue
}
index
,
_
:=
string_utils
.
StringToInt64
(
indexString
)
index
,
_
:=
string_utils
.
StringToInt64
(
indexString
)
field
:=
ToSnakeCase
(
change
.
Path
[
2
])
field
:=
ToSnakeCase
(
change
.
Path
[
2
])
...
@@ -111,6 +98,30 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -111,6 +98,30 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
return
changes
,
nil
return
changes
,
nil
}
}
func
ChildObjectChanges
(
changes
map
[
string
]
interface
{},
objectPath
string
,
fieldPath
string
,
changeFrom
interface
{},
changeTo
interface
{})
{
objectKey
:=
ToSnakeCase
(
objectPath
)
field
:=
ToSnakeCase
(
fieldPath
)
existingObject
,
present
:=
changes
[
objectKey
]
if
present
{
if
object
,
ok
:=
existingObject
.
(
map
[
string
]
interface
{});
ok
{
object
[
field
]
=
FieldChange
{
From
:
changeFrom
,
To
:
changeTo
,
}
changes
[
objectKey
]
=
object
}
}
else
{
fieldChange
:=
map
[
string
]
interface
{}{
field
:
FieldChange
{
From
:
changeFrom
,
To
:
changeTo
,
},
}
changes
[
objectKey
]
=
fieldChange
}
}
// GetAllChanges Returns the diff, structured in json, recursively
// GetAllChanges Returns the diff, structured in json, recursively
// Be warned, here be dragons. Debug this first to understand how it works
// Be warned, here be dragons. Debug this first to understand how it works
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment