diff --git a/src/main/java/com/suse/saltstack/netapi/calls/modules/Match.java b/src/main/java/com/suse/saltstack/netapi/calls/modules/Match.java new file mode 100644 index 000000000..1b350dde3 --- /dev/null +++ b/src/main/java/com/suse/saltstack/netapi/calls/modules/Match.java @@ -0,0 +1,61 @@ +package com.suse.saltstack.netapi.calls.modules; + +import com.google.gson.reflect.TypeToken; +import com.suse.saltstack.netapi.calls.LocalCall; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * salt.modules.match + */ +public class Match { + + public static LocalCall compound(String tgt, Optional minionId) { + LinkedHashMap args = new LinkedHashMap<>(); + args.put("tgt", tgt); + minionId.ifPresent(id -> args.put("minion_id", id)); + return new LocalCall<>("match.compound", Optional.empty(), + Optional.of(args), new TypeToken(){}); + } + + public static LocalCall compound(String tgt) { + return compound(tgt, Optional.empty()); + } + + + public static LocalCall glob(String tgt, Optional minionId) { + LinkedHashMap args = new LinkedHashMap<>(); + args.put("tgt", tgt); + minionId.ifPresent(id -> args.put("minion_id", id)); + return new LocalCall<>("match.glob", Optional.empty(), + Optional.of(args), new TypeToken(){}); + } + + public static LocalCall glob(String tgt) { + return glob(tgt, Optional.empty()); + } + + public static LocalCall grain(String tgt, Optional delimiter) { + LinkedHashMap args = new LinkedHashMap<>(); + args.put("tgt", tgt); + delimiter.ifPresent(d -> args.put("delimiter", d)); + return new LocalCall<>("match.grain", Optional.empty(), + Optional.of(args), new TypeToken(){}); + } + + public static LocalCall list(List tgt, Optional minionId) { + LinkedHashMap args = new LinkedHashMap<>(); + args.put("tgt", tgt.stream().collect(Collectors.joining(","))); + minionId.ifPresent(id -> args.put("minion_id", id)); + return new LocalCall<>("match.list", Optional.empty(), + Optional.of(args), new TypeToken(){}); + } + + public static LocalCall list(String... tgt) { + return list(Arrays.asList(tgt), Optional.empty()); + } +} diff --git a/src/test/java/com/suse/saltstack/netapi/utils/ClientUtilsTest.java b/src/test/java/com/suse/saltstack/netapi/utils/ClientUtilsTest.java index a7a0bbcf8..f7a6cee0d 100644 --- a/src/test/java/com/suse/saltstack/netapi/utils/ClientUtilsTest.java +++ b/src/test/java/com/suse/saltstack/netapi/utils/ClientUtilsTest.java @@ -63,5 +63,4 @@ public void testStreamToString() { new ByteArrayInputStream(TEST_STRING.getBytes())); assertEquals("Result doesn't match test string", TEST_STRING, result); } - }