diff --git a/Cargo.lock b/Cargo.lock index f7b49cb..263886a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,6 +273,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-link", ] @@ -1054,6 +1055,26 @@ dependencies = [ "autocfg", ] +[[package]] +name = "oauth2" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e219e79014df21a225b1860a479e2dcd7cbd9130f4defd4bd0e191ea31d67d" +dependencies = [ + "base64", + "chrono", + "getrandom 0.2.16", + "http", + "rand 0.8.5", + "reqwest", + "serde", + "serde_json", + "serde_path_to_error", + "sha2", + "thiserror 1.0.69", + "url", +] + [[package]] name = "object" version = "0.36.7" @@ -1734,6 +1755,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1984,6 +2015,7 @@ name = "tmf-client" version = "0.1.9" dependencies = [ "env_logger", + "oauth2", "reqwest", "serde", "serde_json", @@ -2190,6 +2222,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index aadc5df..d9d6fec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,12 +23,16 @@ tmf674 = ["tmflib/tmf674"] v4 = ["tmflib/build-V4"] v5 = ["tmflib/build-V5"] insecure = [] -default = ["tmf620","tmf622","tmf629","tmf632","tmf633","tmf637","tmf638","tmf639","tmf645","tmf648","tmf663","tmf674","v4","insecure"] +oauth2 = ["dep:oauth2"] +default = ["tmf620","tmf622","tmf629","tmf632","tmf633","tmf637","tmf638","tmf639","tmf645","tmf648","tmf663","tmf674","v4","insecure","oauth2"] [dependencies] -env_logger = "0.11.8" +env_logger = "0.11.5" +oauth2 = { version = "5.0.0", optional = true} reqwest = {version = "0.12.22", features = ["blocking","rustls-tls"]} -serde = "1.0.219" -serde_json = "1.0.141" +serde = "1.0.214" +serde_json = "1.0.132" +tmflib = "0.1.22" + thiserror = "2.0.12" -tmflib = "0.1.31" + diff --git a/src/lib.rs b/src/lib.rs index 0e4e2b3..5040a94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,7 @@ pub struct QueryOptions { pub limit : Option, /// Offset the results returned pub offset : Option, - /// Filter on name + /// Simple filter on name field, if it exists. pub name : Option, } @@ -160,6 +160,18 @@ pub trait Operations { /// Create a new instance of a TMF object fn create(&self, item : Self::TMF) -> Result; /// Update an existing TMF Object using the provided patch object + /// Update an existing TMF object + /// ``` + /// # use tmf_client::{TMFClient,Operations}; + /// use tmflib::tmf620::category::Category; + /// use tmflib::{HasId,HasName}; + /// let mut existing = Category::new("My Category"); + /// existing.set_name("New Category Name"); + /// let result = TMFClient::new("http://localhost:8080") + /// .tmf620() + /// .category() + /// .update(existing.get_id(),existing); + /// ``` fn update(&self, id : impl Into, patch : Self::TMF) -> Result; /// Delete a specific tmf object by Id /// ``` diff --git a/src/tmf/mod.rs b/src/tmf/mod.rs index 2e61054..ecd5015 100644 --- a/src/tmf/mod.rs +++ b/src/tmf/mod.rs @@ -6,8 +6,19 @@ use std::io::Read; use crate::QueryOptions; use crate::common::tmf_error::TMFError; use tmflib::{HasId,Uri}; -use serde::{de::DeserializeOwned, Serialize}; -// use log::info; +use serde::de::DeserializeOwned; +use serde::Serialize; + +#[cfg(feature = "oauth2")] +use oauth2::basic::BasicClient; + +#[cfg(feature = "oauth2")] +use oauth2::{ + ClientId, + ClientSecret, + AuthUrl, + TokenUrl +}; #[cfg(feature = "tmf620")] pub mod tmf620; @@ -36,6 +47,17 @@ pub mod tmf674; static USER_AGENT : &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); +/// Get a new OAuth toekn +#[cfg(feature = "oauth2")] +pub fn get_token() { + // let _client = BasicClient::new( + // ClientId::new(std::env::var("OAUTH_CLIENT_ID").unwrap()), + // Some(ClientSecret::new(std::env::var("OAUTH_CLIENT_SECRET").unwrap())), + // AuthUrl::new(std::env::var("OAUTH_AUTH_URL").unwrap()).unwrap(), + // Some(TokenUrl::new(std::env::var("OAUTH_TOKEN_URL").unwrap()).unwrap()) + // ); +} + /// Make API call to retrieve a single TMF object pub fn get_tmf(host: Uri, id : String) -> Result,TMFError> { // Return results