项目作者: sothach

项目描述 :
IP Address Compressor
高级语言: Scala
项目地址: git://github.com/sothach/ipcress.git
创建时间: 2019-10-19T08:19:39Z
项目社区:https://github.com/sothach/ipcress

开源协议:

下载


IP Address Compressor

Deployment pipeline

Build Status >>
Coverage Status >>
Codacy Badge

This project is a demo of Play framework / akka-streams

The Problem

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

Example input

  1. 99.243.64.40
  2. 99.243.64.41
  3. 99.243.64.42
  4. 99.244.106.35
  5. 99.244.121.59
  6. 99.244.121.60
  7. 99.244.121.61
  8. 99.244.156.149

A resulting digest will be produced:

  1. 99.243.64.40-99.243.64.42
  2. 99.244.106.35
  3. 99.244.121.59-99.244.121.61
  4. 99.244.156.149

As well as plain text, JSON format may be specified:

  1. [
  2. {"ip": ["99.243.64.40", "99.243.64.42"]},
  3. {"ip": ["99.244.106.35"]},
  4. {"ip": ["99.244.121.59", "99.244.121.61"]},
  5. {"ip": ["99.244.156.149"]}
  6. ]

Design

Workflow: DigesterService

  1. def digestFromSource(request: Source[DigestRequest,_]): Future[Seq[Try[String]]] =
  2. request.async via filter via digester via formatter runWith Sink.seq
  1. +--------+ +--------+ +----------+ +-----------+ +----------+
  2. | (1) | | (2) | | (3) | | (4) | | (5) |
  3. | source | => | filter | => | digester | => | formatter | => | response |
  4. +--------+ +--------+ +----------+ +-----------+ +----------+
  1. Request body is parsed into a iteration over strings, wrapped in a Source
  2. Invalid (e.g., empty) elements are filtered out
  3. Digester algorithm applied to entire collection (needs to be sorted and unique)
  4. Results are formatted as per Accepts header / selection, JSON or Plain
  5. Response body set if results available

Cloud Deployment

see instructions