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

AddStaticKeyPathAsync() method does not return data #121

Open
exytab opened this issue Nov 6, 2019 · 8 comments
Open

AddStaticKeyPathAsync() method does not return data #121

exytab opened this issue Nov 6, 2019 · 8 comments
Assignees

Comments

@exytab
Copy link

exytab commented Nov 6, 2019

I think, it happed because AddStaticKeyPathAsync() method uses ConsulConfigSource.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:(

@Drawaes
Copy link
Owner

Drawaes commented Nov 6, 2019

Ahh you want to add a single key in that case?

@exytab
Copy link
Author

exytab commented Nov 6, 2019

yes, if possible

@Drawaes Drawaes self-assigned this Nov 6, 2019
@Drawaes
Copy link
Owner

Drawaes commented Nov 6, 2019

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.

@exytab
Copy link
Author

exytab commented Nov 6, 2019

Thank you. And please 4.x package will be updated

@Drawaes
Copy link
Owner

Drawaes commented Nov 6, 2019

resolved by #123 also put into 4.1.14 and published for that. You can now do
AddStaticKeyPathAsync( keyName, isSingleKey)

@exytab
Copy link
Author

exytab commented Nov 7, 2019

Thank you, but now all keys from consul start with : symbol.

@exytab
Copy link
Author

exytab commented Nov 12, 2019

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;
}

@Drawaes
Copy link
Owner

Drawaes commented Nov 12, 2019

I can hopefully take a look at this tonight.

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