Skip to content

Commit

Permalink
Merge pull request #329 from sreeise/graph-failure-sync-hot-fix
Browse files Browse the repository at this point in the history
Graph failure sync hot fix
  • Loading branch information
sreeise committed Jan 15, 2022
2 parents 8738079 + 6ef0024 commit 1c0020f
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 80 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "graph-rs-sdk"
version = "0.1.2"
version = "0.1.3"
authors = ["sreeise"]
edition = "2018"
readme = "README.md"
Expand Down Expand Up @@ -42,9 +42,9 @@ rayon = "1"
tokio = { version = "1", features = ["full"] }
url = "2"

graph-oauth = { path = "./graph-oauth", version = "0.1.1" }
graph-http = { path = "./graph-http", version = "0.1.2" }
graph-error = { path = "./graph-error", version = "0.1.1" }
graph-oauth = { path = "./graph-oauth", version = "0.1.2" }
graph-http = { path = "./graph-http", version = "0.1.3" }
graph-error = { path = "./graph-error", version = "0.1.2" }
graph-core = { path = "./graph-core", version = "0.1.1" }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -5,7 +5,7 @@

### Now available on stable Rust at [crates.io](https://crates.io/crates/graph-rs-sdk)

graph-rs-sdk = "0.1.0"
graph-rs-sdk = "0.1.3"

0.1.0 and above use stable Rust. Anything before 0.1.0 uses nightly Rust.

Expand Down Expand Up @@ -111,7 +111,7 @@ pub struct DriveItem {
// ... Any other fields
}

let response: DriveItem = client.v1()
let response: GraphResponse<DriveItem> = client.v1()
.me()
.drive()
.get_items("ITEM_ID")
Expand Down
6 changes: 4 additions & 2 deletions examples/onenote_pages.rs
@@ -1,4 +1,3 @@
use graph_http::GraphResponse;
use graph_rs_sdk::prelude::*;
use std::ffi::OsString;
use std::str::FromStr;
Expand All @@ -18,7 +17,10 @@ static DOWNLOAD_PATH: &str = "DOWNLOAD_PATH";
// Include the file extension such as .html
static FILE_NAME: &str = "FILE_NAME";

fn main() {}
fn main() {
get_page_html_content();
download_page_as_html();
}

fn get_page_html_content() {
let client = Graph::new(ACCESS_TOKEN);
Expand Down
18 changes: 6 additions & 12 deletions graph-codegen/src/api_types/request_metadata.rs
Expand Up @@ -73,7 +73,7 @@ impl RequestMetadata {
}

pub fn transform_secondary_request(&mut self, operation_mapping: &str, original_parent: &str) {
self.operation_mapping = format!("{}", operation_mapping);
self.operation_mapping = operation_mapping.to_string();
self.parent = original_parent.to_pascal_case();
self.original_parent = original_parent.to_pascal_case();
self.resource_identity = ResourceIdentity::from_str(&self.original_parent).ok();
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Metadata for RequestMetadata {
}

fn http_method(&self) -> HttpMethod {
self.http_method.clone()
self.http_method
}

fn fn_name(&self) -> String {
Expand Down Expand Up @@ -184,8 +184,7 @@ impl PathMetadata {
pub fn contains_operation_id_start(&self, operation_id_start: &str) -> bool {
self.metadata
.iter()
.find(|metadata| metadata.operation_id.starts_with(operation_id_start))
.is_some()
.any(|metadata| metadata.operation_id.starts_with(operation_id_start))
}

pub fn path_starts_with(&self, path: &str) -> bool {
Expand All @@ -206,6 +205,7 @@ impl PathMetadata {
self.path = self.path.trim_start_matches(path_start).to_string();
}

#[allow(unused_assignments)]
pub fn operation_id_start(&mut self, pat: &str) {
let mut to = String::new();
if pat.contains('.') {
Expand Down Expand Up @@ -237,17 +237,11 @@ impl PathMetadata {
}

pub fn format_named_path_parameters(&mut self) {
let mut counter = 0;
let mut path = self.path.clone();

for param in self.parameters.iter() {
let param_snake_case = format!("{{{}}}", param.to_snake_case());
if counter == 0 {
path = path.replacen(param.as_str(), param_snake_case.as_str(), 1);
} else {
path = path.replacen(param.as_str(), param_snake_case.as_str(), 1);
}
counter += 1;
path = path.replacen(param.as_str(), param_snake_case.as_str(), 1);
}

self.path = path;
Expand All @@ -262,7 +256,7 @@ impl PathMetadata {
pub fn transform_id_metadata(&mut self) {
self.path = self.path.replacen("{{id}}", "{{RID}}", 1);
let _ = self.parameters.pop_front();
self.param_size = self.param_size - 1;
self.param_size -= 1;
for m in self.metadata.iter_mut() {
m.transform_id_request();
}
Expand Down
5 changes: 2 additions & 3 deletions graph-codegen/src/macros/macro_queue_writer.rs
Expand Up @@ -61,8 +61,7 @@ pub trait MacroQueueWriter {
let metadata = self.request_metadata();
metadata
.iter()
.find(|m| m.request_task() == RequestTask::Download)
.is_some()
.any(|m| m.request_task() == RequestTask::Download)
}

fn write_download_macros(&self, is_async_download: bool) -> Option<String> {
Expand Down Expand Up @@ -326,7 +325,7 @@ pub trait MacroImplWriter {
for path_metadata in path_metadata_queue.iter() {
let method_macros = path_metadata.write_method_macros();
buf.put(method_macros.as_bytes());
if has_downloads == false && path_metadata.has_download_methods() {
if !has_downloads && path_metadata.has_download_methods() {
has_downloads = true;
}
}
Expand Down
16 changes: 6 additions & 10 deletions graph-codegen/src/macros/writer.rs
Expand Up @@ -147,12 +147,10 @@ impl MacroFormatter {
} else {
format!("( {{ doc: $doc:expr, name: $name:ident, response: $T:ty, path: $template:expr, has_body: {} }} )", has_body)
}
} else if param_size > 0 {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, params: [{}], has_body: {} }} )", s, has_body)
} else {
if param_size > 0 {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, params: [{}], has_body: {} }} )", s, has_body)
} else {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, has_body: {} }} )", has_body)
}
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, has_body: {} }} )", has_body)
}
}

