-
Notifications
You must be signed in to change notification settings - Fork 130
feat(storage): Support GCS Object Compose - DRAFT #5717
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
Draft
xlai20
wants to merge
1
commit into
googleapis:main
Choose a base branch
from
xlai20:branch-object-compose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use crate::Result; | ||
| use crate::model::Object; | ||
| use crate::request_options::RequestOptions; | ||
| use std::sync::Arc; | ||
|
|
||
| /// A request builder for [Storage::compose_object][crate::client::Storage::compose_object]. | ||
| /// | ||
| /// # Example | ||
| /// ``` | ||
| /// use google_cloud_storage::client::Storage; | ||
| /// # use google_cloud_storage::builder::storage::ComposeObject; | ||
| /// async fn sample(client: &Storage) -> anyhow::Result<()> { | ||
| /// let response = client | ||
| /// .compose_object("projects/_/buckets/my-bucket", "composite-object") | ||
| /// .add_source("part-1") | ||
| /// .add_source_with_generation("part-2", 123456) | ||
| /// .set_content_type("application/json") | ||
| /// .send() | ||
| /// .await?; | ||
| /// println!("composite object details={response:?}"); | ||
| /// Ok(()) | ||
| /// } | ||
| /// ``` | ||
| #[derive(Clone, Debug)] | ||
| pub struct ComposeObject<S = crate::storage::transport::Storage> { | ||
| stub: Arc<S>, | ||
| request: crate::model::ComposeObjectRequest, | ||
| options: RequestOptions, | ||
| } | ||
|
|
||
| impl<S> ComposeObject<S> { | ||
| pub(crate) fn new<B, D>( | ||
| stub: Arc<S>, | ||
| bucket: B, | ||
| destination: D, | ||
| options: RequestOptions, | ||
| ) -> Self | ||
| where | ||
| B: Into<String>, | ||
| D: Into<String>, | ||
| { | ||
| let mut request = crate::model::ComposeObjectRequest::default(); | ||
| request.destination = Some(crate::model::Object { | ||
| bucket: bucket.into(), | ||
| name: destination.into(), | ||
| ..Default::default() | ||
| }); | ||
| Self { | ||
| stub, | ||
| request, | ||
| options, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<S> ComposeObject<S> | ||
| where | ||
| S: crate::storage::stub::Storage + 'static, | ||
| { | ||
| /// Appends a source object name to the compose request. | ||
| pub fn add_source<T: Into<String>>(mut self, name: T) -> Self { | ||
| let mut source = crate::model::compose_object_request::SourceObject::default(); | ||
| source.name = name.into(); | ||
| self.request.source_objects.push(source); | ||
| self | ||
| } | ||
|
|
||
| /// Appends a source object name and its expected generation to the compose request. | ||
| pub fn add_source_with_generation<T: Into<String>>(mut self, name: T, generation: i64) -> Self { | ||
| let mut source = crate::model::compose_object_request::SourceObject::default(); | ||
| source.name = name.into(); | ||
| source.generation = generation; | ||
| self.request.source_objects.push(source); | ||
| self | ||
| } | ||
|
|
||
| /// Appends a source object name, generation, and generation match precondition. | ||
| pub fn add_source_with_preconditions<T: Into<String>>( | ||
| mut self, | ||
| name: T, | ||
| generation: i64, | ||
| if_generation_match: i64, | ||
| ) -> Self { | ||
| let mut source = crate::model::compose_object_request::SourceObject::default(); | ||
| source.name = name.into(); | ||
| source.generation = generation; | ||
| let mut preconditions = crate::model::compose_object_request::source_object::ObjectPreconditions::default(); | ||
| preconditions.if_generation_match = Some(if_generation_match); | ||
| source.object_preconditions = Some(preconditions); | ||
| self.request.source_objects.push(source); | ||
| self | ||
| } | ||
|
|
||
| /// Sets the generation match precondition for the destination object. | ||
| pub fn set_if_generation_match(mut self, v: i64) -> Self { | ||
| self.request.if_generation_match = Some(v); | ||
| self | ||
| } | ||
|
|
||
| /// Sets the metageneration match precondition for the destination object. | ||
| pub fn set_if_metageneration_match(mut self, v: i64) -> Self { | ||
| self.request.if_metageneration_match = Some(v); | ||
| self | ||
| } | ||
|
|
||
| /// Sets the content type for the destination composite object. | ||
| pub fn set_content_type<T: Into<String>>(mut self, v: T) -> Self { | ||
| if let Some(ref mut dest) = self.request.destination { | ||
| dest.content_type = v.into(); | ||
| } | ||
| self | ||
| } | ||
|
|
||
| /// Sets custom metadata attributes for the destination composite object. | ||
| pub fn set_metadata(mut self, metadata: std::collections::HashMap<String, String>) -> Self { | ||
| if let Some(ref mut dest) = self.request.destination { | ||
| dest.metadata = metadata; | ||
| } | ||
| self | ||
| } | ||
|
|
||
| /// Configures a custom retry policy for this compose request. | ||
| pub fn with_retry_policy<V: Into<google_cloud_gax::retry_policy::RetryPolicyArg>>( | ||
| mut self, | ||
| v: V, | ||
| ) -> Self { | ||
| self.options.retry_policy = v.into().into(); | ||
| self | ||
| } | ||
|
|
||
| /// Sends the compose request to the GCS service and returns the created composite object. | ||
| pub async fn send(self) -> Result<Object> { | ||
| self.stub.compose_object(self.request, self.options).await | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While
set_metadataallows replacing the entire metadata map, it is often more idiomatic in builder patterns to provide a fluent method for adding individual metadata entries. This improves usability when the user only needs to set a few custom attributes without constructing a fullHashMapthemselves.References