pcm-openstack/internal/logic/listsecuritygroupruleslogic.go

59 lines
1.5 KiB
Go

package logic
import (
"context"
"fmt"
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/common"
"gitlink.org.cn/jcce-pcm/utils/tool"
"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 ListSecurityGroupRulesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListSecurityGroupRulesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSecurityGroupRulesLogic {
return &ListSecurityGroupRulesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 安全组规则
func (l *ListSecurityGroupRulesLogic) ListSecurityGroupRules(in *openstack.ListSecurityGroupRulesReq) (*openstack.ListSecurityGroupRulesResp, error) {
// todo: add your logic here and delete this line
var resp openstack.ListSecurityGroupRulesResp
platform, err := common.GetOpenstackConfWithPlatform(in.Platform)
openstackUrl := platform.OpenstackNetworkUrl
if err != nil {
return nil, err
}
token := common.GetToken(in.Platform)
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, openstackUrl+"/v2.0/security-group-rules", 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
}