mirror of
https://github.com/1Panel-dev/KubePi.git
synced 2025-11-03 03:03:27 +08:00
feat : role api 文档
This commit is contained in:
@@ -25,6 +25,181 @@ const docTemplate = `{
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/roles": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "List all roles",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "List all roles",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Create role",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Create role",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles/{name}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Get role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "权限名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Update role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Update role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "角色名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Delete role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Delete role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "角色名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -275,6 +450,73 @@ const docTemplate = `{
|
||||
},
|
||||
"nickName": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"role.PolicyRule": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"resource": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"resourceNames": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"verbs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"role.Role": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apiVersion": {
|
||||
"type": "string"
|
||||
},
|
||||
"builtIn": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"kind": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"rules": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/role.PolicyRule"
|
||||
}
|
||||
},
|
||||
"updateAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,6 +15,181 @@
|
||||
},
|
||||
"basePath": "/kubepi/api/v1",
|
||||
"paths": {
|
||||
"/roles": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "List all roles",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "List all roles",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Create role",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Create role",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/roles/{name}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Get role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "权限名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Update role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Update role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "角色名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Delete role by name",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"roles"
|
||||
],
|
||||
"summary": "Delete role by name",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "角色名称",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/role.Role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -265,6 +440,73 @@
|
||||
},
|
||||
"nickName": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"role.PolicyRule": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"resource": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"resourceNames": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"verbs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"role.Role": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apiVersion": {
|
||||
"type": "string"
|
||||
},
|
||||
"builtIn": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"kind": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"rules": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/role.PolicyRule"
|
||||
}
|
||||
},
|
||||
"updateAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,6 +30,50 @@ definitions:
|
||||
type: string
|
||||
nickName:
|
||||
type: string
|
||||
roles:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: object
|
||||
role.PolicyRule:
|
||||
properties:
|
||||
resource:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
resourceNames:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
verbs:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: object
|
||||
role.Role:
|
||||
properties:
|
||||
apiVersion:
|
||||
type: string
|
||||
builtIn:
|
||||
type: boolean
|
||||
createAt:
|
||||
type: string
|
||||
createdBy:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
kind:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
rules:
|
||||
items:
|
||||
$ref: '#/definitions/role.PolicyRule'
|
||||
type: array
|
||||
updateAt:
|
||||
type: string
|
||||
uuid:
|
||||
type: string
|
||||
type: object
|
||||
user.Authenticate:
|
||||
properties:
|
||||
@@ -91,6 +135,115 @@ info:
|
||||
termsOfService: http://kubeoperator.io
|
||||
title: KubePi Restful API
|
||||
paths:
|
||||
/roles:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: List all roles
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/role.Role'
|
||||
type: array
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: List all roles
|
||||
tags:
|
||||
- roles
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Create role
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/role.Role'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/role.Role'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Create role
|
||||
tags:
|
||||
- roles
|
||||
/roles/{name}:
|
||||
delete:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Delete role by name
|
||||
parameters:
|
||||
- description: 角色名称
|
||||
in: path
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/role.Role'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Delete role by name
|
||||
tags:
|
||||
- roles
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Get role by name
|
||||
parameters:
|
||||
- description: 权限名称
|
||||
in: path
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/role.Role'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Get role by name
|
||||
tags:
|
||||
- roles
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Update role by name
|
||||
parameters:
|
||||
- description: 角色名称
|
||||
in: path
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/role.Role'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Update role by name
|
||||
tags:
|
||||
- roles
|
||||
/users:
|
||||
get:
|
||||
consumes:
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
_ "github.com/KubeOperator/kubepi/cmd/server/docs"
|
||||
_ "github.com/KubeOperator/kubepi/internal/model/v1/docs"
|
||||
_ "github.com/KubeOperator/kubepi/internal/model/v1/role"
|
||||
_ "github.com/KubeOperator/kubepi/internal/model/v1/user"
|
||||
"github.com/KubeOperator/kubepi/internal/route"
|
||||
"github.com/KubeOperator/kubepi/internal/server"
|
||||
|
||||
@@ -50,6 +50,15 @@ func (h *Handler) SearchRoles() iris.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// List Roles
|
||||
// @Tags roles
|
||||
// @Summary List all roles
|
||||
// @Description List all roles
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} []v1Role.Role
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /roles [get]
|
||||
func (h *Handler) ListRoles() iris.Handler {
|
||||
return func(ctx *context.Context) {
|
||||
roles, err := h.roleService.List(common.DBOptions{})
|
||||
@@ -64,6 +73,16 @@ func (h *Handler) ListRoles() iris.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// Create Role
|
||||
// @Tags roles
|
||||
// @Summary Create role
|
||||
// @Description Create role
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body v1Role.Role true "request"
|
||||
// @Success 200 {object} v1Role.Role
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /roles [post]
|
||||
func (h *Handler) CreateRole() iris.Handler {
|
||||
return func(ctx *context.Context) {
|
||||
var req v1Role.Role
|
||||
@@ -84,6 +103,16 @@ func (h *Handler) CreateRole() iris.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Role
|
||||
// @Tags roles
|
||||
// @Summary Delete role by name
|
||||
// @Description Delete role by name
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param name path string true "角色名称"
|
||||
// @Success 200 {object} v1Role.Role
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /roles/{name} [delete]
|
||||
func (h *Handler) DeleteRole() iris.Handler {
|
||||
return func(ctx *context.Context) {
|
||||
roleName := ctx.Params().GetString("name")
|
||||
@@ -114,6 +143,16 @@ func (h *Handler) DeleteRole() iris.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// Update Role
|
||||
// @Tags roles
|
||||
// @Summary Update role by name
|
||||
// @Description Update role by name
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param name path string true "角色名称"
|
||||
// @Success 200 {object} v1Role.Role
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /roles/{name} [put]
|
||||
func (h *Handler) UpdateRole() iris.Handler {
|
||||
return func(ctx *context.Context) {
|
||||
roleName := ctx.Params().GetString("name")
|
||||
@@ -137,6 +176,16 @@ func (h *Handler) UpdateRole() iris.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// Get Role
|
||||
// @Tags roles
|
||||
// @Summary Get role by name
|
||||
// @Description Get role by name
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param name path string true "权限名称"
|
||||
// @Success 200 {object} v1Role.Role
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /roles/{name} [get]
|
||||
func (h *Handler) GetRole() iris.Handler {
|
||||
return func(ctx *context.Context) {
|
||||
roleName := ctx.Params().GetString("name")
|
||||
|
||||
@@ -34,7 +34,7 @@ func NewHandler() *Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// List User
|
||||
// Search User
|
||||
// @Tags users
|
||||
// @Summary Search users
|
||||
// @Description Search users by Condition
|
||||
|
||||
@@ -7,6 +7,7 @@ type UserCreate struct {
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
Authenticate Authenticate `json:"authenticate"`
|
||||
Mfa Mfa `json:"mfa"`
|
||||
Roles []string `json:"roles"`
|
||||
}
|
||||
|
||||
type Authenticate struct {
|
||||
|
||||
Reference in New Issue
Block a user