Skip to content

Commit

Permalink
Merge pull request #75 from juicebox-systems/nt/version-check
Browse files Browse the repository at this point in the history
Add 'Juicebox-Version' header and support 'UpgradeRequired' error
  • Loading branch information
Imperiopolis authored Aug 10, 2023
2 parents e373a71 + aedf534 commit 8ed49bd
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 58 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default-members = ["rust/sdk"]
resolver = "2"

[workspace.package]
version = "0.1.1"
version = "0.2.0"
license = "MIT"
authors = [
"Simon Fell <[email protected]>",
Expand All @@ -30,20 +30,20 @@ authors = [
]

[workspace.dependencies]
juicebox_marshalling = { path = "rust/marshalling", version = "0.1.1" }
juicebox_networking = { path = "rust/networking", version = "0.1.1" }
juicebox_noise = { path = "rust/noise", version = "0.1.1" }
juicebox_oprf = { path = "rust/oprf", version = "0.1.1" }
juicebox_process_group = { path = "rust/process_group", version = "0.1.1" }
juicebox_realm_api = { path = "rust/realm/api", version = "0.1.1" }
juicebox_realm_auth = { path = "rust/realm/auth", version = "0.1.1" }
juicebox_secret_sharing = { path = "rust/secret_sharing", version = "0.1.1" }
juicebox_sdk = { path = "rust/sdk", version = "0.1.1" }
juicebox_sdk_bridge = { path = "rust/sdk/bridge", version = "0.1.1" }
juicebox_sdk_ffi = { path = "rust/sdk/bridge/ffi", version = "0.1.1" }
juicebox_sdk_jni = { path = "rust/sdk/bridge/jni", version = "0.1.1" }
juicebox_sdk_wasm = { path = "rust/sdk/bridge/wasm", version = "0.1.1" }
juicebox_software_realm_runner = { path = "rust/software_realm_runner", version = "0.1.1" }
juicebox_marshalling = { path = "rust/marshalling", version = "0.2.0" }
juicebox_networking = { path = "rust/networking", version = "0.2.0" }
juicebox_noise = { path = "rust/noise", version = "0.2.0" }
juicebox_oprf = { path = "rust/oprf", version = "0.2.0" }
juicebox_process_group = { path = "rust/process_group", version = "0.2.0" }
juicebox_realm_api = { path = "rust/realm/api", version = "0.2.0" }
juicebox_realm_auth = { path = "rust/realm/auth", version = "0.2.0" }
juicebox_secret_sharing = { path = "rust/secret_sharing", version = "0.2.0" }
juicebox_sdk = { path = "rust/sdk", version = "0.2.0" }
juicebox_sdk_bridge = { path = "rust/sdk/bridge", version = "0.2.0" }
juicebox_sdk_ffi = { path = "rust/sdk/bridge/ffi", version = "0.2.0" }
juicebox_sdk_jni = { path = "rust/sdk/bridge/jni", version = "0.2.0" }
juicebox_sdk_wasm = { path = "rust/sdk/bridge/wasm", version = "0.2.0" }
juicebox_software_realm_runner = { path = "rust/software_realm_runner", version = "0.2.0" }

argon2 = "0.5.0"
async-trait = "0.1.64"
Expand Down
2 changes: 1 addition & 1 deletion JuiceboxSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|
s.name = 'JuiceboxSdk'
s.license = 'MIT'
s.author = { 'Nora Trapp' => '[email protected]' }
s.version = '0.1.1'
s.version = '0.2.0'
s.summary = 'A Swift wrapper library for interfacing with the Juicebox service.'

s.homepage = 'https://github.com/juicebox-systems/juicebox-sdk'
Expand Down
4 changes: 2 additions & 2 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
}
dependencies {
implementation 'xyz.juicebox:sdk:0.1.1'
implementation 'xyz.juicebox:sdk:0.2.0'
}
```

Expand All @@ -25,7 +25,7 @@ dependencies {
<dependency>
<groupId>xyz.juicebox</groupId>
<artifactId>sdk</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>
</dependency>
```

