From ad2466575459f33dbb2c495c47df4b6a87316544 Mon Sep 17 00:00:00 2001 From: m-mattia-m Date: Thu, 23 Nov 2023 05:30:44 +0100 Subject: [PATCH] make port in swagger configurable (and document it) --- README.md | 13 ++++++++---- docs/content/docs/self-hosted/domain.md | 20 +++++++++++++++--- docs/content/docs/self-hosted/file.md | 2 ++ internal/api/router.go | 7 ++++++- main.go | 27 ++++++++++++++----------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6827b7d..f1651b3 100644 --- a/README.md +++ b/README.md @@ -169,8 +169,10 @@ data: verifyDns: 8.8.8.8:53 # this is optional -> if not set then the google standard is used ("8.8.8.8:53") activity: enable: - subject: true - message: true + subject: true # this is optional + message: true # this is optional + swagger: + port: false # this is optional ``` ```yaml {filename="k8s-manifest-secret.yaml"} @@ -712,8 +714,11 @@ domain: verifyDns: 8.8.8.8:53 # this is optional -> if not set then the google standard is used ("8.8.8.8:53") activity: enable: - subject: true # required - message: true # required + subject: true # optional + message: true # optional + swagger: + port: false # optional + ``` ## Environment diff --git a/docs/content/docs/self-hosted/domain.md b/docs/content/docs/self-hosted/domain.md index da98a71..b150c69 100644 --- a/docs/content/docs/self-hosted/domain.md +++ b/docs/content/docs/self-hosted/domain.md @@ -13,8 +13,10 @@ domain: verifyDns: 8.8.8.8:53 # this is optional -> if not set then the google standard is used ("8.8.8.8:53") activity: enable: - subject: true - message: true + subject: true # this is optional + message: true # this is optional + swagger: + port: false # this is optional ``` ## DNS @@ -38,4 +40,16 @@ domain: enable: subject: true # optional -> default: false message: true # optional -> default: false -``` \ No newline at end of file +``` + +## Swagger + +It could be, that you don't need the port in the swagger-configuration. For this you can disable it in the config. Note, +the port is needed to start the API. + +```yaml {filename="./configs/config.yaml"} +domain: + swagger: + port: false # this is optional +``` + diff --git a/docs/content/docs/self-hosted/file.md b/docs/content/docs/self-hosted/file.md index 77e96e6..13fe2b2 100644 --- a/docs/content/docs/self-hosted/file.md +++ b/docs/content/docs/self-hosted/file.md @@ -50,6 +50,8 @@ domain: enable: subject: true # optional message: true # optional + swagger: + port: false # this is optional ``` ## Environment diff --git a/internal/api/router.go b/internal/api/router.go index d0bf65b..c7e839e 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -21,8 +21,13 @@ func Router(svc service.Service) *gin.Engine { gin.SetMode(gin.ReleaseMode) } + swaggerPort := "" + if viper.GetBool("domain.swagger.port") { + swaggerPort = fmt.Sprintf(":%s", viper.GetString("server.port")) + } + docs.SwaggerInfo.Schemes = []string{viper.GetString("server.scheme")} - docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", viper.GetString("server.domain"), viper.GetString("server.port")) + docs.SwaggerInfo.Host = fmt.Sprintf("%s%s", viper.GetString("server.domain"), swaggerPort) docs.SwaggerInfo.BasePath = fmt.Sprintf("/%s", viper.GetString("server.version")) r := gin.Default() diff --git a/main.go b/main.go index 21dca83..0f33a97 100644 --- a/main.go +++ b/main.go @@ -151,12 +151,12 @@ func checkIfRequiredConfigurationAttributesSet() { if viper.GetString("server.version") == "" { log.Fatal("failed to get required config attribute: 'server.version'") } - if viper.GetString("logging.enable.console") == "" { - log.Fatal("failed to get required config attribute: 'logging.enable.console'") - } - if viper.GetString("logging.enable.sentry") == "" { - log.Fatal("failed to get required config attribute: 'logging.enable.sentry'") - } + //if viper.GetString("logging.enable.console") == "" { + // log.Fatal("failed to get required config attribute: 'logging.enable.console'") + //} + //if viper.GetString("logging.enable.sentry") == "" { + // log.Fatal("failed to get required config attribute: 'logging.enable.sentry'") + //} if viper.GetString("authentication.oidc.issuer") == "" { log.Fatal("failed to get required config attribute: 'authentication.oidc.issuer'") } @@ -166,10 +166,13 @@ func checkIfRequiredConfigurationAttributesSet() { if viper.GetString("frontend.url") == "" { log.Fatal("failed to get required config attribute: 'frontend.url'") } - if viper.GetString("domain.activity.enable.subject") == "" { - log.Fatal("failed to get required config attribute: 'domain.activity.enable.subject'") - } - if viper.GetString("domain.activity.enable.message") == "" { - log.Fatal("failed to get required config attribute: 'failed to get required config attribute'") - } + //if viper.GetString("domain.activity.enable.subject") == "" { + // log.Fatal("failed to get required config attribute: 'domain.activity.enable.subject'") + //} + //if viper.GetString("domain.activity.enable.message") == "" { + // log.Fatal("failed to get required config attribute: 'domain.activity.enable.message'") + //} + //if viper.GetString("domain.swagger.port") == "" { + // log.Fatal("failed to get required config attribute: 'failed to get required config attribute'") + //} }