Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
afee5303
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,发现更多精彩内容 >>
提交
afee5303
编写于
3月 06, 2013
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3149 from m4tthumphrey/api-deploy-keys
Added methods to manage project deploy keys via API
上级
65d78253
f411772e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
179 addition
and
0 deletion
+179
-0
doc/api/projects.md
doc/api/projects.md
+79
-0
lib/api/projects.rb
lib/api/projects.rb
+43
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+57
-0
未找到文件。
doc/api/projects.md
浏览文件 @
afee5303
...
...
@@ -274,3 +274,82 @@ Parameters:
+
`hook_id`
(required) - The ID of hook to delete
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
## List deploy keys
Get a list of a project's deploy keys.
```
GET /projects/:id/keys
```
```
json
[
{
"id"
:
1
,
"title"
:
"Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
,
},
{
"id"
:
3
,
"title"
:
"Another Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
}
]
```
## Single deploy key
Get a single key.
```
GET /projects/:id/keys/:key_id
```
Parameters:
+
`id`
(required) - The ID of an deploy key
```
json
{
"id"
:
1
,
"title"
:
"Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
}
```
## Add deploy key
Create new deploy key for a project
```
POST /projects/:id/keys
```
Parameters:
+
`title`
(required) - new deploy key's title
+
`key`
(required) - new deploy key
Will return created key with status
`201 Created`
on success, or
`404 Not
found`
on fail.
## Delete deploy key
Delete a deploy key from a project
```
DELETE /projects/:id/keys/:key_id
```
Parameters:
+
`id`
(required) - Deploy key ID
Will return
`200 OK`
on success, or
`404 Not Found`
on fail.
\ No newline at end of file
lib/api/projects.rb
浏览文件 @
afee5303
...
...
@@ -424,6 +424,49 @@ module Gitlab
present
tree
.
data
end
# Get a specific project's keys
#
# Example Request:
# GET /projects/:id/keys
get
":id/keys"
do
present
user_project
.
deploy_keys
,
with:
Entities
::
SSHKey
end
# Get single key owned by currently authenticated user
#
# Example Request:
# GET /projects/:id/keys/:id
get
":id/keys/:key_id"
do
key
=
user_project
.
deploy_keys
.
find
params
[
:key_id
]
present
key
,
with:
Entities
::
SSHKey
end
# Add new ssh key to currently authenticated user
#
# Parameters:
# key (required) - New SSH Key
# title (required) - New SSH Key's title
# Example Request:
# POST /projects/:id/keys
post
":id/keys"
do
attrs
=
attributes_for_keys
[
:title
,
:key
]
key
=
user_project
.
deploy_keys
.
new
attrs
if
key
.
save
present
key
,
with:
Entities
::
SSHKey
else
not_found!
end
end
# Delete existed ssh key of currently authenticated user
#
# Example Request:
# DELETE /projects/:id/keys/:id
delete
":id/keys/:key_id"
do
key
=
user_project
.
deploy_keys
.
find
params
[
:key_id
]
key
.
delete
end
end
end
end
spec/requests/api/projects_spec.rb
浏览文件 @
afee5303
...
...
@@ -11,6 +11,8 @@ describe Gitlab::API do
let!
(
:snippet
)
{
create
(
:snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let!
(
:users_project
)
{
create
(
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
)
}
let!
(
:users_project2
)
{
create
(
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
)
}
let
(
:key
)
{
create
(
:key
,
project:
project
)
}
before
{
project
.
team
<<
[
user
,
:reporter
]
}
describe
"GET /projects"
do
...
...
@@ -380,4 +382,59 @@ describe Gitlab::API do
response
.
status
.
should
==
404
end
end
describe
"GET /projects/:id/keys"
do
it
"should return array of ssh keys"
do
project
.
deploy_keys
<<
key
project
.
save
get
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
key
.
title
end
end
describe
"GET /projects/:id/keys/:key_id"
do
it
"should return a single key"
do
project
.
deploy_keys
<<
key
project
.
save
get
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
key
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
key
.
title
end
it
"should return 404 Not Found with invalid ID"
do
get
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
response
.
status
.
should
==
404
end
end
describe
"POST /projects/:id/keys"
do
it
"should not create an invalid ssh key"
do
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
{
title:
"invalid key"
}
response
.
status
.
should
==
404
end
it
"should create new ssh key"
do
key_attrs
=
attributes_for
:key
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
key_attrs
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
end
describe
"DELETE /projects/:id/keys/:key_id"
do
it
"should delete existing key"
do
project
.
deploy_keys
<<
key
project
.
save
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
key
.
id
}
"
,
user
)
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
end
it
"should return 404 Not Found with invalid ID"
do
delete
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
response
.
status
.
should
==
404
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录