Skip to content

Commit d9119f6

Browse files
committed
add options to override path instead of api title and option to modify skip log paths
1 parent 12da36b commit d9119f6

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build:
66
upx -9 ./build/openapi2krakend
77

88
dockerize: build
9-
docker buildx build --platform=linux/amd64 -f docker/Dockerfile -t okhuz/openapi2krakend:0.1.1 .
9+
docker buildx build --platform=linux/amd64 -f docker/Dockerfile -t okhuz/openapi2krakend:0.1.3 .
1010

1111
test:
1212
go test ./... -v

deployment/deployment.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ spec:
1414
spec:
1515
initContainers:
1616
- name: init-configuration
17-
image: okhuz/openapi2krakend:0.1.1
17+
image: okhuz/openapi2krakend:0.1.3
1818
imagePullPolicy: Always
1919
env:
2020
- name: API_URLS
2121
value: "<comma delimited api specification endpoints, format must be OpenAPI v3>"
22+
- name: LOGGER_SKIP_PATHS
23+
value: "/__health"
24+
- name: PATH_PREFIX
25+
value: "v1"
2226
- name: GLOBAL_TIMEOUT
2327
value: "3600s"
2428
- name: ENABLE_LOGGING

pkg/converter/converter.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/okhuz/openapi2krakend/pkg/extensions"
66
"github.com/okhuz/openapi2krakend/pkg/models"
7+
"github.com/okhuz/openapi2krakend/pkg/utility"
78
"io/fs"
89
"io/ioutil"
910
)
@@ -23,6 +24,7 @@ func Convert(swaggerDirectory string, encoding string, globalTimeout string) mod
2324

2425
host := openApiDefinition.Servers[0].URL
2526
path := sanitizeTitle(openApiDefinition.Info.Title)
27+
pathPrefix := utility.GetEnv("PATH_PREFIX", "")
2628
apiTimeout := globalTimeout
2729

2830
if extensionValue := getExtension(openApiDefinition.Extensions, extensions.TimeOut); extensionValue != "" {
@@ -32,17 +34,20 @@ func Convert(swaggerDirectory string, encoding string, globalTimeout string) mod
3234
for pathUrl, pathItem := range openApiDefinition.Paths {
3335
for methodName, methodObject := range pathItem.Operations() {
3436

35-
endpoint := fmt.Sprintf("%s", pathUrl)
37+
krakendEndpointUrl := fmt.Sprintf("%s", pathUrl)
3638
if numberOfFiles > 1 {
37-
endpoint = fmt.Sprintf("/%s%s", path, pathUrl)
39+
krakendEndpointUrl = fmt.Sprintf("/%s%s", path, pathUrl)
40+
}
41+
if pathPrefix != "" {
42+
krakendEndpointUrl = fmt.Sprintf("/%s%s", pathPrefix, pathUrl)
3843
}
3944

4045
methodTimeout := apiTimeout
4146
if extensionValue := getExtension(methodObject.Extensions, extensions.TimeOut); extensionValue != "" {
4247
methodTimeout = extensionValue
4348
}
4449

45-
krakendEndpoint := models.NewEndpoint(host, endpoint, pathUrl, methodName, encoding, methodTimeout)
50+
krakendEndpoint := models.NewEndpoint(host, krakendEndpointUrl, pathUrl, methodName, encoding, methodTimeout)
4651
if methodObject.Security != nil {
4752
lengthOfSecurity := len(*methodObject.Security)
4853
if lengthOfSecurity > 0 {

pkg/models/configuration.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ func NewConfiguration(outputEncoding string, timeout string) Configuration {
7575
extraConfig["telemetry/logging"] = NewLogging()
7676
}
7777

78+
var loggerSkipPaths = utility.GetEnv("LOGGER_SKIP_PATHS", "")
79+
80+
if loggerSkipPaths != "" {
81+
extraConfig["router"] = Router{
82+
LoggerSkipPaths: strings.Split(loggerSkipPaths, ","),
83+
}
84+
}
85+
7886
return Configuration{
7987
Schema: "https://www.krakend.io/schema/v3.json",
8088
Version: "3",

pkg/models/plugins.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ func NewCors() Cors {
9696
AllowMethods: allowedMethods,
9797
}
9898
}
99+
100+
type Router struct {
101+
LoggerSkipPaths []string `json:"logger_skip_paths"`
102+
}

scripts/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ export ENABLE_CORS=true
99
export ALLOWED_METHODS="GET,POST"
1010
export GLOBAL_TIMEOUT="3600s"
1111
export ENCODING="no-op"
12+
export LOGGER_SKIP_PATHS="/__health"
13+
export PATH_PREFIX="v1"
1214

1315
go run ./pkg

0 commit comments

Comments
 (0)