Skip to content

Commit 706429f

Browse files
committed
Parametrize cloudwatch logs client, default to the rusoto implementation
1 parent 5ece0b8 commit 706429f

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/lib.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@ pub struct ListGroupsParams {
2222
}
2323

2424
pub struct ListGroupsParamsBuilder {
25+
client: Option<CloudWatchLogsClient>,
2526
out: Option<Box<dyn Write>>,
2627
err: Option<Box<dyn Write>>,
2728
}
2829

2930
impl ListGroupsParamsBuilder {
3031
pub fn new() -> ListGroupsParamsBuilder {
3132
ListGroupsParamsBuilder {
33+
client: None,
3234
out: None,
3335
err: None,
3436
}
3537
}
3638

39+
pub fn with_client(mut self, client: CloudWatchLogsClient) -> ListGroupsParamsBuilder {
40+
self.client = Some(client);
41+
self
42+
}
43+
3744
pub fn with_out(mut self, out: Box<dyn Write>) -> ListGroupsParamsBuilder {
3845
self.out = Some(out);
3946
self
@@ -46,7 +53,9 @@ impl ListGroupsParamsBuilder {
4653

4754
pub fn build(self) -> ListGroupsParams {
4855
return ListGroupsParams {
49-
client: CloudWatchLogsClient::new(Region::default()),
56+
client: self
57+
.client
58+
.unwrap_or(CloudWatchLogsClient::new(Region::default())),
5059
out: self.out.unwrap_or(Box::new(stdout())),
5160
err: self.err.unwrap_or(Box::new(stderr())),
5261
};
@@ -109,6 +118,7 @@ pub struct ListStreamsParams {
109118

110119
pub struct ListStreamsParamsBuilder {
111120
log_group_name: String,
121+
client: Option<CloudWatchLogsClient>,
112122
out: Option<Box<dyn Write>>,
113123
err: Option<Box<dyn Write>>,
114124
}
@@ -117,11 +127,17 @@ impl ListStreamsParamsBuilder {
117127
pub fn new(log_group_name: String) -> ListStreamsParamsBuilder {
118128
ListStreamsParamsBuilder {
119129
log_group_name,
130+
client: None,
120131
out: None,
121132
err: None,
122133
}
123134
}
124135

136+
pub fn with_client(mut self, client: CloudWatchLogsClient) -> ListStreamsParamsBuilder {
137+
self.client = Some(client);
138+
self
139+
}
140+
125141
pub fn with_out(mut self, out: Box<dyn Write>) -> ListStreamsParamsBuilder {
126142
self.out = Some(out);
127143
self
@@ -135,7 +151,9 @@ impl ListStreamsParamsBuilder {
135151
pub fn build(self) -> ListStreamsParams {
136152
return ListStreamsParams {
137153
log_group_name: self.log_group_name,
138-
client: CloudWatchLogsClient::new(Region::default()),
154+
client: self
155+
.client
156+
.unwrap_or(CloudWatchLogsClient::new(Region::default())),
139157
out: self.out.unwrap_or(Box::new(stdout())),
140158
err: self.err.unwrap_or(Box::new(stderr())),
141159
};
@@ -212,6 +230,7 @@ pub struct ListEventsParamsBuilder {
212230
log_group_name: String,
213231
start: Option<String>,
214232
end: Option<String>,
233+
client: Option<CloudWatchLogsClient>,
215234
out: Option<Box<dyn Write>>,
216235
err: Option<Box<dyn Write>>,
217236
}
@@ -226,11 +245,17 @@ impl ListEventsParamsBuilder {
226245
log_group_name,
227246
start,
228247
end,
248+
client: None,
229249
out: None,
230250
err: None,
231251
}
232252
}
233253

254+
pub fn with_client(mut self, client: CloudWatchLogsClient) -> ListEventsParamsBuilder {
255+
self.client = Some(client);
256+
self
257+
}
258+
234259
pub fn with_out(mut self, out: Box<dyn Write>) -> ListEventsParamsBuilder {
235260
self.out = Some(out);
236261
self
@@ -246,7 +271,9 @@ impl ListEventsParamsBuilder {
246271
log_group_name: self.log_group_name,
247272
start: self.start,
248273
end: self.end,
249-
client: CloudWatchLogsClient::new(Region::default()),
274+
client: self
275+
.client
276+
.unwrap_or(CloudWatchLogsClient::new(Region::default())),
250277
out: self.out.unwrap_or(Box::new(stdout())),
251278
err: self.err.unwrap_or(Box::new(stderr())),
252279
};

0 commit comments

Comments
 (0)