[API节点]支持HTTP API

This commit is contained in:
刘祥超
2021-01-01 20:49:19 +08:00
parent 9b666ca31e
commit 6b86ce1aef
11 changed files with 286 additions and 36 deletions

View File

@@ -28,7 +28,11 @@ func (this *CreatePopupAction) RunPost(params struct {
ListensJSON []byte
CertIdsJSON []byte
AccessAddrsJSON []byte
IsOn bool
RestIsOn bool
RestListensJSON []byte
IsOn bool
Must *actions.Must
}) {
@@ -59,6 +63,27 @@ func (this *CreatePopupAction) RunPost(params struct {
}
}
// Rest监听地址
restHTTPConfig := &serverconfigs.HTTPProtocolConfig{}
restHTTPSConfig := &serverconfigs.HTTPSProtocolConfig{}
if params.RestIsOn {
restListens := []*serverconfigs.NetworkAddressConfig{}
err = json.Unmarshal(params.RestListensJSON, &restListens)
if err != nil {
this.ErrorPage(err)
return
}
for _, addr := range restListens {
if addr.Protocol.IsHTTPFamily() {
restHTTPConfig.IsOn = true
restHTTPConfig.Listen = append(restHTTPConfig.Listen, addr)
} else if addr.Protocol.IsHTTPSFamily() {
restHTTPSConfig.IsOn = true
restHTTPSConfig.Listen = append(restHTTPSConfig.Listen, addr)
}
}
}
// 证书
certIds := []int64{}
if len(params.CertIdsJSON) > 0 {
@@ -68,7 +93,7 @@ func (this *CreatePopupAction) RunPost(params struct {
return
}
}
if httpsConfig.IsOn && len(httpsConfig.Listen) > 0 && len(certIds) == 0 {
if ((httpsConfig.IsOn && len(httpsConfig.Listen) > 0) || (restHTTPSConfig.IsOn && len(httpsConfig.Listen) > 0)) && len(certIds) == 0 {
this.Fail("请添加至少一个证书")
}
@@ -99,6 +124,10 @@ func (this *CreatePopupAction) RunPost(params struct {
IsOn: true,
SSLPolicyId: sslPolicyId,
}
restHTTPSConfig.SSLPolicyRef = &sslconfigs.SSLPolicyRef{
IsOn: true,
SSLPolicyId: sslPolicyId,
}
}
// 访问地址
@@ -123,11 +152,25 @@ func (this *CreatePopupAction) RunPost(params struct {
return
}
restHTTPJSON, err := json.Marshal(restHTTPConfig)
if err != nil {
this.ErrorPage(err)
return
}
restHTTPSJSON, err := json.Marshal(restHTTPSConfig)
if err != nil {
this.ErrorPage(err)
return
}
createResp, err := this.RPC().APINodeRPC().CreateAPINode(this.AdminContext(), &pb.CreateAPINodeRequest{
Name: params.Name,
Description: params.Description,
HttpJSON: httpJSON,
HttpsJSON: httpsJSON,
RestIsOn: params.RestIsOn,
RestHTTPJSON: restHTTPJSON,
RestHTTPSJSON: restHTTPSJSON,
AccessAddrsJSON: params.AccessAddrsJSON,
IsOn: params.IsOn,
})