GithubHelp home page GithubHelp logo

krakend-flexibleconfig's Introduction

krakend-flexibleconfig

Extended features for KrakenD config parsers

krakend-flexibleconfig's People

Contributors

alombarte avatar deepsource-autofix[bot] avatar deepsourcebot avatar dhontecillas avatar kpacha avatar rgomezcasas avatar taik0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

krakend-flexibleconfig's Issues

Scan the templates recursively with flexible config (subfolders)

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!

recursive call

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?

Flexible configuration to scan a settings folder recursively

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.

Marshal extra_config along with additional items

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.