Skip to content

Commit

Permalink
add version, use go1.22.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-dima committed Apr 26, 2024
1 parent 6dde4a6 commit 62710e0
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*.dll
*.so
*.dylib
kongcomparer
bin/

# Test binary, built with `go test -c`
*.test
Expand Down
20 changes: 20 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- "7"
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/alt-dima/kong-configuration-comparer

go 1.21.1
go 1.22.2

require github.com/kong/go-kong v0.48.0
require github.com/kong/go-kong v0.54.0

require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v1.0.0 // indirect
github.com/kong/semver/v4 v4.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
)
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/kong/go-kong v0.48.0 h1:vK1OpoxO50qlKdwPfmx9ChvkTKRsoCCB3b3iHo1umLc=
github.com/kong/go-kong v0.48.0/go.mod h1:qH4CEFqT83ywmu1TlMZX09clQH4B8/dX88CtT/jdv/E=
github.com/kong/go-kong v0.54.0 h1:HZkZJRREJs/azkgJxMWr2jANQQfg8xXsAiFKu+d1nrs=
github.com/kong/go-kong v0.54.0/go.mod h1:51rSSjgSZKukXgn5nNYbJUx0Et/islqR+LTltwCyjG8=
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
github.com/kong/semver/v4 v4.0.1/go.mod h1:LImQ0oT15pJvSns/hs2laLca2zcYoHu5EsSNY0J6/QA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
Expand Down
88 changes: 49 additions & 39 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/kong/go-kong/kong"
)

var (
version string = "undefined"
)

