Skip to content

Commit

Permalink
chore: update edc 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed May 27, 2024
1 parent 9617751 commit 6c201f6
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 75 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
connector/.gradle
connector/build
testing/connector/.gradle
testing/connector/build
.idea
57 changes: 47 additions & 10 deletions edc-connector-client/src/types/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,13 @@ pub struct Permission {
#[serde(rename = "constraint", alias = "odrl:constraint", default)]
constraints: Vec<Constraint>,
#[serde(alias = "odrl:action")]
#[serde(deserialize_with = "crate::types::policy::odrl::action_deserializer")]
action: Action,
}

impl Permission {
pub fn builder() -> PermissionBuilder {
PermissionBuilder(Permission {
action: Action::new("use".to_string()),
action: Action::new("http://www.w3.org/ns/odrl/2/use".to_string()),
constraints: vec![],
})
}
Expand Down Expand Up @@ -288,18 +287,28 @@ impl PermissionBuilder {
}
}

#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct Action(String);
#[derive(Debug, Serialize, PartialEq, Clone, Deserialize)]
#[serde(untagged)]
pub enum Action {
Simple(String),
Id {
#[serde(rename = "@id")]
id: String,
},
}

impl Action {
pub fn id(&self) -> &String {
&self.0
match self {
Action::Simple(id) => id,
Action::Id { id } => id,
}
}
}

impl Action {
pub fn new(kind: String) -> Self {
Action(kind)
Action::Id { id: kind }
}
}

