mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-01-12 00:06:29 +08:00
feat: Add API interface authentication function (#7146)
This commit is contained in:
@@ -887,20 +887,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/issafety": {
|
||||
"get": {
|
||||
"description": "获取系统安全登录状态",
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Load safety status",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/language": {
|
||||
"get": {
|
||||
"description": "获取系统语言设置",
|
||||
@@ -9507,6 +9493,77 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/api/config/generate/key": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "生成 API 接口密钥",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"System Setting"
|
||||
],
|
||||
"summary": "generate api key",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
},
|
||||
"x-panel-log": {
|
||||
"BeforeFunctions": [],
|
||||
"bodyKeys": [],
|
||||
"formatEN": "generate api key",
|
||||
"formatZH": "生成 API 接口密钥",
|
||||
"paramKeys": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/api/config/update": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "更新 API 接口配置",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"System Setting"
|
||||
],
|
||||
"summary": "Update api config",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.ApiInterfaceConfig"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
},
|
||||
"x-panel-log": {
|
||||
"BeforeFunctions": [],
|
||||
"bodyKeys": [
|
||||
"ipWhiteList"
|
||||
],
|
||||
"formatEN": "update api config =\u003e IP White List: [ipWhiteList]",
|
||||
"formatZH": "更新 API 接口配置 =\u003e IP 白名单: [ipWhiteList]",
|
||||
"paramKeys": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/backup": {
|
||||
"post": {
|
||||
"security": [
|
||||
@@ -15310,6 +15367,20 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.ApiInterfaceConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apiInterfaceStatus": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipWhiteList": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AppInstallInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -19629,6 +19700,12 @@ const docTemplate = `{
|
||||
"allowIPs": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiInterfaceStatus": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"appStoreLastModified": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -19677,6 +19754,9 @@ const docTemplate = `{
|
||||
"fileRecycleBin": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipWhiteList": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipv6": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -23635,15 +23715,29 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"CustomToken": {
|
||||
"description": "自定义 Token 格式,格式:md5('1panel' + 1Panel-Token + 1Panel-Timestamp)。\n` + "`" + `` + "`" + `` + "`" + `\n示例请求头:\ncurl -X GET \"http://localhost:4004/api/v1/resource\" \\\n-H \"1Panel-Token: \u003c1panel_token\u003e\" \\\n-H \"1Panel-Timestamp: \u003ccurrent_unix_timestamp\u003e\"\n` + "`" + `` + "`" + `` + "`" + `\n- ` + "`" + `1Panel-Token` + "`" + ` 为面板 API 接口密钥。",
|
||||
"type": "apiKey",
|
||||
"name": "1Panel-Token",
|
||||
"in": "Header"
|
||||
},
|
||||
"Timestamp": {
|
||||
"description": "- ` + "`" + `1Panel-Timestamp` + "`" + ` 为当前时间的 Unix 时间戳(单位:秒)。",
|
||||
"type": "apiKey",
|
||||
"name": "1Panel-Timestamp",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "localhost",
|
||||
Host: "",
|
||||
BasePath: "/api/v1",
|
||||
Schemes: []string{},
|
||||
Schemes: []string{"http", "https"},
|
||||
Title: "1Panel",
|
||||
Description: "开源Linux面板",
|
||||
InfoInstanceName: "swagger",
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"schemes": [
|
||||
"http",
|
||||
"https"
|
||||
],
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "开源Linux面板",
|
||||
@@ -11,7 +15,6 @@
|
||||
},
|
||||
"version": "1.0"
|
||||
},
|
||||
"host": "localhost",
|
||||
"basePath": "/api/v1",
|
||||
"paths": {
|
||||
"/apps/:key": {
|
||||
@@ -881,20 +884,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/issafety": {
|
||||
"get": {
|
||||
"description": "获取系统安全登录状态",
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Load safety status",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/language": {
|
||||
"get": {
|
||||
"description": "获取系统语言设置",
|
||||
@@ -9501,6 +9490,77 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/api/config/generate/key": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "生成 API 接口密钥",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"System Setting"
|
||||
],
|
||||
"summary": "generate api key",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
},
|
||||
"x-panel-log": {
|
||||
"BeforeFunctions": [],
|
||||
"bodyKeys": [],
|
||||
"formatEN": "generate api key",
|
||||
"formatZH": "生成 API 接口密钥",
|
||||
"paramKeys": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/api/config/update": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "更新 API 接口配置",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"System Setting"
|
||||
],
|
||||
"summary": "Update api config",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.ApiInterfaceConfig"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
},
|
||||
"x-panel-log": {
|
||||
"BeforeFunctions": [],
|
||||
"bodyKeys": [
|
||||
"ipWhiteList"
|
||||
],
|
||||
"formatEN": "update api config =\u003e IP White List: [ipWhiteList]",
|
||||
"formatZH": "更新 API 接口配置 =\u003e IP 白名单: [ipWhiteList]",
|
||||
"paramKeys": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"/settings/backup": {
|
||||
"post": {
|
||||
"security": [
|
||||
@@ -15304,6 +15364,20 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.ApiInterfaceConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apiInterfaceStatus": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipWhiteList": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AppInstallInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -19623,6 +19697,12 @@
|
||||
"allowIPs": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiInterfaceStatus": {
|
||||
"type": "string"
|
||||
},
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"appStoreLastModified": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -19671,6 +19751,9 @@
|
||||
"fileRecycleBin": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipWhiteList": {
|
||||
"type": "string"
|
||||
},
|
||||
"ipv6": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -23629,5 +23712,19 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"CustomToken": {
|
||||
"description": "自定义 Token 格式,格式:md5('1panel' + 1Panel-Token + 1Panel-Timestamp)。\n```\n示例请求头:\ncurl -X GET \"http://localhost:4004/api/v1/resource\" \\\n-H \"1Panel-Token: \u003c1panel_token\u003e\" \\\n-H \"1Panel-Timestamp: \u003ccurrent_unix_timestamp\u003e\"\n```\n- `1Panel-Token` 为面板 API 接口密钥。",
|
||||
"type": "apiKey",
|
||||
"name": "1Panel-Token",
|
||||
"in": "Header"
|
||||
},
|
||||
"Timestamp": {
|
||||
"description": "- `1Panel-Timestamp` 为当前时间的 Unix 时间戳(单位:秒)。",
|
||||
"type": "apiKey",
|
||||
"name": "1Panel-Timestamp",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,15 @@ definitions:
|
||||
oldRule:
|
||||
$ref: '#/definitions/dto.AddrRuleOperate'
|
||||
type: object
|
||||
dto.ApiInterfaceConfig:
|
||||
properties:
|
||||
apiInterfaceStatus:
|
||||
type: string
|
||||
apiKey:
|
||||
type: string
|
||||
ipWhiteList:
|
||||
type: string
|
||||
type: object
|
||||
dto.AppInstallInfo:
|
||||
properties:
|
||||
id:
|
||||
@@ -2951,6 +2960,10 @@ definitions:
|
||||
properties:
|
||||
allowIPs:
|
||||
type: string
|
||||
apiInterfaceStatus:
|
||||
type: string
|
||||
apiKey:
|
||||
type: string
|
||||
appStoreLastModified:
|
||||
type: string
|
||||
appStoreSyncStatus:
|
||||
@@ -2983,6 +2996,8 @@ definitions:
|
||||
type: string
|
||||
fileRecycleBin:
|
||||
type: string
|
||||
ipWhiteList:
|
||||
type: string
|
||||
ipv6:
|
||||
type: string
|
||||
language:
|
||||
@@ -5624,7 +5639,6 @@ definitions:
|
||||
version:
|
||||
type: string
|
||||
type: object
|
||||
host: localhost
|
||||
info:
|
||||
contact: {}
|
||||
description: 开源Linux面板
|
||||
@@ -6181,15 +6195,6 @@ paths:
|
||||
summary: Check System isDemo
|
||||
tags:
|
||||
- Auth
|
||||
/auth/issafety:
|
||||
get:
|
||||
description: 获取系统安全登录状态
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
summary: Load safety status
|
||||
tags:
|
||||
- Auth
|
||||
/auth/language:
|
||||
get:
|
||||
description: 获取系统语言设置
|
||||
@@ -11638,6 +11643,52 @@ paths:
|
||||
formatEN: Update runtime [name]
|
||||
formatZH: 更新运行环境 [name]
|
||||
paramKeys: []
|
||||
/settings/api/config/generate/key:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 生成 API 接口密钥
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: generate api key
|
||||
tags:
|
||||
- System Setting
|
||||
x-panel-log:
|
||||
BeforeFunctions: []
|
||||
bodyKeys: []
|
||||
formatEN: generate api key
|
||||
formatZH: 生成 API 接口密钥
|
||||
paramKeys: []
|
||||
/settings/api/config/update:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 更新 API 接口配置
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.ApiInterfaceConfig'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Update api config
|
||||
tags:
|
||||
- System Setting
|
||||
x-panel-log:
|
||||
BeforeFunctions: []
|
||||
bodyKeys:
|
||||
- ipWhiteList
|
||||
formatEN: 'update api config => IP White List: [ipWhiteList]'
|
||||
formatZH: '更新 API 接口配置 => IP 白名单: [ipWhiteList]'
|
||||
paramKeys: []
|
||||
/settings/backup:
|
||||
post:
|
||||
consumes:
|
||||
@@ -15292,4 +15343,26 @@ paths:
|
||||
formatEN: Update website [primaryDomain]
|
||||
formatZH: 更新网站 [primaryDomain]
|
||||
paramKeys: []
|
||||
schemes:
|
||||
- http
|
||||
- https
|
||||
securityDefinitions:
|
||||
CustomToken:
|
||||
description: |-
|
||||
自定义 Token 格式,格式:md5('1panel' + 1Panel-Token + 1Panel-Timestamp)。
|
||||
```
|
||||
示例请求头:
|
||||
curl -X GET "http://localhost:4004/api/v1/resource" \
|
||||
-H "1Panel-Token: <1panel_token>" \
|
||||
-H "1Panel-Timestamp: <current_unix_timestamp>"
|
||||
```
|
||||
- `1Panel-Token` 为面板 API 接口密钥。
|
||||
in: Header
|
||||
name: 1Panel-Token
|
||||
type: apiKey
|
||||
Timestamp:
|
||||
description: '- `1Panel-Timestamp` 为当前时间的 Unix 时间戳(单位:秒)。'
|
||||
in: header
|
||||
name: 1Panel-Timestamp
|
||||
type: apiKey
|
||||
swagger: "2.0"
|
||||
|
||||
@@ -15,8 +15,26 @@ import (
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
// @host localhost
|
||||
// @BasePath /api/v1
|
||||
// @schemes http https
|
||||
|
||||
// @securityDefinitions.apikey CustomToken
|
||||
// @description 自定义 Token 格式,格式:md5('1panel' + 1Panel-Token + 1Panel-Timestamp)。
|
||||
// @description ```
|
||||
// @description 示例请求头:
|
||||
// @description curl -X GET "http://localhost:4004/api/v1/resource" \
|
||||
// @description -H "1Panel-Token: <1panel_token>" \
|
||||
// @description -H "1Panel-Timestamp: <current_unix_timestamp>"
|
||||
// @description ```
|
||||
// @description - `1Panel-Token` 为面板 API 接口密钥。
|
||||
// @type apiKey
|
||||
// @in Header
|
||||
// @name 1Panel-Token
|
||||
// @securityDefinitions.apikey Timestamp
|
||||
// @type apiKey
|
||||
// @in header
|
||||
// @name 1Panel-Timestamp
|
||||
// @description - `1Panel-Timestamp` 为当前时间的 Unix 时间戳(单位:秒)。
|
||||
|
||||
//go:generate swag init -o ./docs -g main.go -d ../../backend -g ../cmd/server/main.go
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user