参数管理
This commit is contained in:
parent
41118f6d12
commit
cb90dc1f51
127
api_document.md
127
api_document.md
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
# API文档
|
# API文档
|
||||||
|
@ -19,7 +18,6 @@
|
||||||
|
|
||||||
|
|
||||||
### API接口
|
### API接口
|
||||||
---
|
|
||||||
|
|
||||||
#### 用户注册(通过其他平台)
|
#### 用户注册(通过其他平台)
|
||||||
```
|
```
|
||||||
|
@ -4830,8 +4828,133 @@ curl --location --request DELETE 'http://localhost:3000/api/ci/templates/10'
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
#### 参数列表查询
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api/ci/secrets/secrets?owner={owner}&repo={repo}
|
||||||
|
```
|
||||||
|
|
||||||
|
*示例*
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --location --request GET 'http://localhost:3000/api/ci/secrets?owner=test&repo=test'
|
||||||
|
```
|
||||||
|
|
||||||
|
*请求参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 必选 | 类型 | 说明 |
|
||||||
|
| ------ | ---- | ------ | ---------- |
|
||||||
|
| owner | 是 | string | 仓库所有人 |
|
||||||
|
| repo | 是 | string | 仓库名 |
|
||||||
|
|
||||||
|
*返回参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------ | ------ | ------ |
|
||||||
|
| name | string | 参数名 |
|
||||||
|
| data | string | 参数值 |
|
||||||
|
| repo | string | 仓库 |
|
||||||
|
|
||||||
|
返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "test",
|
||||||
|
"data": "test",
|
||||||
|
"repo": "test"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
#### 参数新增/更新
|
||||||
|
|
||||||
|
```
|
||||||
|
POST /api/ci/secrets?owner={owner}&repo={repo}
|
||||||
|
```
|
||||||
|
|
||||||
|
*示例*
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --location --request POST 'http://localhost:3000/api/ci/secrets?owner=test&repo=test' \
|
||||||
|
--data-raw ' {
|
||||||
|
"name": "ip",
|
||||||
|
"data": "1.1.1.1",
|
||||||
|
"id": 21
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
*请求参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 必选 | 类型 | 说明 |
|
||||||
|
| ------ | ---- | ------ | ------------ |
|
||||||
|
| owner | 是 | string | 仓库拥有者 |
|
||||||
|
| repo | 是 | string | 仓库名 |
|
||||||
|
| name | 是 | string | 参数名 |
|
||||||
|
| data | 是 | string | 参数值 |
|
||||||
|
| id | 否 | int | id,更新时传 |
|
||||||
|
|
||||||
|
*返回参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------- | ------ | ------------ |
|
||||||
|
| status | int | 状态码 0成功 |
|
||||||
|
| message | string | 消息 |
|
||||||
|
|
||||||
|
返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"message": "success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
#### 参数删除
|
||||||
|
|
||||||
|
```
|
||||||
|
DELETE /api/ci/secrets/{id}/{name}?owner={owner}&repo={repo}
|
||||||
|
```
|
||||||
|
|
||||||
|
*示例*
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --location --request DELETE 'http://localhost:3000/api/ci/secrets/1/p2?owner=victor&repo=trustieTest' \
|
||||||
|
```
|
||||||
|
|
||||||
|
*请求参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 必选 | 类型 | 说明 |
|
||||||
|
| ------ | ---- | ------ | ------ |
|
||||||
|
| name | 是 | string | 参数名 |
|
||||||
|
| id | 是 | int | 参数id |
|
||||||
|
|
||||||
|
*返回参数说明:*
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------- | ------ | ------------ |
|
||||||
|
| status | int | 状态码 0成功 |
|
||||||
|
| message | string | 返回消息 |
|
||||||
|
|
||||||
|
返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"message": "success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### 解除CI服务器绑定
|
#### 解除CI服务器绑定
|
||||||
```
|
```
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
class Ci::SecretsController < Ci::BaseController
|
||||||
|
|
||||||
|
before_action :load_repo
|
||||||
|
|
||||||
|
# 参数列表
|
||||||
|
def index
|
||||||
|
cloud_account = current_user.ci_cloud_account
|
||||||
|
result = Ci::Drone::API.new(@ci_user.user_hash, cloud_account.drone_url, params[:owner], params[:repo], nil).secrets
|
||||||
|
@secrets = result
|
||||||
|
end
|
||||||
|
|
||||||
|
#新增、更新参数
|
||||||
|
def create
|
||||||
|
cloud_account = current_user.ci_cloud_account
|
||||||
|
options = {
|
||||||
|
name: params[:name],
|
||||||
|
data: params[:data]
|
||||||
|
}
|
||||||
|
id = params[:id]
|
||||||
|
if id
|
||||||
|
result = Ci::Drone::API.new(@ci_user.user_hash, cloud_account.drone_url, params[:owner], params[:repo], options).update_secret
|
||||||
|
if result["id"]
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error(result["message"])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
result = Ci::Drone::API.new(@ci_user.user_hash, cloud_account.drone_url, params[:owner], params[:repo], options).create_secret
|
||||||
|
if result["id"]
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error(result["message"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#删除参数
|
||||||
|
def destroy
|
||||||
|
name = params[:name]
|
||||||
|
if !name.blank?
|
||||||
|
cloud_account = current_user.ci_cloud_account
|
||||||
|
Ci::Drone::API.new(@ci_user.user_hash, cloud_account.drone_url, params[:owner], params[:repo], {name: name}).delete_secret
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("参数名不能为空")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -85,4 +85,24 @@ class Ci::Drone::API < Ci::Drone::Request
|
||||||
post(endpoint, "/api/users", {login: options[:login], email: options[:email], avatar_url:options[:avatar_url],active:true, drone_token: options[:token]})
|
post(endpoint, "/api/users", {login: options[:login], email: options[:email], avatar_url:options[:avatar_url],active:true, drone_token: options[:token]})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a secret.
|
||||||
|
def create_secret
|
||||||
|
post(endpoint, "/api/repos/#{owner}/#{repo}/secrets", {name: options[:name], data: options[:data], pull_request:true, drone_token: drone_token})
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update a secret.
|
||||||
|
def update_secret
|
||||||
|
patch(endpoint, "/api/repos/#{owner}/#{repo}/secrets/#{options[:name]}", { data: options[:data], pull_request:true, drone_token: drone_token})
|
||||||
|
end
|
||||||
|
|
||||||
|
# list of secrets.
|
||||||
|
def secrets
|
||||||
|
get(endpoint, "/api/repos/#{owner}/#{repo}/secrets", drone_token: drone_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
# delete secret.
|
||||||
|
def delete_secret
|
||||||
|
delete(endpoint, "/api/repos/#{owner}/#{repo}/secrets/#{options[:name]}", drone_token: drone_token)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
json.id secret['id']
|
||||||
|
json.name secret['name']
|
|
@ -0,0 +1,3 @@
|
||||||
|
json.array! @secrets do |secret|
|
||||||
|
json.partial! "/ci/secrets/index", secret: secret
|
||||||
|
end
|
|
@ -39,6 +39,12 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :secrets do
|
||||||
|
member do
|
||||||
|
delete :destroy, :path => ":name", to: 'secrets#destroy'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :pipelines do
|
resources :pipelines do
|
||||||
collection do
|
collection do
|
||||||
get :list
|
get :list
|
||||||
|
|
Loading…
Reference in New Issue