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
b7f66df1
Commit
b7f66df1
authored
3 years ago
by
Cornel Rautenbach
Browse files
Options
Downloads
Patches
Plain Diff
Audit - GetChanges method
parent
58ab9602
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
+4
-35
4 additions, 35 deletions
audit/audit.go
with
4 additions
and
35 deletions
audit/audit.go
+
4
−
35
View file @
b7f66df1
...
@@ -26,13 +26,13 @@ type FieldChange struct {
...
@@ -26,13 +26,13 @@ type FieldChange struct {
To
interface
{}
`json:"change_to"`
To
interface
{}
`json:"change_to"`
}
}
func
GetAuditEvent
(
original
interface
{},
new
interface
{},
username
*
string
)
(
Event
,
error
)
{
func
GetChanges
(
original
interface
{},
new
interface
{})
(
map
[
string
]
interface
{},
error
)
{
changes
:=
map
[
string
]
interface
{}{}
changelog
,
err
:=
diff
.
Diff
(
original
,
new
)
changelog
,
err
:=
diff
.
Diff
(
original
,
new
)
if
err
!=
nil
{
if
err
!=
nil
{
return
Event
{}
,
err
return
changes
,
err
}
}
changes
:=
map
[
string
]
interface
{}{}
for
_
,
change
:=
range
changelog
{
for
_
,
change
:=
range
changelog
{
if
len
(
change
.
Path
)
==
1
{
if
len
(
change
.
Path
)
==
1
{
...
@@ -119,38 +119,7 @@ func GetAuditEvent(original interface{}, new interface{}, username *string) (Eve
...
@@ -119,38 +119,7 @@ func GetAuditEvent(original interface{}, new interface{}, username *string) (Eve
}
}
}
}
objectID
:=
getIntValue
(
original
,
"ID"
)
return
changes
,
nil
if
objectID
==
0
{
objectID
=
getIntValue
(
new
,
"ID"
)
}
objectIDString
:=
string_utils
.
Int64ToString
(
objectID
)
if
objectIDString
==
"0"
{
objectIDString
=
getStringValue
(
original
,
"Username"
)
}
if
objectIDString
==
""
{
objectIDString
=
getStringValue
(
new
,
"Username"
)
}
providerID
:=
getIntValue
(
original
,
"ProviderID"
)
if
providerID
==
0
{
providerID
=
getIntValue
(
new
,
"ProviderID"
)
}
auditEvent
:=
Event
{
ObjectID
:
objectIDString
,
ProviderID
:
providerID
,
Source
:
"SYSTEM"
,
Timestamp
:
time
.
Now
(),
Change
:
changes
,
}
if
username
!=
nil
{
auditEvent
.
Source
=
*
username
}
return
auditEvent
,
nil
}
}
var
matchFirstCap
=
regexp
.
MustCompile
(
"(.)([A-Z][a-z]+)"
)
var
matchFirstCap
=
regexp
.
MustCompile
(
"(.)([A-Z][a-z]+)"
)
...
...
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