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

Multi-prefix on JSON configuration file gets overwritten #12

Closed
calvn opened this issue Mar 17, 2015 · 9 comments
Closed

Multi-prefix on JSON configuration file gets overwritten #12

calvn opened this issue Mar 17, 2015 · 9 comments

Comments

@calvn
Copy link
Member

calvn commented Mar 17, 2015

Multi-prefix via configuration file does not seem to work, as keys are unique in JSON.

The following HCL:

consul = "127.0.0.1:8500"
token = "abcd1234"
retry = "10s"
max_stale = "10m"

auth {
  enabled = true
  username = "test"
  password = "test"
}

ssl {
  enabled = true
  verify = false
}

syslog {
  enabled = true
  facility = "LOCAL5"
}

prefix {
  source = "global@nyc1"
  destination = "local/nyc1"
}

prefix {
  source = "global@nyc2"
  destination = "local/nyc2"
}

Converts to this JSON:

{
    "auth": {
        "enabled": true,
        "password": "test",
        "username": "test"
    },
    "consul": "127.0.0.1:8500",
    "max_stale": "10m",
    "prefix": {
        "destination": "local/nyc2",
        "source": "global@nyc2"
    },
    "retry": "10s",
    "ssl": {
        "enabled": true,
        "verify": false
    },
    "syslog": {
        "enabled": true,
        "facility": "LOCAL5"
    },
    "token": "abcd1234"
}

In the example above, prefix configuration for global@nyc1 gets removed/overwritten since a duplicate key exists. A suggestion is to have prefix also accept an array of objects (i.e. hashes) if more than one prefix is specified. The same should apply for destination, so that it can be a string or an array of strings.

{
    "auth": {
        "enabled": true,
        "password": "test",
        "username": "test"
    },
    "consul": "127.0.0.1:8500",
    "max_stale": "10m",
    "prefix": [
        {
            "destination": "local/nyc1",
            "source": "global@nyc1"
        },
        {
            "destination": [
                "local/nyc2",
                "temp/nyc2"
            ],
            "source": "global@nyc2"
        }
    ],
    "retry": "10s",
    "ssl": {
        "enabled": true,
        "verify": false
    },
    "syslog": {
        "enabled": true,
        "facility": "LOCAL5"
    },
    "token": "abcd1234"
}
@calvn calvn changed the title Multi-prefix on configuration file gets overwritten Multi-prefix on JSON configuration file gets overwritten Mar 17, 2015
@calvn
Copy link
Member Author

calvn commented Mar 26, 2015

@sethvargo I was wondering if you have looked into this. I can start working on this and send you a PR if you are busy

@sethvargo
Copy link
Contributor

@cleung2010 thank you for opening an issue.

The JSON you supplied is not a direct translation from the HCL. Top-level keys in HCL are actually keys to arrays of objects in JSON, i.e.:

consul = "127.0.0.1:8500"
token = "abcd1234"
retry = "10s"
max_stale = "10m"

auth {
  enabled = true
  username = "test"
  password = "test"
}

becomes:

{
  "auth": [
    {
      "enabled": true,
      "password": "test",
      "username": "test"
    }
  ]
}

Are you experiencing issues when you specify the prefixes as an array of objects, because that should definitely work?

@calvn
Copy link
Member Author

calvn commented Mar 26, 2015

So I am not using HCL at all as my config file. I want to use multi-prefix via JSON. The readme says I can do it like so in HCL:

prefix {
  source = "global@nyc1"
  destination = "local/nyc1"
}

prefix {
  source = "global@nyc2"
  destination = "local/nyc2"
}

But how can I do this in JSON since keys need to be unique (thus two prefix wouldn't work)?

@sethvargo
Copy link
Contributor

@cleung2010 the same as my example for auth (and the example you provided yourself above):

{
  "prefix": [
    {
      "source": "...",
      "destination": "..."
    }
  ]
}

@calvn
Copy link
Member Author

calvn commented Mar 26, 2015

Oh nice, and I assume the same would apply for destination. I am going to go ahead and close the issue, thanks for clearing this up! It wouldn't hurt to provide a JSON example on the readme for people less familiar with explicit translations done by HCL :)

@calvn calvn closed this as completed Mar 26, 2015
@sethvargo
Copy link
Contributor

@cleung2010 no, destination must be a string. It's the same as the command line. If you want multiple destinations, you need to specify the prefix multiple times.

@calvn
Copy link
Member Author

calvn commented Mar 26, 2015

So

{
"prefix": [
        {
            "destination": "local/nyc1",
            "source": "global@nyc1"
        },
        {
            "destination": "local/nyc2",
            "source": "global@nyc2"
        },
        {
            "destination": "temp/nyc2",
            "source": "global@nyc2"
        }
    ]
}

Instead of

{
"prefix": [
        {
            "destination": "local/nyc1",
            "source": "global@nyc1"
        },
        {
            "destination": [
                "local/nyc2",
                "temp/nyc2"
            ],
            "source": "global@nyc2"
        }
    ]
}

@sethvargo
Copy link
Contributor

Yes

@calvn
Copy link
Member Author

calvn commented Mar 26, 2015

Cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants