Skip to content

Commit e2763e2

Browse files
Fix lints and warnings, add skeleton for Vercel platform. (#134)
* Fix lints and warnings, add skeleton for Vercel platform. * Apply fmt * Auto-fix lints with `clippy --fix` * Apply fmt
1 parent b88dea9 commit e2763e2

31 files changed

Lines changed: 197 additions & 133 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/docs
2+
13
/target
24
*.zip
35
*.txt
@@ -14,4 +16,4 @@ MultiTool.yaml
1416
# Remove any workers user for development
1517
/worker/**
1618
wrangler.toml
17-
wrangler.json
19+
wrangler.json

src/adapters/backend/deploy_meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) type RolloutId = u64;
1616
/// rollout. This struct is mostly used in conjuction with a `BackendClient`
1717
/// to hold the context for the current rollout.
1818
#[derive(Builder, Getters, Clone)]
19-
pub(crate) struct RolloutMetadata {
19+
pub struct RolloutMetadata {
2020
workspace_id: WorkspaceId,
2121
application_id: ApplicationId,
2222
rollout_id: RolloutId,

src/adapters/backend/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tokio::sync::mpsc::Sender;
2323
use tokio::sync::oneshot;
2424
use tokio::time::Duration;
2525

26-
pub(crate) use deploy_meta::*;
26+
pub use deploy_meta::*;
2727
use tracing::trace;
2828

2929
/// Write the CLI's version to a
@@ -84,7 +84,7 @@ impl BackendClient {
8484

8585
pub fn is_authenicated(&self) -> Result<()> {
8686
if self.session.clone().is_some_and(Session::is_not_expired) {
87-
return Ok(());
87+
Ok(())
8888
} else {
8989
bail!("Please login before running this command.");
9090
}
@@ -343,9 +343,9 @@ impl BackendClient {
343343
};
344344
let metrics = StatusCodeMetrics {
345345
app_group: group,
346-
status_2xx_count: item.get_count(&ResponseStatusCode::_2XX) as u32,
347-
status_4xx_count: item.get_count(&ResponseStatusCode::_4XX) as u32,
348-
status_5xx_count: item.get_count(&ResponseStatusCode::_5XX) as u32,
346+
status_2xx_count: item.get_count(&ResponseStatusCode::_2XX),
347+
status_4xx_count: item.get_count(&ResponseStatusCode::_4XX),
348+
status_5xx_count: item.get_count(&ResponseStatusCode::_5XX),
349349
created_at: item.created_at().to_rfc3339(),
350350
};
351351

@@ -427,8 +427,8 @@ impl BackendClient {
427427

428428
pub(crate) async fn create_application<T: AsRef<str>>(
429429
&self,
430-
workspace_id: WorkspaceId,
431-
name: T,
430+
_workspace_id: WorkspaceId,
431+
_name: T,
432432
) -> Result<ApplicationDetails> {
433433
self.is_authenicated()?;
434434

@@ -454,7 +454,7 @@ impl BackendClient {
454454

455455
if workspaces.len() > 1 {
456456
bail!("More than one workspace with the given name found.");
457-
} else if workspaces.len() < 1 {
457+
} else if workspaces.is_empty() {
458458
bail!("No workspace with the given name exists for this account");
459459
} else {
460460
// TODO: We can simplify this code with .ok_or()
@@ -488,7 +488,7 @@ impl BackendClient {
488488

489489
let application = if applications.len() > 1 {
490490
bail!("More than one application with the given name found.");
491-
} else if applications.len() < 1 {
491+
} else if applications.is_empty() {
492492
bail!("No application with the given name exists for this account");
493493
} else {
494494
// TODO: We can simplify this code with .ok_or()
@@ -535,8 +535,8 @@ impl BackendConfig {
535535
// • Convert the Option<T> to a String.
536536
let origin = origin.map(|val| val.as_ref().to_owned());
537537
// • Set up the default configuration values.
538-
let jwt = session.and_then(|session| match session {
539-
Session::User(creds) => Some(creds.jwt),
538+
let jwt = session.map(|session| match session {
539+
Session::User(creds) => creds.jwt,
540540
});
541541
let conf = Configuration {
542542
base_path: origin.unwrap_or(MULTITOOL_ORIGIN.to_string()),

src/adapters/cloudflare/deployments.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ use bon::Builder;
22
use derive_getters::Getters;
33
use serde::{Deserialize, Serialize};
44

5-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
66
pub enum DeploymentStrategy {
77
#[serde(rename = "percentage")]
8+
#[default]
89
Percentage,
910
}
1011

11-
impl Default for DeploymentStrategy {
12-
fn default() -> Self {
13-
Self::Percentage
14-
}
15-
}
16-
1712
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Getters)]
1813
pub struct CreateDeploymentRequest {
1914
#[serde(default)]

src/adapters/cloudflare/metrics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct EventData {
4949

5050
#[derive(Deserialize, Debug)]
5151
pub struct RequestData {
52+
#[allow(dead_code)] // TODO: Why is this dead?
5253
pub url: String,
5354
pub method: String,
5455
pub path: String,
@@ -78,11 +79,11 @@ pub struct CloudflareErrorLog {
7879
pub logs: Vec<String>,
7980
}
8081

81-
impl Into<Vec<CloudflareErrorLog>> for ErrorLogsResponse {
82-
fn into(self) -> Vec<CloudflareErrorLog> {
82+
impl From<ErrorLogsResponse> for Vec<CloudflareErrorLog> {
83+
fn from(val: ErrorLogsResponse) -> Self {
8384
let mut error_logs = Vec::new();
8485

85-
for (_request_id, invocations) in self.invocations {
86+
for (_request_id, invocations) in val.invocations {
8687
// The cf-worker-event entry contains the request/response details
8788
let event_entry = invocations
8889
.iter()

src/adapters/cloudflare/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ impl CloudflareClient {
398398
let count = metrics_response
399399
.result
400400
.calculations
401-
.get(0)
402-
.and_then(|c| c.aggregates.get(0).cloned())
401+
.first()
402+
.and_then(|c| c.aggregates.first().cloned())
403403
.map_or(0, |a| a.count);
404404

405405
Ok(count)

src/adapters/cloudflare/uploads.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ use serde::{Deserialize, Serialize};
44

55
use crate::{adapters::cloudflare::deployments::Binding, fs::wrangler::Wrangler};
66

7+
// this is probably dead because we bundle the upload,
8+
// which we won't do in the future.
9+
#[allow(dead_code)]
710
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
811
pub struct UploadSessionResponse {
912
pub jwt: String,
1013
// Contains a list of lists of file hashes that Cloudflare wants us to upload together
1114
pub buckets: Vec<Vec<String>>,
1215
}
1316

17+
// this is probably dead because we bundle the upload,
18+
// which we won't do in the future.
19+
#[allow(dead_code)]
1420
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1521
pub struct UploadAssetsResponse {
1622
pub jwt: String,

src/adapters/ingresses/apig.rs

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ impl AwsApiGateway {
6868
let error_message = match err {
6969
SdkError::ServiceError(service_err) => {
7070
// Extract the specific service error details
71-
format!(
72-
"{}",
73-
service_err
74-
.err()
75-
.meta()
76-
.message()
77-
.unwrap_or("No error message found")
78-
)
71+
service_err
72+
.err()
73+
.meta()
74+
.message()
75+
.unwrap_or("No error message found")
76+
.to_string()
7977
}
8078
_ => format!("{:?}", err),
8179
};
@@ -110,14 +108,12 @@ impl AwsApiGateway {
110108
let error_message = match err {
111109
SdkError::ServiceError(service_err) => {
112110
// Extract the specific service error details
113-
format!(
114-
"{}",
115-
service_err
116-
.err()
117-
.meta()
118-
.message()
119-
.unwrap_or("No error message found")
120-
)
111+
service_err
112+
.err()
113+
.meta()
114+
.message()
115+
.unwrap_or("No error message found")
116+
.to_string()
121117
}
122118
_ => format!("{:?}", err),
123119
};
@@ -157,14 +153,12 @@ impl AwsApiGateway {
157153
let error_message = match err {
158154
SdkError::ServiceError(service_err) => {
159155
// Extract the specific service error details
160-
format!(
161-
"{}",
162-
service_err
163-
.err()
164-
.meta()
165-
.message()
166-
.unwrap_or("No error message found")
167-
)
156+
service_err
157+
.err()
158+
.meta()
159+
.message()
160+
.unwrap_or("No error message found")
161+
.to_string()
168162
}
169163
_ => format!("{:?}", err),
170164
};
@@ -217,14 +211,12 @@ impl Ingress for AwsApiGateway {
217211
let error_message = match err {
218212
SdkError::ServiceError(service_err) => {
219213
// Extract the specific service error details
220-
format!(
221-
"{}",
222-
service_err
223-
.err()
224-
.meta()
225-
.message()
226-
.unwrap_or("No error message found")
227-
)
214+
service_err
215+
.err()
216+
.meta()
217+
.message()
218+
.unwrap_or("No error message found")
219+
.to_string()
228220
}
229221
_ => format!("{:?}", err),
230222
};
@@ -256,14 +248,12 @@ impl Ingress for AwsApiGateway {
256248
let error_message = match err {
257249
SdkError::ServiceError(service_err) => {
258250
// Extract the specific service error details
259-
format!(
260-
"{}",
261-
service_err
262-
.err()
263-
.meta()
264-
.message()
265-
.unwrap_or("No error message found")
266-
)
251+
service_err
252+
.err()
253+
.meta()
254+
.message()
255+
.unwrap_or("No error message found")
256+
.to_string()
267257
}
268258
_ => format!("{:?}", err),
269259
};
@@ -291,14 +281,12 @@ impl Ingress for AwsApiGateway {
291281
let error_message = match err {
292282
SdkError::ServiceError(service_err) => {
293283
// Extract the specific service error details
294-
format!(
295-
"{}",
296-
service_err
297-
.err()
298-
.meta()
299-
.message()
300-
.unwrap_or("No error message found")
301-
)
284+
service_err
285+
.err()
286+
.meta()
287+
.message()
288+
.unwrap_or("No error message found")
289+
.to_string()
302290
}
303291
_ => format!("{:?}", err),
304292
};
@@ -337,14 +325,12 @@ impl Ingress for AwsApiGateway {
337325
let error_message = match err {
338326
SdkError::ServiceError(service_err) => {
339327
// Extract the specific service error details
340-
format!(
341-
"{}",
342-
service_err
343-
.err()
344-
.meta()
345-
.message()
346-
.unwrap_or("No error message found")
347-
)
328+
service_err
329+
.err()
330+
.meta()
331+
.message()
332+
.unwrap_or("No error message found")
333+
.to_string()
348334
}
349335
_ => format!("{:?}", err),
350336
};
@@ -394,14 +380,12 @@ impl Ingress for AwsApiGateway {
394380
let error_message = match err {
395381
SdkError::ServiceError(service_err) => {
396382
// Extract the specific service error details
397-
format!(
398-
"{}",
399-
service_err
400-
.err()
401-
.meta()
402-
.message()
403-
.unwrap_or("No error message found")
404-
)
383+
service_err
384+
.err()
385+
.meta()
386+
.message()
387+
.unwrap_or("No error message found")
388+
.to_string()
405389
}
406390
_ => format!("{:?}", err),
407391
};

src/adapters/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
pub use backend::BackendClient;
2-
pub(crate) use backend::{LockedState, RolloutMetadata};
1+
pub use backend::{BackendClient, RolloutMetadata};
32
pub use cloudflare::CloudflareClient;
43

4+
pub(crate) use backend::LockedState;
5+
56
pub use ingresses::*;
67
pub use monitors::*;
78
pub use platforms::*;

src/adapters/platforms/lambda.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ impl Platform for LambdaPlatform {
7272
let error_message = match err {
7373
SdkError::ServiceError(service_err) => {
7474
// Extract the specific service error details
75-
format!(
76-
"{}",
77-
service_err
78-
.err()
79-
.meta()
80-
.message()
81-
.unwrap_or("No error message found")
82-
)
75+
service_err
76+
.err()
77+
.meta()
78+
.message()
79+
.unwrap_or("No error message found")
80+
.to_string()
8381
}
8482
_ => format!("{:?}", err),
8583
};
@@ -115,14 +113,12 @@ impl Platform for LambdaPlatform {
115113
let error_message = match err {
116114
SdkError::ServiceError(service_err) => {
117115
// Extract the specific service error details
118-
format!(
119-
"{}",
120-
service_err
121-
.err()
122-
.meta()
123-
.message()
124-
.unwrap_or("No error message found")
125-
)
116+
service_err
117+
.err()
118+
.meta()
119+
.message()
120+
.unwrap_or("No error message found")
121+
.to_string()
126122
}
127123
_ => format!("{:?}", err),
128124
};

0 commit comments

Comments
 (0)