BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f42ee8ca
Commit
f42ee8ca
authored
Jan 20, 2017
by
Yorick Peterse
Committed by
James Lopez
Jan 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'record-used-ssh-keys-once-per-day' into 'master'
Record used SSH keys only once per day Closes #26877 See merge request !8655
parent
c0083759
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
+33
-5
key.rb
app/models/key.rb
+6
-1
record-used-ssh-keys-once-per-day.yml
changelogs/unreleased/record-used-ssh-keys-once-per-day.yml
+4
-0
key_spec.rb
spec/models/key_spec.rb
+23
-4
No files found.
app/models/key.rb
View file @
f42ee8ca
...
...
@@ -4,6 +4,8 @@ class Key < ActiveRecord::Base
include
AfterCommitQueue
include
Sortable
LAST_USED_AT_REFRESH_TIME
=
1
.
day
.
to_i
belongs_to
:user
before_validation
:generate_fingerprint
...
...
@@ -50,7 +52,10 @@ class Key < ActiveRecord::Base
end
def
update_last_used_at
UseKeyWorker
.
perform_async
(
self
.
id
)
lease
=
Gitlab
::
ExclusiveLease
.
new
(
"key_update_last_used_at:
#{
id
}
"
,
timeout:
LAST_USED_AT_REFRESH_TIME
)
return
unless
lease
.
try_obtain
UseKeyWorker
.
perform_async
(
id
)
end
def
add_to_shell
...
...
changelogs/unreleased/record-used-ssh-keys-once-per-day.yml
0 → 100644
View file @
f42ee8ca
---
title
:
Record used SSH keys only once per day
merge_request
:
8655
author
:
spec/models/key_spec.rb
View file @
f42ee8ca
...
...
@@ -30,11 +30,30 @@ describe Key, models: true do
end
describe
"#update_last_used_at"
do
it
"enqueues a UseKeyWorker job"
do
key
=
create
(
:key
)
let
(
:key
)
{
create
(
:key
)
}
context
'when key was not updated during the last day'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
'000000'
)
end
it
'enqueues a UseKeyWorker job'
do
expect
(
UseKeyWorker
).
to
receive
(
:perform_async
).
with
(
key
.
id
)
key
.
update_last_used_at
end
end
context
'when key was updated during the last day'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
end
expect
(
UseKeyWorker
).
to
receive
(
:perform_async
).
with
(
key
.
id
)
key
.
update_last_used_at
it
'does not enqueue a UseKeyWorker job'
do
expect
(
UseKeyWorker
).
not_to
receive
(
:perform_async
)
key
.
update_last_used_at
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