From 4a98f4bc46b6e523a90f4b52aa4a97069a9fa9b4 Mon Sep 17 00:00:00 2001 From: Kurt Wolf Date: Mon, 25 Dec 2023 03:06:32 -0500 Subject: [PATCH] small updates. bump version deps --- core/template/base/README.md.j2 | 2 +- libninja/src/rust.rs | 25 +++++++++++-------------- libninja/src/rust/cargo_toml.rs | 4 ++-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/template/base/README.md.j2 b/core/template/base/README.md.j2 index a32c23e..116d515 100644 --- a/core/template/base/README.md.j2 +++ b/core/template/base/README.md.j2 @@ -5,7 +5,7 @@ Stars - Build Status + Build Status {% block additional_shields %} {% endblock %} diff --git a/libninja/src/rust.rs b/libninja/src/rust.rs index d443b48..c868704 100644 --- a/libninja/src/rust.rs +++ b/libninja/src/rust.rs @@ -241,16 +241,16 @@ fn static_shared_http_client(spec: &HirSpec, opt: &PackageConfig) -> TokenStream } /// Use this method if you want to add custom middleware to the httpclient. + /// It must be called before any requests are made, otherwise it will have no effect. /// Example usage: /// /// ``` - /// init_http_client(|| { - /// default_http_client() - /// .with_middleware(..) - /// }); + /// init_http_client(default_http_client() + /// .with_middleware(..) + /// ); /// ``` - pub fn init_http_client(init: fn() -> httpclient::Client) { - SHARED_HTTPCLIENT.get_or_init(init); + pub fn init_http_client(init: httpclient::Client) { + let _ = SHARED_HTTPCLIENT.set(init); } fn shared_http_client() -> &'static httpclient::Client { @@ -275,21 +275,18 @@ fn shared_oauth2_flow(auth: &Oauth2Auth, spec: &HirSpec, opts: &PackageConfig) - quote! { static SHARED_OAUTH2FLOW: OnceLock = OnceLock::new(); - pub fn init_oauth2_flow(init: fn() -> httpclient_oauth2::OAuth2Flow) { - SHARED_OAUTH2FLOW.get_or_init(init); + pub fn init_oauth2_flow(init: httpclient_oauth2::OAuth2Flow) { + let _ = SHARED_OAUTH2FLOW.set(init); } fn shared_oauth2_flow() -> &'static httpclient_oauth2::OAuth2Flow { - let client_id = std::env::var(#client_id).expect(#client_id_expect); - let client_secret = std::env::var(#client_secret).expect(#client_secret_expect); - let redirect_uri = std::env::var(#redirect_uri).expect(#redirect_uri_expect); SHARED_OAUTH2FLOW.get_or_init(|| httpclient_oauth2::OAuth2Flow { - client_id, - client_secret, + client_id: std::env::var(#client_id).expect(#client_id_expect), + client_secret: std::env::var(#client_secret).expect(#client_secret_expect), init_endpoint: #init_endpoint.to_string(), exchange_endpoint: #exchange_endpoint.to_string(), refresh_endpoint: #refresh_endpoint.to_string(), - redirect_uri, + redirect_uri: std::env::var(#redirect_uri).expect(#redirect_uri_expect), }) } } diff --git a/libninja/src/rust/cargo_toml.rs b/libninja/src/rust/cargo_toml.rs index d9a7c6d..dcc50f6 100644 --- a/libninja/src/rust/cargo_toml.rs +++ b/libninja/src/rust/cargo_toml.rs @@ -44,7 +44,7 @@ pub fn update_cargo_toml(extras: &Extras, opts: &OutputConfig, context: &HashMap } let package_version = package.version().to_string(); - ensure_dependency(&mut m.dependencies, "httpclient", "0.20.0", &[]); + ensure_dependency(&mut m.dependencies, "httpclient", "0.20.2", &[]); ensure_dependency(&mut m.dependencies, "serde", "1.0.137", &["derive"]); ensure_dependency(&mut m.dependencies, "serde_json", "1.0.81", &[]); ensure_dependency(&mut m.dependencies, "futures", "0.3.25", &[]); @@ -77,7 +77,7 @@ pub fn update_cargo_toml(extras: &Extras, opts: &OutputConfig, context: &HashMap ensure_dependency(&mut m.dependencies, "base64", "0.21.0", &[]); } if extras.oauth2 { - ensure_dependency(&mut m.dependencies, "httpclient_oauth2", "0.1.2", &[]); + ensure_dependency(&mut m.dependencies, "httpclient_oauth2", "0.1.3", &[]); } m.example = vec![]; fs::write_file(&cargo, &toml::to_string(&m).unwrap())?;