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 4113290
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
61 changes: 61 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,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<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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ public static ParameterizedType parameterizedType(Type ownerType, Type rawType,
Type... typeArguments) {
return newParameterizedTypeWithOwner(ownerType, rawType, typeArguments);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ public void testStreamToString() {
new ByteArrayInputStream(TEST_STRING.getBytes()));
assertEquals("Result doesn't match test string", TEST_STRING, result);
}

}

0 comments on commit 4113290

Please sign in to comment.