Skip to content
Merged
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
4,151 changes: 4,151 additions & 0 deletions openapi/management-api.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2026 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/

package com.metaformsystems.redline.client.dataplane;

import com.metaformsystems.redline.client.dataplane.dto.UploadResponse;
import com.metaformsystems.redline.client.management.dto.QuerySpec;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

public interface DataPlaneApiClient {
/**
* This is used on the provider side to upload files, such as PDFs etc.
*
* @param metadata optional metadata to describe the file
* @param data an input stream of the file data
*/
UploadResponse uploadMultipart(String participantContextId, Map<String, String> metadata, InputStream data);

/**
* This is used on the provider side to list all uploaded files
*/
List<UploadResponse> getAllUploads();

/**
* This method is used on the consumer side to query all files that are offered on the network
*/
List<UploadResponse> queryProviderFiles(String participantContextId, QuerySpec querySpec);

/**
* Downloads a file from the provider's dataplane
*
* @param fileId the id of the file to download
*/
byte[] downloadFile(String authToken, String fileId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2026 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/

package com.metaformsystems.redline.client.dataplane;

import com.metaformsystems.redline.client.TokenProvider;
import com.metaformsystems.redline.client.dataplane.dto.UploadResponse;
import com.metaformsystems.redline.client.management.dto.QuerySpec;
import com.metaformsystems.redline.repository.ParticipantRepository;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

@Component
public class DataPlaneApiClientImpl implements DataPlaneApiClient {
private final WebClient dataPlaneWebClient;
private final ParticipantRepository participantRepository;
private final TokenProvider tokenProvider;

public DataPlaneApiClientImpl(WebClient dataPlaneWebClient, ParticipantRepository participantRepository, TokenProvider tokenProvider) {
this.dataPlaneWebClient = dataPlaneWebClient.mutate()
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(50 * 1024 * 1024))
.build())
.build();
this.participantRepository = participantRepository;
this.tokenProvider = tokenProvider;
}

@Override
public UploadResponse uploadMultipart(String participantContextId, Map<String, String> metadata, InputStream data) {
var bodyBuilder = new MultipartBodyBuilder();

// Add metadata fields
if (metadata != null) {
bodyBuilder.part("metadata", metadata);
}

// Add file data
bodyBuilder
.part("file", new InputStreamResource(data))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);

return dataPlaneWebClient.post()
.uri("/app/internal/api/control/certs")
.header("Authorization", "Bearer " + getToken(participantContextId))
.contentType(MediaType.MULTIPART_FORM_DATA)
.bodyValue(bodyBuilder.build())
.retrieve()
.bodyToMono(UploadResponse.class)
.block();
}

@Override
public List<UploadResponse> getAllUploads() {
return dataPlaneWebClient.post()
.uri("/app/internal/api/control/certs/request")
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<UploadResponse>>() {
})
.block();
}

@Override
public List<UploadResponse> queryProviderFiles(String participantContextId, QuerySpec querySpec) {
return dataPlaneWebClient.post()
.uri("/app/internal/api/control/certs/request")
.bodyValue(querySpec)
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<UploadResponse>>() {
})
.block();
}

@Override
public byte[] downloadFile(String authToken, String fileId) {

Flux<DataBuffer> dataBufferFlux = dataPlaneWebClient.get()
.uri("/app/public/api/data/certs/" + fileId)
.header("Authorization", authToken)
.retrieve()
.bodyToFlux(DataBuffer.class);

return DataBufferUtils.join(dataBufferFlux)
.map(dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
return bytes;
})
.block();
}

private String getToken(String participantContextId) {
var participantProfile = participantRepository.findByParticipantContextId(participantContextId)
.orElseThrow(() -> new IllegalArgumentException("Participant not found with context id: " + participantContextId));

return tokenProvider.getToken(participantProfile.getClientCredentials().clientId(), participantProfile.getClientCredentials().clientSecret(), "management-api:write management-api:read");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2026 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/

package com.metaformsystems.redline.client.dataplane.dto;

import java.util.Map;

public record UploadResponse(String id, String contentType, Map<String, Object> properties) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2026 Metaform Systems, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
*
*/

package com.metaformsystems.redline.client.management;

import com.metaformsystems.redline.client.management.dto.Catalog;
import com.metaformsystems.redline.client.management.dto.NewAsset;
import com.metaformsystems.redline.client.management.dto.NewCelExpression;
import com.metaformsystems.redline.client.management.dto.NewContractDefinition;
import com.metaformsystems.redline.client.management.dto.NewPolicyDefinition;
import com.metaformsystems.redline.client.management.dto.QuerySpec;
import com.metaformsystems.redline.dao.DataplaneRegistration;

import java.util.List;
import java.util.Map;

public interface ManagementApiClient {
// Assets
void createAsset(String participantContextId, NewAsset asset);

List<Map<String, Object>> queryAssets(String participantContextId, QuerySpec query);

void deleteAsset(String participantContextId, String assetId);

// Policy Definitions
void createPolicy(String participantContextId, NewPolicyDefinition policy);

List<Map<String, Object>> queryPolicyDefinitions(String participantContextId, QuerySpec query);

void deletePolicyDefinition(String participantContextId, String policyId);

// Contract Definitions
void createContractDefinition(String participantContextId, NewContractDefinition contractDefinition);

List<Map<String, Object>> queryContractDefinitions(String participantContextId, QuerySpec query);

void deleteContractDefinition(String participantContextId, String contractDefinitionId);

// Contract Negotiations
void initiateContractNegotiation(String participantContextId, Map<String, Object> negotiationRequest);

Map<String, Object> getContractNegotiation(String participantContextId, String negotiationId);

List<Map<String, Object>> queryContractNegotiations(String participantContextId, QuerySpec query);

// CEL expressions
void createCelExpression(NewCelExpression celExpression);

// Catalog
Catalog getCatalog(String participantContextId, String counterPartyId);

// others
void prepareDataplane(String participantContextId, DataplaneRegistration dataplaneRegistration);

Object getData(String participantContextId, String counterPartyId, String offerId);

Map<String, String> setupTransfer(String participantContextId, String policyId, String providerId);
}
Loading
Loading