This project is a demo of Play framework / akka-streams
Given a list of IP address in quad-octet form, produce a digest with adrresses with consecutive octet #4 values replaced with a range. The purpose of this is for white/blacklist application Both a web Ui and REST API are provided by this service
99.243.64.40
99.243.64.41
99.243.64.42
99.244.106.35
99.244.121.59
99.244.121.60
99.244.121.61
99.244.156.149
A resulting digest will be produced:
99.243.64.40-99.243.64.42
99.244.106.35
99.244.121.59-99.244.121.61
99.244.156.149
As well as plain text, JSON format may be specified:
[
{"ip": ["99.243.64.40", "99.243.64.42"]},
{"ip": ["99.244.106.35"]},
{"ip": ["99.244.121.59", "99.244.121.61"]},
{"ip": ["99.244.156.149"]}
]
def digestFromSource(request: Source[DigestRequest,_]): Future[Seq[Try[String]]] =
request.async via filter via digester via formatter runWith Sink.seq
+--------+ +--------+ +----------+ +-----------+ +----------+
| (1) | | (2) | | (3) | | (4) | | (5) |
| source | => | filter | => | digester | => | formatter | => | response |
+--------+ +--------+ +----------+ +-----------+ +----------+
- Request body is parsed into a iteration over strings, wrapped in a
Source
- Invalid (e.g., empty) elements are filtered out
- Digester algorithm applied to entire collection (needs to be sorted and unique)
- Results are formatted as per
Accepts
header / selection, JSON or Plain - Response body set if results available