func slicePointersToValues(slicePointers []*string) []string {
sliceValues := make([]string, len(slicePointers))
for i, s := range slicePointers {
Expand All @@ -21,6 +25,12 @@ func slicePointersToValues(slicePointers []*string) []string {
}

func main() {
log.Printf("Comparer version: %v \n", version)

if len(os.Args) != 3 {
log.Fatalln("please specify url1 and url2 to compare like: " + os.Args[0] + " http://kong-adm-1 http://kong-adm-2")
}

clientUrl1 := &os.Args[1]
clientUrl2 := &os.Args[2]

Expand All @@ -43,8 +53,8 @@ func main() {
log.Fatalln(err)
}

fmt.Printf("Amount routes in %v: %v \n", *clientUrl1, len(allRoutesClient1))
fmt.Printf("Amount routes in %v: %v \n", *clientUrl2, len(allRoutesClient2))
log.Printf("Amount routes in %v: %v \n", *clientUrl1, len(allRoutesClient1))
log.Printf("Amount routes in %v: %v \n", *clientUrl2, len(allRoutesClient2))

for _, client1Route := range allRoutesClient1 {
result := false
Expand All @@ -58,19 +68,19 @@ func main() {
result = true
//checking route parameters
if *client1Route.PreserveHost != *client2Route.PreserveHost {
fmt.Printf("Route %v PreserveHost %v not equals %v \n", strClient1RoutePaths, *client1Route.PreserveHost, *client2Route.PreserveHost)
log.Printf("Route %v PreserveHost %v not equals %v \n", strClient1RoutePaths, *client1Route.PreserveHost, *client2Route.PreserveHost)
}
if *client1Route.StripPath != *client2Route.StripPath {
fmt.Printf("Route %v StripPath %v not equals %v \n", strClient1RoutePaths, *client1Route.StripPath, *client2Route.StripPath)
log.Printf("Route %v StripPath %v not equals %v \n", strClient1RoutePaths, *client1Route.StripPath, *client2Route.StripPath)
}
if !slices.Equal(slicePointersToValues(client1Route.Methods), slicePointersToValues(client2Route.Methods)) {
fmt.Printf("Route %v Methods not equals \n", strClient1RoutePaths)
log.Printf("Route %v Methods not equals \n", strClient1RoutePaths)
}
if !slices.Equal(slicePointersToValues(client1Route.Hosts), slicePointersToValues(client2Route.Hosts)) {
fmt.Printf("Route %v Hosts not equals \n", strClient1RoutePaths)
log.Printf("Route %v Hosts not equals \n", strClient1RoutePaths)
}
if !slices.Equal(slicePointersToValues(client1Route.Protocols), slicePointersToValues(client2Route.Protocols)) {
fmt.Printf("Route %v Protocols not equals \n", strClient1RoutePaths)
log.Printf("Route %v Protocols not equals \n", strClient1RoutePaths)
}

//check route plugins
Expand All @@ -93,15 +103,15 @@ func main() {
delete(pluginRouteClient1.Config, "okta_consumer")
delete(pluginRouteClient2.Config, "okta_consumer")
if !reflect.DeepEqual(pluginRouteClient1.Config, pluginRouteClient2.Config) {
//fmt.Println(pluginRouteClient1.Config)
//fmt.Println(pluginRouteClient2.Config)
fmt.Println("Route " + strClient1RoutePaths + " plugin config " + *pluginRouteClient1.Name + " not equals in " + *clientUrl2)
//log.Println(pluginRouteClient1.Config)
//log.Println(pluginRouteClient2.Config)
log.Println("Route " + strClient1RoutePaths + " plugin config " + *pluginRouteClient1.Name + " not equals in " + *clientUrl2)
}
break
}
}
if result == false {
fmt.Println("Route " + strClient1RoutePaths + " plugin " + *pluginRouteClient1.Name + " does not exists in " + *clientUrl2)
log.Println("Route " + strClient1RoutePaths + " plugin " + *pluginRouteClient1.Name + " does not exists in " + *clientUrl2)
}
}

Expand All @@ -115,13 +125,13 @@ func main() {
log.Fatalln(err)
}
if *serviceRouteClient1.Host != *serviceRouteClient2.Host {
fmt.Printf("Route %v target service Host not equals \n", strClient1RoutePaths)
log.Printf("Route %v target service Host not equals \n", strClient1RoutePaths)
}
if *serviceRouteClient1.Port != *serviceRouteClient2.Port {
fmt.Printf("Route %v target service Port not equals \n", strClient1RoutePaths)
log.Printf("Route %v target service Port not equals \n", strClient1RoutePaths)
}
if *serviceRouteClient1.Path != *serviceRouteClient2.Path {
fmt.Printf("Route %v target service Path not equals \n", strClient1RoutePaths)
log.Printf("Route %v target service Path not equals \n", strClient1RoutePaths)
}

//check service plugins
Expand All @@ -144,23 +154,23 @@ func main() {
//delete(pluginServiceClient1.Config, "okta_consumer")
//delete(pluginServiceClient2.Config, "okta_consumer")
if !reflect.DeepEqual(pluginServiceClient1.Config, pluginServiceClient2.Config) {
//fmt.Println(pluginServiceClient1.Config)
//fmt.Println(pluginServiceClient2.Config)
fmt.Println("Service " + *serviceRouteClient1.Name + " plugin config " + *pluginServiceClient1.Name + " not equals in " + *clientUrl2)
//log.Println(pluginServiceClient1.Config)
//log.Println(pluginServiceClient2.Config)
log.Println("Service " + *serviceRouteClient1.Name + " plugin config " + *pluginServiceClient1.Name + " not equals in " + *clientUrl2)
}
break
}
}
if result == false {
fmt.Println("Route " + strClient1RoutePaths + " plugin " + *pluginServiceClient1.Name + " does not exists in " + *clientUrl2)
log.Println("Route " + strClient1RoutePaths + " plugin " + *pluginServiceClient1.Name + " does not exists in " + *clientUrl2)
}
}

break
}
}
if result == false {
fmt.Println("Route " + strClient1RoutePaths + " does not exists in " + *clientUrl2)
log.Println("Route " + strClient1RoutePaths + " does not exists in " + *clientUrl2)
}
}

Expand All @@ -174,10 +184,10 @@ func main() {
log.Fatalln(err)
}

fmt.Printf("Amount consumers in %v: %v \n", *clientUrl1, len(allConsumersClient1))
fmt.Printf("Amount consumers in %v: %v \n", *clientUrl2, len(allConsumersClient2))
log.Printf("Amount consumers in %v: %v \n", *clientUrl1, len(allConsumersClient1))
log.Printf("Amount consumers in %v: %v \n", *clientUrl2, len(allConsumersClient2))

fmt.Printf("Only Consumers plugins and ACLs comparison currently implemented!!! \n")
log.Printf("Only Consumers plugins and ACLs comparison currently implemented!!! \n")

