fix(devtool): create serviceurl

This commit is contained in:
rainzm
2021-09-07 10:37:21 +08:00
parent 9bd95312d7
commit d8d330d3d5
3 changed files with 23 additions and 12 deletions
+4 -4
View File
@@ -30,10 +30,10 @@ import (
type SServiceUrl struct {
db.SStatusStandaloneResourceBase
Service string `width:"32" charset:"ascii" list:"user" create:"required"`
ServerId string `width:"128" charset:"ascii" list:"user" create:"required"`
Url string `wdith:"32" charset:"ascii" list:"user"`
ServerAnsibleInfo *SServerAnisbleInfo
Service string `width:"32" charset:"ascii" list:"user" create:"required"`
ServerId string `width:"128" charset:"ascii" list:"user" create:"required"`
Url string `wdith:"32" charset:"ascii" list:"user"`
ServerAnsibleInfo *SServerAnisbleInfo `width:"128" list:"user" create:"required"`
FailedReason string
}
+17 -7
View File
@@ -42,7 +42,18 @@ type Service struct {
Url string
}
func serviceComplete(service Service) (completeUrl string, expectedCode int) {
func serviceComplete(serviceName, address string, port int) (url, checkUrl string, expectedCode int) {
switch serviceName {
case "influxdb":
return fmt.Sprintf("https://%s:%d", address, port), fmt.Sprintf("https://%s:%d/ping", address, port), 204
case "repo":
return fmt.Sprintf("http://%s:%d", address, port), fmt.Sprintf("http://%s:%d", address, port), 200
default:
return fmt.Sprintf("http://%s:%d", address, port), fmt.Sprintf("http://%s:%d", address, port), 200
}
}
func serviceComplete2(service Service) (completeUrl string, expectedCode int) {
switch service.Name {
case "influxdb":
return fmt.Sprintf("%s/ping", service.Url), 204
@@ -104,7 +115,7 @@ func proxyEndpoints(ctx context.Context, proxyEndpointId string, info sServerInf
}
func serviceUrlDirect(ctx context.Context, service Service, proxyEndpointId string, info sServerInfo, host *ansible_api.AnsibleHost) (string, error) {
url, code := serviceComplete(service)
url, code := serviceComplete2(service)
ok, err := checkUrl(ctx, url, code, host)
if err != nil {
return "", err
@@ -200,11 +211,10 @@ func checkProxyEndpoint(ctx context.Context, service Service, proxyEndpointId, a
if err != nil {
return "", err
}
url, code := serviceComplete(service)
nUrl := fmt.Sprintf("https://%s:%d", address, port)
ok, err := checkUrl(ctx, url, code, host)
url, cUrl, code := serviceComplete(service.Name, address, int(port))
ok, err := checkUrl(ctx, cUrl, code, host)
if err != nil {
return "", errors.Wrapf(err, "check url %q", nUrl)
return "", errors.Wrapf(err, "check url %q", cUrl)
}
if !ok {
if recycle != nil {
@@ -215,7 +225,7 @@ func checkProxyEndpoint(ctx context.Context, service Service, proxyEndpointId, a
}
return "", nil
}
return nUrl, nil
return url, nil
}
type sServerInfo struct {
+2 -1
View File
@@ -21,6 +21,7 @@ import (
)
type ServiceUrlCreateOptions struct {
NAME string `help:"Name"`
Service string `help:"service name"`
ServerId string `help:"server id"`
ServerAnsibleInfo SServerAnisbleInfo
@@ -28,7 +29,7 @@ type ServiceUrlCreateOptions struct {
type SServerAnisbleInfo struct {
User string `json:"user"`
IP string `json:"ip"`
Ip string `json:"ip"`
Port int `json:"port"`
Name string `json:"name"`
}