Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Hyper 1 #524

Merged
merged 27 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
926ad7b
Update google-apis-common
IvanUkhov Oct 2, 2024
b70df88
Update google-clis-common
IvanUkhov Oct 2, 2024
98c432c
Export Body and Response
IvanUkhov Oct 2, 2024
a654f2c
Remove get_body_as_string
IvanUkhov Oct 2, 2024
8835901
Introduce to_body
IvanUkhov Oct 3, 2024
82a00cc
Introduce Client
IvanUkhov Oct 3, 2024
5a494f3
Introduce to_response
IvanUkhov Oct 3, 2024
8978b94
Remove to_json and add to_string
IvanUkhov Oct 3, 2024
70bfc8f
Remove the json alias
IvanUkhov Oct 3, 2024
6d3710f
Introduce Client and Connection
IvanUkhov Oct 3, 2024
07a4d62
Run cargo fmt upon generation
IvanUkhov Oct 3, 2024
b6fac32
Make the API code compile
IvanUkhov Oct 3, 2024
a72a918
Make the API documentation compile
IvanUkhov Oct 3, 2024
c171cd6
Switch to the 2021 edition
IvanUkhov Oct 3, 2024
c67b9d3
Rename Connection to Connector
IvanUkhov Oct 3, 2024
4bbf1ee
Address the lints
IvanUkhov Oct 3, 2024
c4fc156
Update the tests
IvanUkhov Oct 3, 2024
1052f0f
Do not try to format the CLIs
IvanUkhov Oct 3, 2024
93a30e0
Start to update the CLIs
IvanUkhov Oct 3, 2024
d15dcfd
Create a separate client for yup-oauth2
IvanUkhov Oct 4, 2024
e05dea3
Add storage1 to the CI
IvanUkhov Oct 4, 2024
f62b45e
Sort out the dependencies
IvanUkhov Oct 5, 2024
35d780e
Address a few lints
IvanUkhov Oct 5, 2024
13ae02e
Adjust a docstring
IvanUkhov Oct 5, 2024
9bb8a42
Fix the usage of FieldMask
IvanUkhov Oct 5, 2024
8e80440
Sort out new lines and trailing whitespace
IvanUkhov Oct 6, 2024
d6bd590
Make clear why CLIs are not being formatted
Byron Oct 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
27 changes: 14 additions & 13 deletions .github/workflows/rust.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: CI

on:
push:
Expand All @@ -8,30 +8,31 @@ on:

jobs:
clippy:
name: Run Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Run clippy
run: |
cargo clippy -- -D warnings
- run: cargo clippy -- -D warnings

build-and-test:
name: Build and test
runs-on: ubuntu-latest
env:
# The environment variable is set to test only on a few selected APIs,
# speeding up the integration process. See etc/api/api-list-ci.yaml.
CI: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: |
- run: |
source ~/.profile
cargo test
make test-gen
make gen-all-cli cargo-api ARGS=test
make cargo-api ARGS='check --all-features'
make cargo-api ARGS='check --no-default-features'
make cargo-api ARGS=check
make cargo-api ARGS=doc
make cargo-cli ARGS=check
make docs-all
env:
# The environment variable is set to test only on a few selected APIs,
# speeding up the integration process. See etc/api/api-list-ci.yaml.
CI: true
RUSTDOCFLAGS: -A warnings
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]

