Skip to content

Commit

Permalink
implement Match module functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidd committed Sep 23, 2015
1 parent 9283ad1 commit 36f8e93
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/com/suse/saltstack/netapi/calls/modules/Match.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> compound(String tgt, Optional<String> minionId) {
LinkedHashMap<String, Object> 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<Boolean>(){});
}

public static LocalCall<Boolean> compound(String tgt) {
return compound(tgt, Optional.empty());
}

public static LocalCall<Boolean> glob(String tgt, Optional<String> minionId) {
LinkedHashMap<String, Object> 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<Boolean>(){});
}

public static LocalCall<Boolean> glob(String tgt) {
return glob(tgt, Optional.empty());
}

public static LocalCall<Boolean> grain(String tgt, Optional<String> delimiter) {
LinkedHashMap<String, Object> 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<Boolean>(){});
}

public static LocalCall<Boolean> list(List<String> tgt, Optional<String> minionId) {
LinkedHashMap<String, Object> 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<Boolean>(){});
}

public static LocalCall<Boolean> list(String... tgt) {
return list(Arrays.asList(tgt), Optional.empty());
}
}

0 comments on commit 36f8e93

Please sign in to comment.