Expand Down Expand Up @@ -220,12 +218,10 @@ impl MacroFormatter {
} else {
format!("( {{ doc: $doc:expr, name: $name:ident, response: $T:ty, path: $template:expr, method: $m:expr, has_body: {} }} )", has_body)
}
} else if param_size > 0 {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, method: $m:expr, params: [{}], has_body: {} }} )", s, has_body)
} else {
if param_size > 0 {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, method: $m:expr, params: [{}], has_body: {} }} )", s, has_body)
} else {
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, method: $m:expr, has_body: {} }} )", has_body)
}
format!("( {{ name: $name:ident, response: $T:ty, path: $template:expr, method: $m:expr, has_body: {} }} )", has_body)
}
}

Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/openapi/mod.rs
Expand Up @@ -164,7 +164,7 @@ impl OpenApi {
.paths
.clone()
.into_par_iter()
.map(|(path, path_item)| (path.transform_path(), path_item.clone()))
.map(|(path, path_item)| (path.transform_path(), path_item))
.collect();
}

Expand Down
1 change: 1 addition & 0 deletions graph-codegen/src/openapi/operation.rs
Expand Up @@ -138,6 +138,7 @@ impl Operation {
self.request_body.is_some()
}

#[allow(unused_assignments)]
pub fn request_metadata(&self, http_method: HttpMethod) -> RequestMetadata {
let operation_mapping = self.operation_id.operation_mapping();
let mut parent = String::new();
Expand Down
5 changes: 1 addition & 4 deletions graph-codegen/src/openapi/reference.rs
Expand Up @@ -35,10 +35,7 @@ impl Reference {

pub fn is_ref_type_download(&self) -> bool {
if let Some(ref_) = self.ref_.as_ref() {
return match ref_.as_str() {
"#/components/schemas/microsoft.graph.report" => true,
_ => false,
};
return matches!(ref_.as_str(), "#/components/schemas/microsoft.graph.report");
}
false
}
Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/traits/filter_path.rs
Expand Up @@ -54,7 +54,7 @@ pub trait FilterPath {
self.paths()
.into_par_iter()
.filter(|(path, _path_item)| path.contains(pat))
.map(|(path, path_item)| (path.clone(), path_item.clone()))
.map(|(path, path_item)| (path, path_item))
.collect()
}

Expand Down
3 changes: 2 additions & 1 deletion graph-codegen/src/traits/request.rs
Expand Up @@ -138,6 +138,7 @@ impl RequestParser for &str {
op_mapping
}

#[allow(unused_assignments)]
fn transform_path(&self) -> String {
let mut path = self.to_string();
let path_clone = path.clone();
Expand All @@ -159,7 +160,7 @@ impl RequestParser for &str {

for name in capture_names.iter() {
if capture.name(name).is_some() {
if let Some(path_matcher) = PathMatcher::from_str(name).ok() {
if let Ok(path_matcher) = PathMatcher::from_str(name) {
if !s.contains("RID") {
match path_matcher {
PathMatcher::PathId => {
Expand Down
2 changes: 1 addition & 1 deletion graph-error/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "graph-error"
version = "0.1.1"
version = "0.1.2"
authors = ["sreeise"]
edition = "2018"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions graph-error/src/error.rs
Expand Up @@ -270,8 +270,8 @@ impl WithGraphError for reqwest::blocking::Response {
let headers = Some(GraphHeaders::from(&self));
let error_message = self.json().unwrap_or_default();
Err(GraphError {
code,
headers,
code,
error_message,
})
} else {
Expand All @@ -292,8 +292,8 @@ impl WithGraphErrorAsync for reqwest::Response {
let headers = Some(GraphHeaders::from(&self));
let error_message = self.json().await.unwrap_or_default();
Err(GraphError {
code,
headers,
code,
error_message,
})
} else {
Expand Down
14 changes: 0 additions & 14 deletions graph-error/src/graph_failure.rs
@@ -1,7 +1,5 @@
use crate::download::{AsyncDownloadError, BlockingDownloadError};
use crate::error::GraphError;
use crate::internal::GraphRsError;
use crate::ioerror::{AsyncIoError, ThreadedIoError};
use std::cell::BorrowMutError;
use std::io::ErrorKind;
use std::str::Utf8Error;
Expand Down Expand Up @@ -70,18 +68,6 @@ pub enum GraphFailure {

#[error("Crypto Error (Unknown)")]
CryptoError,

#[error("Blocking download error:\n{0:#?}")]
BlockingDownloadError(#[from] BlockingDownloadError),

#[error("Async download error:\n{0:#?}")]
AsyncDownloadError(#[from] AsyncDownloadError),

#[error("Async Io error:\n{0:#?}")]
AsyncIoError(#[from] AsyncIoError),

#[error("Threaded Io error:\n{0:#?}")]
ThreadedIoError(#[from] ThreadedIoError),
}

impl GraphFailure {
Expand Down
2 changes: 1 addition & 1 deletion graph-http/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "graph-http"
version = "0.1.2"
version = "0.1.3"
authors = ["sreeise"]
edition = "2018"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion graph-http/src/async_client/client.rs
Expand Up @@ -302,7 +302,7 @@ impl HttpClient<std::sync::Arc<tokio::sync::Mutex<AsyncClient>>> {
RequestAttribute::Method(method) => client.method = method,
RequestAttribute::Body(body) => client.body = Some(body),
RequestAttribute::BodyFile(path) => {
let buffer = futures::executor::block_on(tokio::fs::read_to_string(path))?;
let buffer = tokio::fs::read_to_string(path).await?;
client.body = Some(buffer.into());
}
RequestAttribute::Headers(headers) => client.headers = headers,
Expand Down
2 changes: 1 addition & 1 deletion graph-http/src/dispatch.rs
Expand Up @@ -91,7 +91,7 @@ where
return Err(self.error.unwrap_or_default());
}
let response = self.request.send()?;
Ok(std::convert::TryFrom::try_from(response)?)
std::convert::TryFrom::try_from(response)
}
}

Expand Down
16 changes: 11 additions & 5 deletions graph-http/src/intoresponse.rs
Expand Up @@ -287,7 +287,8 @@ impl<'a, T> IntoResponseAsync<'a, T> {
return Err(self.error.unwrap_or_default());
}

let response = self.client.response().await?;
let request = self.client.build().await;
let response = request.send().await?;
let headers = response.headers().clone();
let status = response.status();
let url = GraphUrl::from(response.url());
Expand All @@ -300,7 +301,8 @@ impl<'a, T> IntoResponseAsync<'a, T> {
return Err(self.error.unwrap_or_default());
}

let response = self.client.response().await?;
let request = self.client.build().await;
let response = request.send().await?;
let headers = response.headers().clone();
let status = response.status();
let url = GraphUrl::from(response.url());
Expand All @@ -313,7 +315,8 @@ impl<'a, T> IntoResponseAsync<'a, T> {
return Err(self.error.unwrap_or_default());
}

let response = self.client.response().await?;
let request = self.client.build().await;
let response = request.send().await?;
let headers = response.headers().clone();
let status = response.status();
let url = GraphUrl::from(response.url());
Expand All @@ -335,7 +338,8 @@ where
if self.error.is_some() {
return Err(self.error.unwrap_or_default());
}
let response = self.client.response().await?;
let request = self.client.build().await;
let response = request.send().await?;
AsyncTryFrom::<reqwest::Response>::async_try_from(response).await
}
}
Expand All @@ -350,7 +354,9 @@ impl<'a> IntoResponseAsync<'a, NoContent> {
if self.error.is_some() {
return Err(self.error.unwrap_or_default());
}
let response = self.client.response().await?;

let request = self.client.build().await;
let response = request.send().await?;
GraphResponse::<serde_json::Value>::async_from_no_content(response).await
}
}
Expand Down
2 changes: 1 addition & 1 deletion graph-oauth/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "graph-oauth"
version = "0.1.1"
version = "0.1.2"
authors = ["sreeise"]
edition = "2018"
license = "MIT"
Expand Down
7 changes: 2 additions & 5 deletions graph-oauth/src/accesstoken.rs
Expand Up @@ -299,11 +299,8 @@ impl AccessToken {
/// let mut access_token = AccessToken::default();
/// println!("{:#?}", access_token.refresh_token());
/// ```
pub fn refresh_token(self) -> Option<String> {
match self.refresh_token {
Some(t) => Some(t),
None => None,
}
pub fn refresh_token(&self) -> Option<String> {
self.refresh_token.clone()
}

/// Get the id token.
Expand Down

0 comments on commit 1c0020f

Please sign in to comment.