Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
3c42d730
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c42d730
编写于
6月 13, 2017
作者:
A
Alexis Reigel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add primary keyid attribute to gpg keys
上级
7e13d967
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
73 addition
and
7 deletion
+73
-7
app/models/gpg_key.rb
app/models/gpg_key.rb
+14
-1
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
+17
-0
db/schema.rb
db/schema.rb
+2
-0
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+12
-0
spec/features/commits_spec.rb
spec/features/commits_spec.rb
+2
-2
spec/lib/gitlab/gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+14
-0
spec/models/gpg_key_spec.rb
spec/models/gpg_key_spec.rb
+8
-0
spec/support/gpg_helpers.rb
spec/support/gpg_helpers.rb
+4
-4
未找到文件。
app/models/gpg_key.rb
浏览文件 @
3c42d730
...
...
@@ -20,7 +20,14 @@ class GpgKey < ActiveRecord::Base
# the error about the fingerprint
unless:
->
{
errors
.
has_key?
(
:key
)
}
before_validation
:extract_fingerprint
validates
:primary_keyid
,
presence:
true
,
uniqueness:
true
,
# only validate when the `key` is valid, as we don't want the user to show
# the error about the fingerprint
unless:
->
{
errors
.
has_key?
(
:key
)
}
before_validation
:extract_fingerprint
,
:extract_primary_keyid
after_create
:notify_user
def
key
=
(
value
)
...
...
@@ -49,6 +56,12 @@ class GpgKey < ActiveRecord::Base
self
.
fingerprint
=
Gitlab
::
Gpg
.
fingerprints_from_key
(
key
).
first
end
def
extract_primary_keyid
# we can assume that the result only contains one item as the validation
# only allows one key
self
.
primary_keyid
=
Gitlab
::
Gpg
.
primary_keyids_from_key
(
key
).
first
end
def
notify_user
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
end
...
...
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
0 → 100644
浏览文件 @
3c42d730
class
AddPrimaryKeyidToGpgKeys
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_column
:gpg_keys
,
:primary_keyid
,
:string
add_concurrent_index
:gpg_keys
,
:primary_keyid
end
def
down
remove_concurrent_index
:gpg_keys
,
:primary_keyid
if
index_exists?
(
:gpg_keys
,
:primary_keyid
)
remove_column
:gpg_keys
,
:primary_keyid
,
:string
end
end
db/schema.rb
浏览文件 @
3c42d730
...
...
@@ -546,8 +546,10 @@ ActiveRecord::Schema.define(version: 20170725145659) do
t
.
integer
"user_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"primary_keyid"
end
add_index
"gpg_keys"
,
[
"primary_keyid"
],
name:
"index_gpg_keys_on_primary_keyid"
,
using: :btree
add_index
"gpg_keys"
,
[
"user_id"
],
name:
"index_gpg_keys_on_user_id"
,
using: :btree
create_table
"identities"
,
force: :cascade
do
|
t
|
...
...
lib/gitlab/gpg.rb
浏览文件 @
3c42d730
...
...
@@ -12,6 +12,18 @@ module Gitlab
end
end
def
primary_keyids_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
return
[]
if
import
.
imported
==
0
fingerprints
=
import
.
imports
.
map
(
&
:fingerprint
)
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
map
{
|
raw_key
|
raw_key
.
primary_subkey
.
keyid
}
end
end
def
emails_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
...
...
spec/features/commits_spec.rb
浏览文件 @
3c42d730
...
...
@@ -220,8 +220,8 @@ describe 'Commits' do
Dir
.
mktmpdir
do
|
dir
|
FileUtils
.
cd
dir
do
`git clone --quiet
#{
remote_path
}
.`
`git commit --quiet -S
#{
GpgHelpers
::
User1
.
key_
id
}
--allow-empty -m "signed commit, verified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User2
.
key_
id
}
--allow-empty -m "signed commit, unverified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User1
.
primary_key
id
}
--allow-empty -m "signed commit, verified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User2
.
primary_key
id
}
--allow-empty -m "signed commit, unverified key/email"`
`git push --quiet`
end
end
...
...
spec/lib/gitlab/gpg_spec.rb
浏览文件 @
3c42d730
...
...
@@ -15,6 +15,20 @@ describe Gitlab::Gpg do
end
end
describe
'.primary_keyids_from_key'
do
it
'returns the keyid'
do
expect
(
described_class
.
primary_keyids_from_key
(
GpgHelpers
::
User1
.
public_key
)
).
to
eq
[
GpgHelpers
::
User1
.
primary_keyid
]
end
it
'returns an empty array when the key is invalid'
do
expect
(
described_class
.
primary_keyids_from_key
(
'bogus'
)
).
to
eq
[]
end
end
describe
'.emails_from_key'
do
it
'returns the emails'
do
expect
(
...
...
spec/models/gpg_key_spec.rb
浏览文件 @
3c42d730
...
...
@@ -21,6 +21,14 @@ describe GpgKey do
expect
(
gpg_key
.
fingerprint
).
to
eq
GpgHelpers
::
User1
.
fingerprint
end
end
describe
'extract_primary_keyid'
do
it
'extracts the primary keyid from the gpg key'
do
gpg_key
=
described_class
.
new
(
key:
GpgHelpers
::
User1
.
public_key
)
gpg_key
.
valid?
expect
(
gpg_key
.
primary_keyid
).
to
eq
GpgHelpers
::
User1
.
primary_keyid
end
end
end
describe
'#key='
do
...
...
spec/support/gpg_helpers.rb
浏览文件 @
3c42d730
...
...
@@ -90,8 +90,8 @@ module GpgHelpers
KEY
end
def
key_
id
'00AC8B1D'
def
primary_key
id
fingerprint
[
-
16
..-
1
]
end
def
fingerprint
...
...
@@ -179,8 +179,8 @@ module GpgHelpers
KEY
end
def
key_
id
'911EFD65'
def
primary_key
id
fingerprint
[
-
16
..-
1
]
end
def
fingerprint
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录