Expand All @@ -309,10 +318,30 @@ pub enum Constraint {
Atomic(AtomicConstraint),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum LeftOperand {
Simple(String),
Id {
#[serde(rename = "@id")]
id: String,
},
}

impl LeftOperand {
pub fn simple(op: &str) -> LeftOperand {
LeftOperand::Simple(op.to_string())
}

pub fn id(op: &str) -> LeftOperand {
LeftOperand::Id { id: op.to_string() }
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct AtomicConstraint {
#[serde(rename = "leftOperand", alias = "odrl:leftOperand")]
left_operand: String,
left_operand: LeftOperand,
#[serde(alias = "odrl:operator")]
operator: Operator,
#[serde(rename = "rightOperand", alias = "odrl:rightOperand")]
Expand Down Expand Up @@ -342,21 +371,29 @@ impl Operator {
impl AtomicConstraint {
pub fn new<T: ToValue>(left_operand: &str, operator: &str, right_operand: T) -> Self {
AtomicConstraint::new_with_operator(
left_operand,
LeftOperand::Simple(left_operand.to_string()),
Operator::Simple(operator.to_string()),
right_operand,
)
}

pub fn new_with_operator<T: ToValue>(
left_operand: &str,
left_operand: impl Into<LeftOperand>,
operator: Operator,
right_operand: T,
) -> Self {
Self {
left_operand: left_operand.to_string(),
left_operand: left_operand.into(),
operator,
right_operand: PropertyValue(right_operand.into_value()),
}
}
}

impl From<&str> for LeftOperand {
fn from(value: &str) -> Self {
LeftOperand::Id {
id: value.to_string(),
}
}
}
54 changes: 4 additions & 50 deletions edc-connector-client/src/types/policy/odrl.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@
use std::fmt;

use serde::{
de::{MapAccess, Visitor},
Deserializer,
};

use crate::types::policy::Action;

pub(crate) fn action_deserializer<'de, D>(deserializer: D) -> Result<Action, D::Error>
where
D: Deserializer<'de>,
{
struct ActionVisitor;

impl<'de> Visitor<'de> for ActionVisitor {
type Value = Action;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("string or map")
}

fn visit_str<E>(self, value: &str) -> Result<Action, E>
where
E: serde::de::Error,
{
Ok(Action(value.to_string()))
}

fn visit_map<M>(self, mut map: M) -> Result<Action, M::Error>
where
M: MapAccess<'de>,
{
let mut action = None;
while let Some(key) = map.next_key::<String>()? {
match key.as_str() {
"action" | "odrl:type" | "type" => action = Some(Action(map.next_value()?)),
_ => {}
}
}
action.ok_or_else(|| serde::de::Error::missing_field("action"))
}
}

deserializer.deserialize_any(ActionVisitor)
}

#[cfg(test)]
mod tests {
use serde_json::json;
Expand All @@ -71,7 +24,6 @@ mod tests {

let policy = serde_json::from_value::<Policy>(json).unwrap();

dbg!(&policy);
assert_eq!(policy.kind(), &PolicyKind::Set);
assert_eq!(policy.permissions().len(), 1);

Expand Down Expand Up @@ -99,10 +51,12 @@ mod tests {
"@type": "odrl:Set",
"odrl:permission": {
"odrl:action": {
"odrl:type": "http://www.w3.org/ns/odrl/2/use"
"@id": "http://www.w3.org/ns/odrl/2/use"
},
"odrl:constraint": {
"odrl:leftOperand": "https://w3id.org/edc/v0.0.1/ns/foo",
"odrl:leftOperand": {
"@id": "https://w3id.org/edc/v0.0.1/ns/foo"
},
"odrl:operator": {
"@id": "odrl:eq"
},
Expand Down
4 changes: 2 additions & 2 deletions edc-connector-client/tests/policy-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ mod get {

let permission = &definition.policy().permissions()[0];

assert_eq!(permission.action().id(), "http://www.w3.org/ns/odrl/2/use");
assert_eq!(permission.action().id(), "odrl:use");
assert_eq!(permission.constraints().len(), 1);

let constraint = &permission.constraints()[0];

assert_eq!(
constraint,
&Constraint::Atomic(AtomicConstraint::new_with_operator(
"https://w3id.org/edc/v0.0.1/ns/foo",
"edc:foo",
Operator::id("odrl:eq"),
"bar"
))
Expand Down
11 changes: 7 additions & 4 deletions testing/conf/consumer-connector.config/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ edc.receiver.http.endpoint=http://host.docker.internal:19999

edc.public.key.alias=public-key

edc.transfer.dataplane.token.signer.privatekey.alias=1
edc.transfer.dataplane.sync.endpoint=http://consumer-connector:9291/public

edc.transfer.proxy.token.signer.privatekey.alias=sync-transfer
edc.transfer.proxy.token.signer.privatekey.alias=sync-transfer-private-key
edc.transfer.proxy.token.verifier.publickey.alias=sync-transfer-public-key
edc.transfer.dataplane.sync.endpoint=http://consumer-connector:9291/public

web.http.public.port=9291
web.http.public.path=/public
Expand All @@ -38,3 +36,8 @@ edc.negotiation.state-machine.iteration-wait-millis=100
edc.transfer.send.retry.limit=1
edc.transfer.send.retry.base-delay.ms=10
edc.transfer.state-machine.iteration-wait-millis=10

testing.edc.vaults.1.key=sync-transfer-private-key
testing.edc.vaults.1.value=sync-transfer
testing.edc.vaults.2.key=sync-transfer-public-key
testing.edc.vaults.2.value=sync-transfer-public
Binary file not shown.
11 changes: 7 additions & 4 deletions testing/conf/provider-connector.config/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ edc.receiver.http.endpoint=http://host.docker.internal:19999

edc.public.key.alias=public-key

edc.transfer.dataplane.token.signer.privatekey.alias=1
edc.transfer.dataplane.sync.endpoint=http://provider-connector:9192/public

edc.transfer.proxy.token.signer.privatekey.alias=sync-transfer
edc.transfer.proxy.token.signer.privatekey.alias=sync-transfer-private-key
edc.transfer.proxy.token.verifier.publickey.alias=sync-transfer-public-key
edc.transfer.dataplane.sync.endpoint=http://provider-connector:9192/public

web.http.public.port=9291
web.http.public.path=/public
Expand All @@ -38,3 +36,8 @@ edc.negotiation.state-machine.iteration-wait-millis=100
edc.transfer.send.retry.limit=1
edc.transfer.send.retry.base-delay.ms=10
edc.transfer.state-machine.iteration-wait-millis=10

testing.edc.vaults.1.key=sync-transfer-private-key
testing.edc.vaults.1.value=-----BEGIN PRIVATE KEY-----\r\nMC4CAQAwBQYDK2VwBCIEIMDCT6pEU+PD+sWmKNhz4Fbwhh6V3QUO4smT+BAFwQFd\r\n-----END PRIVATE KEY-----
testing.edc.vaults.2.key=sync-transfer-public-key
testing.edc.vaults.2.value=-----BEGIN PUBLIC KEY-----\r\nMCowBQYDK2VwAyEAqloQFekUvv9rWGfiSYmnX1lhYxxvzklW1+dk02/Koes=\r\n-----END PUBLIC KEY-----
1 change: 0 additions & 1 deletion testing/connector/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies {
implementation(libs.edc.control.plane.edr.receiver)
implementation(libs.edc.dsp)
implementation(libs.edc.configuration.filesystem)
implementation(libs.edc.vault.filesystem)
implementation(libs.edc.iam.mock)
implementation(libs.edc.management.api)
implementation(libs.edc.cache.api)
Expand Down
3 changes: 1 addition & 2 deletions testing/connector/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format.version = "1.1"

[versions]
edc = "0.6.3"
edc = "0.7.0"
shadow = "8.1.1"

[libraries]
Expand All @@ -12,7 +12,6 @@ edc-control-plane-core = { module = "org.eclipse.edc:control-plane-core", versio
edc-control-plane-edr-receiver = { module = "org.eclipse.edc:edr-store-receiver", version.ref = "edc" }
edc-dsp = { module = "org.eclipse.edc:dsp", version.ref = "edc" }
edc-configuration-filesystem = { module = "org.eclipse.edc:configuration-filesystem", version.ref = "edc" }
edc-vault-filesystem = { module = "org.eclipse.edc:vault-filesystem", version.ref = "edc" }
edc-iam-mock = { module = "org.eclipse.edc:iam-mock", version.ref = "edc" }
edc-management-api = { module = "org.eclipse.edc:management-api", version.ref = "edc" }
edc-cache-api = { module = "org.eclipse.edc:edr-cache-api", version.ref = "edc" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.testing.edc;

import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;

import java.util.Map;

public class VaultSeedExtension implements ServiceExtension {


public static final String VAULT_TESTING_PREFIX = "testing.edc.vaults";

public static final String VAULT_TESTING_KEY = "key";
public static final String VAULT_TESTING_VALUE = "value";

@Inject
private Vault vault;


@Override
public void initialize(ServiceExtensionContext context) {
ServiceExtension.super.initialize(context);

var config = context.getConfig(VAULT_TESTING_PREFIX);
var secrets = config.partition().map((partition) -> {
var key = partition.getString(VAULT_TESTING_KEY);
var value = partition.getString(VAULT_TESTING_VALUE);
return Map.entry(key,value);
}).toList();

secrets.forEach(secret -> vault.storeSecret(secret.getKey(), secret.getValue()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

org.testing.edc.VaultSeedExtension
1 change: 1 addition & 0 deletions testing/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- "29193:9193" # connector management
- "29194:9194" # connector protocol
- "29291:9291" # data-plane public
- "1044:1044" # data-plane public
environment:
EDC_VAULT: /config/vault.properties
EDC_KEYSTORE: /config/vault-keys.p12
Expand Down

0 comments on commit 6c201f6

Please sign in to comment.