Skip to content

A dumb microservice with CF (codice fiscale) utils

License

Notifications You must be signed in to change notification settings

torrefatto/kofi

Repository files navigation

KoFi

Microservice to check or create a Codice Fiscale

How to

Develop

To prepare a development environment use pipenv. Install it and then run

$ pipenv install --dev .

To enter a development-ready environment

$ pipenv shell

You'll get a shell with all the needed dependencies. If you have GNU_make installed, a set of targets are available to ease the tasks. In the following, these targets will be used. You can avoid using them, reading the Makefile source and using the commands therein instead.

To start a development session

$ pipenv run kofi

Alternatively, you can use the development docker image. Build it with:

$ make docker-dev-build

Run it with:

$ make docker-dev-run

You'll find the server on localhost:1312. You will find a graphiql page (needs internet connectivity :-/ ).

Production

Build the package, install and run it:

$ make dist

Otherwise, build the docker image:

$ make docker-build

This will build torrefatto/kofi:<tag> with the tag being the current version. You can run it and bind to the 1312 port:

$ docker run -t torrefatto/kofi:<tag>

or in whatever orchestrator you prefer.

API

ReST

There are two endpoints:

  • /api/verify [GET]
query parameters:
  • cf: the Codice Fiscale string

returns:

{"isCorrect": "<bool>", "isOmocode": "<bool>", "cf": "<str>"}
  • /api/interpolate [GET]
query parameters:
  • name
  • surname
  • gender
  • date_of_birth in YYYYMMDD format
  • place_of_birth

returns:

{"cf": "<str>"}

GraphQL

As usual, there is just the /graphql endpoint. It accepts the following queries:

schema {
  query: codiceFiscaleQuery
}

type codiceFiscaleQuery {
  """The body of the verify response."""
  verify(
    """The Codice Fiscale string."""
    cf: String!
  ): verifyType

  """Query to obtain one person's codice fiscale"""
  interpolate(
    """Person's first name(s)"""
    name: String!

    """Person's last name(s)"""
    surname: String!

    """Person's official gender"""
    gender: Gender!

    """Person's date of birth"""
    dateOfBirth: String!

    """Person's place of birth"""
    placeOfBirth: String!
  ): interpolateType
}

"""One's official gender."""
enum Gender {
  """Male"""
  M

  """Female"""
  F
}

"""The result of person's data interpolation"""
type interpolateType {
  """One person's codice fiscale."""
  codiceFiscale: String
}

"""The result of checks on the CF."""
type verifyType {
  """If the CF is omocode, ."""
  isOmocode: Boolean

  """If the CF is correct."""
  isCorrect: Boolean
}

being genderType an enum comprising M and F values