Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion hosts/ureq/examples/azure_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::env;
use std::io::Write;

use borink_object_storage_proto::ListOptions;
use borink_object_storage_proto::azure::Container;
use borink_object_storage_ureq::azure;

Expand All @@ -12,6 +13,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = env::var("AZURE_STORAGE_ACCESS_TOKEN")?;
let key = env::args().nth(1).ok_or("missing object key")?;
let container = Container::new(&endpoint, &container)?;
std::io::stdout().write_all(&azure::get(&container, &token, &key)?)?;
let mut blobs = azure::Blobs::new(&container, &token, &ListOptions::default())?;
std::io::stdout().write_all(&blobs.get(&key)?)?;
Ok(())
}
20 changes: 5 additions & 15 deletions hosts/ureq/examples/azure_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use std::env;

use borink_object_storage_proto::azure as proto;
use borink_object_storage_proto::azure::{AzureNamespace, Container};
use borink_object_storage_proto::{Error, ListEntry, ListItem, ListMarker, ListOptions};
use borink_object_storage_proto::azure::Container;
use borink_object_storage_proto::{ListEntry, ListItem, ListMarker, ListOptions};
use borink_object_storage_ureq::azure;

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -14,21 +13,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let prefix = env::args().nth(1).unwrap_or_default();
let container = Container::new(&endpoint, &container)?;

// Every page shares the template: an empty buffer is refused with the
// size it needs.
// Every page shares the client's list template.
let options = ListOptions {
max_results: Some(1000),
..ListOptions::default()
};
let prepare = |buf: &mut [u8]| {
proto::prepare_list(&container, &token, AzureNamespace::Unknown, &options, buf)
};
let size = match prepare(&mut []) {
Err(Error::Capacity(capacity)) => capacity.required,
other => return Err(format!("{other:?}").into()),
};
let mut bytes = vec![0; size];
let template = prepare(&mut bytes)?;
let mut blobs = azure::Blobs::new(&container, &token, &options)?;

let mut marker: Option<String> = None;
let mut body = Vec::new();
Expand All @@ -41,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
marker: marker.as_deref().map(ListMarker::Text),
..ListItem::new(&prefix)
};
let page = azure::list(&template, &bytes, &item, &mut body, &mut entries)?;
let page = blobs.list(&item, &mut body, &mut entries)?;
for entry in &entries[..page.filled] {
println!("{}", entry.key);
}
Expand Down
4 changes: 3 additions & 1 deletion hosts/ureq/examples/s3_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::env;
use std::io::Write;

use borink_object_storage_proto::ListOptions;
use borink_object_storage_proto::s3::{Bucket, Service};
use borink_object_storage_proto::sigv4::Credentials;
use borink_object_storage_ureq::s3;
Expand All @@ -27,6 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Some(token) = &session_token {
credentials = credentials.with_session_token(token)?;
}
std::io::stdout().write_all(&s3::get(&bucket, &credentials, &key)?)?;
let mut objects = s3::Objects::new(&bucket, credentials, &ListOptions::default())?;
std::io::stdout().write_all(&objects.get(&key)?)?;
Ok(())
}
24 changes: 5 additions & 19 deletions hosts/ureq/examples/s3_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use std::env;

use borink_object_storage_proto::s3::{self as proto, Bucket, Service};
use borink_object_storage_proto::s3::{Bucket, Service};
use borink_object_storage_proto::sigv4::Credentials;
use borink_object_storage_proto::{Error, ListEntry, ListItem, ListMarker, ListOptions};
use borink_object_storage_proto::{ListEntry, ListItem, ListMarker, ListOptions};
use borink_object_storage_ureq::s3;

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -28,19 +28,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
credentials = credentials.with_session_token(token)?;
}

// Every page shares the template: an empty buffer is refused with the
// size it needs.
// Every page shares the client's list template.
let options = ListOptions {
max_results: Some(1000),
..ListOptions::default()
};
let prepare = |buf: &mut [u8]| proto::prepare_list(&bucket, &credentials, &options, buf);
let size = match prepare(&mut []) {
Err(Error::Capacity(capacity)) => capacity.required,
other => return Err(format!("{other:?}").into()),
};
let mut bytes = vec![0; size];
let template = prepare(&mut bytes)?;
let mut objects = s3::Objects::new(&bucket, credentials, &options)?;

let mut marker: Option<String> = None;
let mut body = Vec::new();
Expand All @@ -52,14 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
marker: marker.as_deref().map(ListMarker::Text),
..ListItem::new(&prefix)
};
let page = s3::list(
&template,
&bytes,
&credentials,
&item,
&mut body,
&mut entries,
)?;
let page = objects.list(&item, &mut body, &mut entries)?;
for entry in &entries[..page.filled] {
println!("{}", entry.key);
}
Expand Down
Loading
Loading