influxdb-rs/influxdb-rust

DeserializationError on "SHOW DATABASES" using non-admin credentials

JEnoch opened this issue · 1 comments

  • Rust Version: 1.50.0
  • Runtime version (e.g. Tokio): InfluxDB 1.8.3
  • OS Version: MacOS 10.15

Steps to Reproduce:

  1. Start a fresh InfluxDB with credentials for an admin and a non-admin user. For instance:
docker run -e INFLUXDB_HTTP_AUTH_ENABLED=true -e INFLUXDB_USER=foo -e INFLUXDB_USER_PASSWORD=bar -e INFLUXDB_ADMIN_USER=admin -e INFLUXDB_ADMIN_PASSWORD=password -p 8086:8086 influxdb:1.8
  1. Run the query "SHOW DATABASES" using the Serde integration and the non-admin credentials. For instance:
use influxdb::Client;
use serde::Deserialize;

#[tokio::main]
async fn main() -> Result<(), influxdb::Error> {
    let client = Client::new("http://localhost:8086", "unused").with_auth("foo", "bar");

    #[derive(Deserialize)]
    struct Database {
        name: String,
    }

    let read_query = influxdb::Query::raw_read_query("SHOW DATABASES");
    let mut result = client.json_query(read_query).await?;
    for db in &result.deserialize_next::<Database>()?.series[0].values {
        println!("{}", db.name);
    }
    Ok(())
}

Result:

Error: DeserializationError { error: "could not deserialize: missing field `values`" }

The similar query using curl returns the following:

$ curl 'http://localhost:8086/query?db=unused&u=foo&p=bar&q=SHOW+DATABASES'
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"]}]}]

Thus, in this case the serie contains the "name" and the "columns" field, but no "values" field.
The deserialization of Series must be adapted to this case, setting values to an empty Vec.
PR to come...