Skip to content

feat: Add MMDB Key-Value Store#71

Merged
jshlbrd merged 3 commits intomainfrom
jshlbrd/kv-mmdb
Jan 19, 2023
Merged

feat: Add MMDB Key-Value Store#71
jshlbrd merged 3 commits intomainfrom
jshlbrd/kv-mmdb

Conversation

@jshlbrd
Copy link
Contributor

@jshlbrd jshlbrd commented Jan 15, 2023

Description

  • Adds an MMDB KV store

Motivation and Context

MMDB is an alternative to the IP database (IPDB) component. Unlike that feature, this one does not interpret data from the database before returning it to the caller, which makes it more modular at the expense of potentially requiring more user configuration -- any file in MMDB format is supported.

How Has This Been Tested?

Tested locally via integration test. Tests can be recreated using these examples:

local sub = import '../../build/config/substation.libsonnet';

local kv = sub.interfaces.processor.kv_store(
	settings={key: 'addr', set_key: 'mmdb'},
	options={type: 'get', 'kv_options': sub.interfaces.kv_store.mmdb(
		settings={file: '/path/to/file.mmdb'}
	)}
);

kv
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/brexhq/substation/config"
	"github.com/brexhq/substation/process"
)

func main() {
	cfg, err := os.ReadFile("./config.json")
	if err != nil {
		panic(err)
	}

	conf := config.Config{}
	if err := json.Unmarshal(cfg, &conf); err != nil {
		panic(err)
	}

	processor, err := process.NewApplier(conf)
	if err != nil {
		panic(err)
	}

	fmt.Println("> printing processor settings ...")
	fmt.Println(processor)

	b := []byte(`{"addr":"8.8.8.8"}`)
	fmt.Println("> printing raw data ...")
	fmt.Println(string(b))

	b, err = process.ApplyBytes(context.TODO(), b, processor)
	if err != nil {
		panic(err)
	}

	fmt.Println("> printing processed data ...")
	fmt.Println(string(b))
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@jshlbrd jshlbrd marked this pull request as ready for review January 17, 2023 22:47
@jshlbrd jshlbrd requested a review from a team as a code owner January 17, 2023 22:47
@jshlbrd jshlbrd merged commit cee1932 into main Jan 19, 2023
@jshlbrd jshlbrd deleted the jshlbrd/kv-mmdb branch January 19, 2023 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants