Skip to content

Commit 454dc1e

Browse files
authored
feat(common): update user model fields (#2041)
* feat(common): update user model fields * types
1 parent 14fc644 commit 454dc1e

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

cargo-shuttle/src/util/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,28 @@ pub async fn check_version(runtime_path: &Path) -> Result<()> {
130130
runtime_path.display()
131131
);
132132

133-
// should always be a valid semver
134-
let my_version = semver::Version::from_str(crate::VERSION).unwrap();
133+
let cli_version =
134+
semver::Version::from_str(crate::VERSION).expect("crate version to be a valid semver");
135135

136136
if !runtime_path.try_exists()? {
137137
bail!("shuttle-runtime binary not found");
138138
}
139139

140140
// Get runtime version from shuttle-runtime cli
141-
// It should print the version and exit immediately, so a timeout is used to not launch servers with non-Shuttle setups
141+
// It should print the version and exit immediately, so a timeout is used
142+
// to not get blocked by blocking programs that don't use the Shuttle runtime.
142143
let stdout = tokio::time::timeout(Duration::from_millis(3000), async move {
143144
tokio::process::Command::new(runtime_path)
144145
.arg("--version")
145146
.kill_on_drop(true) // if the binary does not halt on its own, not killing it will leak child processes
146147
.output()
147148
.await
148-
.context("Failed to run the shuttle-runtime binary to check its version")
149+
.context("Failed to run the binary with shuttle-runtime to check its version")
149150
.map(|o| o.stdout)
150151
})
151152
.await
152-
.context("Checking the version of shuttle-runtime timed out. Make sure the executable is using #[shuttle-runtime::main].")??;
153+
.context("Checking the version of shuttle-runtime timed out. Make sure the executable is using #[shuttle_runtime::main].")??;
153154

154-
// Parse the version, splitting the version from the name and
155-
// and pass it to `to_semver()`.
156155
let runtime_version = semver::Version::from_str(
157156
std::str::from_utf8(&stdout)
158157
.context("shuttle-runtime version should be valid utf8")?
@@ -161,14 +160,14 @@ pub async fn check_version(runtime_path: &Path) -> Result<()> {
161160
.1
162161
.trim(),
163162
)
164-
.context("failed to convert user's runtime version to semver")?;
163+
.context("failed to convert runtime version to semver")?;
165164

166-
if semvers_are_compatible(&my_version, &runtime_version) {
165+
if semvers_are_compatible(&cli_version, &runtime_version) {
167166
Ok(())
168167
} else {
169168
Err(VersionMismatchError {
170169
shuttle_runtime: runtime_version,
171-
cargo_shuttle: my_version,
170+
cargo_shuttle: cli_version,
172171
})
173172
.context("shuttle-runtime and Shuttle CLI have incompatible versions")
174173
}

common/src/models/user.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ use super::project::ProjectUsageResponse;
1515
#[typeshare::typeshare]
1616
pub struct UserResponse {
1717
pub id: String,
18-
/// Auth0 id (deprecated)
19-
pub name: Option<String>,
2018
/// Auth0 id
2119
pub auth0_id: Option<String>,
22-
pub created_at: Option<DateTime<Utc>>,
20+
pub created_at: DateTime<Utc>,
2321
// deprecated
2422
pub key: Option<String>,
2523
pub account_tier: AccountTier,
26-
pub subscriptions: Vec<Subscription>,
24+
pub subscriptions: Option<Vec<Subscription>>,
2725
pub flags: Option<Vec<String>>,
2826
}
2927

@@ -39,15 +37,17 @@ impl UserResponse {
3937
self.account_tier.to_string_fancy()
4038
)
4139
.unwrap();
42-
if !self.subscriptions.is_empty() {
43-
writeln!(&mut s, " Subscriptions:").unwrap();
44-
for sub in &self.subscriptions {
45-
writeln!(
46-
&mut s,
47-
" - {}: Type: {}, Quantity: {}, Created: {}, Updated: {}",
48-
sub.id, sub.r#type, sub.quantity, sub.created_at, sub.updated_at,
49-
)
50-
.unwrap();
40+
if let Some(subs) = self.subscriptions.as_ref() {
41+
if !subs.is_empty() {
42+
writeln!(&mut s, " Subscriptions:").unwrap();
43+
for sub in subs {
44+
writeln!(
45+
&mut s,
46+
" - {}: Type: {}, Quantity: {}, Created: {}, Updated: {}",
47+
sub.id, sub.r#type, sub.quantity, sub.created_at, sub.updated_at,
48+
)
49+
.unwrap();
50+
}
5151
}
5252
}
5353
if let Some(flags) = self.flags.as_ref() {

common/types.ts

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)