Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for shamir recovery invitation #8819

Merged
merged 20 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
TESTBED_SERVER: http://localhost:6777
services:
parsec-testbed-server:
image: ghcr.io/scille/parsec-cloud/parsec-testbed-server:3.1.1-a.0.dev.20041.677dcc5
image: ghcr.io/scille/parsec-cloud/parsec-testbed-server:3.1.1-a.0.dev.20049.b16ce69
ports:
- 6777:6777
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# https://github.com/Scille/parsec-cloud/pkgs/container/parsec-cloud%2Fparsec-testbed-server
services:
parsec-testbed-server:
image: ghcr.io/scille/parsec-cloud/parsec-testbed-server:3.1.1-a.0.dev.20041.677dcc5
image: ghcr.io/scille/parsec-cloud/parsec-testbed-server:3.1.1-a.0.dev.20049.b16ce69
ports:
- 6777:6777
steps:
Expand Down
18 changes: 18 additions & 0 deletions bindings/electron/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,14 @@ export interface InviteListItemDevice {
created_on: number
status: InvitationStatus
}
export interface InviteListItemShamirRecovery {
tag: "ShamirRecovery"
addr: string
token: string
created_on: number
claimer_user_id: string
status: InvitationStatus
}
export interface InviteListItemUser {
tag: "User"
addr: string
Expand All @@ -1335,6 +1343,7 @@ export interface InviteListItemUser {
}
export type InviteListItem =
| InviteListItemDevice
| InviteListItemShamirRecovery
| InviteListItemUser


Expand Down Expand Up @@ -1421,6 +1430,14 @@ export interface ParsedParsecAddrInvitationDevice {
organization_id: string
token: string
}
export interface ParsedParsecAddrInvitationShamirRecovery {
tag: "InvitationShamirRecovery"
hostname: string
port: number
use_ssl: boolean
organization_id: string
token: string
}
export interface ParsedParsecAddrInvitationUser {
tag: "InvitationUser"
hostname: string
Expand Down Expand Up @@ -1469,6 +1486,7 @@ export interface ParsedParsecAddrWorkspacePath {
}
export type ParsedParsecAddr =
| ParsedParsecAddrInvitationDevice
| ParsedParsecAddrInvitationShamirRecovery
| ParsedParsecAddrInvitationUser
| ParsedParsecAddrOrganization
| ParsedParsecAddrOrganizationBootstrap
Expand Down
208 changes: 208 additions & 0 deletions bindings/electron/src/meths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5468,6 +5468,74 @@ fn variant_invite_list_item_js_to_rs<'a>(
status,
})
}
"InviteListItemShamirRecovery" => {
let addr = {
let js_val: Handle<JsString> = obj.get(cx, "addr")?;
{
let custom_from_rs_string = |s: String| -> Result<_, String> {
libparsec::ParsecInvitationAddr::from_any(&s).map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let token = {
let js_val: Handle<JsString> = obj.get(cx, "token")?;
{
let custom_from_rs_string =
|s: String| -> Result<libparsec::InvitationToken, _> {
libparsec::InvitationToken::from_hex(s.as_str())
.map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let created_on = {
let js_val: Handle<JsNumber> = obj.get(cx, "createdOn")?;
{
let v = js_val.value(cx);
let custom_from_rs_f64 = |n: f64| -> Result<_, &'static str> {
libparsec::DateTime::from_timestamp_micros((n * 1_000_000f64) as i64)
.map_err(|_| "Out-of-bound datetime")
};
match custom_from_rs_f64(v) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let claimer_user_id = {
let js_val: Handle<JsString> = obj.get(cx, "claimerUserId")?;
{
let custom_from_rs_string = |s: String| -> Result<libparsec::UserID, _> {
libparsec::UserID::from_hex(s.as_str()).map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let status = {
let js_val: Handle<JsString> = obj.get(cx, "status")?;
{
let js_string = js_val.value(cx);
enum_invitation_status_js_to_rs(cx, js_string.as_str())?
}
};
Ok(libparsec::InviteListItem::ShamirRecovery {
addr,
token,
created_on,
claimer_user_id,
status,
})
}
"InviteListItemUser" => {
let addr = {
let js_val: Handle<JsString> = obj.get(cx, "addr")?;
Expand Down Expand Up @@ -5584,6 +5652,62 @@ fn variant_invite_list_item_rs_to_js<'a>(
JsString::try_new(cx, enum_invitation_status_rs_to_js(status)).or_throw(cx)?;
js_obj.set(cx, "status", js_status)?;
}
libparsec::InviteListItem::ShamirRecovery {
addr,
token,
created_on,
claimer_user_id,
status,
..
} => {
let js_tag = JsString::try_new(cx, "InviteListItemShamirRecovery").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_addr = JsString::try_new(cx, {
let custom_to_rs_string =
|addr: libparsec::ParsecInvitationAddr| -> Result<String, &'static str> {
Ok(addr.to_url().into())
};
match custom_to_rs_string(addr) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "addr", js_addr)?;
let js_token = JsString::try_new(cx, {
let custom_to_rs_string =
|x: libparsec::InvitationToken| -> Result<String, &'static str> { Ok(x.hex()) };
match custom_to_rs_string(token) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "token", js_token)?;
let js_created_on = JsNumber::new(cx, {
let custom_to_rs_f64 = |dt: libparsec::DateTime| -> Result<f64, &'static str> {
Ok((dt.as_timestamp_micros() as f64) / 1_000_000f64)
};
match custom_to_rs_f64(created_on) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
});
js_obj.set(cx, "createdOn", js_created_on)?;
let js_claimer_user_id = JsString::try_new(cx, {
let custom_to_rs_string =
|x: libparsec::UserID| -> Result<String, &'static str> { Ok(x.hex()) };
match custom_to_rs_string(claimer_user_id) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "claimerUserId", js_claimer_user_id)?;
let js_status =
JsString::try_new(cx, enum_invitation_status_rs_to_js(status)).or_throw(cx)?;
js_obj.set(cx, "status", js_status)?;
}
libparsec::InviteListItem::User {
addr,
token,
Expand Down Expand Up @@ -5883,6 +6007,60 @@ fn variant_parsed_parsec_addr_js_to_rs<'a>(
token,
})
}
"ParsedParsecAddrInvitationShamirRecovery" => {
let hostname = {
let js_val: Handle<JsString> = obj.get(cx, "hostname")?;
js_val.value(cx)
};
let port = {
let js_val: Handle<JsNumber> = obj.get(cx, "port")?;
{
let v = js_val.value(cx);
if v < (u32::MIN as f64) || (u32::MAX as f64) < v {
cx.throw_type_error("Not an u32 number")?
}
let v = v as u32;
v
}
};
let use_ssl = {
let js_val: Handle<JsBoolean> = obj.get(cx, "useSsl")?;
js_val.value(cx)
};
let organization_id = {
let js_val: Handle<JsString> = obj.get(cx, "organizationId")?;
{
let custom_from_rs_string = |s: String| -> Result<_, String> {
libparsec::OrganizationID::try_from(s.as_str()).map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let token = {
let js_val: Handle<JsString> = obj.get(cx, "token")?;
{
let custom_from_rs_string =
|s: String| -> Result<libparsec::InvitationToken, _> {
libparsec::InvitationToken::from_hex(s.as_str())
.map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
Ok(libparsec::ParsedParsecAddr::InvitationShamirRecovery {
hostname,
port,
use_ssl,
organization_id,
token,
})
}
"ParsedParsecAddrInvitationUser" => {
let hostname = {
let js_val: Handle<JsString> = obj.get(cx, "hostname")?;
Expand Down Expand Up @@ -6201,6 +6379,36 @@ fn variant_parsed_parsec_addr_rs_to_js<'a>(
.or_throw(cx)?;
js_obj.set(cx, "token", js_token)?;
}
libparsec::ParsedParsecAddr::InvitationShamirRecovery {
hostname,
port,
use_ssl,
organization_id,
token,
..
} => {
let js_tag =
JsString::try_new(cx, "ParsedParsecAddrInvitationShamirRecovery").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_hostname = JsString::try_new(cx, hostname).or_throw(cx)?;
js_obj.set(cx, "hostname", js_hostname)?;
let js_port = JsNumber::new(cx, port as f64);
js_obj.set(cx, "port", js_port)?;
let js_use_ssl = JsBoolean::new(cx, use_ssl);
js_obj.set(cx, "useSsl", js_use_ssl)?;
let js_organization_id = JsString::try_new(cx, organization_id).or_throw(cx)?;
js_obj.set(cx, "organizationId", js_organization_id)?;
let js_token = JsString::try_new(cx, {
let custom_to_rs_string =
|x: libparsec::InvitationToken| -> Result<String, &'static str> { Ok(x.hex()) };
match custom_to_rs_string(token) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "token", js_token)?;
}
libparsec::ParsedParsecAddr::InvitationUser {
hostname,
port,
Expand Down
7 changes: 7 additions & 0 deletions bindings/generator/api/addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ class InvitationDevice:
organization_id: OrganizationID
token: InvitationToken

class InvitationShamirRecovery:
hostname: str
port: U32
use_ssl: bool
organization_id: OrganizationID
token: InvitationToken

class PkiEnrollment:
hostname: str
port: U32
Expand Down
31 changes: 31 additions & 0 deletions bindings/generator/api/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@ async def client_new_device_invitation(
raise NotImplementedError


class ClientNewShamirRecoveryInvitationError(ErrorVariant):
class Offline:
pass

class NotAllowed:
pass

class UserNotFound:
pass

class Internal:
pass


async def client_new_shamir_recovery_invitation(
client: Handle,
send_email: bool,
) -> Result[
NewInvitationInfo,
ClientNewShamirRecoveryInvitationError,
]:
raise NotImplementedError


class ClientCancelInvitationError(ErrorVariant):
class Offline:
pass
Expand Down Expand Up @@ -393,6 +417,13 @@ class Device:
created_on: DateTime
status: InvitationStatus

class ShamirRecovery:
addr: ParsecInvitationAddr
token: InvitationToken
created_on: DateTime
claimer_user_id: UserID
status: InvitationStatus


class ListInvitationsError(ErrorVariant):
class Offline:
Expand Down
Loading
Loading