From f63f0ea954e329a7603a33c8b21675cd3f4e535e Mon Sep 17 00:00:00 2001 From: okhuz Date: Sun, 24 Jul 2022 13:59:27 +0200 Subject: [PATCH] add additional_paths to add more paths to standard config --- Makefile | 2 +- README.md | 25 +++++++++++++------------ deployment/deployment.yaml | 2 +- pkg/converter/converter.go | 11 +++++++++++ scripts/run.sh | 1 + 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index d3f752f..dcf678f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ build: upx -9 ./build/openapi2krakend dockerize: build - docker buildx build --platform=linux/amd64 -f docker/Dockerfile -t okhuz/openapi2krakend:0.1.5 . + docker buildx build --platform=linux/amd64 -f docker/Dockerfile -t okhuz/openapi2krakend:0.1.6 . test: go test ./... -v diff --git a/README.md b/README.md index 56f2704..9296ced 100644 --- a/README.md +++ b/README.md @@ -47,18 +47,19 @@ configuration file. #### Environment Variables for openApi2krakend -| Name | Description | Type | Default | Required | -|-----------------|---------------------------------------------------------------------------|----------|--------------------------------------------------------|:--------:| -| ENABLE_LOGGING | Enable logging plugin for KrakenD | `bool` | `false` | no | -| LOG_LEVEL | Log level | `string` | `WARNING` | no | -| LOG_PREFIX | Log prefix for filtering | `string` | `[KRAKEND]` | no | -| LOG_SYSLOG | Enable syslog | `bool` | `true` | no | -| LOG_STDOUT | Enable stdout | `bool` | `true` | no | -| ENABLE_CORS | Enable CORS plugin for KrakenD | `bool` | `false` | no | -| ALLOWED_ORIGINS | Comma seperated allowed origins, it will be used when ENABLE_CORS is true | `string` | `*` | no | -| ALLOWED_METHODS | Comma seperated allowed methods, it will be used when ENABLE_CORS is true | `string` | `GET,HEAD,POST,PUT,DELETE,CONNECT,OPTIONS,TRACE,PATCH` | no | - | GLOBAL_TIMEOUT | Sets global timeout across all endpoints | `string` | `3000ms` | no | -| ENCODING | Sets default encoding. Values are json, safejson, xml, rss, string, no-op | `string` | `json` | no | +| Name | Description | Type | Default | Required | +|------------------|---------------------------------------------------------------------------|----------|--------------------------------------------------------|:--------:| +| ENABLE_LOGGING | Enable logging plugin for KrakenD | `bool` | `false` | no | +| LOG_LEVEL | Log level | `string` | `WARNING` | no | +| LOG_PREFIX | Log prefix for filtering | `string` | `[KRAKEND]` | no | +| LOG_SYSLOG | Enable syslog | `bool` | `true` | no | +| LOG_STDOUT | Enable stdout | `bool` | `true` | no | +| ENABLE_CORS | Enable CORS plugin for KrakenD | `bool` | `false` | no | +| ALLOWED_ORIGINS | Comma seperated allowed origins, it will be used when ENABLE_CORS is true | `string` | `*` | no | +| ALLOWED_METHODS | Comma seperated allowed methods, it will be used when ENABLE_CORS is true | `string` | `GET,HEAD,POST,PUT,DELETE,CONNECT,OPTIONS,TRACE,PATCH` | no | + | GLOBAL_TIMEOUT | Sets global timeout across all endpoints | `string` | `3000ms` | no | +| ENCODING | Sets default encoding. Values are json, safejson, xml, rss, string, no-op | `string` | `json` | no | +| ADDITIONAL_PATHS | Comma seperated set of URLs to add every swagger for additional paths | `string` | `` | no | ````shell kubectl apply -f ./deployment diff --git a/deployment/deployment.yaml b/deployment/deployment.yaml index 29baab4..922bdc9 100644 --- a/deployment/deployment.yaml +++ b/deployment/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: initContainers: - name: init-configuration - image: okhuz/openapi2krakend:0.1.4 + image: okhuz/openapi2krakend:0.1.6 imagePullPolicy: Always env: - name: API_URLS diff --git a/pkg/converter/converter.go b/pkg/converter/converter.go index 982f7a8..41fe995 100644 --- a/pkg/converter/converter.go +++ b/pkg/converter/converter.go @@ -7,6 +7,7 @@ import ( "github.com/okhuz/openapi2krakend/pkg/utility" "io/fs" "io/ioutil" + "strings" ) func Convert(swaggerDirectory string, encoding string, globalTimeout string) models.Configuration { @@ -77,6 +78,16 @@ func Convert(swaggerDirectory string, encoding string, globalTimeout string) mod configuration.InsertEndpoint(krakendEndpoint) } } + + additionalPaths := utility.GetEnv("ADDITIONAL_PATHS", "") + if additionalPaths != "" { + additionalPathArray := strings.Split(additionalPaths, ",") + for _, v := range additionalPathArray { + additionalEndpoint := models.NewEndpoint(host, fmt.Sprintf("/%s%s", path, v), v, "get", encoding, apiTimeout) + additionalEndpoint.InsertHeadersToPass("Authorization") + configuration.InsertEndpoint(additionalEndpoint) + } + } } return configuration } diff --git a/scripts/run.sh b/scripts/run.sh index fe71342..eddb0b8 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -11,5 +11,6 @@ export ENCODING="no-op" export LOGGER_SKIP_PATHS="/__health" export PATH_PREFIX="v1" export DEBUG=true +export ADDITIONAL_PATHS="/management/prometheus" go run ./pkg