Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in parsing yaml format configuration files #5

Closed
x1ah opened this issue Mar 29, 2021 · 1 comment · Fixed by #6
Closed

Bug in parsing yaml format configuration files #5

x1ah opened this issue Mar 29, 2021 · 1 comment · Fixed by #6
Labels

Comments

@x1ah
Copy link
Contributor

x1ah commented Mar 29, 2021

Describe the bug
If use the yaml format configuration file, the nested map will not be parsed normally.

To Reproduce

# config.yml

version: 2
timeout: 3000ms
cache_ttl: 300s
port: 8989
output_encoding: json
name: CoolUserService
endpoints:
  - endpoint: /_health
    extra_config:
      'github.com/devopsfaith/krakend/proxy':
        static:
          data:
            status: OK
          strategy: always
    backend:
      - url_pattern: /
        host:
          - 'http://fake-backend'

then run gateway with ./krakend-ce run -d -c config.yml. After start, if run curl localhost:8989/_health, the static response will not be returned normally. Because the configuration file is parsed incorrectly. I found that the problem is in the viper package.

// main.go
package main

import (
	"fmt"

	viper "github.com/devopsfaith/krakend-viper"
)

func main() {
	parser := viper.New()
	cfg, _ := parser.Parse("config.yml")
	fmt.Printf("%+v\n", cfg.Endpoints[0].ExtraConfig["github.com/devopsfaith/krakend/proxy"].(map[string]interface{})["static"].(map[string]interface{})["data"])
}

This code snippet will panic, because cfg.Endpoints[0].ExtraConfig["github.com/devopsfaith/krakend/proxy"].(map[string]interface{})["static"] type is map[interface{}]interface{}, can't convert to map[string]interface{}. In krakend, appear here: https://github.com/devopsfaith/krakend/blob/5e10125d6f474676256f80a99d00010fb97a9b04/proxy/static.go#L71-L74

Releated issue

@kpacha kpacha transferred this issue from luraproject/lura Mar 29, 2021
x1ah added a commit to x1ah/krakend-viper that referenced this issue Apr 2, 2021
x1ah added a commit to x1ah/krakend-viper that referenced this issue Apr 2, 2021
@kpacha kpacha closed this as completed in #6 Apr 13, 2021
@github-actions
Copy link

github-actions bot commented Apr 7, 2022

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot added the locked label Apr 7, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant