Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1970c7ed
Commit
1970c7ed
authored
Feb 19, 2020
by
Tan Le
Committed by
Dylan Griffith
Feb 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add internal YARD doc for public interface
Aid developer in future work with this mega class.
parent
4caa2f25
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
50 deletions
+91
-50
app/services/audit_event_service.rb
app/services/audit_event_service.rb
+24
-1
ee/app/services/ee/audit_event_service.rb
ee/app/services/ee/audit_event_service.rb
+67
-23
ee/spec/services/ee/audit_events/protected_branch_audit_event_service_spec.rb
...audit_events/protected_branch_audit_event_service_spec.rb
+0
-26
No files found.
app/services/audit_event_service.rb
View file @
1970c7ed
# frozen_string_literal: true
# frozen_string_literal: true
class
AuditEventService
class
AuditEventService
# Instantiates a new service
#
# @param author [User] the user who authors the change
# @param entity [Object] an instance of either Project/Group/User type. This
# param is also used to determine at which level the audit events are
# shown.
# - Project: events are visible at Project level
# - Group: events are visible at Group level
# - User: events are visible at Instance level
# @param details [Hash] details to be added to audit event
#
# @return [AuditEventService]
def
initialize
(
author
,
entity
,
details
=
{})
def
initialize
(
author
,
entity
,
details
=
{})
@author
,
@entity
,
@details
=
author
,
entity
,
details
@author
=
author
@entity
=
entity
@details
=
details
end
end
# Builds the @details attribute for authentication
#
# This uses the @author as the target object being changed
#
# @return [AuditEventService]
def
for_authentication
def
for_authentication
@details
=
{
@details
=
{
with:
@details
[
:with
],
with:
@details
[
:with
],
...
@@ -16,11 +35,15 @@ class AuditEventService
...
@@ -16,11 +35,15 @@ class AuditEventService
self
self
end
end
# Writes event to a file and creates an event record in DB
#
# @return [SecurityEvent] persited if saves and non-persisted if fails
def
security_event
def
security_event
log_security_event_to_file
log_security_event_to_file
log_security_event_to_database
log_security_event_to_database
end
end
# Writes event to a file
def
log_security_event_to_file
def
log_security_event_to_file
file_logger
.
info
(
base_payload
.
merge
(
formatted_details
))
file_logger
.
info
(
base_payload
.
merge
(
formatted_details
))
end
end
...
...
ee/app/services/ee/audit_event_service.rb
View file @
1970c7ed
...
@@ -4,6 +4,11 @@ module EE
...
@@ -4,6 +4,11 @@ module EE
module
AuditEventService
module
AuditEventService
extend
::
Gitlab
::
Utils
::
Override
extend
::
Gitlab
::
Utils
::
Override
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# Builds the @details attribute for member
#
# @param member [Member] the member whom is changed
# @return [AuditEventService]
def
for_member
(
member
)
def
for_member
(
member
)
action
=
@details
[
:action
]
action
=
@details
[
:action
]
old_access_level
=
@details
[
:old_access_level
]
old_access_level
=
@details
[
:old_access_level
]
...
@@ -56,6 +61,14 @@ module EE
...
@@ -56,6 +61,14 @@ module EE
self
self
end
end
# Builds the @details attribute for project group link
#
# This expects [String] :action of :destroy, :create, :update to be
# specified in @details attribute
#
# @param group_link [ProjectGroupLink] the project group link being changed
#
# @return [AuditEventService]
def
for_project_group_link
(
group_link
)
def
for_project_group_link
(
group_link
)
@details
=
custom_project_link_group_attributes
(
group_link
)
@details
=
custom_project_link_group_attributes
(
group_link
)
.
merge
(
author_name:
@author
.
name
,
.
merge
(
author_name:
@author
.
name
,
...
@@ -66,6 +79,9 @@ module EE
...
@@ -66,6 +79,9 @@ module EE
self
self
end
end
# Builds the @details attribute for a failed login
#
# @return [AuditEventService]
def
for_failed_login
def
for_failed_login
ip
=
@details
[
:ip_address
]
ip
=
@details
[
:ip_address
]
auth
=
@details
[
:with
]
||
'STANDARD'
auth
=
@details
[
:with
]
||
'STANDARD'
...
@@ -80,6 +96,9 @@ module EE
...
@@ -80,6 +96,9 @@ module EE
self
self
end
end
# Builds the @details attribute for changes
#
# @return [AuditEventService]
def
for_changes
def
for_changes
@details
=
@details
=
{
{
...
@@ -91,9 +110,11 @@ module EE
...
@@ -91,9 +110,11 @@ module EE
target_type:
@entity
.
class
.
name
,
target_type:
@entity
.
class
.
name
,
target_details:
@details
[
:target_details
]
||
@entity
.
name
target_details:
@details
[
:target_details
]
||
@entity
.
name
}
}
self
self
end
end
# Write event to file and create an event record in DB
def
security_event
def
security_event
prepare_security_event
prepare_security_event
...
@@ -106,6 +127,10 @@ module EE
...
@@ -106,6 +127,10 @@ module EE
end
end
end
end
# Creates an event record in DB
#
# @return [nil] if audit events is not enabled
# @return [SecurityEvent] if record is persisted
def
unauth_security_event
def
unauth_security_event
return
unless
audit_events_enabled?
return
unless
audit_events_enabled?
...
@@ -120,14 +145,33 @@ module EE
...
@@ -120,14 +145,33 @@ module EE
)
)
end
end
# Builds the @details attribute for user
#
# This uses the [User] @entity as the target object being changed
#
# @param full_path [String] required if it is different from the User model
# in @entity. This is for backward compatability and this parameter will
# be dropped after all of these incorrect usages are removed.
#
# @return [AuditEventService]
def
for_user
(
full_path
=
@entity
.
full_path
)
def
for_user
(
full_path
=
@entity
.
full_path
)
for_custom_model
(
'user'
,
full_path
)
for_custom_model
(
'user'
,
full_path
)
end
end
# Builds the @details attribute for project
#
# This uses the [Project] @entity as the target object being changed
#
# @return [AuditEventService]
def
for_project
def
for_project
for_custom_model
(
'project'
,
@entity
.
full_path
)
for_custom_model
(
'project'
,
@entity
.
full_path
)
end
end
# Builds the @details attribute for group
#
# This uses the [Group] @entity as the target object being changed
#
# @return [AuditEventService]
def
for_group
def
for_group
for_custom_model
(
'group'
,
@entity
.
full_path
)
for_custom_model
(
'group'
,
@entity
.
full_path
)
end
end
...
...
ee/spec/services/ee/audit_events/protected_branch_audit_event_service_spec.rb
View file @
1970c7ed
...
@@ -68,30 +68,4 @@ describe EE::AuditEvents::ProtectedBranchAuditEventService do
...
@@ -68,30 +68,4 @@ describe EE::AuditEvents::ProtectedBranchAuditEventService do
end
end
end
end
end
end
describe
'#enabled?'
do
let
(
:service
)
{
described_class
.
new
(
author
,
protected_branch
,
:any
)
}
subject
{
service
.
enabled?
}
context
'when not licensed'
do
before
do
stub_licensed_features
(
audit_events:
false
,
extended_audit_events:
false
,
admin_audit_log:
false
)
end
it
{
is_expected
.
to
be
(
false
)
}
end
context
'when licensed'
do
before
do
stub_licensed_features
(
audit_events:
true
,
extended_audit_events:
false
,
admin_audit_log:
false
)
end
it
{
is_expected
.
to
be
(
true
)
}
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment