-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEtcdConfigurationProvider.cs
49 lines (46 loc) · 1.47 KB
/
EtcdConfigurationProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using EtcdNet;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
namespace ConfigClient
{
public class EtcdConfigurationProvider : ConfigurationProvider
{
private EtcdConfigurationSource source;
public EtcdConfigurationProvider(EtcdConfigurationSource source)
{
this.source = source;
}
public override void Load()
{
EtcdClientOpitions options = new EtcdClientOpitions()
{
Urls = source.Options.Urls,
Username = source.Options.Username,
Password = source.Options.Password,
UseProxy = false,
IgnoreCertificateError = true
};
EtcdClient etcdClient = new EtcdClient(options);
try
{
EtcdResponse resp = etcdClient.GetNodeAsync(source.Options.RootKey,
recursive: true, sorted: true).Result;
if (resp.Node.Nodes != null)
{
foreach (var node in resp.Node.Nodes)
{
// child node
Data[node.Key] = node.Value;
}
}
}
catch (EtcdCommonException.KeyNotFound)
{
// key does not
Console.WriteLine("key not found exception");
}
}
}
}