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
f4dc57f6
Commit
f4dc57f6
authored
Nov 17, 2021
by
Tiger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log an activity event when an Agent token is created
parent
4ef36dfb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
app/services/clusters/agent_tokens/create_service.rb
app/services/clusters/agent_tokens/create_service.rb
+12
-0
spec/services/clusters/agent_tokens/create_service_spec.rb
spec/services/clusters/agent_tokens/create_service_spec.rb
+19
-0
No files found.
app/services/clusters/agent_tokens/create_service.rb
View file @
f4dc57f6
...
...
@@ -11,6 +11,8 @@ module Clusters
token
=
::
Clusters
::
AgentToken
.
new
(
filtered_params
.
merge
(
created_by_user:
current_user
))
if
token
.
save
log_activity_event!
(
token
)
ServiceResponse
.
success
(
payload:
{
secret:
token
.
token
,
token:
token
})
else
ServiceResponse
.
error
(
message:
token
.
errors
.
full_messages
)
...
...
@@ -26,6 +28,16 @@ module Clusters
def
filtered_params
params
.
slice
(
*
ALLOWED_PARAMS
)
end
def
log_activity_event!
(
token
)
token
.
agent
.
activity_events
.
create!
(
kind: :token_created
,
level: :info
,
recorded_at:
token
.
created_at
,
user:
current_user
,
agent_token:
token
)
end
end
end
end
spec/services/clusters/agent_tokens/create_service_spec.rb
View file @
f4dc57f6
...
...
@@ -47,6 +47,21 @@ RSpec.describe Clusters::AgentTokens::CreateService do
expect
(
token
.
name
).
to
eq
(
params
[
:name
])
end
it
'creates an activity event'
do
expect
{
subject
}.
to
change
{
::
Clusters
::
Agents
::
ActivityEvent
.
count
}.
by
(
1
)
token
=
subject
.
payload
[
:token
].
reload
event
=
cluster_agent
.
activity_events
.
last
expect
(
event
).
to
have_attributes
(
kind:
'token_created'
,
level:
'info'
,
recorded_at:
token
.
created_at
,
user:
token
.
created_by_user
,
agent_token:
token
)
end
context
'when params are invalid'
do
let
(
:params
)
{
{
agent_id:
'bad_id'
}
}
...
...
@@ -54,6 +69,10 @@ RSpec.describe Clusters::AgentTokens::CreateService do
expect
{
subject
}.
not_to
change
(
::
Clusters
::
AgentToken
,
:count
)
end
it
'does not create an activity event'
do
expect
{
subject
}.
not_to
change
{
::
Clusters
::
Agents
::
ActivityEvent
.
count
}
end
it
'returns validation errors'
,
:aggregate_failures
do
expect
(
subject
.
status
).
to
eq
(
:error
)
expect
(
subject
.
message
).
to
eq
([
"Agent must exist"
,
"Name can't be blank"
])
...
...
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