feat: Add support for setup API to influxdb_client
- Check if database has default user, org, bucket - Set up initial user, org and bucket - Set up a new user, org and bucket - Add examples and test - Add necessary models Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>pull/24376/head
parent
580298e0b2
commit
c876c18961
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||
[dependencies] # In alphabetical order
|
||||
bytes = { version = "1.0", default-features = false }
|
||||
futures = { version = "0.3.5", default-features = false }
|
||||
reqwest = { version = "0.11", features = ["stream"] }
|
||||
reqwest = { version = "0.11", features = ["stream", "json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.44"
|
||||
snafu = "0.6.6"
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let influx_url = "http://localhost:8888";
|
||||
let token = "some-token";
|
||||
|
||||
let client = influxdb2_client::Client::new(influx_url, token);
|
||||
|
||||
println!("{:?}", client.setup().await?);
|
||||
println!(
|
||||
"{:?}",
|
||||
client
|
||||
.setup_init(
|
||||
"some-user",
|
||||
"some-org",
|
||||
"some-bucket",
|
||||
Some("some-password".to_string()),
|
||||
Some(1),
|
||||
None
|
||||
)
|
||||
.await?
|
||||
);
|
||||
println!(
|
||||
"{:?}",
|
||||
client
|
||||
.setup_new(
|
||||
"some-new-user",
|
||||
"some-new-org",
|
||||
"some-new-bucket",
|
||||
Some("some-new-password".to_string()),
|
||||
Some(1),
|
||||
None,
|
||||
)
|
||||
.await?
|
||||
);
|
||||
Ok(())
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
//! InfluxDB v2.0 Client API
|
||||
pub mod setup;
|
||||
pub mod ready;
|
|
@ -1,7 +1,7 @@
|
|||
use reqwest::{Method, StatusCode};
|
||||
use snafu::ResultExt;
|
||||
|
||||
use super::{Client, Http, RequestError, ReqwestProcessing};
|
||||
use crate::{Client, Http, RequestError, ReqwestProcessing};
|
||||
|
||||
impl Client {
|
||||
/// Get the readiness of an instance at startup
|
|
@ -0,0 +1,194 @@
|
|||
use crate::{Client, Http, RequestError, ReqwestProcessing, Serializing};
|
||||
use reqwest::{Method, StatusCode};
|
||||
use snafu::ResultExt;
|
||||
|
||||
use crate::models::{IsOnboarding, OnboardingRequest, OnboardingResponse};
|
||||
|
||||
impl Client {
|
||||
/// Check if database has default user, org, bucket
|
||||
pub async fn setup(&self) -> Result<IsOnboarding, RequestError> {
|
||||
let setup_url = format!("{}/api/v2/setup", self.url);
|
||||
let response = self
|
||||
.request(Method::GET, &setup_url)
|
||||
.send()
|
||||
.await
|
||||
.context(ReqwestProcessing)?;
|
||||
|
||||
match response.status() {
|
||||
StatusCode::OK => Ok(response
|
||||
.json::<IsOnboarding>()
|
||||
.await
|
||||
.context(ReqwestProcessing)?),
|
||||
_ => {
|
||||
let status = response.status();
|
||||
let text = response.text().await.context(ReqwestProcessing)?;
|
||||
Http { status, text }.fail()?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set up initial user, org and bucket
|
||||
pub async fn setup_init(
|
||||
&self,
|
||||
username: &str,
|
||||
org: &str,
|
||||
bucket: &str,
|
||||
password: Option<String>,
|
||||
retention_period_hrs: Option<i32>,
|
||||
retention_period_seconds: Option<i32>,
|
||||
) -> Result<OnboardingResponse, RequestError> {
|
||||
let setup_init_url = format!("{}/api/v2/setup", self.url);
|
||||
|
||||
let body = OnboardingRequest {
|
||||
username: username.into(),
|
||||
org: org.into(),
|
||||
bucket: bucket.into(),
|
||||
password: password,
|
||||
retention_period_hrs,
|
||||
retention_period_seconds,
|
||||
};
|
||||
|
||||
let response = self
|
||||
.request(Method::POST, &setup_init_url)
|
||||
.body(serde_json::to_string(&body).context(Serializing)?)
|
||||
.send()
|
||||
.await
|
||||
.context(ReqwestProcessing)?;
|
||||
|
||||
match response.status() {
|
||||
StatusCode::OK => Ok(response
|
||||
.json::<OnboardingResponse>()
|
||||
.await
|
||||
.context(ReqwestProcessing)?),
|
||||
_ => {
|
||||
let status = response.status();
|
||||
let text = response.text().await.context(ReqwestProcessing)?;
|
||||
Http { status, text }.fail()?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set up a new user, org and bucket
|
||||
pub async fn setup_new(
|
||||
&self,
|
||||
username: &str,
|
||||
org: &str,
|
||||
bucket: &str,
|
||||
password: Option<String>,
|
||||
retention_period_hrs: Option<i32>,
|
||||
retention_period_seconds: Option<i32>,
|
||||
) -> Result<OnboardingResponse, RequestError> {
|
||||
let setup_new_url = format!("{}/api/v2/setup/user", self.url);
|
||||
|
||||
let body = OnboardingRequest {
|
||||
username: username.into(),
|
||||
org: org.into(),
|
||||
bucket: bucket.into(),
|
||||
password: password,
|
||||
retention_period_hrs,
|
||||
retention_period_seconds,
|
||||
};
|
||||
|
||||
let response = self
|
||||
.request(Method::POST, &setup_new_url)
|
||||
.body(serde_json::to_string(&body).context(Serializing)?)
|
||||
.send()
|
||||
.await
|
||||
.context(ReqwestProcessing)?;
|
||||
|
||||
match response.status() {
|
||||
StatusCode::OK => Ok(response
|
||||
.json::<OnboardingResponse>()
|
||||
.await
|
||||
.context(ReqwestProcessing)?),
|
||||
_ => {
|
||||
let status = response.status();
|
||||
let text = response.text().await.context(ReqwestProcessing)?;
|
||||
Http { status, text }.fail()?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use mockito::mock;
|
||||
|
||||
type Error = Box<dyn std::error::Error>;
|
||||
type Result<T = (), E = Error> = std::result::Result<T, E>;
|
||||
|
||||
#[tokio::test]
|
||||
async fn setup() -> Result {
|
||||
let token = "some-token";
|
||||
|
||||
let mock_server = mock("GET", "/api/v2/setup")
|
||||
.match_header("Authorization", format!("Token {}", token).as_str())
|
||||
.create();
|
||||
|
||||
let client = Client::new(&mockito::server_url(), token);
|
||||
|
||||
let _result = client.setup().await;
|
||||
|
||||
mock_server.assert();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn setup_init() -> Result {
|
||||
let token = "some-token";
|
||||
let username = "some-user";
|
||||
let org = "some-org";
|
||||
let bucket = "some-bucket";
|
||||
let password = "some-password";
|
||||
let retention_period_hrs = 1;
|
||||
|
||||
let mock_server = mock("POST", "/api/v2/setup")
|
||||
.match_header("Authorization", format!("Token {}", token).as_str())
|
||||
.match_body(
|
||||
format!(
|
||||
r#"{{"username":"{}","org":"{}","bucket":"{}","password":"{}","retentionPeriodHrs":{},}}"#,
|
||||
username, org, bucket, password, retention_period_hrs
|
||||
).as_str(),
|
||||
)
|
||||
.create();
|
||||
|
||||
let client = Client::new(&mockito::server_url(), token);
|
||||
|
||||
let _result = client
|
||||
.setup_init(username, org, bucket, password, retention_period_hrs)
|
||||
.await;
|
||||
|
||||
mock_server.assert();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn setup_new() -> Result {
|
||||
let token = "some-token";
|
||||
let username = "some-user";
|
||||
let org = "some-org";
|
||||
let bucket = "some-bucket";
|
||||
let password = "some-password";
|
||||
let retention_period_hrs = 1;
|
||||
|
||||
let mock_server = mock("POST", "/api/v2/setup/user")
|
||||
.match_header("Authorization", format!("Token {}", token).as_str())
|
||||
.match_body(
|
||||
format!(
|
||||
r#"{{"username":"{}","org":"{}","bucket":"{}","password":"{}","retentionPeriodHrs":{}}}"#,
|
||||
username, org, bucket, password, retention_period_hrs
|
||||
).as_str(),
|
||||
)
|
||||
.create();
|
||||
|
||||
let client = Client::new(&mockito::server_url(), token);
|
||||
|
||||
let _result = client
|
||||
.setup_new(username, org, bucket, password, retention_period_hrs)
|
||||
.await;
|
||||
|
||||
mock_server.assert();
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -303,4 +303,5 @@ cpu,host=server01,region=us-west usage=0.87
|
|||
}
|
||||
}
|
||||
|
||||
mod ready;
|
||||
pub mod api;
|
||||
pub mod models;
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Authorization to create
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Authorization {
|
||||
/// If inactive the token is inactive and requests using the token will be
|
||||
/// rejected.
|
||||
#[serde(rename = "status", skip_serializing_if = "Option::is_none")]
|
||||
pub status: Option<Status>,
|
||||
/// A description of the token.
|
||||
#[serde(rename = "description", skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(rename = "createdAt", skip_serializing_if = "Option::is_none")]
|
||||
pub created_at: Option<String>,
|
||||
#[serde(rename = "updatedAt", skip_serializing_if = "Option::is_none")]
|
||||
pub updated_at: Option<String>,
|
||||
/// ID of org that authorization is scoped to.
|
||||
#[serde(rename = "orgID")]
|
||||
pub org_id: String,
|
||||
/// List of permissions for an auth. An auth must have at least one
|
||||
/// Permission.
|
||||
#[serde(rename = "permissions")]
|
||||
pub permissions: Vec<crate::models::Permission>,
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
/// Passed via the Authorization Header and Token Authentication type.
|
||||
#[serde(rename = "token", skip_serializing_if = "Option::is_none")]
|
||||
pub token: Option<String>,
|
||||
/// ID of user that created and owns the token.
|
||||
#[serde(rename = "userID", skip_serializing_if = "Option::is_none")]
|
||||
pub user_id: Option<String>,
|
||||
/// Name of user that created and owns the token.
|
||||
#[serde(rename = "user", skip_serializing_if = "Option::is_none")]
|
||||
pub user: Option<String>,
|
||||
/// Name of the org token is scoped to.
|
||||
#[serde(rename = "org", skip_serializing_if = "Option::is_none")]
|
||||
pub org: Option<String>,
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::AuthorizationAllOfLinks>,
|
||||
}
|
||||
|
||||
impl Authorization {
|
||||
pub fn new(org_id: String, permissions: Vec<crate::models::Permission>) -> Authorization {
|
||||
Authorization {
|
||||
status: None,
|
||||
description: None,
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
org_id,
|
||||
permissions,
|
||||
id: None,
|
||||
token: None,
|
||||
user_id: None,
|
||||
user: None,
|
||||
org: None,
|
||||
links: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If inactive the token is inactive and requests using the token will be
|
||||
/// rejected.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Status {
|
||||
#[serde(rename = "active")]
|
||||
Active,
|
||||
#[serde(rename = "inactive")]
|
||||
Inactive,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AuthorizationAllOfLinks {
|
||||
/// URI of resource.
|
||||
#[serde(rename = "self", skip_serializing_if = "Option::is_none")]
|
||||
pub _self: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "user", skip_serializing_if = "Option::is_none")]
|
||||
pub user: Option<String>,
|
||||
}
|
||||
|
||||
impl AuthorizationAllOfLinks {
|
||||
pub fn new() -> AuthorizationAllOfLinks {
|
||||
AuthorizationAllOfLinks {
|
||||
_self: None,
|
||||
user: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Bucket Schema
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Bucket {
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::BucketLinks>,
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub _type: Option<Type>,
|
||||
#[serde(rename = "name")]
|
||||
pub name: String,
|
||||
#[serde(rename = "description", skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(rename = "orgID", skip_serializing_if = "Option::is_none")]
|
||||
pub org_id: Option<String>,
|
||||
#[serde(rename = "rp", skip_serializing_if = "Option::is_none")]
|
||||
pub rp: Option<String>,
|
||||
#[serde(rename = "createdAt", skip_serializing_if = "Option::is_none")]
|
||||
pub created_at: Option<String>,
|
||||
#[serde(rename = "updatedAt", skip_serializing_if = "Option::is_none")]
|
||||
pub updated_at: Option<String>,
|
||||
/// Rules to expire or retain data. No rules means data never expires.
|
||||
#[serde(rename = "retentionRules")]
|
||||
pub retention_rules: Vec<crate::models::RetentionRule>,
|
||||
#[serde(rename = "labels", skip_serializing_if = "Option::is_none")]
|
||||
pub labels: Option<Vec<crate::models::Label>>,
|
||||
}
|
||||
|
||||
impl Bucket {
|
||||
pub fn new(name: String, retention_rules: Vec<crate::models::RetentionRule>) -> Bucket {
|
||||
Bucket {
|
||||
links: None,
|
||||
id: None,
|
||||
_type: None,
|
||||
name,
|
||||
description: None,
|
||||
org_id: None,
|
||||
rp: None,
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
retention_rules,
|
||||
labels: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bucket Type
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
#[serde(rename = "user")]
|
||||
User,
|
||||
#[serde(rename = "system")]
|
||||
System,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct BucketLinks {
|
||||
/// URI of resource.
|
||||
#[serde(rename = "labels", skip_serializing_if = "Option::is_none")]
|
||||
pub labels: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "members", skip_serializing_if = "Option::is_none")]
|
||||
pub members: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "org", skip_serializing_if = "Option::is_none")]
|
||||
pub org: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "owners", skip_serializing_if = "Option::is_none")]
|
||||
pub owners: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "self", skip_serializing_if = "Option::is_none")]
|
||||
pub _self: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "write", skip_serializing_if = "Option::is_none")]
|
||||
pub write: Option<String>,
|
||||
}
|
||||
|
||||
impl BucketLinks {
|
||||
pub fn new() -> BucketLinks {
|
||||
BucketLinks {
|
||||
labels: None,
|
||||
members: None,
|
||||
org: None,
|
||||
owners: None,
|
||||
_self: None,
|
||||
write: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// List all buckets
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Buckets {
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::Links>,
|
||||
#[serde(rename = "buckets", skip_serializing_if = "Option::is_none")]
|
||||
pub buckets: Option<Vec<crate::models::Bucket>>,
|
||||
}
|
||||
|
||||
impl Buckets {
|
||||
pub fn new() -> Buckets {
|
||||
Buckets {
|
||||
links: None,
|
||||
buckets: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Label {
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
#[serde(rename = "orgID", skip_serializing_if = "Option::is_none")]
|
||||
pub org_id: Option<String>,
|
||||
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
/// Key/Value pairs associated with this label. Keys can be removed by
|
||||
/// sending an update with an empty value.
|
||||
#[serde(rename = "properties", skip_serializing_if = "Option::is_none")]
|
||||
pub properties: Option<::std::collections::HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
pub fn new() -> Label {
|
||||
Label {
|
||||
id: None,
|
||||
org_id: None,
|
||||
name: None,
|
||||
properties: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Links {
|
||||
/// URI of resource.
|
||||
#[serde(rename = "next", skip_serializing_if = "Option::is_none")]
|
||||
pub next: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "self")]
|
||||
pub _self: String,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "prev", skip_serializing_if = "Option::is_none")]
|
||||
pub prev: Option<String>,
|
||||
}
|
||||
|
||||
impl Links {
|
||||
pub fn new(_self: String) -> Links {
|
||||
Links {
|
||||
next: None,
|
||||
_self,
|
||||
prev: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//! InfluxDB Models
|
||||
//!
|
||||
//! Roughly follows the OpenAPI specification
|
||||
|
||||
pub mod user;
|
||||
pub use self::user::{User, UserLinks, Users, UsersLinks};
|
||||
pub mod organization;
|
||||
pub use self::organization::{Organization, OrganizationLinks, Organizations};
|
||||
pub mod bucket;
|
||||
pub use self::bucket::{Bucket, BucketLinks, Buckets};
|
||||
pub mod onboarding;
|
||||
pub use self::onboarding::{IsOnboarding, OnboardingRequest, OnboardingResponse};
|
||||
pub mod links;
|
||||
pub use self::links::Links;
|
||||
pub mod permission;
|
||||
pub use self::permission::Permission;
|
||||
pub mod label;
|
||||
pub use self::label::Label;
|
||||
pub mod authorization;
|
||||
pub use self::authorization::{Authorization, AuthorizationAllOfLinks};
|
||||
pub mod resource;
|
||||
pub use self::resource::Resource;
|
||||
pub mod retention_rule;
|
||||
pub use self::retention_rule::RetentionRule;
|
|
@ -0,0 +1,73 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct IsOnboarding {
|
||||
/// True means that the influxdb instance has NOT had initial setup; false
|
||||
/// means that the database has been setup.
|
||||
#[serde(rename = "allowed", skip_serializing_if = "Option::is_none")]
|
||||
pub allowed: Option<bool>,
|
||||
}
|
||||
|
||||
impl IsOnboarding {
|
||||
pub fn new() -> IsOnboarding {
|
||||
IsOnboarding { allowed: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct OnboardingRequest {
|
||||
#[serde(rename = "username")]
|
||||
pub username: String,
|
||||
#[serde(rename = "password", skip_serializing_if = "Option::is_none")]
|
||||
pub password: Option<String>,
|
||||
#[serde(rename = "org")]
|
||||
pub org: String,
|
||||
#[serde(rename = "bucket")]
|
||||
pub bucket: String,
|
||||
#[serde(
|
||||
rename = "retentionPeriodSeconds",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub retention_period_seconds: Option<i32>,
|
||||
/// Retention period *in nanoseconds* for the new bucket. This key's name
|
||||
/// has been misleading since OSS 2.0 GA, please transition to use
|
||||
/// `retentionPeriodSeconds`
|
||||
#[serde(rename = "retentionPeriodHrs", skip_serializing_if = "Option::is_none")]
|
||||
pub retention_period_hrs: Option<i32>,
|
||||
}
|
||||
|
||||
impl OnboardingRequest {
|
||||
pub fn new(username: String, org: String, bucket: String) -> OnboardingRequest {
|
||||
OnboardingRequest {
|
||||
username,
|
||||
password: None,
|
||||
org,
|
||||
bucket,
|
||||
retention_period_seconds: None,
|
||||
retention_period_hrs: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct OnboardingResponse {
|
||||
#[serde(rename = "user", skip_serializing_if = "Option::is_none")]
|
||||
pub user: Option<crate::models::User>,
|
||||
#[serde(rename = "org", skip_serializing_if = "Option::is_none")]
|
||||
pub org: Option<crate::models::Organization>,
|
||||
#[serde(rename = "bucket", skip_serializing_if = "Option::is_none")]
|
||||
pub bucket: Option<crate::models::Bucket>,
|
||||
#[serde(rename = "auth", skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<crate::models::Authorization>,
|
||||
}
|
||||
|
||||
impl OnboardingResponse {
|
||||
pub fn new() -> OnboardingResponse {
|
||||
OnboardingResponse {
|
||||
user: None,
|
||||
org: None,
|
||||
bucket: None,
|
||||
auth: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Organization {
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::OrganizationLinks>,
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
#[serde(rename = "name")]
|
||||
pub name: String,
|
||||
#[serde(rename = "description", skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(rename = "createdAt", skip_serializing_if = "Option::is_none")]
|
||||
pub created_at: Option<String>,
|
||||
#[serde(rename = "updatedAt", skip_serializing_if = "Option::is_none")]
|
||||
pub updated_at: Option<String>,
|
||||
/// If inactive the organization is inactive.
|
||||
#[serde(rename = "status", skip_serializing_if = "Option::is_none")]
|
||||
pub status: Option<Status>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct OrganizationLinks {
|
||||
/// URI of resource.
|
||||
#[serde(rename = "self", skip_serializing_if = "Option::is_none")]
|
||||
pub _self: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "members", skip_serializing_if = "Option::is_none")]
|
||||
pub members: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "owners", skip_serializing_if = "Option::is_none")]
|
||||
pub owners: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "labels", skip_serializing_if = "Option::is_none")]
|
||||
pub labels: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "secrets", skip_serializing_if = "Option::is_none")]
|
||||
pub secrets: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "buckets", skip_serializing_if = "Option::is_none")]
|
||||
pub buckets: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "tasks", skip_serializing_if = "Option::is_none")]
|
||||
pub tasks: Option<String>,
|
||||
/// URI of resource.
|
||||
#[serde(rename = "dashboards", skip_serializing_if = "Option::is_none")]
|
||||
pub dashboards: Option<String>,
|
||||
}
|
||||
|
||||
impl Organization {
|
||||
pub fn new(name: String) -> Organization {
|
||||
Organization {
|
||||
links: None,
|
||||
id: None,
|
||||
name,
|
||||
description: None,
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
status: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If inactive the organization is inactive.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Status {
|
||||
#[serde(rename = "active")]
|
||||
Active,
|
||||
#[serde(rename = "inactive")]
|
||||
Inactive,
|
||||
}
|
||||
|
||||
impl OrganizationLinks {
|
||||
pub fn new() -> OrganizationLinks {
|
||||
OrganizationLinks {
|
||||
_self: None,
|
||||
members: None,
|
||||
owners: None,
|
||||
labels: None,
|
||||
secrets: None,
|
||||
buckets: None,
|
||||
tasks: None,
|
||||
dashboards: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Organizations {
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::Links>,
|
||||
#[serde(rename = "orgs", skip_serializing_if = "Option::is_none")]
|
||||
pub orgs: Option<Vec<crate::models::Organization>>,
|
||||
}
|
||||
|
||||
impl Organizations {
|
||||
pub fn new() -> Organizations {
|
||||
Organizations {
|
||||
links: None,
|
||||
orgs: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Permission {
|
||||
#[serde(rename = "action")]
|
||||
pub action: Action,
|
||||
#[serde(rename = "resource")]
|
||||
pub resource: crate::models::Resource,
|
||||
}
|
||||
|
||||
impl Permission {
|
||||
pub fn new(action: Action, resource: crate::models::Resource) -> Permission {
|
||||
Permission { action, resource }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Action {
|
||||
#[serde(rename = "read")]
|
||||
Read,
|
||||
#[serde(rename = "write")]
|
||||
Write,
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Resource {
|
||||
#[serde(rename = "type")]
|
||||
pub _type: Type,
|
||||
/// If ID is set that is a permission for a specific resource. if it is not
|
||||
/// set it is a permission for all resources of that resource type.
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
/// Optional name of the resource if the resource has a name field.
|
||||
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
/// If orgID is set that is a permission for all resources owned my that
|
||||
/// org. if it is not set it is a permission for all resources of that
|
||||
/// resource type.
|
||||
#[serde(rename = "orgID", skip_serializing_if = "Option::is_none")]
|
||||
pub org_id: Option<String>,
|
||||
/// Optional name of the organization of the organization with orgID.
|
||||
#[serde(rename = "org", skip_serializing_if = "Option::is_none")]
|
||||
pub org: Option<String>,
|
||||
}
|
||||
|
||||
impl Resource {
|
||||
pub fn new(_type: Type) -> Resource {
|
||||
Resource {
|
||||
_type,
|
||||
id: None,
|
||||
name: None,
|
||||
org_id: None,
|
||||
org: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
#[serde(rename = "authorizations")]
|
||||
Authorizations,
|
||||
#[serde(rename = "buckets")]
|
||||
Buckets,
|
||||
#[serde(rename = "dashboards")]
|
||||
Dashboards,
|
||||
#[serde(rename = "orgs")]
|
||||
Orgs,
|
||||
#[serde(rename = "sources")]
|
||||
Sources,
|
||||
#[serde(rename = "tasks")]
|
||||
Tasks,
|
||||
#[serde(rename = "telegrafs")]
|
||||
Telegrafs,
|
||||
#[serde(rename = "users")]
|
||||
Users,
|
||||
#[serde(rename = "variables")]
|
||||
Variables,
|
||||
#[serde(rename = "scrapers")]
|
||||
Scrapers,
|
||||
#[serde(rename = "secrets")]
|
||||
Secrets,
|
||||
#[serde(rename = "labels")]
|
||||
Labels,
|
||||
#[serde(rename = "views")]
|
||||
Views,
|
||||
#[serde(rename = "documents")]
|
||||
Documents,
|
||||
#[serde(rename = "notificationRules")]
|
||||
NotificationRules,
|
||||
#[serde(rename = "notificationEndpoints")]
|
||||
NotificationEndpoints,
|
||||
#[serde(rename = "checks")]
|
||||
Checks,
|
||||
#[serde(rename = "dbrp")]
|
||||
Dbrp,
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RetentionRule {
|
||||
#[serde(rename = "type")]
|
||||
pub _type: Type,
|
||||
/// Duration in seconds for how long data will be kept in the database. 0
|
||||
/// means infinite.
|
||||
#[serde(rename = "everySeconds")]
|
||||
pub every_seconds: i32,
|
||||
/// Shard duration measured in seconds.
|
||||
#[serde(
|
||||
rename = "shardGroupDurationSeconds",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub shard_group_duration_seconds: Option<i64>,
|
||||
}
|
||||
|
||||
impl RetentionRule {
|
||||
pub fn new(_type: Type, every_seconds: i32) -> RetentionRule {
|
||||
RetentionRule {
|
||||
_type,
|
||||
every_seconds,
|
||||
shard_group_duration_seconds: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
#[serde(rename = "expire")]
|
||||
Expire,
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// User Information
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
#[serde(rename = "oauthID", skip_serializing_if = "Option::is_none")]
|
||||
pub oauth_id: Option<String>,
|
||||
#[serde(rename = "name")]
|
||||
pub name: String,
|
||||
/// If inactive the user is inactive.
|
||||
#[serde(rename = "status", skip_serializing_if = "Option::is_none")]
|
||||
pub status: Option<Status>,
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::UserLinks>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn new(name: String) -> User {
|
||||
User {
|
||||
id: None,
|
||||
oauth_id: None,
|
||||
name,
|
||||
status: None,
|
||||
links: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If inactive the user is inactive.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
|
||||
pub enum Status {
|
||||
#[serde(rename = "active")]
|
||||
Active,
|
||||
#[serde(rename = "inactive")]
|
||||
Inactive,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct UserLinks {
|
||||
#[serde(rename = "self", skip_serializing_if = "Option::is_none")]
|
||||
pub _self: Option<String>,
|
||||
}
|
||||
|
||||
impl UserLinks {
|
||||
pub fn new() -> UserLinks {
|
||||
UserLinks { _self: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// List of Users
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Users {
|
||||
#[serde(rename = "links", skip_serializing_if = "Option::is_none")]
|
||||
pub links: Option<crate::models::UsersLinks>,
|
||||
#[serde(rename = "users", skip_serializing_if = "Option::is_none")]
|
||||
pub users: Option<Vec<crate::models::User>>,
|
||||
}
|
||||
|
||||
impl Users {
|
||||
pub fn new() -> Users {
|
||||
Users {
|
||||
links: None,
|
||||
users: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct UsersLinks {
|
||||
#[serde(rename = "self", skip_serializing_if = "Option::is_none")]
|
||||
pub _self: Option<String>,
|
||||
}
|
||||
|
||||
impl UsersLinks {
|
||||
pub fn new() -> UsersLinks {
|
||||
UsersLinks { _self: None }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue