Răsfoiți Sursa

Merge pull request #179 from nickbabcock/passwordless-influx

Allow omission of password for passwordless influxdb user
Nick Babcock 4 ani în urmă
părinte
comite
30446b3a3b
3 a modificat fișierele cu 43 adăugiri și 2 ștergeri
  1. 35 1
      OhmGraphite.Test/InfluxTest.cs
  2. 2 1
      OhmGraphite/InfluxWriter.cs
  3. 6 0
      docker-compose.yml

+ 35 - 1
OhmGraphite.Test/InfluxTest.cs

@@ -27,7 +27,7 @@ namespace OhmGraphite.Test
                         Assert.Contains("/intelcpu/0/temperature/0", content);
                         Assert.Contains("/intelcpu/0/temperature/0", content);
                         break;
                         break;
                     }
                     }
-                    catch (Exception ex)
+                    catch (Exception)
                     {
                     {
                         if (attempts >= 10)
                         if (attempts >= 10)
                         {
                         {
@@ -39,5 +39,39 @@ namespace OhmGraphite.Test
                 }
                 }
             }
             }
         }
         }
+
+        [Fact, Trait("Category", "integration")]
+        public async void CanInsertIntoPasswordLessInfluxdb()
+        {
+            var config = new InfluxConfig(new Uri("http://influx-passwordless:8086"), "mydb", "my_user", null);
+            using (var writer = new InfluxWriter(config, "my-pc"))
+            using (var client = new HttpClient())
+            {
+                for (int attempts = 0; ; attempts++)
+                {
+                    try
+                    {
+                        await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
+
+                        var resp = await client.GetAsync(
+                            "http://influx-passwordless:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
+                        Assert.True(resp.IsSuccessStatusCode);
+                        var content = await resp.Content.ReadAsStringAsync();
+                        Assert.Contains("/intelcpu/0/temperature/0", content);
+                        break;
+                    }
+                    catch (Exception)
+                    {
+                        if (attempts >= 10)
+                        {
+                            throw;
+                        }
+
+                        Thread.Sleep(TimeSpan.FromSeconds(1));
+                    }
+                }
+            }
+        }
+
     }
     }
 }
 }

+ 2 - 1
OhmGraphite/InfluxWriter.cs

@@ -25,7 +25,8 @@ namespace OhmGraphite
         public async Task ReportMetrics(DateTime reportTime, IEnumerable<ReportedValue> sensors)
         public async Task ReportMetrics(DateTime reportTime, IEnumerable<ReportedValue> sensors)
         {
         {
             var payload = new LineProtocolPayload();
             var payload = new LineProtocolPayload();
-            var client = new LineProtocolClient(_config.Address, _config.Db, _config.User, _config.Password);
+            var password = _config.User != null ? (_config.Password ?? "") : null;
+            var client = new LineProtocolClient(_config.Address, _config.Db, _config.User, password);
 
 
             foreach (var point in sensors.Select(x => NewPoint(reportTime, x)))
             foreach (var point in sensors.Select(x => NewPoint(reportTime, x)))
             {
             {

+ 6 - 0
docker-compose.yml

@@ -6,6 +6,12 @@ services:
       INFLUXDB_DB: "mydb"
       INFLUXDB_DB: "mydb"
       INFLUXDB_USER: "my_user"
       INFLUXDB_USER: "my_user"
       INFLUXDB_USER_PASSWORD: "my_pass"
       INFLUXDB_USER_PASSWORD: "my_pass"
+  influx-passwordless:
+    image: influxdb:alpine
+    environment:
+      INFLUXDB_DB: "mydb"
+      INFLUXDB_USER: "my_user"
+      INFLUXDB_HTTP_AUTH_ENABLED: "false"
   graphite:
   graphite:
     image: graphiteapp/graphite-statsd
     image: graphiteapp/graphite-statsd
     environment:
     environment: