From bb815f36da9f00c0256b8d791b354ea0bd924c45 Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Sun, 15 Jan 2023 13:43:37 +0100 Subject: [PATCH] Google Cloud Storage download functions (#53) --- .../google/storage-v1/ext/apis/objects_api.rs | 248 +++++++++++++++++ .../storage_v1/apis/objects_api.rs | 253 ++++++++++++++++++ 2 files changed, 501 insertions(+) diff --git a/gcloud-protos-generator/openapi/google/storage-v1/ext/apis/objects_api.rs b/gcloud-protos-generator/openapi/google/storage-v1/ext/apis/objects_api.rs index 46fe13427..c5e36944e 100644 --- a/gcloud-protos-generator/openapi/google/storage-v1/ext/apis/objects_api.rs +++ b/gcloud-protos-generator/openapi/google/storage-v1/ext/apis/objects_api.rs @@ -177,3 +177,251 @@ pub async fn storage_objects_insert_ext_bytes( storage_objects_insert_ext_stream(configuration, params, content_type, bytes_stream).await } + +/// Retrieves the contents of an object as bytes +pub async fn storage_objects_get_bytes( + configuration: &configuration::Configuration, + params: StoragePeriodObjectsPeriodGetParams) -> Result> { + let local_var_configuration = configuration; + + // unbox the parameters + let bucket = params.bucket; + let object = params.object; + let fields = params.fields; + let key = params.key; + let oauth_token = params.oauth_token; + let pretty_print = params.pretty_print; + let quota_user = params.quota_user; + let upload_type = params.upload_type; + let user_ip = params.user_ip; + let generation = params.generation; + let if_generation_match = params.if_generation_match; + let if_generation_not_match = params.if_generation_not_match; + let if_metageneration_match = params.if_metageneration_match; + let if_metageneration_not_match = params.if_metageneration_not_match; + let projection = params.projection; + let user_project = params.user_project; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!( + "{}/b/{bucket}/o/{object}", + local_var_configuration.base_path, + bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket), + object = crate::google_rest_apis::storage_v1::apis::urlencode(object) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + // The user-supplied `alt` parameter is ignored, because it must be "media" + local_var_req_builder = local_var_req_builder.query(&[("alt", "media".to_string())]); + + if let Some(ref local_var_str) = fields { + local_var_req_builder = + local_var_req_builder.query(&[("fields", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = key { + local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = oauth_token { + local_var_req_builder = + local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = pretty_print { + local_var_req_builder = + local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = quota_user { + local_var_req_builder = + local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = upload_type { + local_var_req_builder = + local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_ip { + local_var_req_builder = + local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = generation { + local_var_req_builder = + local_var_req_builder.query(&[("generation", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_not_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_not_match { + local_var_req_builder = local_var_req_builder + .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = projection { + local_var_req_builder = + local_var_req_builder.query(&[("projection", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_project { + local_var_req_builder = + local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]); + } + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(local_var_resp.bytes().await?) + } else { + let local_var_content = local_var_resp.text().await?; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; + Err(Error::ResponseError(local_var_error)) + } +} + +/// Retrieves the contents of an object as stream +pub async fn storage_objects_get_stream( + configuration: &configuration::Configuration, + params: StoragePeriodObjectsPeriodGetParams) -> Result>,Error> { + let local_var_configuration = configuration; + + // unbox the parameters + let bucket = params.bucket; + let object = params.object; + let fields = params.fields; + let key = params.key; + let oauth_token = params.oauth_token; + let pretty_print = params.pretty_print; + let quota_user = params.quota_user; + let upload_type = params.upload_type; + let user_ip = params.user_ip; + let generation = params.generation; + let if_generation_match = params.if_generation_match; + let if_generation_not_match = params.if_generation_not_match; + let if_metageneration_match = params.if_metageneration_match; + let if_metageneration_not_match = params.if_metageneration_not_match; + let projection = params.projection; + let user_project = params.user_project; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!( + "{}/b/{bucket}/o/{object}", + local_var_configuration.base_path, + bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket), + object = crate::google_rest_apis::storage_v1::apis::urlencode(object) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + // The user-supplied `alt` parameter is ignored, because it must be "media" + local_var_req_builder = local_var_req_builder.query(&[("alt", "media".to_string())]); + + if let Some(ref local_var_str) = fields { + local_var_req_builder = + local_var_req_builder.query(&[("fields", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = key { + local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = oauth_token { + local_var_req_builder = + local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = pretty_print { + local_var_req_builder = + local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = quota_user { + local_var_req_builder = + local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = upload_type { + local_var_req_builder = + local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_ip { + local_var_req_builder = + local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = generation { + local_var_req_builder = + local_var_req_builder.query(&[("generation", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_not_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_not_match { + local_var_req_builder = local_var_req_builder + .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = projection { + local_var_req_builder = + local_var_req_builder.query(&[("projection", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_project { + local_var_req_builder = + local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]); + } + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(local_var_resp.bytes_stream()) + } else { + let local_var_content = local_var_resp.text().await?; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; + Err(Error::ResponseError(local_var_error)) + } +} diff --git a/gcloud-sdk/src/rest_apis/google_rest_apis/storage_v1/apis/objects_api.rs b/gcloud-sdk/src/rest_apis/google_rest_apis/storage_v1/apis/objects_api.rs index 73133147b..b59889720 100644 --- a/gcloud-sdk/src/rest_apis/google_rest_apis/storage_v1/apis/objects_api.rs +++ b/gcloud-sdk/src/rest_apis/google_rest_apis/storage_v1/apis/objects_api.rs @@ -2557,3 +2557,256 @@ pub async fn storage_objects_insert_ext_bytes( storage_objects_insert_ext_stream(configuration, params, content_type, bytes_stream).await } + +/// Retrieves the contents of an object as bytes +pub async fn storage_objects_get_bytes( + configuration: &configuration::Configuration, + params: StoragePeriodObjectsPeriodGetParams, +) -> Result> { + let local_var_configuration = configuration; + + // unbox the parameters + let bucket = params.bucket; + let object = params.object; + let fields = params.fields; + let key = params.key; + let oauth_token = params.oauth_token; + let pretty_print = params.pretty_print; + let quota_user = params.quota_user; + let upload_type = params.upload_type; + let user_ip = params.user_ip; + let generation = params.generation; + let if_generation_match = params.if_generation_match; + let if_generation_not_match = params.if_generation_not_match; + let if_metageneration_match = params.if_metageneration_match; + let if_metageneration_not_match = params.if_metageneration_not_match; + let projection = params.projection; + let user_project = params.user_project; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!( + "{}/b/{bucket}/o/{object}", + local_var_configuration.base_path, + bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket), + object = crate::google_rest_apis::storage_v1::apis::urlencode(object) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + // The user-supplied `alt` parameter is ignored, because it must be "media" + local_var_req_builder = local_var_req_builder.query(&[("alt", "media".to_string())]); + + if let Some(ref local_var_str) = fields { + local_var_req_builder = + local_var_req_builder.query(&[("fields", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = key { + local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = oauth_token { + local_var_req_builder = + local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = pretty_print { + local_var_req_builder = + local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = quota_user { + local_var_req_builder = + local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = upload_type { + local_var_req_builder = + local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_ip { + local_var_req_builder = + local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = generation { + local_var_req_builder = + local_var_req_builder.query(&[("generation", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_not_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_not_match { + local_var_req_builder = local_var_req_builder + .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = projection { + local_var_req_builder = + local_var_req_builder.query(&[("projection", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_project { + local_var_req_builder = + local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]); + } + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(local_var_resp.bytes().await?) + } else { + let local_var_content = local_var_resp.text().await?; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; + Err(Error::ResponseError(local_var_error)) + } +} + +/// Retrieves the contents of an object as stream +pub async fn storage_objects_get_stream( + configuration: &configuration::Configuration, + params: StoragePeriodObjectsPeriodGetParams, +) -> Result< + impl futures::stream::Stream>, + Error, +> { + let local_var_configuration = configuration; + + // unbox the parameters + let bucket = params.bucket; + let object = params.object; + let fields = params.fields; + let key = params.key; + let oauth_token = params.oauth_token; + let pretty_print = params.pretty_print; + let quota_user = params.quota_user; + let upload_type = params.upload_type; + let user_ip = params.user_ip; + let generation = params.generation; + let if_generation_match = params.if_generation_match; + let if_generation_not_match = params.if_generation_not_match; + let if_metageneration_match = params.if_metageneration_match; + let if_metageneration_not_match = params.if_metageneration_not_match; + let projection = params.projection; + let user_project = params.user_project; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!( + "{}/b/{bucket}/o/{object}", + local_var_configuration.base_path, + bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket), + object = crate::google_rest_apis::storage_v1::apis::urlencode(object) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + // The user-supplied `alt` parameter is ignored, because it must be "media" + local_var_req_builder = local_var_req_builder.query(&[("alt", "media".to_string())]); + + if let Some(ref local_var_str) = fields { + local_var_req_builder = + local_var_req_builder.query(&[("fields", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = key { + local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = oauth_token { + local_var_req_builder = + local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = pretty_print { + local_var_req_builder = + local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = quota_user { + local_var_req_builder = + local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = upload_type { + local_var_req_builder = + local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_ip { + local_var_req_builder = + local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = generation { + local_var_req_builder = + local_var_req_builder.query(&[("generation", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_generation_not_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifGenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_match { + local_var_req_builder = + local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = if_metageneration_not_match { + local_var_req_builder = local_var_req_builder + .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = projection { + local_var_req_builder = + local_var_req_builder.query(&[("projection", &local_var_str.to_string())]); + } + if let Some(ref local_var_str) = user_project { + local_var_req_builder = + local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]); + } + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(local_var_resp.bytes_stream()) + } else { + let local_var_content = local_var_resp.text().await?; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; + Err(Error::ResponseError(local_var_error)) + } +}