Skip to content

Commit 0ff7391

Browse files
committed
[centril/websocket-use-ids]: Merge remote-tracking branch 'origin/master' into centril/websocket-use-ids
2 parents 6cc4313 + ac0053c commit 0ff7391

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace SpacetimeDB.Internal;
2+
3+
using System.Runtime.InteropServices;
4+
5+
// We store time information in microseconds in internal usages.
6+
//
7+
// These utils allow to encode it as such in FFI and BSATN contexts
8+
// and convert to standard C# types.
9+
10+
[StructLayout(LayoutKind.Sequential)] // we should be able to use it in FFI
11+
[SpacetimeDB.Type] // we should be able to encode it to BSATN too
12+
public partial struct DateTimeOffsetRepr(DateTimeOffset time)
13+
{
14+
public ulong MicrosecondsSinceEpoch = (ulong)time.Ticks / 10;
15+
16+
public readonly DateTimeOffset ToStd() =>
17+
DateTimeOffset.UnixEpoch.AddTicks(10 * (long)MicrosecondsSinceEpoch);
18+
}
19+
20+
[StructLayout(LayoutKind.Sequential)] // we should be able to use it in FFI
21+
[SpacetimeDB.Type] // we should be able to encode it to BSATN too
22+
public partial struct TimeSpanRepr(TimeSpan duration)
23+
{
24+
public ulong Microseconds = (ulong)duration.Ticks / 10;
25+
26+
public readonly TimeSpan ToStd() => TimeSpan.FromTicks(10 * (long)Microseconds);
27+
}

crates/cli/src/subcommands/logout.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::Config;
2+
use clap::{Arg, ArgMatches, Command};
3+
use reqwest::Url;
4+
5+
pub fn cli() -> Command {
6+
Command::new("logout").arg(
7+
Arg::new("auth-host")
8+
.long("auth-host")
9+
.default_value("https://spacetimedb.com")
10+
.help("Log out from a custom auth server"),
11+
)
12+
}
13+
14+
pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
15+
let host: &String = args.get_one("auth-host").unwrap();
16+
let host = Url::parse(host)?;
17+
18+
if let Some(web_session_token) = config.web_session_token() {
19+
let client = reqwest::Client::new();
20+
client
21+
.post(host.join("auth/cli/logout")?)
22+
.header("Authorization", format!("Bearer {}", web_session_token))
23+
.send()
24+
.await?;
25+
}
26+
27+
config.clear_login_tokens();
28+
config.save();
29+
30+
Ok(())
31+
}

0 commit comments

Comments
 (0)