Skip to content

Commit

Permalink
Set opcode on import
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie authored Dec 15, 2023
1 parent 08032ef commit 751e327
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/aserto/directory/v3/DirectoryClient.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/aserto/model/ImportElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -22,4 +26,8 @@ public Object getObject() {
public Relation getRelation() {
return relation;
}

public Opcode getOpcode() {
return opcode;
}
}
17 changes: 10 additions & 7 deletions src/test/java/DirectoryClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -428,13 +429,15 @@ private List<ImportElement> importCitadelDataList() {
Relation mortyEditorRelation = Directory.buildRelation("group", "editor", "member", "user", "[email protected]");
Relation managerRelation = Directory.buildRelation("user", "[email protected]", "manager", "user", "[email protected]");

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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/utils/Topaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 751e327

Please sign in to comment.