for _, client1Consumer := range allConsumersClient1 {
result := false
Expand All @@ -202,21 +212,21 @@ func main() {
for _, pluginConsumerClient2 := range allPluginsConsumerClient2 {
if *pluginConsumerClient1.Name == *pluginConsumerClient2.Name && *pluginConsumerClient1.Enabled == *pluginConsumerClient2.Enabled {
result = true
//fmt.Println(pluginConsumerClient1.Config)
//log.Println(pluginConsumerClient1.Config)
//delete(pluginConsumerClient1.Config, "append")
//delete(pluginConsumerClient2.Config, "append")
//delete(pluginConsumerClient1.Config, "okta_consumer")
//delete(pluginConsumerClient2.Config, "okta_consumer")
if !reflect.DeepEqual(pluginConsumerClient1.Config, pluginConsumerClient2.Config) {
//fmt.Println(pluginConsumerClient1.Config)
//fmt.Println(pluginConsumerClient2.Config)
fmt.Println("Consumer " + *client1Consumer.Username + " plugin config " + *pluginConsumerClient1.Name + " not equals in " + *clientUrl2)
//log.Println(pluginConsumerClient1.Config)
//log.Println(pluginConsumerClient2.Config)
log.Println("Consumer " + *client1Consumer.Username + " plugin config " + *pluginConsumerClient1.Name + " not equals in " + *clientUrl2)
}
break
}
}
if result == false {
fmt.Println("Consumer " + *client1Consumer.Username + " plugin " + *pluginConsumerClient1.Name + " does not exists in " + *clientUrl2)
log.Println("Consumer " + *client1Consumer.Username + " plugin " + *pluginConsumerClient1.Name + " does not exists in " + *clientUrl2)
}
}

Expand All @@ -240,14 +250,14 @@ func main() {
}
}
if result == false {
fmt.Println("Consumer " + *client1Consumer.Username + " ACL " + *aclConsumerClient1.Group + " does not exists in " + *clientUrl2)
log.Println("Consumer " + *client1Consumer.Username + " ACL " + *aclConsumerClient1.Group + " does not exists in " + *clientUrl2)
}
}
break
}
}
if result == false {
fmt.Println("Consumer " + *client1Consumer.Username + " does not exists in " + *clientUrl2)
log.Println("Consumer " + *client1Consumer.Username + " does not exists in " + *clientUrl2)
}
}

Expand Down Expand Up @@ -278,8 +288,8 @@ func main() {
}
}

fmt.Printf("Amount global plugins in %v: %v \n", *clientUrl1, len(allGlobalPluginsClient1))
fmt.Printf("Amount global plugins in %v: %v \n", *clientUrl2, len(allGlobalPluginsClient2))
log.Printf("Amount global plugins in %v: %v \n", *clientUrl1, len(allGlobalPluginsClient1))
log.Printf("Amount global plugins in %v: %v \n", *clientUrl2, len(allGlobalPluginsClient2))

for _, globalPluginClient1 := range allGlobalPluginsClient1 {
result := false
Expand All @@ -292,15 +302,15 @@ func main() {
delete(globalPluginClient1.Config, "okta_consumer")
delete(globalPluginClient2.Config, "okta_consumer")
if !reflect.DeepEqual(globalPluginClient1.Config, globalPluginClient2.Config) {
//fmt.Println(pluginRouteClient1.Config)
//fmt.Println(pluginRouteClient2.Config)
fmt.Println("Global plugin config " + *globalPluginClient1.Name + " not equals in " + *clientUrl2)
//log.Println(pluginRouteClient1.Config)
//log.Println(pluginRouteClient2.Config)
log.Println("Global plugin config " + *globalPluginClient1.Name + " not equals in " + *clientUrl2)
}
break
}
}
if result == false {
fmt.Println("Global plugin " + *globalPluginClient1.Name + " does not exists in " + *clientUrl2)
log.Println("Global plugin " + *globalPluginClient1.Name + " does not exists in " + *clientUrl2)
}
}

Expand All @@ -315,8 +325,8 @@ func main() {
// log.Fatalln(err)
// }

// fmt.Printf("Amount consumer groups in %v: %v \n", *clientUrl1, len(allConsGroupsClient1))
// fmt.Printf("Amount consumer groups in %v: %v \n", *clientUrl2, len(allConsGroupsClient2))
// log.Printf("Amount consumer groups in %v: %v \n", *clientUrl1, len(allConsGroupsClient1))
// log.Printf("Amount consumer groups in %v: %v \n", *clientUrl2, len(allConsGroupsClient2))

// for _, consGroupClient1 := range allConsGroupsClient1 {
// result := false
Expand Down Expand Up @@ -345,14 +355,14 @@ func main() {
// }
// }
// if result == false {
// fmt.Println("Consumer " + *consGroupClient1.Name + " plugin " + *groupConsumerClient1.Username + " does not exists in " + *clientUrl2)
// log.Println("Consumer " + *consGroupClient1.Name + " plugin " + *groupConsumerClient1.Username + " does not exists in " + *clientUrl2)
// }
// }
// break
// }
// }
// if result == false {
// fmt.Println("Cons Group " + *consGroupClient1.Name + " does not exists in " + *clientUrl2)
// log.Println("Cons Group " + *consGroupClient1.Name + " does not exists in " + *clientUrl2)
// }
// }
}

0 comments on commit 62710e0

Please sign in to comment.