Merge pull request #782 from influxdata/client
feat: Implement database list API in the client.pull/24376/head
commit
669e20f70b
|
@ -18,3 +18,9 @@ pub struct WalMetadataQuery {
|
|||
pub struct WalMetadataResponse {
|
||||
pub segments: Vec<SegmentSummary>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
/// Body of the response to the /databases endpoint.
|
||||
pub struct ListDatabasesResponse {
|
||||
pub names: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use data_types::database_rules::DatabaseRules;
|
|||
use reqwest::{Method, Url};
|
||||
|
||||
use crate::errors::{ClientError, CreateDatabaseError, Error, ServerErrorResponse};
|
||||
use data_types::DatabaseName;
|
||||
use data_types::{http::ListDatabasesResponse, DatabaseName};
|
||||
|
||||
// TODO: move DatabaseRules / WriterId to the API client
|
||||
|
||||
|
@ -125,6 +125,19 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
/// List databases.
|
||||
pub async fn list_databases(&self) -> Result<ListDatabasesResponse, Error> {
|
||||
const LIST_DATABASES_PATH: &str = "iox/api/v1/databases";
|
||||
let url = self.url_for(LIST_DATABASES_PATH);
|
||||
|
||||
let r = self.http.request(Method::GET, url).send().await?;
|
||||
|
||||
match r {
|
||||
r if r.status() == 200 => Ok(r.json::<ListDatabasesResponse>().await?),
|
||||
r => Err(ServerErrorResponse::from_response(r).await.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the request path for relative `path`.
|
||||
///
|
||||
/// # Safety
|
||||
|
@ -262,6 +275,23 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_list_databases() {
|
||||
let endpoint = maybe_skip_integration!();
|
||||
let c = ClientBuilder::default().build(endpoint).unwrap();
|
||||
|
||||
c.set_writer_id(NonZeroU32::new(42).unwrap())
|
||||
.await
|
||||
.expect("set ID failed");
|
||||
|
||||
let name = rand_name();
|
||||
c.create_database(&name, &DatabaseRules::default())
|
||||
.await
|
||||
.expect("create database failed");
|
||||
let r = c.list_databases().await.expect("list databases failed");
|
||||
assert!(r.names.contains(&name));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
// Ensures the Default impl does not panic
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
use arrow_deps::{arrow, datafusion::physical_plan::collect};
|
||||
use data_types::{
|
||||
database_rules::DatabaseRules,
|
||||
http::WalMetadataQuery,
|
||||
http::{ListDatabasesResponse, WalMetadataQuery},
|
||||
names::{org_and_bucket_to_database, OrgBucketMappingError},
|
||||
DatabaseName,
|
||||
};
|
||||
|
@ -460,12 +460,6 @@ async fn read<M: ConnectionManager + Send + Sync + Debug + 'static>(
|
|||
Ok(Response::new(Body::from(results.into_bytes())))
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
/// Body of the response to the /databases endpoint.
|
||||
struct ListDatabasesResponse {
|
||||
names: Vec<String>,
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug")]
|
||||
async fn list_databases<M>(req: Request<Body>) -> Result<Response<Body>, ApplicationError>
|
||||
where
|
||||
|
|
Loading…
Reference in New Issue