Skip to content

Commit

Permalink
fix(rust): fix some ci failures
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed Jun 26, 2024
1 parent cff54a6 commit 28e050d
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 50 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

18 changes: 13 additions & 5 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ This file contains attributions for any 3rd-party open source code used in this
| equivalent | Apache-2.0, MIT | https://crates.io/crates/equivalent |
| errno | MIT, Apache-2.0 | https://crates.io/crates/errno |
| error-code | BSL-1.0 | https://crates.io/crates/error-code |
| etcetera | MIT, Apache-2.0 | https://crates.io/crates/etcetera |
| event-listener | Apache-2.0, MIT | https://crates.io/crates/event-listener |
| event-listener-strategy | Apache-2.0, MIT | https://crates.io/crates/event-listener-strategy |
| fastrand | Apache-2.0, MIT | https://crates.io/crates/fastrand |
| fd-lock | MIT, Apache-2.0 | https://crates.io/crates/fd-lock |
| fdeflate | MIT, Apache-2.0 | https://crates.io/crates/fdeflate |
| ff | MIT, Apache-2.0 | https://crates.io/crates/ff |
| fiat-crypto | MIT, Apache-2.0, BSD-1-Clause | https://crates.io/crates/fiat-crypto |
| finl_unicode | MIT, Apache-2.0 | https://crates.io/crates/finl_unicode |
| flate2 | MIT, Apache-2.0 | https://crates.io/crates/flate2 |
| flexi_logger | MIT, Apache-2.0 | https://crates.io/crates/flexi_logger |
| flume | Apache-2.0, MIT | https://crates.io/crates/flume |
Expand Down Expand Up @@ -487,11 +489,12 @@ This file contains attributions for any 3rd-party open source code used in this
| spin | MIT | https://crates.io/crates/spin |
| spki | Apache-2.0, MIT | https://crates.io/crates/spki |
| sqlformat | MIT, Apache-2.0 | https://crates.io/crates/sqlformat |
| sqlx | MIT, Apache-2.0 | https://crates.io/crates/sqlx |
| sqlx-core | MIT, Apache-2.0 | https://crates.io/crates/sqlx-core |
| sqlx-macros | MIT, Apache-2.0 | https://crates.io/crates/sqlx-macros |
| sqlx-macros-core | MIT, Apache-2.0 | https://crates.io/crates/sqlx-macros-core |
| sqlx-sqlite | MIT, Apache-2.0 | https://crates.io/crates/sqlx-sqlite |
| sqlx | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| sqlx-core | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| sqlx-macros | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| sqlx-macros-core | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| sqlx-postgres | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| sqlx-sqlite | MIT, Apache-2.0 | https://github.com/etorreborre/sqlx?rev=5fec648d2de0cbeed738dcf1c6f5bc9194fc439b |
| stable_deref_trait | MIT, Apache-2.0 | https://crates.io/crates/stable_deref_trait |
| static_assertions | MIT, Apache-2.0 | https://crates.io/crates/static_assertions |
| stm32-device-signature | MIT, Apache-2.0 | https://crates.io/crates/stm32-device-signature |
Expand All @@ -500,6 +503,7 @@ This file contains attributions for any 3rd-party open source code used in this
| stm32h7 | MIT, Apache-2.0 | https://crates.io/crates/stm32h7 |
| stm32h7xx-hal | 0BSD | https://crates.io/crates/stm32h7xx-hal |
| str-buf | BSL-1.0 | https://crates.io/crates/str-buf |
| stringprep | MIT, Apache-2.0 | https://crates.io/crates/stringprep |
| strip-ansi-escapes | Apache-2.0, MIT | https://crates.io/crates/strip-ansi-escapes |
| strsim | MIT | https://crates.io/crates/strsim |
| strum | MIT | https://crates.io/crates/strum |
Expand Down Expand Up @@ -586,6 +590,7 @@ This file contains attributions for any 3rd-party open source code used in this
| waker-fn | Apache-2.0, MIT | https://crates.io/crates/waker-fn |
| walkdir | Unlicense, MIT | https://crates.io/crates/walkdir |
| want | MIT | https://crates.io/crates/want |
| wasite | Apache-2.0, BSL-1.0, MIT | https://crates.io/crates/wasite |
| wasm-bindgen | MIT, Apache-2.0 | https://crates.io/crates/wasm-bindgen |
| wasm-bindgen-backend | MIT, Apache-2.0 | https://crates.io/crates/wasm-bindgen-backend |
| wasm-bindgen-futures | MIT, Apache-2.0 | https://crates.io/crates/wasm-bindgen-futures |
Expand All @@ -604,6 +609,7 @@ This file contains attributions for any 3rd-party open source code used in this
| web-time | MIT, Apache-2.0 | https://crates.io/crates/web-time |
| weezl | MIT, Apache-2.0 | https://crates.io/crates/weezl |
| which | MIT | https://crates.io/crates/which |
| whoami | Apache-2.0, BSL-1.0, MIT | https://crates.io/crates/whoami |
| winapi | MIT, Apache-2.0 | https://crates.io/crates/winapi |
| winapi-i686-pc-windows-gnu | MIT, Apache-2.0 | https://crates.io/crates/winapi-i686-pc-windows-gnu |
| winapi-util | Unlicense, MIT | https://crates.io/crates/winapi-util |
Expand Down Expand Up @@ -637,3 +643,5 @@ This file contains attributions for any 3rd-party open source code used in this
| zeroize_derive | Apache-2.0, MIT | https://crates.io/crates/zeroize_derive |
| zstd | MIT | https://crates.io/crates/zstd |
| zstd-safe | MIT, Apache-2.0 | https://crates.io/crates/zstd-safe |