Expand Down
5 changes: 5 additions & 0 deletions android/src/main/kotlin/xyz/juicebox/sdk/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class Client private constructor (
"JuiceboxSdk-Android/${Native.sdkVersion()}"
)

urlConnection.setRequestProperty(
"X-Juicebox-Version",
Native.sdkVersion()
)

request.headers?.forEach {
urlConnection.setRequestProperty(it.name, it.value)
}
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/kotlin/xyz/juicebox/sdk/DeleteError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ enum class DeleteError {
*/
INVALID_AUTH,

/**
* The SDK software is too old to communicate with this realm and
* must be upgraded.
*/
UPGRADE_REQUIRED,

/**
* A software error has occurred. This request should not be retried
* with the same parameters. Verify your inputs, check for software
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/kotlin/xyz/juicebox/sdk/RecoverError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ enum class RecoverError {
*/
INVALID_AUTH,

/**
* The SDK software is too old to communicate with this realm and
* must be upgraded.
*/
UPGRADE_REQUIRED,

/**
* A software error has occurred. This request should not be retried
* with the same parameters. Verify your inputs, check for software
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/kotlin/xyz/juicebox/sdk/RegisterError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ enum class RegisterError {
*/
INVALID_AUTH,

/**
* The SDK software is too old to communicate with this realm and
* must be upgraded.
*/
UPGRADE_REQUIRED,

/**
* A software error has occurred. This request should not be retried
* with the same parameters. Verify your inputs, check for software
Expand Down
19 changes: 16 additions & 3 deletions rust/networking/src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ use crate::{http, rpc};
pub struct ClientOptions<'a> {
pub additional_root_certs: Vec<Certificate>,
pub timeout: Duration,
pub user_agent: &'a str,
pub default_headers: HashMap<&'a str, &'a str>,
}

impl<'a> Default for ClientOptions<'a> {
fn default() -> Self {
Self {
additional_root_certs: Vec::new(),
timeout: Duration::from_secs(30),
user_agent: concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
default_headers: HashMap::from([(
"User-Agent",
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
)]),
}
}
}
Expand All @@ -42,8 +45,18 @@ impl<F: rpc::Service> Client<F> {
pub fn new(options: ClientOptions) -> Self {
let mut b = reqwest::Client::builder()
.timeout(options.timeout)
.user_agent(options.user_agent)
.use_rustls_tls();

let mut default_headers = reqwest::header::HeaderMap::new();
for (key, value) in options.default_headers {
if let (Ok(header_name), Ok(header_value)) =
(HeaderName::from_str(key), HeaderValue::from_str(value))
{
default_headers.append(header_name, header_value);
}
}
b = b.default_headers(default_headers);

for c in options.additional_root_certs {
b = b.add_root_certificate(c);
}
Expand Down
2 changes: 2 additions & 0 deletions rust/realm/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use zeroize::Zeroize;

use juicebox_marshalling::{bytes, to_be4};

pub const JUICEBOX_VERSION_HEADER: &str = "X-Juicebox-Version";

#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct SecretBytesArray<const N: usize>(#[serde(with = "bytes")] [u8; N]);

Expand Down
4 changes: 2 additions & 2 deletions rust/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ cargo add juicebox_sdk
Or add the following line to your Cargo.toml:

```
juicebox_sdk = "0.1.1"
juicebox_sdk = "0.2.0"
```

Additionally, you may wish to enable the `tokio` or `reqwest` [features](#features) to simplify usage:

```
juicebox_sdk = { version = "0.1.1", features = ["tokio", "reqwest"] }
juicebox_sdk = { version = "0.2.0", features = ["tokio", "reqwest"] }
```

### Usage
Expand Down
Loading

0 comments on commit 8ed49bd

Please sign in to comment.