Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
983 stars 132 forks source link

JsonDecodeError For GenerateRandomBytesRequest #455

Open SpadeA-Tang opened 8 months ago

SpadeA-Tang commented 8 months ago

It seems desearialize json is failed. The code is listed below and would you mind giving some feedbacks whether the code is inappropriate?

Err(JsonDecodeError("{\n \"data\": \"re9uM3jHgyBO55Bb5thfEc51X7qdvTFlTmYPDWU07rvSLXwKTXVQIecmyOtmjgrdH0RE+/LZ0XKNtiJKoLbm3y6+D3PWQHcmq6OgguWuQxJ23drOhypxfZdXaN2o1+xz7T31TVPqOnm3zlp8z4wtsR6cVupxgzYb5zguv5EQ73I=\",\n \"dataCrc32c\": \"589474822\"\n}\n", Error("Invalid byte 43, offset 68.", line: 2, column: 184)))

#[tokio::main]
async fn main() {
    let secret = yup_oauth2::read_authorized_user_secret(
        "/home/spadea/.config/gcloud/application_default_credentials.json",
    )
    .await
    .unwrap();

    let auth = AuthorizedUserAuthenticator::builder(secret)
        .build()
        .await
        .unwrap();

    let hub = CloudKMS::new(
        hyper::Client::builder().build(
            hyper_rustls::HttpsConnectorBuilder::new()
                .with_native_roots()
                .https_or_http()
                .enable_http1()
                .build(),
        ),
        auth,
    );

    let mut req = GenerateRandomBytesRequest::default();
    req.length_bytes = Some(128);
    req.protection_level = Some(String::from("HSM"));
    let result = hub
        .projects()
        .locations_generate_random_bytes(req, "projects/xxx/locations/xxx")
        .doit()
        .await;

    println!("{:?}", result);
}
Byron commented 8 months ago

It's a problem with it trying to decode that JSON with data being base64 encoded into binary data, as declared in the datatype.

Its probably related to one of the many issues related to confused URL/Base64 encoding. The problem is that it's unclear how to figure out the kind of encoding just by looking at the API description, and thus far nobody was able to contribute a fix.

SpadeA-Tang commented 8 months ago

It's a problem with it trying to decode that JSON with data being base64 encoded into binary data, as declared in the datatype.

Its probably related to one of the many issues related to confused URL/Base64 encoding. The problem is that it's unclear how to figure out the kind of encoding just by looking at the API description, and thus far nobody was able to contribute a fix.

Thanks for the reply.