2018-03-14 14:12:26 +08:00
|
|
|
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
|
2017-12-03 19:11:16 +08:00
|
|
|
// RAINBOND, Application Management Platform
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-12-03 19:11:16 +08:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
|
|
|
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
|
|
|
// must be obtained first.
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-12-03 19:11:16 +08:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-12-03 19:11:16 +08:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2017-12-07 16:37:09 +08:00
|
|
|
"github.com/go-chi/chi"
|
2018-04-24 16:44:59 +08:00
|
|
|
"github.com/goodrain/rainbond/api/handler"
|
|
|
|
api_model "github.com/goodrain/rainbond/api/model"
|
|
|
|
httputil "github.com/goodrain/rainbond/util/http"
|
2017-12-03 19:11:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//CloudManager cloud manager
|
|
|
|
type CloudManager struct{}
|
|
|
|
|
|
|
|
var defaultCloudManager *CloudManager
|
|
|
|
|
|
|
|
//GetCloudRouterManager get cloud Manager
|
|
|
|
func GetCloudRouterManager() *CloudManager {
|
|
|
|
if defaultCloudManager != nil {
|
|
|
|
return defaultCloudManager
|
|
|
|
}
|
|
|
|
defaultCloudManager = &CloudManager{}
|
|
|
|
return defaultCloudManager
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show Show
|
|
|
|
func (c *CloudManager) Show(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Write([]byte("cloud urls"))
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:37:09 +08:00
|
|
|
//CreateToken CreateToken
|
|
|
|
// swagger:operation POST /cloud/auth cloud createToken
|
2017-12-03 19:11:16 +08:00
|
|
|
//
|
2017-12-07 16:37:09 +08:00
|
|
|
// 产生token
|
2017-12-03 19:11:16 +08:00
|
|
|
//
|
2017-12-07 16:37:09 +08:00
|
|
|
// create token
|
2017-12-03 19:11:16 +08:00
|
|
|
//
|
|
|
|
// ---
|
2017-12-03 19:35:48 +08:00
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
2017-12-03 19:11:16 +08:00
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
2017-12-03 19:35:48 +08:00
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
2017-12-07 16:37:09 +08:00
|
|
|
func (c *CloudManager) CreateToken(w http.ResponseWriter, r *http.Request) {
|
2017-12-03 19:11:16 +08:00
|
|
|
var gt api_model.GetUserToken
|
2017-12-07 10:48:10 +08:00
|
|
|
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, >.Body, nil); !ok {
|
2017-12-03 19:11:16 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ti, err := handler.GetCloudManager().TokenDispatcher(>)
|
|
|
|
if err != nil {
|
|
|
|
err.Handle(r, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httputil.ReturnSuccess(r, w, ti)
|
|
|
|
}
|
2017-12-07 09:56:08 +08:00
|
|
|
|
2017-12-07 16:37:09 +08:00
|
|
|
//GetTokenInfo GetTokenInfo
|
|
|
|
// swagger:operation GET /cloud/auth/{eid} cloud getTokenInfo
|
|
|
|
//
|
|
|
|
// 获取tokeninfo
|
|
|
|
//
|
|
|
|
// get token info
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
|
|
|
func (c *CloudManager) GetTokenInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
|
eid := chi.URLParam(r, "eid")
|
|
|
|
ti, err := handler.GetCloudManager().GetTokenInfo(eid)
|
|
|
|
if err != nil {
|
|
|
|
err.Handle(r, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httputil.ReturnSuccess(r, w, ti)
|
|
|
|
}
|
|
|
|
|
|
|
|
//UpdateToken UpdateToken
|
2017-12-07 17:25:27 +08:00
|
|
|
// swagger:operation PUT /cloud/auth/{eid} cloud updateToken
|
2017-12-07 16:37:09 +08:00
|
|
|
//
|
|
|
|
// 更新token
|
|
|
|
//
|
|
|
|
// update token info
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
|
|
|
func (c *CloudManager) UpdateToken(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var ut api_model.UpdateToken
|
|
|
|
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &ut.Body, nil); !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
eid := chi.URLParam(r, "eid")
|
|
|
|
err := handler.GetCloudManager().UpdateTokenTime(eid, ut.Body.ValidityPeriod)
|
|
|
|
if err != nil {
|
|
|
|
err.Handle(r, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
}
|
|
|
|
|
2017-12-07 09:56:08 +08:00
|
|
|
//GetAPIManager GetAPIManager
|
|
|
|
// swagger:operation GET /cloud/api/manager cloud GetAPIManager
|
|
|
|
//
|
|
|
|
// 获取api管理
|
|
|
|
//
|
|
|
|
// get api manager
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
|
|
|
func (c *CloudManager) GetAPIManager(w http.ResponseWriter, r *http.Request) {
|
|
|
|
apiMap := handler.GetTokenIdenHandler().GetAPIManager()
|
|
|
|
httputil.ReturnSuccess(r, w, apiMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
//AddAPIManager AddAPIManager
|
|
|
|
// swagger:operation POST /cloud/api/manager cloud addAPIManager
|
|
|
|
//
|
2017-12-08 10:16:29 +08:00
|
|
|
// 添加api管理
|
2017-12-07 09:56:08 +08:00
|
|
|
//
|
|
|
|
// get api manager
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
|
|
|
func (c *CloudManager) AddAPIManager(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var am api_model.APIManager
|
2017-12-07 10:48:10 +08:00
|
|
|
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &am.Body, nil); !ok {
|
2017-12-07 09:56:08 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err := handler.GetTokenIdenHandler().AddAPIManager(&am)
|
|
|
|
if err != nil {
|
|
|
|
err.Handle(r, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
//DeleteAPIManager DeleteAPIManager
|
|
|
|
// swagger:operation DELETE /cloud/api/manager cloud deleteAPIManager
|
|
|
|
//
|
2017-12-08 10:16:29 +08:00
|
|
|
// 删除api管理
|
2017-12-07 09:56:08 +08:00
|
|
|
//
|
|
|
|
// delete api manager
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// - application/x-protobuf
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// - application/xml
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// default:
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
|
|
|
// description: 统一返回格式
|
|
|
|
func (c *CloudManager) DeleteAPIManager(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var am api_model.APIManager
|
2017-12-07 10:48:10 +08:00
|
|
|
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &am.Body, nil); !ok {
|
2017-12-07 09:56:08 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err := handler.GetTokenIdenHandler().DeleteAPIManager(&am)
|
|
|
|
if err != nil {
|
|
|
|
err.Handle(r, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
}
|