Skip to content

Commit

Permalink
Merge pull request #214 from actiontech/fix-issue2309
Browse files Browse the repository at this point in the history
Fix issue2309
  • Loading branch information
LordofAvernus authored Mar 20, 2024
2 parents 0e5d696 + 36590e0 commit cd99b64
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 2 deletions.
74 changes: 73 additions & 1 deletion api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,37 @@
}
}
},
"/v1/dms/users/gen_token": {
"post": {
"tags": [
"dms"
],
"summary": "Gen user access token.",
"operationId": "GenAccessToken",
"parameters": [
{
"type": "string",
"x-go-name": "ExpirationDays",
"name": "expiration_days",
"in": "query"
}
],
"responses": {
"200": {
"description": "GenAccessTokenReply",
"schema": {
"$ref": "#/definitions/GenAccessTokenReply"
}
},
"default": {
"description": "GenericResp",
"schema": {
"$ref": "#/definitions/GenericResp"
}
}
}
}
},
"/v1/dms/users/{user_uid}": {
"get": {
"tags": [
Expand Down Expand Up @@ -3763,6 +3794,24 @@
}
},
"definitions": {
"AccessTokenInfo": {
"type": "object",
"properties": {
"access_token": {
"type": "string",
"x-go-name": "AccessToken"
},
"is_expired": {
"type": "boolean",
"x-go-name": "IsExpired"
},
"token_expired_timestamp": {
"type": "string",
"x-go-name": "ExpiredTime"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
},
"AddDBServicePreCheckReply": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -4795,6 +4844,26 @@
},
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"GenAccessTokenReply": {
"type": "object",
"properties": {
"code": {
"description": "code",
"type": "integer",
"format": "int64",
"x-go-name": "Code"
},
"data": {
"$ref": "#/definitions/AccessTokenInfo"
},
"message": {
"description": "message",
"type": "string",
"x-go-name": "Message"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
},
"GenericResp": {
"description": "GenericResp defines the return code and msg",
"type": "object",
Expand Down Expand Up @@ -5360,6 +5429,9 @@
"description": "A dms user",
"type": "object",
"properties": {
"access_token_info": {
"$ref": "#/definitions/AccessTokenInfo"
},
"authentication_type": {
"description": "user authentication type\nldap UserAuthenticationTypeLDAP\ndms UserAuthenticationTypeDMS\noauth2 UserAuthenticationTypeOAUTH2\nunknown UserAuthenticationTypeUnknown",
"type": "string",
Expand Down Expand Up @@ -7634,7 +7706,7 @@
"x-go-name": "Uid"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"UpdateCompanyNotice": {
"description": "A companynotice",
Expand Down
52 changes: 51 additions & 1 deletion api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ basePath: /
consumes:
- application/json
definitions:
AccessTokenInfo:
properties:
access_token:
type: string
x-go-name: AccessToken
is_expired:
type: boolean
x-go-name: IsExpired
token_expired_timestamp:
type: string
x-go-name: ExpiredTime
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
AddDBServicePreCheckReply:
properties:
code:
Expand Down Expand Up @@ -795,6 +808,21 @@ definitions:
x-go-name: IsFeishuNotificationEnabled
type: object
x-go-package: github.com/actiontech/dms/api/dms/service/v1
GenAccessTokenReply:
properties:
code:
description: code
format: int64
type: integer
x-go-name: Code
data:
$ref: '#/definitions/AccessTokenInfo'
message:
description: message
type: string
x-go-name: Message
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
GenericResp:
description: GenericResp defines the return code and msg
properties:
Expand Down Expand Up @@ -1226,6 +1254,8 @@ definitions:
GetUser:
description: A dms user
properties:
access_token_info:
$ref: '#/definitions/AccessTokenInfo'
authentication_type:
description: |-
user authentication type
Expand Down Expand Up @@ -3067,7 +3097,7 @@ definitions:
type: string
x-go-name: Uid
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
x-go-package: github.com/actiontech/dms/api/dms/service/v1
UpdateCompanyNotice:
description: A companynotice
properties:
Expand Down Expand Up @@ -6129,6 +6159,26 @@ paths:
summary: Get user op permission info, This API is used by other component such as sqle&auth to check user permissions.
tags:
- dms
/v1/dms/users/gen_token:
post:
operationId: GenAccessToken
parameters:
- in: query
name: expiration_days
type: string
x-go-name: ExpirationDays
responses:
"200":
description: GenAccessTokenReply
schema:
$ref: '#/definitions/GenAccessTokenReply'
default:
description: GenericResp
schema:
$ref: '#/definitions/GenericResp'
summary: Gen user access token.
tags:
- dms
/v1/dms/webhooks:
post:
operationId: WebHookSendMessage
Expand Down
17 changes: 17 additions & 0 deletions internal/apiserver/service/dms_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,23 @@ func (a *DMSController) GetUser(c echo.Context) error {
return NewOkRespWithReply(c, reply)
}

// swagger:route POST /v1/dms/users/gen_token dms GenAccessToken
//
// Gen user access token.
//
// responses:
// 200: body:GenAccessTokenReply
// default: body:GenericResp
func (a *DMSController) GenAccessToken(c echo.Context) error {
req := new(dmsV1.GenAccessToken)
err := bindAndValidateReq(c, req)
if nil != err {
return NewErrResp(c, err, apiError.BadRequestErr)
}
reply := &dmsV1.GenAccessTokenReply{}
return NewOkRespWithReply(c, reply)
}

// swagger:route POST /v1/dms/user_groups dms AddUserGroup
//
// Add user group.
Expand Down
1 change: 1 addition & 0 deletions internal/apiserver/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s *APIServer) initRouter() error {
userV1.PUT("/:user_uid", s.DMSController.UpdateUser)
userV1.GET(dmsV1.GetUserOpPermissionRouterWithoutPrefix(":user_uid"), s.DMSController.GetUserOpPermission)
userV1.PUT("", s.DMSController.UpdateCurrentUser)
userV1.POST("/gen_token", s.DMSController.GenAccessToken)

sessionv1 := v1.Group(dmsV1.SessionRouterGroup)
sessionv1.POST("", s.DMSController.AddSession)
Expand Down
22 changes: 22 additions & 0 deletions pkg/dms-common/api/dms/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ type GetUser struct {
// user bind name space
UserBindProjects []UserBindProject `json:"user_bind_projects"`
ThirdPartyUserInfo string `json:"third_party_user_info"`
// access token
AccessTokenInfo AccessTokenInfo `json:"access_token_info"`
}

type AccessTokenInfo struct {
AccessToken string `json:"access_token"`
ExpiredTime string `json:"token_expired_timestamp" example:"RFC3339"`
IsExpired bool `json:"is_expired"`
}

type UserBindProject struct {
Expand Down Expand Up @@ -298,3 +306,17 @@ type ListUserReply struct {
// Generic reply
base.GenericResp
}

// swagger:parameters GenAccessToken
type GenAccessToken struct {
ExpirationDays string `param:"expiration_days" json:"expiration_days" validate:"required"`
}

// swagger:model GenAccessTokenReply
type GenAccessTokenReply struct {
// Get user reply
Data *AccessTokenInfo `json:"data"`

// Generic reply
base.GenericResp
}

0 comments on commit cd99b64

Please sign in to comment.