Skip to content

Commit

Permalink
config: Use external-address directly for Swagger docs
Browse files Browse the repository at this point in the history
Now `external-address` is used straightforwardly and independently of the TLS
config.

Signed-off-by: Tatiana Nesterenko <tatiana@nspcc.io>
  • Loading branch information
tatiana-nspcc committed Jun 3, 2024
1 parent 5750187 commit e81faa8
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions cmd/neofs-rest-gw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import (
)

const (
docsURL = baseURL + "/docs"
swaggerURL = docsURL + "/swagger.json"
schemeHTTP = "http"
schemeHTTPS = "https"
docsURL = baseURL + "/docs"
swaggerURL = docsURL + "/swagger.json"
)

var (
Expand Down Expand Up @@ -65,30 +63,26 @@ func main() {
servers := make(openapi3.Servers, len(serverCfg.Endpoints))
for i, endpointInfo := range serverCfg.Endpoints {
if endpointInfo.ExternalAddress != "" {
var scheme string
// Determine the scheme based on whether TLS is enabled and set up e.TLSServer.
if endpointInfo.TLS.Enabled {
scheme = schemeHTTPS
e.TLSServer.ReadTimeout = endpointInfo.ReadTimeout
e.TLSServer.WriteTimeout = endpointInfo.WriteTimeout
e.TLSServer.IdleTimeout = endpointInfo.KeepAlive

if endpointInfo.TLS.CertCAFile != "" {
ca, err := loadCA(endpointInfo.TLS.CertCAFile)
if err != nil {
logger.Fatal("reading server certificate", zap.Error(err))
}
e.TLSServer.TLSConfig = &tls.Config{ClientCAs: ca}
}
} else {
scheme = schemeHTTP
}
servers[i] = &openapi3.Server{
URL: fmt.Sprintf("%s://%s%s", scheme, endpointInfo.ExternalAddress, baseURL),
URL: fmt.Sprintf("%s%s", endpointInfo.ExternalAddress, baseURL),

Check warning on line 67 in cmd/neofs-rest-gw/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-rest-gw/main.go#L67

Added line #L67 was not covered by tests
}
} else {
logger.Info("Endpoint with missing external-address", zap.String("address", endpointInfo.Address))
}

if endpointInfo.TLS.Enabled {
e.TLSServer.ReadTimeout = endpointInfo.ReadTimeout
e.TLSServer.WriteTimeout = endpointInfo.WriteTimeout
e.TLSServer.IdleTimeout = endpointInfo.KeepAlive

Check warning on line 76 in cmd/neofs-rest-gw/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-rest-gw/main.go#L73-L76

Added lines #L73 - L76 were not covered by tests

if endpointInfo.TLS.CertCAFile != "" {
ca, err := loadCA(endpointInfo.TLS.CertCAFile)
if err != nil {
logger.Fatal("reading server certificate", zap.Error(err))

Check warning on line 81 in cmd/neofs-rest-gw/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-rest-gw/main.go#L78-L81

Added lines #L78 - L81 were not covered by tests
}
e.TLSServer.TLSConfig = &tls.Config{ClientCAs: ca}

Check warning on line 83 in cmd/neofs-rest-gw/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-rest-gw/main.go#L83

Added line #L83 was not covered by tests
}
}
}
swagger.Servers = servers

Expand Down

0 comments on commit e81faa8

Please sign in to comment.