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..97d5e1bcf --- /dev/null +++ b/src/main/java/com/suse/saltstack/netapi/calls/modules/Match.java @@ -0,0 +1,60 @@ +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()); + } +}