How to escape forward slash "/" in key name so that I can have key name as "test/key" ?

1,148 views
Skip to first unread message

Gaurav Kumar

unread,
Sep 8, 2015, 9:31:25 PM9/8/15
to Consul
By default a forward slash "/" is considered as key delimiter for nested keys. I would like to use it as literal so that I can have a key with a name like "test/key". How do I go about it? I tried to escape it like "test//key" but that didn't work. 

Gaurav Kumar

unread,
Sep 10, 2015, 4:45:11 PM9/10/15
to Consul
Any ideas?

Ryan Uber

unread,
Sep 10, 2015, 4:48:36 PM9/10/15
to consu...@googlegroups.com
Guarav,

This likely won't be possible because there would then be no sane way to address the key from the HTTP API. The difference between a key labeled "foo/bar", and a key "bar" nested inside of the "foo" keyspace would be indistinguishable. It is recommended that you use another delimiter, such as a period or a dash.

Hope that helps!

Any ideas?
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/97050a17-719e-4812-84d6-99ed3f3cebe1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael Fischer

unread,
Sep 10, 2015, 4:50:56 PM9/10/15
to consu...@googlegroups.com
What about URI-escaping the key name?  test%2Fkey

Gaurav Kumar

unread,
Sep 10, 2015, 4:55:28 PM9/10/15
to Consul
What about URI-escaping the key name?  test%2Fkey

I will like that very much :)
FWIW, I wanted to use docker image name as key in consul and since docker images already contain forward slash, I had to replace the slash with dash. 

Ryan Uber

unread,
Sep 10, 2015, 5:02:49 PM9/10/15
to consu...@googlegroups.com
If I remember correctly, the reason we didn't do this before was because we would need to swap out the HTTP muxer or write a custom one in order to handle it. Basically the URL gets completely decoded before looking up the route, which makes it impossible to detect with the default serve mux in Go. This could have changed since, but I'd have to check.

Another option here that we have used before is to checksum the key name and store by that. So for example, when you store a key for "user/org", you instead store the key as md5("user/org"), then do the same hashing whenever you need to look it up again. This only provides a one-way lookup (can't really reverse it to the original value), but if you needed to you could store the original name in the key's data. Just throwing that out there in case it helps.

Reply all
Reply to author
Forward
0 new messages