Rainbond/api/region/defineSources.go

135 lines
4.0 KiB
Go
Raw Normal View History

2018-03-14 14:12:26 +08:00
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
2017-11-22 15:09:28 +08:00
// RAINBOND, Application Management Platform
2018-03-14 14:33:31 +08:00
2017-11-22 15:09:28 +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-11-22 15:09:28 +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-11-22 15:09:28 +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 region
//DefineSources DefineSources
2018-07-16 19:06:57 +08:00
// func (t *tenant) DefineSources(ss *api_model.SourceSpec) DefineSourcesInterface {
// return &DefineSources{
// tenant: *tenant,
// Model: Body{
// SourceSpec: ss,
// },
// }
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //DefineSources DefineSources
// type DefineSources struct {
// tenant
// Model Body
// }
2018-07-16 19:06:57 +08:00
// //Body Body
// type Body struct {
// SourceSpec *api_model.SourceSpec `json:"source_spec"`
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //DefineSourcesInterface DefineSourcesInterface
// type DefineSourcesInterface interface {
// GetSource(sourceAlias string) ([]byte, error)
// PostSource(sourceAlias string) error
// PutSource(SourcesAlias string) error
// DeleteSource(sourceAlias string) error
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //GetSource GetSource
// func (d *DefineSources) GetSource(sourceAlias string) ([]byte, error) {
// resp, status, err := request(
// fmt.Sprintf("/v2/tenants/%s/sources/%s/%s",
// d.tenant.tenantID, d.Model.SourceSpec.Alias, d.Model.SourceSpec.SourceBody.EnvName),
// "GET",
// nil,
// )
// if err != nil {
// logrus.Errorf("get define source %s error, %v", d.Model.SourceSpec.SourceBody.EnvName, err)
// return nil, err
// }
// if status > 400 {
// if status == 404 {
// return nil, fmt.Errorf("source %s is not exist", d.Model.SourceSpec.SourceBody.EnvName)
// }
// return nil, fmt.Errorf("get define source %s failed", d.Model.SourceSpec.SourceBody.EnvName)
// }
// //valJ, err := simplejson.NewJson(resp)
// return resp, nil
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //PostSource PostSource
// func (d *DefineSources) PostSource(sourceAlias string) error {
// data, err := ffjson.Marshal(d.Model)
// if err != nil {
// return err
// }
// _, status, err := request(
// fmt.Sprintf("/v2/tenants/%s/sources/%s",
// d.tenant.tenantID, d.Model.SourceSpec.Alias),
// "POST",
// data,
// )
// if err != nil {
// logrus.Errorf("create define source error, %v", err)
// return err
// }
// if status > 400 {
// logrus.Errorf("create define source error")
// return fmt.Errorf("cretae define source failed")
// }
// return nil
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //PutSource PutSource
// func (d *DefineSources) PutSource(sourceAlias string) error {
// data, err := ffjson.Marshal(d.Model)
// if err != nil {
// return err
// }
// _, status, err := request(
// fmt.Sprintf("/v2/tenants/%s/sources/%s/%s",
// d.tenant.tenantID, d.Model.SourceSpec.Alias, d.Model.SourceSpec.SourceBody.EnvName),
// "PUT",
// data,
// )
// if err != nil {
// logrus.Errorf("update define source error, %v", err)
// return err
// }
// if status > 400 {
// logrus.Errorf("update define source error")
// return fmt.Errorf("update define source failed")
// }
// return nil
// }
2017-11-22 15:09:28 +08:00
2018-07-16 19:06:57 +08:00
// //DeleteSource DeleteSource
// func (d *DefineSources) DeleteSource(sourceAlias string) error {
// _, status, err := request(
// fmt.Sprintf("/v2/tenants/%s/sources/%s/%s",
// d.tenant.tenantID, d.Model.SourceSpec.Alias, d.Model.SourceSpec.SourceBody.EnvName),
// "DELETE",
// nil,
// )
// if err != nil {
// logrus.Errorf("delete define source error, %v", err)
// return err
// }
// if status > 400 {
// logrus.Errorf("delete define source %s error", d.Model.SourceSpec.SourceBody.EnvName)
// }
// return nil
// }