2018-03-16 11:47:06 +08:00
|
|
|
|
// RAINBOND, Application Management Platform
|
|
|
|
|
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
// 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"
|
|
|
|
|
"os"
|
2018-03-16 12:16:57 +08:00
|
|
|
|
"strconv"
|
2018-03-16 11:47:06 +08:00
|
|
|
|
|
2019-01-24 11:28:17 +08:00
|
|
|
|
"github.com/goodrain/rainbond/api/handler/cloud"
|
2018-03-16 11:47:06 +08:00
|
|
|
|
|
2018-04-24 16:44:59 +08:00
|
|
|
|
"github.com/goodrain/rainbond/db"
|
|
|
|
|
"github.com/goodrain/rainbond/db/model"
|
2018-03-16 11:47:06 +08:00
|
|
|
|
|
2018-04-24 16:44:59 +08:00
|
|
|
|
"github.com/goodrain/rainbond/api/middleware"
|
|
|
|
|
httputil "github.com/goodrain/rainbond/util/http"
|
2018-03-16 11:47:06 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//ChargesVerifyController service charges verify
|
2018-04-02 19:22:07 +08:00
|
|
|
|
// swagger:operation GET /v2/tenants/{tenant_name}/chargesverify v2 chargesverify
|
2018-03-16 11:47:06 +08:00
|
|
|
|
//
|
|
|
|
|
// 应用扩大资源申请接口,公有云云市验证,私有云不验证
|
|
|
|
|
//
|
|
|
|
|
// service charges verify
|
|
|
|
|
//
|
|
|
|
|
// ---
|
|
|
|
|
// consumes:
|
|
|
|
|
// - application/json
|
|
|
|
|
// - application/x-protobuf
|
|
|
|
|
//
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// - application/xml
|
|
|
|
|
//
|
|
|
|
|
// responses:
|
|
|
|
|
// default:
|
|
|
|
|
// schema:
|
|
|
|
|
// "$ref": "#/responses/commandResponse"
|
2018-03-27 11:39:48 +08:00
|
|
|
|
// description: 状态码非200,表示验证过程发生错误。状态码200,msg代表实际状态:success, illegal_quantity, missing_tenant, owned_fee, region_unauthorized, lack_of_memory
|
2018-03-16 11:47:06 +08:00
|
|
|
|
func ChargesVerifyController(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*model.Tenants)
|
|
|
|
|
if tenant.EID == "" {
|
|
|
|
|
eid := r.FormValue("eid")
|
|
|
|
|
if eid == "" {
|
2019-02-12 16:41:14 +08:00
|
|
|
|
httputil.ReturnError(r, w, 400, "enterprise id can not found")
|
2018-03-16 11:47:06 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
tenant.EID = eid
|
|
|
|
|
db.GetManager().TenantDao().UpdateModel(tenant)
|
|
|
|
|
}
|
|
|
|
|
quantity := r.FormValue("quantity")
|
|
|
|
|
if quantity == "" {
|
|
|
|
|
httputil.ReturnError(r, w, 400, "quantity can not found")
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-03-16 12:16:57 +08:00
|
|
|
|
quantityInt, err := strconv.Atoi(quantity)
|
2018-03-16 11:47:06 +08:00
|
|
|
|
if err != nil {
|
2018-03-16 12:16:57 +08:00
|
|
|
|
httputil.ReturnError(r, w, 400, "quantity type must be int")
|
2018-03-16 11:47:06 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-01-24 11:28:17 +08:00
|
|
|
|
|
|
|
|
|
if publicCloud := os.Getenv("PUBLIC_CLOUD"); publicCloud != "true" {
|
|
|
|
|
err := cloud.PriChargeSverify(tenant, quantityInt)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err.Handle(r, w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
|
|
|
|
} else {
|
|
|
|
|
reason := r.FormValue("reason")
|
|
|
|
|
if err := cloud.PubChargeSverify(tenant, quantityInt, reason); err != nil {
|
|
|
|
|
err.Handle(r, w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httputil.ReturnSuccess(r, w, nil)
|
2018-03-16 11:47:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|