Skip to content

Commit

Permalink
add additional_paths to add more paths to standard config
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaOralK committed Jul 24, 2022
1 parent eb44522 commit f63f0ea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deployment/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f63f0ea

Please sign in to comment.