Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/APIDevTools/swagger-cli
rev: v4.0.3
rev: v4.0.4
hooks:
- id: swagger-validation
name: Check market-api spec
Expand All @@ -20,3 +20,6 @@ repos:
- id: swagger-validation
name: Check payment-api spec
files: specs/payment-api.yaml$
- id: swagger-validation
name: Check network-api spec
files: specs/net-api.yaml$
31 changes: 21 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ license = "LGPL-3.0"
edition = "2021"

[features]
default = []
default = ['provider', 'requestor']
cli = ['structopt']

sgx = [
'graphene-sgx', 'lazy_static', 'secp256k1',
'openssl', 'secp256k1/serde', 'secp256k1/rand',
'ya-client-model/sgx', 'rand']
'ya-client-model/sgx', 'rand', 'hex']

provider= []
requestor = []

[workspace]
members = [
Expand All @@ -23,31 +27,38 @@ members = [

[workspace.dependencies]
secp256k1 = ">=0.23,<0.28"
serde = { version = "1.0.146" }
serde_json = "1.0.96"
thiserror = "1.0.40"
rand = "0.8.5"
chrono = { version = "0.4", default-features = false }
openssl = "0.10"
hex = "0.4"

[dependencies]
ya-client-model = { version = "^0.5", path = "model" }
ya-client-model = { version = "^0.5", path = "model", features=["debug"] }
awc = { version = "3", default-features = false }
actix-codec = "0.5"
bytes = "1"
chrono = { version = "0.4", default-features = false }
hex = { workspace=true, optional = true}
chrono = { workspace=true, default-features = false }
envy = "0.4"
futures = "0.3"
hex = "0.4"
heck = "0.4.1"
log = "0.4"
mime = "0.3.17"
serde = "1"
serde_json = "1.0"
serde = { workspace=true }
serde_json = { workspace=true }
serde_qs = "0.12"
thiserror = "1.0.40"
thiserror = { workspace=true }
url = "2"

graphene-sgx = { version = "0.3.3", optional = true }
lazy_static = { version = "1.4", optional = true }
secp256k1 = { workspace=true, optional = true }
rand = { version = "0.8.5", optional = true }
rand = { workspace=true, optional = true }
structopt = { version = "0.3", optional = true }
openssl = { version = "0.10", optional = true }
openssl = { workspace=true, optional = true }

[dev-dependencies]
actix-rt = "2.7.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Yagna public API
# Golem Node REST API [![CI](https://github.com/golemfactory/ya-client/actions/workflows/rust.yml/badge.svg)](https://github.com/golemfactory/ya-client/actions/workflows/rust.yml)

Public Yagna REST APIs client binding with Data Model and specifications in
[OpenAPI](http://spec.openapis.org/) format.
Expand Down
31 changes: 23 additions & 8 deletions model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,41 @@ repository = "https://github.com/golemfactory/ya-client"
license = "LGPL-3.0"
edition = "2018"

[[example]]
name = "gen-json-schema"
required-features = ["json-schema"]

[features]
default = []
default = ['node-id-compat']
node-id-compat = []
json-schema = ["schemars", "schemars/chrono", "serde_json/preserve_order"]
server = []
debug = []
sgx = ['secp256k1', 'openssl', 'hex', 'secp256k1/serde', 'rand']
with-diesel = ['diesel']
sgx = ['secp256k1', 'openssl', 'hex', 'secp256k1/serde']

[dependencies]
bigdecimal = { version = "0.2", features = ["serde"]}
chrono = { version = "0.4", features = ["serde"]}
chrono = { workspace=true, features = ["serde", "clock"]}
derive_more = "0.99"
rand = "0.8"
serde = { version = "1.0.146", features = ["derive"] }
serde_json = "1.0.96"
rand = { workspace=true, optional = true }
serde = { workspace=true, features = ["derive"] }
serde_json = { workspace=true }
strum = "0.24.1"
strum_macros = "0.24.3"
thiserror = "1.0"
thiserror = { workspace=true }

diesel = { version = "1.4", optional = true }
hex = { version = "0.4", optional = true}
secp256k1 = { workspace = true, optional = true }
openssl = { version = "0.10", optional = true }
openssl = { workspace=true, optional = true }

schemars = { version = "0.8", optional = true }

[dev-dependencies]
flexbuffers="2.0.0"
serde_yaml = "0.9.21"
json-schema-diff = "0.1.6"

[package.metadata.release]
dev-version = false
Expand Down
58 changes: 58 additions & 0 deletions model/examples/gen-json-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use schemars::gen::SchemaSettings;
use schemars::schema_for;
use serde_yaml;
use ya_client_model::net::*;

fn main() {
let mut net_api_schema: serde_json::Value =
serde_yaml::from_str(include_str!("../../specs/net-api.yaml")).unwrap();

let objects = net_api_schema
.get_mut("components")
.unwrap()
.get_mut("schemas")
.unwrap()
.as_object_mut()
.unwrap();

let settings = SchemaSettings::draft07().with(|s| {
s.option_nullable = true;
s.option_add_null_type = false;
s.inline_subschemas = false;
});
let mut gen = settings.into_generator();

let mut show_diff_for = |name, schema, skip| {
let lhs: serde_json::Value = objects.remove(name).unwrap().clone();
let rhs: serde_json::Value = serde_json::to_value(schema).unwrap();
let df = json_schema_diff::diff(lhs, rhs.clone()).unwrap();

if df.is_empty() || skip {
eprintln!("{}", serde_yaml::to_string(&rhs).unwrap());
eprintln!("{} is equal", name);
} else {
eprintln!("# {}", name);
eprintln!("{}", serde_yaml::to_string(&rhs).unwrap());
eprintln!("# {} changes", name);
for change in df {
eprintln!("{:20} {:?}", change.path, change.change);
}
}
//eprintln!("L: {}", serde_json::to_string_pretty(&lhs).unwrap());
};
show_diff_for("Node", gen.root_schema_for::<Node>(), false);
show_diff_for("Address", gen.root_schema_for::<Address>(), false);
show_diff_for("Connection", gen.root_schema_for::<Connection>(), false);
show_diff_for("Network", gen.root_schema_for::<Network>(), false);
show_diff_for("Protocol", gen.root_schema_for::<Protocol>(), true);
show_diff_for("Proxy", gen.root_schema_for::<Proxy>(), false);

for key in objects.keys() {
eprintln!(
"show_diff_for(\"{}\", gen.root_schema_for::<{}>(), false);",
key, key
);
}

assert!(objects.is_empty())
}
24 changes: 15 additions & 9 deletions model/src/activity.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
pub mod activity_state;
pub mod activity_usage;
//! The Activity API.

mod activity_state;
mod activity_usage;
mod create_activity;

#[cfg(feature = "sgx")]
#[doc(hidden)]
pub mod encrypted;
pub mod exe_script_command;
pub mod exe_script_command_result;
pub mod exe_script_command_state;
pub mod exe_script_request;
pub mod provider_event;
pub mod runtime_event;
mod exe_script_command;
mod exe_script_command_result;
mod exe_script_command_state;
mod exe_script_request;
mod provider_event;
mod runtime_event;
#[cfg(feature = "sgx")]
#[doc(hidden)]
mod sgx_credentials;

pub use self::activity_state::{ActivityState, State, StatePair};
Expand All @@ -20,9 +25,10 @@ pub use self::exe_script_command::{ExeScriptCommand, FileSet, SetEntry, SetObjec
pub use self::exe_script_command_result::{CommandOutput, CommandResult, ExeScriptCommandResult};
pub use self::exe_script_command_state::ExeScriptCommandState;
pub use self::exe_script_request::ExeScriptRequest;
pub use self::provider_event::ProviderEvent;
pub use self::provider_event::{ProviderEvent, ProviderEventType};
pub use self::runtime_event::{RuntimeEvent, RuntimeEventKind};
#[cfg(feature = "sgx")]
pub use self::sgx_credentials::SgxCredentials;

#[doc(hidden)]
pub const ACTIVITY_API_PATH: &str = "/activity-api/v1";
25 changes: 15 additions & 10 deletions model/src/activity/activity_state.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
/*
* Yagna Activity API
*
* It conforms with capability level 1 of the [Activity API specification](https://golem-network.gitbook.io/golem-internal-documentation-test/golem-activity-protocol/golem-activity-api).
*
* The version of the OpenAPI document: v1
*
* Generated by: https://openapi-generator.tech
*/

use serde::{Deserialize, Serialize};

/// Reported activity state
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActivityState {
/// Pair with current state and optional pending state.
#[serde(rename = "state")]
pub state: StatePair,
/// Reason for Activity termination (specified when Activity in Terminated state).
Expand All @@ -23,6 +15,7 @@ pub struct ActivityState {
}

impl ActivityState {
/// `true` if activity is terminated or during termination.
pub fn alive(&self) -> bool {
self.state.alive()
}
Expand All @@ -48,19 +41,22 @@ impl From<StatePair> for ActivityState {
}
}

/// Pair with current state and optional pending state.
#[derive(
Clone, Copy, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
)]
pub struct StatePair(pub State, pub Option<State>);

impl StatePair {
/// `true` if activity is terminated or during termination.
pub fn alive(&self) -> bool {
!matches!(
(&self.0, &self.1),
(State::Terminated, _) | (_, Some(State::Terminated))
)
}

/// Creates transition state from current state to new state.
pub fn to_pending(&self, state: State) -> Self {
StatePair(self.0, Some(state))
}
Expand All @@ -72,15 +68,24 @@ impl From<State> for StatePair {
}
}

/// Represents activity state.
#[derive(
Clone, Default, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
)]
pub enum State {
/// Activity is new and uninitialized.
#[default]
New,
/// Activity is configured (agreement data is read).
Initialized,
/// Activity is ready to start, deploy command ends successfully.
/// Activity can be started with start command.
Deployed,
/// Activity is running.
Ready,
/// Activity is terminated.
Terminated,
/// Running activity that for some reason
/// is not reporting its state for some time.
Unresponsive,
}
2 changes: 2 additions & 0 deletions model/src/activity/activity_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

use serde::{Deserialize, Serialize};

/// Struct for reporting current usage vector.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActivityUsage {
/// Current usage vector
#[serde(rename = "currentUsage", skip_serializing_if = "Option::is_none")]
pub current_usage: Option<Vec<f64>>,
/// Report timestamp in number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka “UNIX timestamp”).
#[serde(rename = "timestamp")]
pub timestamp: i64,
}
9 changes: 9 additions & 0 deletions model/src/activity/create_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "sgx")]
use crate::activity::sgx_credentials::SgxCredentials;

