-
Notifications
You must be signed in to change notification settings - Fork 2
feat: file upload cel expressions and constraints #28
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
Open
timdah
wants to merge
6
commits into
main
Choose a base branch
from
feat/file-upload-access-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−85
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7155713
feat: file upload cel and permissions body part
timdah 0ab4d48
fix: policy definition
timdah 014df34
e2e: include cel expression and constraint
timdah 9cd32af
test: update and add tests
timdah 1cb5a45
test: fix dataplane url
timdah 675cd08
chore: update license header
timdah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| * | ||
| * Contributors: | ||
| * Metaform Systems, Inc. - initial API and implementation | ||
| * Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - CEL and policy creation for uploaded file | ||
| * | ||
| */ | ||
|
|
||
|
|
@@ -21,13 +22,7 @@ | |
| import com.metaformsystems.redline.domain.repository.ParticipantRepository; | ||
| import com.metaformsystems.redline.infrastructure.client.dataplane.DataPlaneApiClient; | ||
| import com.metaformsystems.redline.infrastructure.client.management.ManagementApiClient; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.Asset; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.Catalog; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.CelExpression; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.ContractNegotiation; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.ContractRequest; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.TransferProcess; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.TransferRequest; | ||
| import com.metaformsystems.redline.infrastructure.client.management.dto.*; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.stereotype.Service; | ||
|
|
@@ -39,20 +34,12 @@ | |
| import java.io.InputStream; | ||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.*; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static com.metaformsystems.redline.domain.service.Constants.ASSET_PERMISSION; | ||
| import static com.metaformsystems.redline.domain.service.Constants.MEMBERSHIP_CONTRACT_DEFINITION; | ||
| import static com.metaformsystems.redline.domain.service.Constants.MEMBERSHIP_EXPRESSION; | ||
| import static com.metaformsystems.redline.domain.service.Constants.MEMBERSHIP_EXPRESSION_ID; | ||
| import static com.metaformsystems.redline.domain.service.Constants.MEMBERSHIP_POLICY; | ||
| import static com.metaformsystems.redline.domain.service.Constants.*; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't do wildcard imports. please leave individual imports in place. |
||
|
|
||
| @Service | ||
| public class DataAccessService { | ||
|
|
@@ -72,11 +59,23 @@ public DataAccessService(DataPlaneApiClient dataPlaneApiClient, WebDidResolver w | |
| } | ||
|
|
||
| @Transactional | ||
| public void uploadFileForParticipant(Long participantId, Map<String, Object> publicMetadata, Map<String, Object> privateMetadata, InputStream fileStream, String contentType, String originalFilename) { | ||
| public void uploadFileForParticipant(Long participantId, Map<String, Object> publicMetadata, Map<String, Object> privateMetadata, InputStream fileStream, String contentType, String originalFilename, List<CelExpression> celExpressions, List<PolicySet.Constraint> constraints) { | ||
|
|
||
| var participant = participantRepository.findById(participantId).orElseThrow(() -> new ObjectNotFoundException("Participant not found with id: " + participantId)); | ||
| var participantContextId = participant.getParticipantContextId(); | ||
|
|
||
|
|
||
| //-1. create CEL expressions | ||
| if (celExpressions != null) { | ||
| celExpressions.forEach(celExpression -> { | ||
| try { | ||
| managementApiClient.createCelExpression(celExpression); | ||
| } catch (WebClientResponseException.Conflict e) { | ||
| //do nothing, CEL expression already exists | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| //0. upload file to data plane | ||
| var assetId = UUID.randomUUID().toString(); | ||
| publicMetadata.put("assetId", assetId); | ||
|
|
@@ -105,16 +104,23 @@ public void uploadFileForParticipant(Long participantId, Map<String, Object> pub | |
| } | ||
|
|
||
| //2. create policy | ||
| var policy = MEMBERSHIP_POLICY; | ||
| policy.setId(UUID.randomUUID().toString()); | ||
| var policy = NewPolicyDefinition.Builder.aNewPolicyDefinition() | ||
| .id(UUID.randomUUID().toString()) | ||
| .policy(new PolicySet(List.of(new PolicySet.Permission("use", | ||
| new ArrayList<>(List.of(MEMBERSHIP_CONSTRAINT)) | ||
| )))).build(); | ||
| if (constraints != null) { | ||
| policy.getPolicy().getPermission().getFirst().getConstraint().addAll(constraints); | ||
| } | ||
| managementApiClient.createPolicy(participantContextId, policy); | ||
|
|
||
| //3. create contract definition if none exists | ||
| var contractDef = MEMBERSHIP_CONTRACT_DEFINITION; | ||
| contractDef.setId(UUID.randomUUID().toString()); | ||
| contractDef.setContractPolicyId(policy.getId()); | ||
| contractDef.setAccessPolicyId(policy.getId()); | ||
| managementApiClient.createContractDefinition(participantContextId, contractDef); | ||
| var contractDef = NewContractDefinition.Builder.aNewContractDefinition(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use builder fluently |
||
| contractDef.id(UUID.randomUUID().toString()); | ||
| contractDef.contractPolicyId(policy.getId()); | ||
| contractDef.accessPolicyId(policy.getId()); | ||
| contractDef.assetsSelector(Set.of(new Criterion("id", "=", assetId))); | ||
| managementApiClient.createContractDefinition(participantContextId, contractDef.build()); | ||
|
|
||
|
|
||
| //2. track uploaded file in DB | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at the dataAccessService, this will always create
Permissionobjects. Since we're pulling this up into the API, it would be better to accept aPolicyDefinitionobject rather than just constraints for full flexibility