1
0

InfluxConfig.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace OhmGraphite
  3. {
  4. public class InfluxConfig
  5. {
  6. public InfluxConfig(Uri address, string db, string user, string password)
  7. {
  8. Address = address;
  9. Db = db;
  10. User = user;
  11. Password = password;
  12. }
  13. public Uri Address { get; }
  14. public string Db { get; }
  15. public string User { get; }
  16. public string Password { get; }
  17. public static InfluxConfig ParseAppSettings(IAppConfig config)
  18. {
  19. string influxAddress = config["influx_address"];
  20. if (!Uri.TryCreate(influxAddress, UriKind.Absolute, out var addr))
  21. {
  22. throw new ApplicationException($"Unable to parse {influxAddress} into a Uri");
  23. }
  24. var db = config["influx_db"];
  25. if (string.IsNullOrEmpty(db))
  26. {
  27. throw new ApplicationException("influx_db must be specified in the config");
  28. }
  29. var user = config["influx_user"];
  30. var password = config["influx_password"];
  31. return new InfluxConfig(addr, db, user, password);
  32. }
  33. }
  34. }