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
b9d3f9a9
Commit
b9d3f9a9
authored
Mar 21, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed key deletion
🐛
parent
ae843e55
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
16 deletions
+29
-16
app/models/key.rb
app/models/key.rb
+2
-2
app/services/geo/notify_key_change_service.rb
app/services/geo/notify_key_change_service.rb
+4
-3
app/services/geo/schedule_key_change_service.rb
app/services/geo/schedule_key_change_service.rb
+3
-2
app/workers/geo_key_change_notify_worker.rb
app/workers/geo_key_change_notify_worker.rb
+2
-2
app/workers/geo_key_refresh_worker.rb
app/workers/geo_key_refresh_worker.rb
+2
-2
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+2
-2
spec/lib/gitlab/geo_spec.rb
spec/lib/gitlab/geo_spec.rb
+11
-0
spec/workers/geo_key_refresh_worker_spec.rb
spec/workers/geo_key_refresh_worker_spec.rb
+3
-3
No files found.
app/models/key.rb
View file @
b9d3f9a9
...
...
@@ -57,7 +57,7 @@ class Key < ActiveRecord::Base
end
def
add_to_shell
Gitlab
::
Geo
.
notify_
ssh_key_change
(
id
,
:create
)
if
Gitlab
::
Geo
.
primary?
Gitlab
::
Geo
.
notify_
key_change
(
id
,
key
,
:create
)
if
Gitlab
::
Geo
.
primary?
GitlabShellWorker
.
perform_async
(
:add_key
,
shell_id
,
...
...
@@ -74,7 +74,7 @@ class Key < ActiveRecord::Base
end
def
remove_from_shell
Gitlab
::
Geo
.
notify_
ssh_key_change
(
id
,
:delete
)
if
Gitlab
::
Geo
.
primary?
Gitlab
::
Geo
.
notify_
key_change
(
id
,
key
,
:delete
)
if
Gitlab
::
Geo
.
primary?
GitlabShellWorker
.
perform_async
(
:remove_key
,
shell_id
,
...
...
app/services/geo/notify_key_change_service.rb
View file @
b9d3f9a9
module
Geo
class
NotifyKeyChangeService
<
BaseNotify
def
initialize
(
key_id
,
change
)
def
initialize
(
key_id
,
key
,
action
)
@id
=
key_id
@action
=
change
@key
=
key
@action
=
action
end
def
execute
key_change
=
{
'id'
=>
@id
,
'action'
=>
@action
}
key_change
=
{
'id'
=>
@id
,
'
key'
=>
@key
,
'
action'
=>
@action
}
content
=
{
key_change:
key_change
}.
to_json
::
Gitlab
::
Geo
.
secondary_nodes
.
each
do
|
node
|
...
...
app/services/geo/schedule_key_change_service.rb
View file @
b9d3f9a9
module
Geo
class
ScheduleKeyChangeService
attr_reader
:id
,
:action
attr_reader
:id
,
:
key
,
:
action
def
initialize
(
key_change
)
@id
=
key_change
[
'id'
]
@key
=
key_change
[
'key'
]
@action
=
key_change
[
'action'
]
end
def
execute
GeoKeyRefreshWorker
.
perform_async
(
@id
,
@action
)
GeoKeyRefreshWorker
.
perform_async
(
@id
,
@
key
,
@
action
)
end
end
end
app/workers/geo_key_change_notify_worker.rb
View file @
b9d3f9a9
...
...
@@ -7,8 +7,8 @@ class GeoKeyChangeNotifyWorker
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
def
perform
(
key_id
,
change
)
Geo
::
NotifyKeyChangeService
.
new
(
key_id
,
change
).
execute
def
perform
(
key_id
,
key
,
action
)
Geo
::
NotifyKeyChangeService
.
new
(
key_id
,
key
,
action
).
execute
end
private
...
...
app/workers/geo_key_refresh_worker.rb
View file @
b9d3f9a9
...
...
@@ -7,7 +7,7 @@ class GeoKeyRefreshWorker
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
def
perform
(
key_id
,
action
)
def
perform
(
key_id
,
key
,
action
)
action
=
action
.
to_sym
case
action
...
...
@@ -18,7 +18,7 @@ class GeoKeyRefreshWorker
when
:delete
# we are physically removing the key after model is removed
# so we must reconstruct ids to schedule removal
key
=
Key
.
new
(
id:
key_id
)
key
=
Key
.
new
(
id:
key_id
,
key:
key
)
key
.
remove_from_shell
else
fail
"Invalid action:
#{
action
}
"
...
...
lib/gitlab/geo.rb
View file @
b9d3f9a9
...
...
@@ -42,8 +42,8 @@ module Gitlab
::
Geo
::
EnqueueWikiUpdateService
.
new
(
project
).
execute
end
def
self
.
notify_
ssh_key_change
(
key_id
,
change
)
GeoKeyChangeNotifyWorker
.
perform_async
(
key_id
,
change
)
def
self
.
notify_
key_change
(
key_id
,
key
,
action
)
GeoKeyChangeNotifyWorker
.
perform_async
(
key_id
,
key
,
action
)
end
def
self
.
bulk_notify_job
...
...
spec/lib/gitlab/geo_spec.rb
View file @
b9d3f9a9
...
...
@@ -79,4 +79,15 @@ describe Gitlab::Geo, lib: true do
described_class
.
notify_project_update
(
project
)
end
end
describe
'notify_ssh_key_change'
do
let
(
:key
)
{
FactoryGirl
.
build
(
:key
)
}
it
'schedule async notification'
do
expect
(
GeoKeyChangeNotifyWorker
).
to
receive
(
:perform_async
).
and_call_original
expect_any_instance_of
(
GeoKeyChangeNotifyWorker
).
to
receive
(
:perform
)
described_class
.
notify_key_change
(
key
.
id
,
key
,
'create'
)
end
end
end
spec/workers/geo_key_refresh_worker_spec.rb
View file @
b9d3f9a9
require
'spec_helper'
describe
GeoKeyRefreshWorker
do
subject
(
:key_create
)
{
described_class
.
new
.
perform
(
key
.
id
,
'create'
)
}
subject
(
:key_delete
)
{
described_class
.
new
.
perform
(
key
.
id
,
'delete'
)
}
subject
(
:key_create
)
{
described_class
.
new
.
perform
(
key
.
id
,
key
.
key
,
'create'
)
}
subject
(
:key_delete
)
{
described_class
.
new
.
perform
(
key
.
id
,
key
.
key
,
'delete'
)
}
let
(
:key
)
{
FactoryGirl
.
create
(
:key
)
}
context
'key creation'
do
...
...
@@ -15,7 +15,7 @@ describe GeoKeyRefreshWorker do
context
'key removal'
do
it
'removes key from the shell'
do
expect
(
Key
).
to
receive
(
:new
).
with
(
id:
key
.
id
)
{
key
}
expect
(
Key
).
to
receive
(
:new
).
with
(
id:
key
.
id
,
key:
key
.
key
)
{
key
}
expect
(
key
).
to
receive
(
:remove_from_shell
)
expect
{
key_delete
}.
not_to
raise_error
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