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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
113d2ff5
Commit
113d2ff5
authored
Jun 24, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store and display public key fingerprint
parent
05a7e8b9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
13 deletions
+60
-13
app/models/key.rb
app/models/key.rb
+31
-9
app/views/profiles/keys/_key.html.haml
app/views/profiles/keys/_key.html.haml
+3
-1
app/views/profiles/keys/show.html.haml
app/views/profiles/keys/show.html.haml
+3
-0
db/migrate/20130624162710_add_fingerprint_to_key.rb
db/migrate/20130624162710_add_fingerprint_to_key.rb
+6
-0
db/schema.rb
db/schema.rb
+2
-3
lib/tasks/migrate/migrate_keys.rake
lib/tasks/migrate/migrate_keys.rake
+15
-0
No files found.
app/models/key.rb
View file @
113d2ff5
...
...
@@ -15,6 +15,8 @@
require
'digest/md5'
class
Key
<
ActiveRecord
::
Base
include
Gitlab
::
Popen
belongs_to
:user
attr_accessible
:key
,
:title
...
...
@@ -34,16 +36,10 @@ class Key < ActiveRecord::Base
def
fingerprintable_key
return
true
unless
key
# Don't test if there is no key.
file
=
Tempfile
.
new
(
'key_file'
)
begin
file
.
puts
key
file
.
rewind
fingerprint_output
=
`ssh-keygen -lf
#{
file
.
path
}
2>&1`
# Catch stderr.
ensure
file
.
close
file
.
unlink
# deletes the temp file
unless
generate_fingerpint
errors
.
add
(
:key
,
"can't be fingerprinted"
)
false
end
errors
.
add
(
:key
,
"can't be fingerprinted"
)
if
$?
.
exitstatus
!=
0
end
# projects that has this key
...
...
@@ -54,4 +50,30 @@ class Key < ActiveRecord::Base
def
shell_id
"key-
#{
id
}
"
end
private
def
generate_fingerpint
cmd_status
=
0
cmd_output
=
''
file
=
Tempfile
.
new
(
'gitlab_key_file'
)
begin
file
.
puts
key
file
.
rewind
cmd_output
,
cmd_status
=
popen
(
"ssh-keygen -lf
#{
file
.
path
}
"
,
'/tmp'
)
ensure
file
.
close
file
.
unlink
# deletes the temp file
end
if
cmd_status
.
zero?
cmd_output
.
gsub
/([\d\h]{2}:)+[\d\h]{2}/
do
|
match
|
self
.
fingerprint
=
match
end
true
else
false
end
end
end
app/views/profiles/keys/_key.html.haml
View file @
113d2ff5
%li
=
link_to
profile_key_path
(
key
)
do
%strong
=
key
.
title
%span
(
#{
key
.
fingerprint
}
)
%span
.cgray
added
=
time_ago_in_words
(
key
.
created_at
)
ago
=
link_to
'Remove'
,
profile_key_path
(
key
),
confirm:
'Are you sure?'
,
method: :delete
,
class:
"btn btn-small btn-remove delete-key pull-right"
=
link_to
'Remove'
,
profile_key_path
(
key
),
confirm:
'Are you sure?'
,
method: :delete
,
class:
"btn btn-small btn-remove delete-key pull-right"
app/views/profiles/keys/show.html.haml
View file @
113d2ff5
...
...
@@ -12,6 +12,9 @@
%strong
=
@key
.
created_at
.
stamp
(
"Aug 21, 2011"
)
.span8
%p
%span
.light
Fingerprint:
%strong
=
@key
.
fingerprint
%pre
.well-pre
=
@key
.
key
...
...
db/migrate/20130624162710_add_fingerprint_to_key.rb
0 → 100644
View file @
113d2ff5
class
AddFingerprintToKey
<
ActiveRecord
::
Migration
def
change
add_column
:keys
,
:fingerprint
,
:string
remove_column
:keys
,
:identifier
end
end
db/schema.rb
View file @
113d2ff5
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
2013062
211534
0
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
2013062
416271
0
)
do
create_table
"deploy_keys_projects"
,
:force
=>
true
do
|
t
|
t
.
integer
"deploy_key_id"
,
:null
=>
false
...
...
@@ -77,11 +77,10 @@ ActiveRecord::Schema.define(:version => 20130622115340) do
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
string
"title"
t
.
string
"identifier"
t
.
string
"type"
t
.
string
"fingerprint"
end
add_index
"keys"
,
[
"identifier"
],
:name
=>
"index_keys_on_identifier"
add_index
"keys"
,
[
"user_id"
],
:name
=>
"index_keys_on_user_id"
create_table
"merge_requests"
,
:force
=>
true
do
|
t
|
...
...
lib/tasks/migrate/migrate_keys.rake
0 → 100644
View file @
113d2ff5
desc
"GITLAB | Migrate SSH Keys"
task
migrate_keys: :environment
do
puts
"This will add fingerprint to ssh keys in db"
ask_to_continue
Key
.
find_each
(
batch_size:
20
)
do
|
key
|
if
key
.
valid?
&&
key
.
save
print
'.'
else
print
'F'
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