Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/base-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Base Pipeline

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
GO_VERSION: "1.25.6"
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5.5.0
with:
go-version: ${{ env.GO_VERSION }}

- name: Check formatting
run: |
files=$(gofmt -l ./)

if [ -n "$files" ]; then
while IFS= read -r file; do
echo "::warning file=$file::File is not gofmt formatted"
done <<< "$files"
exit 1
else
echo "✅ All files are properly formatted."
fi

test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5.5.0
with:
go-version: ${{ env.GO_VERSION }}

- name: Build
run: |
make build

- name: Test
run: |
make test
32 changes: 32 additions & 0 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build container

on:
workflow_run:
workflows:
- "Base Pipeline"
branches:
- "main"
types:
- completed
push:
tags:
- "v*.*.*"

env:
GO_VERSION: "1.25.5"
jobs:
container:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Build and push container
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: ko-build/setup-ko@v0.7
- run: ko build --bare ./cmd/observation-encoder
5 changes: 5 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defaultPlatforms:
- linux/amd64
- linux/arm64
defaultLdflags:
- -X main.commit={{.Git.FullCommit}}
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ observation-encoder -config /path/to/config/file

# Sample config file

```json
{
"address": "127.0.0.1",
"port": "10000",
"cert":
{
"interval": 100,
"cert_dir": "/path/to/certificates/dir"
},
"api":
{
"active": true,
"address": "127.0.0.1",
"port": "10001"
}
}
```toml
address = "127.0.0.1"
port = "10000"

[cert]
interval = 100
cert_dir = "/path/to/certs/dir"

[api]
active = true
address = "127.0.0.1"
port = "10001"

[nats]
url = "nats://127.0.0.1:4222"
subject_prefix = "observations"
subject_southbound = "test.subject"
ttl = 3600

[libtapir]
debug = true
```
97 changes: 88 additions & 9 deletions cmd/observation-encoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import (
"syscall"
"time"

//"github.com/nats-io/nats.go"
"github.com/pelletier/go-toml/v2"

"github.com/dnstapir/observation-encoder/internal/api"
"github.com/dnstapir/observation-encoder/internal/app"
"github.com/dnstapir/observation-encoder/internal/cert"
"github.com/dnstapir/observation-encoder/internal/common"
"github.com/dnstapir/observation-encoder/internal/libtapir"
"github.com/dnstapir/observation-encoder/internal/logger"
"github.com/dnstapir/observation-encoder/internal/nats"
)

var commit = "BAD-BUILD"

type conf struct {
app.Conf
Debug bool `toml:"debug"`
Api api.Conf `toml:"api"`
Cert cert.Conf `toml:"cert"`
Debug bool `toml:"debug"`
Api api.Conf `toml:"api"`
Cert cert.Conf `toml:"cert"`
Nats nats.Conf `toml:"nats"`
Libtapir libtapir.Conf `toml:"libtapir"`
}

func main() {
Expand Down Expand Up @@ -87,32 +90,103 @@ func main() {
confDecoder.Decode(&mainConf)
file.Close() // TODO okay to close here while also using defer above?

// TODO create different loggers with different debug settings
debugFlag = debugFlag || mainConf.Debug

/*
******************************************************************
********************** SET UP NATS *******************************
******************************************************************
*/
natslog, err := logger.Create(
logger.Conf{
Debug: debugFlag || mainConf.Nats.Debug,
})
if err != nil {
log.Error("Error creating nats log: %s", err)
}

mainConf.Nats.Log = natslog
natsHandle, err := nats.Create(mainConf.Nats)
if err != nil {
log.Error("Could not create NATS handle: %s", err)
os.Exit(-1)
}

/*
******************************************************************
********************** SET UP LIBTAPIR ***************************
******************************************************************
*/
libtapirlog, err := logger.Create(
logger.Conf{
Debug: debugFlag || mainConf.Libtapir.Debug,
})
if err != nil {
log.Error("Error creating libtapir log: %s", err)
}

mainConf.Libtapir.Log = libtapirlog
libtapirHandle, err := libtapir.Create(mainConf.Libtapir)
if err != nil {
log.Error("Could not create libtapir handle: %s", err)
os.Exit(-1)
}

/*
******************************************************************
********************** SET UP MAIN APP ***************************
******************************************************************
*/
applog, err := logger.Create(
logger.Conf{
Debug: debugFlag || mainConf.Debug,
})
if err != nil {
log.Error("Error creating app log: %s", err)
} else {
applog.Debug("Debug logging enabled")
}

mainConf.Log = applog
mainConf.NatsHandle = natsHandle
mainConf.LibtapirHandle = libtapirHandle
appHandle, err := app.Create(mainConf.Conf)
if err != nil {
log.Error("Error creating application: '%s'", err)
os.Exit(-1)
}

mainConf.Cert.Log = applog
/*
******************************************************************
********************** SET UP CERT HANDLER ***********************
******************************************************************
*/
certlog, err := logger.Create(
logger.Conf{
Debug: debugFlag || mainConf.Cert.Debug,
})
if err != nil {
log.Error("Error creating cert log: %s", err)
}

mainConf.Cert.Log = certlog
certHandle, err := cert.Create(mainConf.Cert)
if err != nil {
log.Error("Error creating cert manager: '%s'", err)
os.Exit(-1)
}

mainConf.Api.Log = applog
/*
******************************************************************
********************** SET UP API ********************************
******************************************************************
*/
apilog, err := logger.Create(
logger.Conf{
Debug: debugFlag || mainConf.Api.Debug,
})
if err != nil {
log.Error("Error creating API log: %s", err)
}
mainConf.Api.Log = apilog
mainConf.Api.App = appHandle
mainConf.Api.Certs = certHandle
apiHandle, err := api.Create(mainConf.Api)
Expand All @@ -121,6 +195,11 @@ func main() {
os.Exit(-1)
}

/*
******************************************************************
********************** START RUNNING STUFF ***********************
******************************************************************
*/
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
defer close(sigChan)
Expand Down
49 changes: 47 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
module github.com/dnstapir/observation-encoder

go 1.24.6
go 1.25.6

require github.com/pelletier/go-toml/v2 v2.2.4
require (
github.com/dnstapir/tapir v0.0.0-20260115113810-71a904f35f68
github.com/nats-io/nats.go v1.48.0
github.com/pelletier/go-toml/v2 v2.2.4
)

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/eclipse/paho.golang v0.23.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/gookit/goutil v0.7.3 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.18.4 // indirect
github.com/lestrrat-go/blackmagic v1.0.4 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.6 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.6 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/miekg/dns v1.1.72 // indirect
github.com/nats-io/nkeys v0.4.15 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/ryanuber/columnize v2.1.2+incompatible // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/segmentio/asm v1.2.1 // indirect
github.com/smhanov/dawg v0.0.0-20220118194912-66057bdbf2e3 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/viper v1.21.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/exp v0.0.0-20260209203927-2842357ff358 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/term v0.40.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/tools v0.42.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
Loading