From 751e3277b3b528ca38f4cf336814707a03f7641d Mon Sep 17 00:00:00 2001 From: Bogdan Irimie Date: Fri, 15 Dec 2023 10:21:22 +0200 Subject: [PATCH] Set opcode on import --- .../aserto/directory/v3/DirectoryClient.java | 5 +++-- .../java/com/aserto/model/ImportElement.java | 12 ++++++++++-- src/test/java/DirectoryClientTest.java | 17 ++++++++++------- src/test/java/utils/Topaz.java | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/aserto/directory/v3/DirectoryClient.java b/src/main/java/com/aserto/directory/v3/DirectoryClient.java index b34cbe9..6ca1553 100644 --- a/src/main/java/com/aserto/directory/v3/DirectoryClient.java +++ b/src/main/java/com/aserto/directory/v3/DirectoryClient.java @@ -1,5 +1,6 @@ package com.aserto.directory.v3; +import com.aserto.directory.importer.v3.Opcode; import com.aserto.utils.MessageChunker; import com.aserto.directory.common.v3.ObjectIdentifier; import com.aserto.directory.common.v3.PaginationRequest; @@ -385,9 +386,9 @@ public void onCompleted() { importStream.forEach(importElement -> { if (importElement.getObject() != null) { - writer.onNext(ImportRequest.newBuilder().setObject(importElement.getObject()).build()); + writer.onNext(ImportRequest.newBuilder().setOpCode(importElement.getOpcode()).setObject(importElement.getObject()).build()); } else if (importElement.getRelation() != null) { - writer.onNext(ImportRequest.newBuilder().setRelation(importElement.getRelation()).build()); + writer.onNext(ImportRequest.newBuilder().setOpCode(importElement.getOpcode()).setRelation(importElement.getRelation()).build()); } }); writer.onCompleted(); diff --git a/src/main/java/com/aserto/model/ImportElement.java b/src/main/java/com/aserto/model/ImportElement.java index 5531ce7..73cfcbe 100644 --- a/src/main/java/com/aserto/model/ImportElement.java +++ b/src/main/java/com/aserto/model/ImportElement.java @@ -2,17 +2,21 @@ import com.aserto.directory.common.v3.Object; import com.aserto.directory.common.v3.Relation; +import com.aserto.directory.importer.v3.Opcode; public class ImportElement { private Object object; private Relation relation; + private Opcode opcode; - public ImportElement(Object object) { + public ImportElement(Object object, Opcode opcode) { this.object = object; + this.opcode = opcode; } - public ImportElement(Relation relation){ + public ImportElement(Relation relation, Opcode opcode) { this.relation = relation; + this.opcode = opcode; } public Object getObject() { @@ -22,4 +26,8 @@ public Object getObject() { public Relation getRelation() { return relation; } + + public Opcode getOpcode() { + return opcode; + } } diff --git a/src/test/java/DirectoryClientTest.java b/src/test/java/DirectoryClientTest.java index 983e788..e5a7292 100644 --- a/src/test/java/DirectoryClientTest.java +++ b/src/test/java/DirectoryClientTest.java @@ -2,6 +2,7 @@ import com.aserto.directory.common.v3.ObjectDependency; import com.aserto.directory.exporter.v3.ExportResponse; import com.aserto.directory.exporter.v3.Option; +import com.aserto.directory.importer.v3.Opcode; import com.aserto.directory.model.v3.GetManifestResponse; import com.aserto.directory.v3.Directory; import com.aserto.directory.v3.DirectoryClient; @@ -428,13 +429,15 @@ private List importCitadelDataList() { Relation mortyEditorRelation = Directory.buildRelation("group", "editor", "member", "user", "morty@the-citadel.com"); Relation managerRelation = Directory.buildRelation("user", "rick@the-citadel.com", "manager", "user", "morty@the-citadel.com"); - importElements.add(new ImportElement(rick)); - importElements.add(new ImportElement(morty)); - importElements.add(new ImportElement(adminGroup)); - importElements.add(new ImportElement(editorGroup)); - importElements.add(new ImportElement(rickAdminRelation)); - importElements.add(new ImportElement(mortyEditorRelation)); - importElements.add(new ImportElement(managerRelation)); + + Opcode opcode = Opcode.OPCODE_SET; + importElements.add(new ImportElement(rick, opcode)); + importElements.add(new ImportElement(morty, opcode)); + importElements.add(new ImportElement(adminGroup, opcode)); + importElements.add(new ImportElement(editorGroup, opcode)); + importElements.add(new ImportElement(rickAdminRelation, opcode)); + importElements.add(new ImportElement(mortyEditorRelation, opcode)); + importElements.add(new ImportElement(managerRelation, opcode)); return importElements; } diff --git a/src/test/java/utils/Topaz.java b/src/test/java/utils/Topaz.java index 3d5aefb..dac31bf 100644 --- a/src/test/java/utils/Topaz.java +++ b/src/test/java/utils/Topaz.java @@ -77,7 +77,7 @@ public Integer call() throws Exception { } private void configure() throws IOException, InterruptedException { - ProcessBuilder pb = new ProcessBuilder("topaz", "configure", "-r", "ghcr.io/aserto-policies/policy-todo:2.1.0", "-n", "todo", "-d", "-s"); + ProcessBuilder pb = new ProcessBuilder("topaz", "configure", "-r", "ghcr.io/aserto-policies/policy-todo:2.1.0", "-n", "todo", "-d", "-f"); pb.inheritIO(); Process process = pb.start(); process.waitFor();