Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refactoring the SD-Factory #71

Merged
merged 17 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
20 changes: 12 additions & 8 deletions .github/workflows/helm-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ on:
required: false
type: string
upgrade_from:
description: 'portal chart version to upgrade from'
# portal version from 3.1 release
default: '1.3.0'
description: 'SD Factory chart version to upgrade from'
# SD Factory version from 3.2 release
default: '2.1.7'
required: false
type: string

Expand Down Expand Up @@ -90,13 +90,17 @@ jobs:
- name: Run chart-testing (lint)
run: ct lint --charts charts/sdfactory --config charts/chart-testing-config.yaml

# Preparing a kind cluster to install and test charts on
- name: Create kind cluster
uses: helm/[email protected]
if: ${{ env.CHART_CHANGED == 'true' }}

# install the chart to the kind cluster and run helm test
# define charts to test with the --charts parameter
- name: Run chart-testing (install)
run: ct install --charts charts/sdfactory --config charts/chart-testing-config.yaml --helm-extra-set-args "--set=image.tag=testing --set=image.repository=kind-registry:5000/sdfactory"
if: ${{ env.CHART_CHANGED == 'true' }}
if: github.event_name != 'pull_request' || steps.list-changed.outputs.changed == 'true'
# Upgrade the released chart version with the locally available chart
# default value for event_name != workflow_dispatch
- name: Run helm upgrade
run: |
helm repo add tractusx-dev https://eclipse-tractusx.github.io/charts/dev
helm install sdf tractusx-dev/sdfactory
helm upgrade sdf charts/sdfactory
if: github.event_name != 'pull_request' || steps.list-changed.outputs.changed == 'true'
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]
- NA

## [2.1.7] - 2023-10-05

### Added
- Unification of SDFactory versions for different contexts and MIW
- Added support for FC schema.
- Added type to the subject
- Added BPN to the ServiceOffering subject as it was before

### Changed
- Updated helm lint

### Removed
- Disable signing VC

## [2.1.6] - 2023-08-21

Expand Down
157 changes: 77 additions & 80 deletions DEPENDENCIES
almadigabor marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ further processing.
## Software Version

```shell
Software version: 2.1.6
Helm Chart version: 2.1.7
Software version: 2.1.7
Helm Chart version: 2.1.8

```

Expand Down
4 changes: 2 additions & 2 deletions charts/sdfactory/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ sources:
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)

version: "2.1.7"
version: "2.1.8"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.

appVersion: "2.1.6"
appVersion: "2.1.7"
2 changes: 1 addition & 1 deletion charts/sdfactory/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sdfactory