2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_abac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ockam_executor = { version = "0.80.0", path = "../ockam_executor", default-featu
regex = { version = "1.10.5", default-features = false, optional = true }
rustyline = { version = "14.0.0", optional = true }
rustyline-derive = { version = "0.10.0", optional = true }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true, features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true }
str-buf = "3.0.3"
tokio = { version = "1.38", default-features = false, optional = true, features = ["sync", "time", "rt", "rt-multi-thread", "macros"] }
tracing = { version = "0.1", default-features = false, features = ["attributes"] }
Expand Down
3 changes: 1 addition & 2 deletions implementations/rust/ockam/ockam_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ reqwest = { version = "0.12", default-features = false, features = ["json", "rus
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
sha2 = "0.10.8"
#sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b" }
strip-ansi-escapes = "0.2"
sysinfo = "0.30"
thiserror = "1.0"
Expand Down
3 changes: 1 addition & 2 deletions implementations/rust/ockam/ockam_app_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ ockam_multiaddr = { path = "../ockam_multiaddr", version = "0.55.0", features =
ockam_transport_tcp = { path = "../ockam_transport_tcp", version = "^0.117.0", default-features = false, features = ["std"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
#sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite", "migrate", "postgres", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b" }
thiserror = "1.0"
tokio = { version = "1.38.0", features = ["full"] }
tracing = { version = "0.1", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ teardown() {

run_success "$OCKAM" vault show v1 --output json --jq .
assert_output --partial "\"name\":\"v1\""
assert_output --partial "\"is_kms\":false"
assert_output --partial "\"use_aws_kms\":\"No\""

run_success "$OCKAM" vault show v1 --output json --jq .vault.name
assert_output --partial "v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ teardown() {

run_success "$OCKAM" vault show v1 --output json
assert_output --partial "\"name\":\"v1\""
assert_output --partial "\"is_kms\":false"
assert_output --partial "\"use_aws_kms\":\"No\""

run_success "$OCKAM" vault list --output json
assert_output --partial "\"name\":\"v1\""
assert_output --partial "\"is_kms\":false"
assert_output --partial "\"use_aws_kms\":\"No\""

run_success "$OCKAM" vault create v2

run_success "$OCKAM" vault show v2 --output json
assert_output --partial "\"name\":\"v2\""
assert_output --partial "\"is_kms\":false"
assert_output --partial "\"use_aws_kms\":\"No\""

run_success "$OCKAM" vault list --output json
assert_output --partial "\"name\":\"v1\""
assert_output --partial "\"name\":\"v2\""
assert_output --partial "\"is_kms\":false"
assert_output --partial "\"use_aws_kms\":\"No\""
}

@test "vault - CRUD" {
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_bare = { version = "0.5.0", default-features = false, features = ["alloc"] }
serde_json = { version = "1.0", optional = true }
sha2 = { version = "0.10", default-features = false }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true, features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true }
tokio-retry = { version = "0.3.0", default-features = false, optional = true }
tracing = { version = "0.1", default_features = false }
tracing-attributes = { version = "0.1", default_features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ impl Encode<'_, Any> for CredentialAndPurposeKey {
}
}

// Database serialization / deserialization

impl Type<Any> for TimestampInSeconds {
fn type_info() -> <Any as Database>::TypeInfo {
<i64 as Type<Any>>::type_info()
}
}

impl Encode<'_, Any> for TimestampInSeconds {
fn encode_by_ref(&self, buf: &mut <Any as HasArguments>::ArgumentBuffer) -> IsNull {
<i64 as Encode<'_, Any>>::encode_by_ref(&(self.0 as i64), buf)
}
}

// Low-level representation of a table row
#[derive(FromRow)]
struct CachedCredentialRow {
Expand Down
15 changes: 0 additions & 15 deletions implementations/rust/ockam/ockam_identity/src/models/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
use minicbor::{Decode, Encode};
use serde::{Deserialize, Serialize};
use sqlx::database::HasArguments;
use sqlx::encode::IsNull;
use sqlx::{Any, Database, Type};

/// Timestamp in seconds (UTC)
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode, Serialize, Deserialize)]
#[rustfmt::skip]
#[cbor(transparent)]
#[serde(transparent)]
pub struct TimestampInSeconds(#[n(0)] pub u64);

impl Type<Any> for TimestampInSeconds {
fn type_info() -> <Any as Database>::TypeInfo {
<i64 as Type<Any>>::type_info()
}
}

impl sqlx::Encode<'_, Any> for TimestampInSeconds {
fn encode_by_ref(&self, buf: &mut <Any as HasArguments>::ArgumentBuffer) -> IsNull {
<i64 as sqlx::Encode<'_, Any>>::encode_by_ref(&(self.0 as i64), buf)
}
}
9 changes: 3 additions & 6 deletions implementations/rust/ockam/ockam_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ default = ["std"]
# Feature (enabled by default): "std" enables functionality expected to
# be available on a standard platform.
std = [
"chrono",
"ockam_core/std",
"ockam_transport_core/std",
"once_cell/std",
Expand Down Expand Up @@ -69,11 +68,10 @@ metrics = []
# message flows within Ockam apps.
debugger = ["ockam_core/debugger"]

storage = ["std", "time", "serde_json", "sqlx", "tokio-retry", "regex"]
storage = ["std", "time", "serde_json", "sqlx", "tokio-retry", "regex", "tempfile"]

[dependencies]
cfg-if = "1.0.0"
chrono = { version = "0.4", optional = true }
fs2 = { version = "0.4.3", optional = true }
futures = { version = "0.3.30", default-features = false }
heapless = { version = "0.8", features = ["mpmc_large"], optional = true }
Expand All @@ -87,9 +85,8 @@ opentelemetry = { version = "0.23.0", features = ["logs", "metrics", "trace"], o
regex = { version = "1.10.5", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1", optional = true }
#sqlx = { version = "0.7.4", optional = true, features = ["sqlite", "postgres", "migrate", "runtime-tokio", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true, features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
tempfile = { version = "3.10.1" }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true, features = ["postgres", "sqlite", "any", "migrate", "runtime-tokio"] }
tempfile = { version = "3.10.1", optional = true }
time = { version = "0.3.36", default-features = false, optional = true }
tokio = { version = "1.38", default-features = false, optional = true, features = ["sync", "time", "rt", "rt-multi-thread", "macros"] }
tokio-retry = { version = "0.3.0", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ impl PolicyTrustContextId {
/// This migration updates policies to not rely on trust_context_id,
/// also introduces `node_name` and replicates policy for each existing node
pub(crate) async fn migrate_update_policies(connection: &mut AnyConnection) -> Result<bool> {
let mut transaction = sqlx::Connection::begin(&mut *connection)
.await
.into_core()?;
let mut transaction = Connection::begin(&mut *connection).await.into_core()?;

let query_node_names = query_as("SELECT name FROM node");
let node_names: Vec<NodeNameRow> = query_node_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ impl SplitPolicies {
}

pub(crate) async fn migrate_policies(connection: &mut AnyConnection) -> Result<bool> {
let mut transaction = sqlx::Connection::begin(&mut *connection)
.await
.into_core()?;
let mut transaction = Connection::begin(&mut *connection).await.into_core()?;

let query_policies =
query_as("SELECT resource_name, action, expression, node_name FROM resource_policy");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- This migration allows the path column to be NULL
-- This case indicates that the vault 'name' has all its keys stored in the current database
-- When the path is NULL then the vault 'name' has all its keys stored in the current database
CREATE TABLE new_vault
(
name TEXT PRIMARY KEY, -- User-specified name for a vault
Expand All @@ -9,7 +9,19 @@ CREATE TABLE new_vault
);

INSERT INTO new_vault (name, path, is_default, is_kms)
SELECT name, NULL, is_default, is_kms
SELECT
name,
-- set the path to NULL when the vault is stored in the database
CASE
WHEN path LIKE '%database.sqlite3%' THEN NULL
ELSE path
END as path,
-- fix the setting of the is_default flag which could occur more than once
CASE
WHEN name = 'default' THEN 1
ELSE 0
END as is_default,
is_kms
FROM vault;

DROP TABLE vault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ockam_core::errcode::{Kind, Origin};
use sqlx::any::{install_default_drivers, AnyConnectOptions};
use sqlx::pool::PoolOptions;
use sqlx::{Any, ConnectOptions, Pool};
#[cfg(feature = "std")]
use tempfile::NamedTempFile;
use tokio_retry::strategy::{jitter, FixedInterval};
use tokio_retry::Retry;
Expand Down Expand Up @@ -307,6 +308,7 @@ impl Clean {
}

/// This function can be used to run some test code with the 3 different databases implementations
#[cfg(feature = "std")]
pub async fn with_dbs<F, Fut>(f: F) -> Result<()>
where
F: Fn(SqlxDatabase) -> Fut + Send + Sync + 'static,
Expand All @@ -329,6 +331,7 @@ where

/// This function can be used to run some test code with the 3 different databases implementations
/// of the application database
#[cfg(feature = "std")]
pub async fn with_application_dbs<F, Fut>(f: F) -> Result<()>
where
F: Fn(SqlxDatabase) -> Fut + Send + Sync + 'static,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl Boolean {
impl<'d> Decode<'d, Any> for Boolean {
fn decode(value: <Any as HasValueRef<'d>>::ValueRef) -> Result<Self, BoxDynError> {
match value.type_info().kind() {
AnyTypeInfoKind::Bool => Ok(Boolean(sqlx::ValueRef::to_owned(&value).decode())),
AnyTypeInfoKind::Bool => Ok(Boolean(ValueRef::to_owned(&value).decode())),
AnyTypeInfoKind::Integer => {
let v: i64 = sqlx::ValueRef::to_owned(&value).decode();
let v: i64 = ValueRef::to_owned(&value).decode();
Ok(Boolean(v == 1))
}
other => Err(format!("expected BOOLEAN or INTEGER, got {:?}", other).into()),
Expand Down
3 changes: 1 addition & 2 deletions implementations/rust/ockam/ockam_vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ rand = { version = "0.8", default-features = false }
rand_pcg = { version = "0.3.1", default-features = false, optional = true }
serde = { version = "1", default-features = false, features = ["derive"] }
sha2 = { version = "0.10", default-features = false }
#sqlx = { version = "0.7.4", optional = true, features = ["migrate", "postgres", "sqlite", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true, features = ["runtime-tokio", "sqlite", "postgres", "migrate", "any"] }
sqlx = { git = "https://github.com/etorreborre/sqlx", rev = "5fec648d2de0cbeed738dcf1c6f5bc9194fc439b", optional = true }
static_assertions = "1.1.0"
tracing = { version = "0.1", default-features = false }
x25519-dalek = { version = "2.0.1", default_features = false, features = ["precomputed-tables", "static_secrets", "zeroize"] }
Expand Down

0 comments on commit 28e050d

Please sign in to comment.