Skip to content

Commit

Permalink
Move http client from agency_client to vcx_shared (#1037)
Browse files Browse the repository at this point in the history
* Extract http client to vcx_shared

* Remove feature-discover JS tests

---------

Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas authored Oct 30, 2023
1 parent a89d6b3 commit 4405813
Show file tree
Hide file tree
Showing 50 changed files with 307 additions and 560 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions agency_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ edition.workspace = true
doctest = false

[dependencies]
async-trait = "0.1.53"
env_logger = "0.9.0"
log = "0.4.16"
lazy_static = "1.3"
serde = "1.0.97"
serde_json = "1.0.40"
serde_derive = "1.0.97"
reqwest = "0.11.10"
regex = "1.1.0"
url = { version = "2.3", features = ["serde"] }
uuid = { version = "0.8", default-features = false, features = ["v4"]}
thiserror = "1.0.37"
async-trait = "0.1.73"
shared_vcx = { path = "../shared_vcx" }
16 changes: 8 additions & 8 deletions agency_client/src/errors/mapping_sharedvcx.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use shared_vcx::errors::error::{SharedVcxError, SharedVcxErrorKind};
use shared_vcx::errors::validation::{ValidationError, ValidationErrorKind};

use crate::errors::error::{AgencyClientError, AgencyClientErrorKind};

impl From<SharedVcxErrorKind> for AgencyClientErrorKind {
fn from(error: SharedVcxErrorKind) -> Self {
impl From<ValidationErrorKind> for AgencyClientErrorKind {
fn from(error: ValidationErrorKind) -> Self {
match error {
SharedVcxErrorKind::InvalidDid => AgencyClientErrorKind::InvalidDid,
SharedVcxErrorKind::InvalidVerkey => AgencyClientErrorKind::InvalidVerkey,
SharedVcxErrorKind::NotBase58 => AgencyClientErrorKind::NotBase58,
ValidationErrorKind::InvalidDid => AgencyClientErrorKind::InvalidDid,
ValidationErrorKind::InvalidVerkey => AgencyClientErrorKind::InvalidVerkey,
ValidationErrorKind::NotBase58 => AgencyClientErrorKind::NotBase58,
}
}
}

impl From<SharedVcxError> for AgencyClientError {
fn from(error: SharedVcxError) -> Self {
impl From<ValidationError> for AgencyClientError {
fn from(error: ValidationError) -> Self {
let kind: AgencyClientErrorKind = error.kind().into();
AgencyClientError::from_msg(kind, error.to_string())
}
Expand Down
121 changes: 0 additions & 121 deletions agency_client/src/httpclient.rs

This file was deleted.

34 changes: 31 additions & 3 deletions agency_client/src/internal/messaging.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
use core::u8;

use serde_json::Value;
use shared_vcx::http_client::post_message;

use crate::{
agency_client::AgencyClient,
errors::error::{AgencyClientError, AgencyClientErrorKind, AgencyClientResult},
httpclient,
messages::{a2a_message::Client2AgencyMessage, forward::ForwardV2},
testing::mocking::AgencyMockDecrypted,
testing::{
mocking,
mocking::{AgencyMock, AgencyMockDecrypted, HttpClientMockResponse},
},
};

impl AgencyClient {
pub async fn post_to_agency(&self, body_content: Vec<u8>) -> AgencyClientResult<Vec<u8>> {
let url = self.get_agency_url_full()?;
httpclient::post_message(body_content, url).await
if mocking::agency_mocks_enabled() {
if HttpClientMockResponse::has_response() {
warn!("post_message >> mocking response for POST {}", &url);
return HttpClientMockResponse::get_response();
}
if AgencyMockDecrypted::has_decrypted_mock_responses() {
warn!(
"post_message >> will use mocked decrypted response for POST {}",
&url
);
return Ok(vec![]);
}
let mocked_response = AgencyMock::get_response();
warn!(
"post_message >> mocking response of length {} for POST {}",
mocked_response.len(),
&url
);
return Ok(mocked_response);
}
post_message(body_content, url).await.map_err(|err| {
AgencyClientError::from_msg(
AgencyClientErrorKind::PostMessageFailed,
format!("Cannot send message to agency: {err}"),
)
})
}

pub async fn prepare_message_for_agency(
Expand Down
2 changes: 0 additions & 2 deletions agency_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern crate serde_derive;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;

mod utils;

#[macro_use]
Expand All @@ -18,7 +17,6 @@ pub mod agency_client;
pub mod api;
pub mod configuration;

pub mod httpclient;
pub mod messages;
pub mod testing;
pub mod wallet;
Expand Down
3 changes: 1 addition & 2 deletions agents/node/vcxagent-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
"demo:faber:mysql": "node demo/faber.js --mysql",
"demo:alice:sign": "node demo/alice-signature.js",
"demo:faber:verify": "node demo/faber-verify-signature.js",
"test:integration": "npm run test:integration:issue-verify && npm run test:integration:signing && npm run test:integration:messaging && npm run test:integration:tails && npm run test:integration:trustping && npm run test:integration:feature-discovery && npm run test:integration:public-invite && npm run test:integration:out-of-band && npm run test:integration:endpoint && npm run test:integration:connection",
"test:integration": "npm run test:integration:issue-verify && npm run test:integration:signing && npm run test:integration:messaging && npm run test:integration:tails && npm run test:integration:trustping && npm run test:integration:public-invite && npm run test:integration:out-of-band && npm run test:integration:endpoint && npm run test:integration:connection",
"test:integration:issue-verify": "jest --forceExit --env=node --runInBand test/issue-verify.spec.js",
"test:integration:signing": "jest --forceExit --env=node --runInBand test/sign-verify.spec.js",
"test:integration:messaging": "jest --forceExit --env=node --runInBand test/messaging.spec.js",
"test:integration:tails": "jest --forceExit --env=node --runInBand test/distribute-tails.spec.js",
"test:integration:trustping": "jest --forceExit --env=node --runInBand test/trustping.spec.js",
"test:integration:feature-discovery": "jest --forceExit --env=node --runInBand test/feature-discovery.spec.js",
"test:integration:public-invite": "jest --forceExit --env=node --runInBand test/public-invite.spec.js",
"test:integration:out-of-band": "jest --forceExit --env=node --runInBand test/out-of-band.spec.js",
"test:integration:endpoint": "jest --forceExit --env=node --runInBand test/endpoint.spec.js",
Expand Down
6 changes: 0 additions & 6 deletions agents/node/vcxagent-core/src/services/service-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ module.exports.createServiceConnections = function createServiceConnections ({ l
await connection.sendPing()
}

async function discoverTheirFeatures (connectionId) {
const connection = await getVcxConnection(connectionId)
await connection.sendDiscoveryFeatures()
}

return {
// inviter
inviterConnectionCreate,
Expand All @@ -206,7 +201,6 @@ module.exports.createServiceConnections = function createServiceConnections ({ l
updateAllReceivedMessages,

sendPing,
discoverTheirFeatures,

getState,
listIds,
Expand Down
45 changes: 0 additions & 45 deletions agents/node/vcxagent-core/test/feature-discovery.spec.js

This file was deleted.

11 changes: 0 additions & 11 deletions agents/node/vcxagent-core/test/utils/alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ module.exports.createAlice = async function createAlice (serviceEndpoint = 'http
await vcxAgent.agentShutdownVcx()
}

async function discoverTheirFeatures () {
logger.info('Alice is going to request Faber\'s Aries features.')
await vcxAgent.agentInitVcx()

const res = await vcxAgent.serviceConnections.discoverTheirFeatures(connectionId)
logger.info(`Operation result = ${JSON.stringify(res)}`)

await vcxAgent.agentShutdownVcx()
}

async function unpackMsg (encryptedMsg) {
logger.info(`Alice is going to unpack message of length ${encryptedMsg.length}`)
await vcxAgent.agentInitVcx()
Expand Down Expand Up @@ -287,7 +277,6 @@ module.exports.createAlice = async function createAlice (serviceEndpoint = 'http
getTailsHash,
downloadReceivedMessagesV2,
sendPing,
discoverTheirFeatures,
unpackMsg
}
}
1 change: 1 addition & 0 deletions agents/rust/aries-vcx-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
serde = "1.0.145"
aries-vcx = { path = "../../../aries_vcx" }
aries_vcx_core = { path = "../../../aries_vcx_core", features = ["credx", "vdrtools_wallet"] }
shared_vcx = { path = "../../../shared_vcx" }
async-trait = "0.1.64"
derive_builder = "0.12.0"
serde_json = "1.0.85"
Expand Down
2 changes: 2 additions & 0 deletions agents/rust/aries-vcx-agent/src/error/error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ pub enum AgentErrorKind {
CredDefAlreadyCreated,
#[error("Mediated connections not configured")]
MediatedConnectionServiceUnavailable,
#[error("Failed to submit http request")]
PostMessageFailed,
}
Loading

0 comments on commit 4405813

Please sign in to comment.