Extended features for KrakenD config parsers
krakendio / krakend-flexibleconfig Goto Github PK
View Code? Open in Web Editor NEWExtended features for KrakenD config parsers
License: Apache License 2.0
Extended features for KrakenD config parsers
License: Apache License 2.0
It would be nice if we could organize the templates in subfolders, for example:
.
├── templates
│ ├── contextA
│ │ └── endpoints.tmpl
│ │
│ └── contextB
│ │ └── anotherFolder
│ │ │ └── anotherFolderEndpoints.tmpl
│ │ │
│ │ └── serveiceb.tmpl
I am not allowed to do it at this moment because the flexible configuration just scans the root of the path FC_TEMPLATES
The workaround I am using is to copy recursively the templates from the subfolders to the root of the templates folder when creating the docker image.
Thank you, keep up the great work guys!
I have 4 files
a.json
{
"b": {{ include "b.json" }}
}
b.json
{
"c:" {{ include "c.json" }},
"d": {{ include "d.json" }}
}
c.json
{
"id": 1,
"name": 1,
"name1": 1
}
d.json
{
"id": 2,
"name": 2,
"name1": 2
}
how about this case?
We are using flexible configuration in such a way settings are grouped by different criteria such as API version, domain...
Ideally the flexible configuration should be able to scan a folder in a recursive manner.
root
│ settings_01.json
│
└───folder1
│ │ settings_01.json
│ │ settings_02.json
│ │ ...
│
└───folder2
│ settings_01.json
│ settings_02.json
Keys added to the map may include a prefix with a path relative to the root folder such as folder1.settings_01
or folder2.settings_01
to guarantee uniqueness.
Consider the following json group, i would like to add a auth
validator for the following endpoint, this auth
validator is placed in another template file auth.tmpl
endpoint.json
{
"group": [
{
"endpoint": "/nick/{nick}",
"method": "GET",
"input_query_strings": [],
"auth": "validator", // for adding auth.
"extra_config": {
"validation/cel": [ // HOW DO I ADD THIS BLOCK ALONG WITH MY AUTH TEMPLATE?
{
"check_expr": "req_params.Nick.matches('k.*')"
}
]
},
"backend": [
{
"extra_config": {},
"url_pattern": "/demo",
"method": "GET",
"host": [
"http://service-a:8080"
]
}
],
"input_headers": [
"Content-Type"
]
}
]
}
auth.tmpl
"auth/validator": {
"alg": "HS256",
"jwk_local_path": "symmetric.json",
"roles_key": "roles",
"roles": [
"user",
"admin"
],
"disable_jwk_security": true
}
krakend.tmpl
{
"$schema": "https://www.krakend.io/schema/v3.json",
"version": 3,
"port": 8080,
"output_encoding": "json",
"name": "API",
"endpoints": [
{{- $first := true -}}
{{- range $idx, $setting := keys . -}} // range over all settings files
{{- range $i, $a := (index $ $setting) -}} // range over all files in settings folder
{{- range $j, $b := . -}}
{{- if $first -}}
{{$first = false}}
{{- else -}},
{{- end -}}
{
"endpoint": "{{ $b.endpoint }}",
"method": "{{ $b.method }}",
"input_query_strings": {{ marshal $b.input_query_strings }},
"extra_config": {
{{- if $b.auth -}}
{{- if eq $b.auth "signer" -}}
{{ include "auth_signer.tmpl" }}
{{- else if eq $b.auth "validator" -}}
{{ include "auth.tmpl" }}
{{- else if eq $b.auth "none" -}}
{{- end -}}
{{- end -}}
},
"backend": {{ marshal $b.backend }},
"input_headers": {{ marshal $b.input_headers}}
}
{{- end -}}
{{- end -}}
{{- end -}}
],
"extra_config": {
{{- include "telemetry.tmpl" -}},
{{- include "headers.tmpl" -}},
{{- include "token_revoker.tmpl" -}},
{{- include "rate_limit_backend.tmpl" -}}
}
}
my folder structure is as follows
krakend.tmpl
config
|--partials
|--auth.tmpl
|--auth_signer.tmpl
|--settings
|--endpoint.json
|--endpoint-2.json
|--endpoint-3.json
Now my question is how do i add other items to extra_config
such as following
"validation/json-schema": {
"type": "object"
}
I am unable to use {{ marshal $b.extra_config }}
since I'm already adding auth
to the same extra_config object. Pleas help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.