pcm-openstack/internal/logic/showsecuritygrouprulelogic.go

61 lines
1.8 KiB
Go

package logic
import (
"bytes"
"context"
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/common"
"k8s.io/apimachinery/pkg/util/json"
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
"github.com/zeromicro/go-zero/core/logx"
)
type ShowSecurityGroupRuleLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewShowSecurityGroupRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowSecurityGroupRuleLogic {
return &ShowSecurityGroupRuleLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ShowSecurityGroupRuleLogic) ShowSecurityGroupRule(in *openstack.ShowSecurityGroupRuleReq) (*openstack.ShowSecurityGroupRuleResp, error) {
// todo: add your logic here and delete this line
var resp openstack.ShowSecurityGroupRuleResp
platform, err := common.GetOpenstackConfWithPlatform(in.Platform)
openstackUrl := platform.OpenstackNetworkUrl
// openstackUrl := l.svcCtx.Config.OpenstackConfig.OpenstackNetworkUrl
if err != nil {
return nil, err
}
reqByte, err := json.Marshal(in)
body, err := common.SendRequest("GET", openstackUrl+"/v2.0/security-groups", bytes.NewBuffer(reqByte), in.Platform)
json.Unmarshal(*body, &resp)
return &resp, nil
/* token := common.GetToken()
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, openstackUrl+"/v2.0/security-group-rules/"+in.SecurityGroupRuleId, nil, token)
if err != nil {
return nil, err
}
if statusCode == 200 {
err := json.Unmarshal(body, &resp)
if err != nil {
fmt.Println(err)
}
resp.Code = 200
resp.Msg = "Success"
} else if statusCode != 200 {
json.Unmarshal(body, &resp)
resp.Code = 400
resp.Msg = "Failure"
}
return &resp, nil*/
}