Skip to content

Commit

Permalink
Use axiomhq/pkg/cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Oct 6, 2021
1 parent 8993a18 commit ba98de6
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 156 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ FROM alpine
LABEL maintainer="Axiom, Inc. <[email protected]>"

# Upgrade packages and install ca-certificates.
RUN apk update --no-cache \
&& apk upgrade --no-cache \
&& apk add --no-cache ca-certificates
RUN apk update --no-cache && \
apk upgrade --no-cache && \
apk add --no-cache ca-certificates

# Copy binary into image.
COPY axiom-syslog-proxy /usr/bin/axiom-syslog-proxy
Expand Down
56 changes: 12 additions & 44 deletions cmd/axiom-syslog-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,45 @@ package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"

"github.com/axiomhq/axiom-go/axiom"
"github.com/axiomhq/pkg/version"
"github.com/axiomhq/pkg/cmd"
"go.uber.org/zap"

"github.com/axiomhq/axiom-syslog-proxy/server"
)

const (
exitOK int = iota
exitConfig
exitInternal
)

var (
addrTCP = flag.String("addr-tcp", ":601", "Listen address <ip>:<port>")
addrUDP = flag.String("addr-udp", ":514", "Listen address <ip>:<port>")
)

func main() {
os.Exit(Main())
cmd.Run("axiom-syslog-proxy", run,
cmd.WithRequiredEnvVars("AXIOM_DATASET"),
cmd.WithValidateAxiomCredentials(),
)
}

func Main() int {
// Export `AXIOM_TOKEN` and `AXIOM_ORG_ID` for Axiom Cloud
// Export `AXIOM_URL` and `AXIOM_TOKEN` for Axiom Selfhost

log.Print("starting axiom-syslog-proxy version ", version.Release())
func run(ctx context.Context, log *zap.Logger, client *axiom.Client) error {
// Export `AXIOM_TOKEN`, `AXIOM_ORG_ID` and `AXIOM_DATASET` for Axiom Cloud.
// Export `AXIOM_URL`, `AXIOM_TOKEN` and `AXIOM_DATASET` for Axiom Selfhost.

flag.Parse()

ctx, cancel := signal.NotifyContext(context.Background(),
os.Interrupt,
os.Kill,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
)
defer cancel()

dataset := os.Getenv("AXIOM_DATASET")
if dataset == "" {
log.Print("AXIOM_DATASET is required")
return exitConfig
}

client, err := axiom.NewClient()
if err != nil {
log.Print(err)
return exitConfig
} else if err = client.ValidateCredentials(ctx); err != nil {
log.Print(err)
return exitConfig
}

config := &server.Config{
Dataset: dataset,
Dataset: os.Getenv("AXIOM_DATASET"),
AddrUDP: *addrUDP,
AddrTCP: *addrTCP,
}

srv, err := server.NewServer(client, config)
if err != nil {
log.Print(err)
return exitInternal
return cmd.Error("create server", err)
}

srv.Run()

return exitOK
return nil
}
80 changes: 49 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@ module github.com/axiomhq/axiom-syslog-proxy
go 1.17

require (
github.com/axiomhq/axiom-go v0.6.0
github.com/axiomhq/axiom-go v0.6.2
github.com/axiomhq/logmanager v1.0.6
github.com/axiomhq/pkg v0.1.0
github.com/axiomhq/pkg v0.2.0
github.com/buger/jsonparser v1.1.1
github.com/golangci/golangci-lint v1.42.1
github.com/goreleaser/goreleaser v0.177.0
github.com/goreleaser/goreleaser v0.180.3
github.com/hashicorp/golang-lru v0.5.4
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.19.1
gotest.tools/gotestsum v1.7.0
)

require (
4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect
cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go/storage v1.15.0 // indirect
cloud.google.com/go v0.94.0 // indirect
cloud.google.com/go/kms v0.1.0 // indirect
cloud.google.com/go/storage v1.16.1 // indirect
code.gitea.io/sdk/gitea v0.15.0 // indirect
github.com/AlekSi/pointer v1.1.0 // indirect
github.com/Antonboom/errname v0.1.4 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/azure-sdk-for-go v54.0.0+incompatible // indirect
github.com/Azure/azure-storage-blob-go v0.13.0 // indirect
github.com/Azure/azure-sdk-for-go v57.0.0+incompatible // indirect
github.com/Azure/azure-storage-blob-go v0.14.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
github.com/Azure/go-autorest/autorest v0.11.20 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.15 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.3 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/DisgoOrg/disgohook v1.4.3 // indirect
github.com/DisgoOrg/log v1.1.0 // indirect
github.com/DisgoOrg/restclient v1.2.7 // indirect
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
Expand All @@ -47,7 +52,18 @@ require (
github.com/apex/log v1.9.0 // indirect
github.com/ashanbrown/forbidigo v1.2.0 // indirect
github.com/ashanbrown/makezero v0.0.0-20210520155254-b6261585ddde // indirect
github.com/aws/aws-sdk-go v1.38.35 // indirect
github.com/atc0005/go-teams-notify/v2 v2.6.0 // indirect
github.com/aws/aws-sdk-go v1.40.34 // indirect
github.com/aws/aws-sdk-go-v2 v1.9.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
github.com/aws/smithy-go v1.8.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bkielbasa/cyclop v1.2.0 // indirect
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
Expand All @@ -74,8 +90,7 @@ require (
github.com/ettle/strcase v0.1.1 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/fzipp/gocyclo v0.3.1 // indirect
github.com/go-critic/go-critic v0.5.6 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
Expand All @@ -91,6 +106,7 @@ require (
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
Expand All @@ -107,9 +123,9 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/rpmpack v0.0.0-20210410105602-e20c988a6f5a // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 // indirect
github.com/goreleaser/chglog v0.1.2 // indirect
github.com/goreleaser/fileglob v1.2.0 // indirect
Expand All @@ -134,7 +150,6 @@ require (
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d // indirect
github.com/kevinburke/ssh_config v1.1.0 // indirect
github.com/kisielk/errcheck v1.6.0 // indirect
Expand Down Expand Up @@ -213,25 +228,28 @@ require (
github.com/xanzy/ssh-agent v0.3.0 // indirect
github.com/yeya24/promlinter v0.1.0 // indirect
go.opencensus.io v0.23.0 // indirect
gocloud.dev v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210505214959-0714010a04ed // indirect
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
gocloud.dev v0.24.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.46.0 // indirect
google.golang.org/api v0.56.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
Loading

0 comments on commit ba98de6

Please sign in to comment.