![Version: 2.1.7](https://img.shields.io/badge/Version-2.1.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.1.6](https://img.shields.io/badge/AppVersion-2.1.6-informational?style=flat-square)
![Version: 2.1.8](https://img.shields.io/badge/Version-2.1.8-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.1.7](https://img.shields.io/badge/AppVersion-2.1.7-informational?style=flat-square)

Helm Charts for SD Factory application. Self-Description Factory component is responsible for the creation of Self Descriptions.

Expand Down
102 changes: 27 additions & 75 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<version>3.1.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tsystems</groupId>
<artifactId>sd-factory</artifactId>
<version>2.1.6</version>
<version>2.1.7</version>
<description>Self-Description Hub Prototype</description>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
<resource.delimiter>^</resource.delimiter>
<spring-cloud.version>2022.0.1</spring-cloud.version>
<spring-cloud.version>2022.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -32,11 +32,6 @@
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
Expand Down Expand Up @@ -85,23 +80,23 @@
<dependency>
<groupId>com.danubetech</groupId>
<artifactId>verifiable-credentials-java</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>4.0.3</version>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<artifactId>protobuf-javalite</artifactId>
<version>3.22.3</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
Expand All @@ -128,73 +123,30 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-core</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.22.3</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>21.1.1</version>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.4.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
<id>danubetech-maven-public</id>
Expand Down Expand Up @@ -248,8 +200,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022,2023 T-Systems International GmbH
* Copyright (c) 2022,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2022 T-Systems International GmbH
* Copyright (c) 2021,2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -18,61 +18,72 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.selfdescriptionfactory.service;
package org.eclipse.tractusx.selfdescriptionfactory;

import com.danubetech.verifiablecredentials.CredentialSubject;
import com.danubetech.verifiablecredentials.VerifiableCredential;
import foundation.identity.jsonld.JsonLDUtils;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.selfdescriptionfactory.api.vrel3.ApiApiDelegate;
import org.eclipse.tractusx.selfdescriptionfactory.model.vrel3.SelfdescriptionPostRequest;
import org.eclipse.tractusx.selfdescriptionfactory.service.clearinghouse.ClearingHouse;
import org.eclipse.tractusx.selfdescriptionfactory.service.wallet.CustodianWallet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.core.convert.ConversionService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.UUID;
import java.util.*;

/**
* A service to create and manipulate of Self-Description document
*/
@Service
@RequiredArgsConstructor
@Slf4j
@Profile("catena-x-ctx")
public class SDFactoryCatenaX implements SDFactory{
public class SDFactory implements ApiApiDelegate {
@Value("${app.verifiableCredentials.durationDays:90}")
private int duration;

private final CustodianWallet custodianWallet;
private final ConversionService conversionService;
private final ClearingHouse clearingHouse;

@Override
@PreAuthorize("hasAuthority(@securityRoles.createRole)")
public void createVC(Object document) {
var claimsHolder = Optional.ofNullable(conversionService.convert(document, Claims.class)).orElseThrow();
var claims = new LinkedHashMap<>(claimsHolder.claims());
var holder = claims.remove("holder");
var issuer = claims.remove("issuer");
var externalId = claims.remove("externalId");
var credentialSubject = CredentialSubject.fromJsonObject(claims);
@Override
public ResponseEntity<Void> selfdescriptionPost(SelfdescriptionPostRequest selfdescriptionPostRequest) {
var processed = Objects.requireNonNull(conversionService.convert(selfdescriptionPostRequest, SelfDescription.class), "Converted SD-Document is null. Very strange");
var verifiableCredential = VerifiableCredential.builder()
.contexts(claimsHolder.vocabularies())
.contexts(processed.getContexts())
.id(URI.create("http://example.org/" + UUID.randomUUID()))
.issuer(URI.create(processed.getIssuer()))
.issuanceDate(new Date())
.id(URI.create(UUID.randomUUID().toString()))
.expirationDate(Date.from(Instant.now().plus(Duration.ofDays(duration))))
.credentialSubject(credentialSubject)
.credentialSubject(CredentialSubject.fromJsonObject(processed))
.type(processed.getType())
.build();
JsonLDUtils.jsonLdAdd(verifiableCredential, "issuer", issuer);
//var vc = custodianWallet.getSignedVC(verifiableCredential);
clearingHouse.sendToClearingHouse(verifiableCredential, externalId.toString());
// This call signs the VC at MIW as it was in versions prior to CH
// var verifiableCredentialSigned = custodianWallet.getSignedVC(verifiableCredential);
clearingHouse.sendToClearingHouse(verifiableCredential, processed.getExternalId());

return new ResponseEntity<>(HttpStatus.ACCEPTED);
}

@Getter
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class SelfDescription extends LinkedHashMap<String, Object> {
private final List<URI> contexts;
private final String holder;
private final String issuer;
private final String externalId;
private final String type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
import com.fasterxml.jackson.databind.json.JsonMapper;
import feign.Feign;
import feign.Target;
import feign.form.spring.SpringFormEncoder;
import org.eclipse.tractusx.selfdescriptionfactory.service.keycloak.KeycloakClient;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -44,9 +49,11 @@ ObjectMapper nonNullObjectMapper() {
}

@Bean
public KeycloakClient keycloakClient(ObjectFactory<HttpMessageConverters> converters){
public KeycloakClient keycloakClient(ObjectFactory<HttpMessageConverters> converters, ObjectProvider<HttpMessageConverterCustomizer> customizerProvider){
return Feign.builder()
.decoder(new SpringDecoder(converters))
.decoder(new SpringDecoder(converters, customizerProvider))
.encoder(new SpringFormEncoder(new SpringEncoder(converters)))
.contract(new SpringMvcContract())
.target(Target.EmptyTarget.create(KeycloakClient.class));
}
}
Loading