Implement uuid functionality, update api description
This commit is contained in:
parent
6753b316d1
commit
f63655bac4
@ -5,31 +5,51 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class DefaultController {
|
public class DefaultController {
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public Map<Object, Object> index() {
|
public Object index() {
|
||||||
|
|
||||||
Map<Object, Object> map = new HashMap<>();
|
class Endpoint {
|
||||||
map.put("name", "PasswordAPI");
|
public String name;
|
||||||
map.put("endpoint", "/api");
|
public Map<Object, Object> params;
|
||||||
|
}
|
||||||
|
|
||||||
Map<Object, Object> params = new HashMap<>();
|
class Api {
|
||||||
params.put("length", "int");
|
public String name;
|
||||||
params.put("upper", "[on | off]");
|
public List<Endpoint> endpoints;
|
||||||
params.put("lower", "[on | off]");
|
}
|
||||||
params.put("number", "[on | off]");
|
|
||||||
params.put("special", "[on | off]");
|
|
||||||
params.put("exclude", "string");
|
|
||||||
params.put("repeat", "int");
|
|
||||||
|
|
||||||
map.put("params", params);
|
Api api = new Api();
|
||||||
return map;
|
api.name = "PasswordAPI";
|
||||||
|
api.endpoints = new ArrayList<>();
|
||||||
|
|
||||||
|
//Password endpoint
|
||||||
|
Endpoint passwordEndpoint = new Endpoint();
|
||||||
|
passwordEndpoint.name = "/api";
|
||||||
|
passwordEndpoint.params = new HashMap<>();
|
||||||
|
passwordEndpoint.params.put("length", "int");
|
||||||
|
passwordEndpoint.params.put("upper", "[on | off]");
|
||||||
|
passwordEndpoint.params.put("lower", "[on | off]");
|
||||||
|
passwordEndpoint.params.put("number", "[on | off]");
|
||||||
|
passwordEndpoint.params.put("special", "[on | off]");
|
||||||
|
passwordEndpoint.params.put("exclude", "string");
|
||||||
|
passwordEndpoint.params.put("repeat", "int");
|
||||||
|
api.endpoints.add(passwordEndpoint);
|
||||||
|
|
||||||
|
//UUID endpoint
|
||||||
|
Endpoint uuidEndpoint = new Endpoint();
|
||||||
|
uuidEndpoint.name = "/uuid";
|
||||||
|
uuidEndpoint.params = new HashMap<>();
|
||||||
|
uuidEndpoint.params.put("repeat", "int");
|
||||||
|
uuidEndpoint.params.put("braces", "[on | off]");
|
||||||
|
api.endpoints.add(uuidEndpoint);
|
||||||
|
|
||||||
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://passwordwolf.com/?length=8&upper=off&lower=off&special=off&exclude=012345&repeat=20
|
// https://passwordwolf.com/?length=8&upper=off&lower=off&special=off&exclude=012345&repeat=20
|
||||||
@ -54,4 +74,20 @@ public class DefaultController {
|
|||||||
.generate();
|
.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/uuid")
|
||||||
|
public LinkedList<String> generateUUID(
|
||||||
|
@RequestParam(required = false, defaultValue = "8") int repeat,
|
||||||
|
@RequestParam(required = false, defaultValue = "false") String braces) {
|
||||||
|
var list = new LinkedList<String>();
|
||||||
|
for (int i = 0; i < repeat; i++) {
|
||||||
|
list.add(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
if (braces.equals("on")) {
|
||||||
|
list = list.stream()
|
||||||
|
.map(s -> "{" + s + "}")
|
||||||
|
.collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user