minio-rs/src/s3/builders/get_object_prompt.rs
Henk-Jan Lebbink 20d8654e34
Function names updated to reflect AWS names. Updated docs (#150)
* updated inline doc

* updated inline doc

* API naming conform AWS

* fixed clippy issues

* fixed minor API naming issues
2025-05-09 15:53:44 -07:00

128 lines
3.7 KiB
Rust

// MinIO Rust Library for Amazon S3 Compatible Cloud Storage
// Copyright 2024 MinIO, Inc.
//
// 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
//
// http://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::s3::multimap::{Multimap, MultimapExt};
use crate::s3::segmented_bytes::SegmentedBytes;
use crate::s3::sse::SseCustomerKey;
use crate::s3::utils::{check_bucket_name, check_object_name};
use crate::s3::{
client::Client,
error::Error,
response::GetObjectPromptResponse,
types::{S3Api, S3Request, ToS3Request},
};
use bytes::Bytes;
use http::Method;
use serde_json::json;
#[derive(Debug, Clone, Default)]
pub struct GetObjectPrompt {
client: Client,
bucket: String,
object: String,
prompt: String,
lambda_arn: Option<String>,
version_id: Option<String>,
region: Option<String>,
ssec: Option<SseCustomerKey>,
extra_headers: Option<Multimap>,
extra_query_params: Option<Multimap>,
}
// builder interface
impl GetObjectPrompt {
pub fn new(client: Client, bucket: String, object: String, prompt: String) -> Self {
GetObjectPrompt {
client,
bucket,
object,
prompt,
..Default::default()
}
}
pub fn lambda_arn(mut self, lambda_arn: &str) -> Self {
self.lambda_arn = Some(lambda_arn.to_string());
self
}
pub fn extra_headers(mut self, extra_headers: Option<Multimap>) -> Self {
self.extra_headers = extra_headers;
self
}
pub fn extra_query_params(mut self, extra_query_params: Option<Multimap>) -> Self {
self.extra_query_params = extra_query_params;
self
}
pub fn version_id(mut self, version_id: Option<String>) -> Self {
self.version_id = version_id;
self
}
pub fn region(mut self, region: Option<String>) -> Self {
self.region = region;
self
}
pub fn ssec(mut self, ssec: Option<SseCustomerKey>) -> Self {
self.ssec = ssec;
self
}
}
impl S3Api for GetObjectPrompt {
type S3Response = GetObjectPromptResponse;
}
impl ToS3Request for GetObjectPrompt {
fn to_s3request(self) -> Result<S3Request, Error> {
{
check_bucket_name(&self.bucket, true)?;
check_object_name(&self.object)?;
if self.client.is_aws_host() {
return Err(Error::UnsupportedApi("ObjectPrompt".into()));
}
if self.ssec.is_some() && !self.client.is_secure() {
return Err(Error::SseTlsRequired(None));
}
}
let mut query_params: Multimap = self.extra_query_params.unwrap_or_default();
query_params.add_version(self.version_id);
query_params.add(
"lambdaArn",
self.lambda_arn
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
);
let prompt_body = json!({ "prompt": self.prompt });
let body: SegmentedBytes = SegmentedBytes::from(Bytes::from(prompt_body.to_string()));
Ok(S3Request::new(self.client, Method::POST)
.region(self.region)
.bucket(Some(self.bucket))
.object(Some(self.object))
.query_params(query_params)
.headers(self.extra_headers.unwrap_or_default())
.body(Some(body)))
}
}