1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::api::*;
use crate::{ApiError, ByteStream, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct ObjectsClient {
pub http_client: HttpClient,
}
impl ObjectsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Lists objects in your environment. You can define a prefix to list a subset of your objects. If you do not set a prefix, Lattice returns all available objects. By default this endpoint will list local objects only.
///
/// # Arguments
///
/// * `prefix` - Filters the objects based on the specified prefix path. If no path is specified, all objects are returned.
/// * `since_timestamp` - Sets the age for the oldest objects to query across the environment.
/// * `page_token` - Base64 and URL-encoded cursor returned by the service to continue paging.
/// * `all_objects_in_mesh` - Lists objects across all environment nodes in a Lattice Mesh.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn list_objects(
&self,
request: &ListObjectsQueryRequest,
options: Option<RequestOptions>,
) -> Result<ListResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"api/v1/objects",
None,
QueryBuilder::new()
.string("prefix", request.prefix.clone())
.datetime("sinceTimestamp", request.since_timestamp.clone())
.string("pageToken", request.page_token.clone())
.bool("allObjectsInMesh", request.all_objects_in_mesh.clone())
.build(),
options,
)
.await
}
/// Fetches an object from your environment using the objectPath path parameter.
///
/// # Arguments
///
/// * `object_path` - The path of the object to fetch.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// Streaming file download (use .into_bytes() to collect or stream chunks)
pub async fn get_object(
&self,
object_path: &String,
options: Option<RequestOptions>,
) -> Result<ByteStream, ApiError> {
self.http_client
.execute_stream_request(
Method::GET,
&format!("api/v1/objects/{}", object_path),
None,
None,
options,
)
.await
}
/// Uploads an object. The object must be 1 GiB or smaller.
///
/// # Arguments
///
/// * `object_path` - Path of the Object that is to be uploaded.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn upload_object(
&self,
object_path: &String,
request: &Vec<u8>,
options: Option<RequestOptions>,
) -> Result<PathMetadata, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("api/v1/objects/{}", object_path),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
/// Deletes an object from your environment given the objectPath path parameter.
///
/// # Arguments
///
/// * `object_path` - The path of the object to delete.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// Empty response
pub async fn delete_object(
&self,
object_path: &String,
options: Option<RequestOptions>,
) -> Result<(), ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("api/v1/objects/{}", object_path),
None,
None,
options,
)
.await
}
/// Returns metadata for a specified object path. Use this to fetch metadata such as object size (size_bytes), its expiry time (expiry_time), or its latest update timestamp (last_updated_at).
///
/// # Arguments
///
/// * `object_path` - The path of the object to query.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// Empty response
pub async fn get_object_metadata(
&self,
object_path: &String,
options: Option<RequestOptions>,
) -> Result<(), ApiError> {
self.http_client
.execute_request(
Method::HEAD,
&format!("api/v1/objects/{}", object_path),
None,
None,
options,
)
.await
}
}