Open exytab opened 4 years ago
Ahh you want to add a single key in that case?
yes, if possible
Okay that isn't how I have seen it used before but is a reasonable request I will look at the best way to support that later today.
Thank you. And please 4.x package will be updated
resolved by #123 also put into 4.1.14 and published for that. You can now do
AddStaticKeyPathAsync( keyName, isSingleKey)
Thank you, but now all keys from consul start with :
symbol.
I think the problem is in JsonKeyValueParser()
method when you create Key: key.Key + ConfigurationPath.KeyDelimiter + kv.Key
.
Maybe, simple fix will be something like this:
private async Task<Dictionary<string, string>> BuildDictionaryAsync(string keyPath,
HttpResponseMessage response)
{
var content = await response.Content.ReadAsStringAsync();
var keys = JsonConvert.DeserializeObject<KeyValue[]>(content);
var parsedKeys = keys.SelectMany(k => _parser.Parse(k)).Distinct(new KeyValueComparer(keyPath, ConsulPath[0], CorePath));
var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var kv in parsedKeys)
{
- var key = kv.Key.Substring(keyPath.Length).Replace(ConsulPath[0], CorePath);
+ var key = kv.Key.Substring(keyPath.Length + Microsoft.Extensions.Configuration.ConfigurationPath.KeyDelimiter.Length).Replace(ConsulPath[0], CorePath);
var value = kv.IsDerivedKey ? kv.Value : kv.Value == null ? null : kv.ValueFromBase64();
dictionary[key] = value;
}
return dictionary;
}
I can hopefully take a look at this tonight.
I think, it happed because
AddStaticKeyPathAsync()
method usesConsulConfigSource.FormValidKey()
which adds/
character to the end.In consul documentation path looks like
/kv/:key
. https://demo.consul.io/v1/kv/hi - works https://demo.consul.io/v1/kv/hi/ - not:(