refactor data source storage

make the associated data stuff work in a type safe way
This commit is contained in:
nora 2024-04-15 22:01:56 +02:00
parent b5a28e4e94
commit 854f7bb2bc
11 changed files with 286 additions and 269 deletions

View file

@ -5,7 +5,9 @@ edition = "2021"
[dependencies]
eyre = "0.6.12"
reqwest = "0.12.3"
reqwest = { version = "0.12.3", default-features = false, features = ["charset", "http2", "rustls-tls"]}
terustform = { path = "../terustform" }
tokio = { version = "1.37.0", features = ["full"] }
dto = { git = "https://github.com/nilstrieb-lehre/davinci-cors.git", rev = "bef75a802cf48cf63d171136c2cea67b83055387" }

View file

@ -0,0 +1,3 @@
pub struct _CorsClient {
client: reqwest::Client
}

View file

@ -1,25 +1,39 @@
mod client;
use std::collections::HashMap;
use terustform::{
datasource::{self, DataSource},
provider::Provider,
provider::{MkDataSource, Provider},
AttrPath, DResult, StringValue, Value, ValueModel,
};
#[tokio::main]
async fn main() -> eyre::Result<()> {
terustform::start(&ExampleProvider {}).await
terustform::start(ExampleProvider {}).await
}
pub struct ExampleProvider {}
impl Provider for ExampleProvider {
type Data = ();
fn name(&self) -> String {
"example".to_owned()
"corsschool".to_owned()
}
fn data_sources(&self) -> Vec<Box<dyn DataSource>> {
vec![ExampleDataSource {}.erase()]
fn schema(&self) -> datasource::Schema {
datasource::Schema {
description: "uwu".to_owned(),
attributes: HashMap::new(),
}
}
async fn configure(&self, _config: Value) -> DResult<Self::Data> {
Ok(())
}
fn data_sources(&self) -> Vec<MkDataSource<Self::Data>> {
vec![ExampleDataSource::erase()]
}
}
@ -34,11 +48,13 @@ struct ExampleDataSourceModel {
#[terustform::async_trait]
impl DataSource for ExampleDataSource {
fn name(&self, provider_name: &str) -> String {
type ProviderData = ();
fn name(provider_name: &str) -> String {
format!("{provider_name}_kitty")
}
fn schema(&self) -> datasource::Schema {
fn schema() -> datasource::Schema {
datasource::Schema {
description: "an example".to_owned(),
attributes: HashMap::from([
@ -70,6 +86,10 @@ impl DataSource for ExampleDataSource {
}
}
fn new(_data: Self::ProviderData) -> DResult<Self> {
Ok(ExampleDataSource {})
}
async fn read(&self, config: Value) -> DResult<Value> {
let mut model = ExampleDataSourceModel::from_value(config, &AttrPath::root())?;