resolver = "2"
members = [
"google-apis-common",
"google-clis-common",
Expand Down
6 changes: 4 additions & 2 deletions etc/api/api-list-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
api:
list:
spanner:
- v1
- v1
storage:
- v1
youtube:
- v3
- v3
6 changes: 0 additions & 6 deletions etc/api/type-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@ make:
cargo:
keywords: [protocol, web, api]
doc_base_url: https://docs.rs
dependencies:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a great idea to bring it all into the generator file.

- hyper = "^ 0.14"
- http = "^0.2"
- tokio = "^1.0"
- tower-service = "^0.3.1"
- url = "= 1.7"
8 changes: 1 addition & 7 deletions etc/api/type-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,5 @@ make:
output_dir: src
cargo:
keywords: [cli]
is_executable: YES
is_executable: true
doc_base_url: http://byron.github.io/google-apis-rs
dependencies:
- clap = "^2.0"
- http = "^0.2"
- hyper = { version = "0.14", features = ["full"] }
- tokio = { version = "^ 1.0", features = ["full"] }
- tower-service = "^0.3.1"
29 changes: 13 additions & 16 deletions google-apis-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ edition = "2021"
[lib]
doctest = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
mime = "^ 0.3"
serde = { version = "^ 1.0", features = ["derive"] }
serde_with = "3.0"
serde_json = "^ 1.0"

base64 = "0.22"
chrono = { version = "0.4.35", default-features = false, features = ["clock", "serde"] }
url = "2.0"
percent-encoding = "2.0"

yup-oauth2 = { version = "9", optional = true }
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
http = "1"
http-body-util = "0.1"
hyper = { version = "1", features = ["client", "http2"] }
hyper-util = "0.1"
itertools = "0.13"
hyper = { version = "^ 0.14", features = ["client", "http2"] }
http = "^0.2"
tokio = { version = "^1.0", features = ["time"] }
tower-service = "^0.3.1"
mime = "0.3"
percent-encoding = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_with = "3"
tokio = { version = "1", features = ["time"] }
url = "2"
yup-oauth2 = { version = "11", optional = true }
62 changes: 21 additions & 41 deletions google-apis-common/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! By default, [`GetToken`] is implemented for:
//! - [`Authenticator`] : An authenticator which supports a variety of authentication methods
//! - [`String`] : Plain oauth2 token in String format
//! - [`String`] : Plain OAuth2 token in String format
//! - [`NoToken`] : No token, used for APIs which do not require a token
//!
//! # Usage
Expand All @@ -24,29 +24,21 @@
//!
//! # Example
//! ```rust
//! use core::future::Future;
//! use core::pin::Pin;
//! use std::future::Future;
//! use std::pin::Pin;
//!
//! use google_apis_common::{GetToken, oauth2};
//!
//! use http::Uri;
//! use hyper::client::connect::Connection;
//! use tokio::io::{AsyncRead, AsyncWrite};
//! use tower_service::Service;
//! use oauth2::authenticator::Authenticator;
//! use google_apis_common::GetToken;
//! use yup_oauth2::authenticator::Authenticator;
//!
//! #[derive(Clone)]
//! struct AuthenticatorWithRetry<S> {
//! auth: Authenticator<S>,
//! retries: usize,
//! }
//!
//! impl<S> GetToken for AuthenticatorWithRetry<S>
//! impl<C> GetToken for AuthenticatorWithRetry<C>
//! where
//! S: Service<Uri> + Clone + Send + Sync + 'static,
//! S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static,
//! S::Future: Send + Unpin + 'static,
//! S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
//! C: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static,
//! {
//! fn get_token<'a>(
//! &'a self,
Expand All @@ -71,6 +63,7 @@
//! [`oauth2`]: https://docs.rs/oauth2/latest/oauth2/
//! [`AccessToken`]: https://docs.rs/oauth2/latest/oauth2/struct.AccessToken.html
//! [`Authenticator`]: yup_oauth2::authenticator::Authenticator

use std::future::Future;
use std::pin::Pin;

Expand Down Expand Up @@ -114,8 +107,8 @@ impl GetToken for String {
}
}

/// In the event that the API endpoint does not require an oauth2 token, `NoToken` should be provided to the hub to avoid specifying an
/// authenticator.
/// In the event that the API endpoint does not require an OAuth2 token, `NoToken` should be
/// provided to the hub to avoid specifying an authenticator.
#[derive(Default, Clone)]
pub struct NoToken;

Expand All @@ -126,30 +119,17 @@ impl GetToken for NoToken {
}

#[cfg(feature = "yup-oauth2")]
mod yup_oauth2_impl {
use super::{GetToken, GetTokenOutput};

use http::Uri;
use hyper::client::connect::Connection;
use tokio::io::{AsyncRead, AsyncWrite};
use tower_service::Service;
use yup_oauth2::authenticator::Authenticator;

impl<S> GetToken for Authenticator<S>
where
S: Service<Uri> + Clone + Send + Sync + 'static,
S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static,
S::Future: Send + Unpin + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
fn get_token<'a>(&'a self, scopes: &'a [&str]) -> GetTokenOutput<'a> {
Box::pin(async move {
self.token(scopes)
.await
.map(|t| t.token().map(|t| t.to_owned()))
.map_err(|e| e.into())
})
}
impl<C> GetToken for yup_oauth2::authenticator::Authenticator<C>
where
C: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static,
{
fn get_token<'a>(&'a self, scopes: &'a [&str]) -> GetTokenOutput<'a> {
Box::pin(async move {
self.token(scopes)
.await
.map(|t| t.token().map(|t| t.to_owned()))
.map_err(|e| e.into())
})
}
}

Expand Down
Loading
Loading