Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate unique client id by default #4

Merged
merged 15 commits into from
Jul 12, 2023
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
name: goreleaser
steps:
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.13
go-version: 1.19
id: go

- name: Check out code into the Go module directory
Expand All @@ -40,7 +40,7 @@ jobs:
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin

- name: goreleaser
uses: goreleaser/goreleaser-action@master
uses: goreleaser/goreleaser-action@v3
with:
args: release
workdir: ${{github.workspace}}/mqtt-mirror
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Create helm package
uses: stefanprodan/kube-tools@v1
with:
helm: 2.16.1
helm: 2.17.0
command: |
export SEMVER=${GITHUB_REF#refs/tags/v}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.14.x]
go-version: [1.18.x, 1.19.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
5 changes: 2 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ dockers:
# GOARM of the built binary that should be used.
goarm: ''

# Name templates of the built binaries that should be used.
binaries:
ids:
- mqtt-mirror

# Templates of the Docker image names.
Expand Down Expand Up @@ -70,7 +69,7 @@ dockers:
brews:
-
# Github repository to push the tap to.
github:
tap:
owner: 4nte
name: homebrew-tap

Expand Down
Binary file added bin/mqtt-mirror
Binary file not shown.
4 changes: 4 additions & 0 deletions chart/mqtt-mirror/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
- name: VERBOSE
value: "{{ .Values.verbose }}"
{{end}}
{{ if .Values.name }}
- name: NAME
value: "{{ .Values.name }}"
{{end}}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
1 change: 1 addition & 0 deletions chart/mqtt-mirror/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ image:
pullPolicy: IfNotPresent

verbose: false
name: "" # name of the mqtt-mirror instance (used as clientID)

mqtt:
source: ""
Expand Down
22 changes: 17 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package cmd

import (
"fmt"
"github.com/4nte/mqtt-mirror/internal"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"net/url"
"os"
"os/signal"
"syscall"

"github.com/4nte/mqtt-mirror/internal"
"github.com/dchest/uniuri"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var ( // Flags
Expand All @@ -20,6 +22,8 @@ var ( // Flags
targetURI string
configFile string

instanceName string

Topics []string
)

Expand Down Expand Up @@ -93,6 +97,11 @@ var rootCmd = &cobra.Command{
if target == "" {
target = viper.GetString("target")
}
var instanceName = viper.GetString("name")
if len(instanceName) == 0 {
instanceName = uniuri.NewLen(8)

}

topicFilter := viper.GetStringSlice("topic_filter")
isVerbose := viper.GetBool("verbose")
Expand All @@ -106,7 +115,7 @@ var rootCmd = &cobra.Command{
panic(err)
}

terminate, err := internal.Mirror(*sourceURL, *targetURL, topicFilter, isVerbose, 0)
terminate, err := internal.Mirror(*sourceURL, *targetURL, topicFilter, isVerbose, 0, instanceName)
if err != nil {
panic(err)
}
Expand All @@ -124,6 +133,8 @@ func init() {
rootCmd.PersistentFlags().StringVar(&sourceURI, "source", "", "mqtt source URI")
rootCmd.PersistentFlags().StringVar(&targetURI, "target", "", "mqtt target URI")

rootCmd.PersistentFlags().StringVarP(&instanceName, "name", "", "", "mqtt-mirror instance name. If not specified, will be randomly generated")

rootCmd.PersistentFlags().StringVar(&targetURI, "config", "", "config file")

err := viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source"))
Expand All @@ -134,6 +145,7 @@ func init() {
viper.BindPFlag("target", rootCmd.PersistentFlags().Lookup("target"))
viper.BindPFlag("topic_filter", rootCmd.PersistentFlags().Lookup("topic_filter"))
viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
viper.BindPFlag("name", rootCmd.PersistentFlags().Lookup("name"))
}

func initConfig() {
Expand Down
Binary file added go-mirror
Binary file not shown.
55 changes: 51 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
module github.com/4nte/mqtt-mirror

go 1.15
go 1.19

require (
github.com/dchest/uniuri v1.2.0
github.com/docker/go-connections v0.4.0
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.8.0
github.com/surgemq/message v0.0.0-20151017233315-2b7ca1ac6121
github.com/testcontainers/testcontainers-go v0.9.0
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect
)

require (
github.com/gorilla/websocket v1.5.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
)

require (
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/containerd/containerd v1.4.1 // indirect
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible // indirect
github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.2.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
go.uber.org/zap v1.23.0
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 // indirect
google.golang.org/grpc v1.17.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading