Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tables and table data #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions cmd/config-server/service/data_source_content.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package service

import (
"context"

"github.com/TencentBlueKing/bk-bscp/pkg/iam/meta"
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
)

// CreateTableContent implements pbcs.ConfigServer.
func (s *Service) CreateTableContent(ctx context.Context, req *pbcs.CreateTableContentReq) (
*pbcs.CreateTableContentResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.CreateTableContent(kit.RpcCtx(), &pbds.CreateTableContentReq{
BizId: req.BizId,
DataSourceMappingId: req.DataSourceMappingId,
Content: req.GetContent(),
})
if err != nil {
return nil, err
}

return &pbcs.CreateTableContentResp{Ids: resp.GetIds()}, nil
}

// ListTableContent implements pbcs.ConfigServer.
func (s *Service) ListTableContent(ctx context.Context, req *pbcs.ListTableContentReq) (
*pbcs.ListTableContentResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.ListTableContent(kit.RpcCtx(), &pbds.ListTableContentReq{
BizId: req.BizId,
DataSourceMappingId: req.DataSourceMappingId,
SearchValue: req.SearchValue,
Start: req.Start,
Limit: req.Limit,
All: req.All,
})
if err != nil {
return nil, err
}

return &pbcs.ListTableContentResp{
Details: resp.GetDetails(),
Fields: resp.GetFields(),
}, nil
}

// UpdateTableContent implements pbcs.ConfigServer.
func (s *Service) UpdateTableContent(ctx context.Context, req *pbcs.UpdateTableContentReq) (
*pbcs.UpdateTableContentResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

contents := make([]*pbds.UpdateTableContentReq_Item, 0)
for _, v := range req.GetContents() {
contents = append(contents, &pbds.UpdateTableContentReq_Item{
TableContentId: v.TableContentId,
Content: v.GetContent(),
})
}

resp, err := s.client.DS.UpdateTableContent(kit.RpcCtx(), &pbds.UpdateTableContentReq{
BizId: req.BizId,
DataSourceMappingId: req.DataSourceMappingId,
Contents: contents,
})
if err != nil {
return nil, err
}

return &pbcs.UpdateTableContentResp{Ids: resp.GetIds()}, nil
}

// CheckTableField implements pbcs.ConfigServer.
func (s *Service) CheckTableField(ctx context.Context, req *pbcs.CheckTableFieldReq) (*pbcs.CheckTableFieldResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.CheckTableField(kit.RpcCtx(), &pbds.CheckTableFieldReq{
BizId: req.BizId,
DataSourceMappingId: req.DataSourceMappingId,
FieldName: req.FieldName,
})
if err != nil {
return nil, err
}

return &pbcs.CheckTableFieldResp{Exist: resp.Exist}, nil
}
150 changes: 150 additions & 0 deletions cmd/config-server/service/data_source_mapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package service

import (
"context"

"github.com/TencentBlueKing/bk-bscp/pkg/iam/meta"
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
)

// ListDataSourceTable get data source tables
func (s *Service) ListDataSourceTable(ctx context.Context, req *pbcs.ListDataSourceTableReq) (
*pbcs.ListDataSourceTableResp, error) {
kit := kit.FromGrpcContext(ctx)

res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.ListDataSourceTable(kit.RpcCtx(), &pbds.ListDataSourceTableReq{
BizId: req.BizId,
SearchValue: req.SearchValue,
Start: req.Start,
Limit: req.Limit,
All: req.All,
DataSourceType: req.DataSourceType,
})
if err != nil {
return nil, err
}

return &pbcs.ListDataSourceTableResp{
Count: resp.GetCount(),
Details: resp.GetDetails(),
}, nil
}

// CreateDataSourceTable create data source table
func (s *Service) CreateDataSourceTable(ctx context.Context, req *pbcs.CreateDataSourceTableReq) (
*pbcs.CreateDataSourceTableResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.CreateDataSourceTable(kit.RpcCtx(), &pbds.CreateDataSourceTableReq{
BizId: req.GetBizId(),
Spec: req.GetSpec(),
})
if err != nil {
return nil, err
}

return &pbcs.CreateDataSourceTableResp{Id: resp.Id}, nil
}

func (s *Service) GetDataSourceTable(ctx context.Context, req *pbcs.GetDataSourceTableReq) (
*pbcs.GetDataSourceTableResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

resp, err := s.client.DS.GetDataSourceTable(kit.RpcCtx(), &pbds.GetDataSourceTableReq{
BizId: req.BizId,
DataSourceMappingId: req.DataSourceMappingId,
})
if err != nil {
return nil, err
}

return &pbcs.GetDataSourceTableResp{Details: resp.Details}, nil
}

// UpdateDataSourceTable 编辑托管表格数据源
func (s *Service) UpdateDataSourceTable(ctx context.Context, req *pbcs.UpdateDataSourceTableReq) (
*pbcs.UpdateDataSourceTableResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

_, err = s.client.DS.UpdateDataSourceTable(kit.RpcCtx(), &pbds.UpdateDataSourceTableReq{
BizId: req.GetBizId(),
Spec: req.GetSpec(),
DataSourceMappingId: req.GetDataSourceMappingId(),
})
if err != nil {
return nil, err
}

return &pbcs.UpdateDataSourceTableResp{}, nil
}

// DeleteDataSourceTable 删除托管表格数据源
func (s *Service) DeleteDataSourceTable(ctx context.Context, req *pbcs.DeleteDataSourceTableReq) (
*pbcs.DeleteDataSourceTableResp, error) {
kit := kit.FromGrpcContext(ctx)
res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.Credential, Action: meta.Manage}, BizID: req.BizId},
}
err := s.authorizer.Authorize(kit, res...)
if err != nil {
return nil, err
}

_, err = s.client.DS.DeleteDataSourceTable(kit.RpcCtx(), &pbds.DeleteDataSourceTableReq{
BizId: req.GetBizId(),
DataSourceMappingId: req.GetDataSourceMappingId(),
})
if err != nil {
return nil, err
}

return &pbcs.DeleteDataSourceTableResp{}, nil
}
Loading