/// Create new activity request.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateActivityRequest {
/// Agreement identifier for which we want to create activity.
#[serde(rename = "agreementId")]
pub agreement_id: String,
/// For secure computing (sgx) scenario, it is requestor public key needed for e2e encyprtion.
#[serde(rename = "requestorPubKey", skip_serializing_if = "Option::is_none")]
pub requestor_pub_key: Option<String>,
}

impl CreateActivityRequest {
/// New request for given agreement id.
pub fn new(agreement_id: String) -> CreateActivityRequest {
CreateActivityRequest {
agreement_id,
Expand All @@ -20,15 +24,19 @@ impl CreateActivityRequest {
}
}

/// Create new activity response.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CreateActivityResult {
/// Id of new activity.
#[serde(rename = "activityId")]
pub activity_id: String,
/// For secure computing (sgx) scenario, it is compute unit credentials.
#[serde(rename = "credentials", skip_serializing_if = "Option::is_none")]
pub credentials: Option<Credentials>,
}

impl CreateActivityResult {
/// Creates result for simple scenario
pub fn new(activity_id: String) -> CreateActivityResult {
CreateActivityResult {
activity_id,
Expand All @@ -37,6 +45,7 @@ impl CreateActivityResult {
}
}

#[doc(hidden)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Credentials {
Expand Down
Loading