diff --git a/pkg/file/builder.go b/pkg/file/builder.go index df9a26d..aa8104c 100644 --- a/pkg/file/builder.go +++ b/pkg/file/builder.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sync" "github.com/blang/semver/v4" "github.com/kong/go-database-reconciler/pkg/konnect" @@ -12,7 +13,11 @@ import ( "github.com/kong/go-kong/kong" ) -const ratelimitingAdvancedPluginName = "rate-limiting-advanced" +const ( + ratelimitingAdvancedPluginName = "rate-limiting-advanced" + basicAuthPasswordWarning = "Warning: import/export of basic-auth" + + "credentials using decK doesn't work due to hashing of passwords in Kong." +) type stateBuilder struct { targetContent *Content @@ -37,6 +42,8 @@ type stateBuilder struct { checkRoutePaths bool + warnBasicAuth sync.Once + isConsumerGroupScopedPluginSupported bool err error @@ -361,6 +368,9 @@ func (b *stateBuilder) consumers() { var basicAuths []kong.BasicAuth for _, cred := range c.BasicAuths { + b.warnBasicAuth.Do(func() { + b.rawState.Warnings = append(b.rawState.Warnings, basicAuthPasswordWarning) + }) cred.Consumer = utils.GetConsumerReference(c.Consumer) basicAuths = append(basicAuths, *cred) } @@ -811,7 +821,7 @@ func (b *stateBuilder) routes() { } } if len(unsupportedRoutes) > 0 { - utils.PrintRouteRegexWarning(unsupportedRoutes) + b.rawState.Warnings = append(b.rawState.Warnings, utils.PrintRouteRegexWarning(unsupportedRoutes)) } } } diff --git a/pkg/utils/types.go b/pkg/utils/types.go index 8bd33c9..55905ad 100644 --- a/pkg/utils/types.go +++ b/pkg/utils/types.go @@ -54,6 +54,9 @@ type KongRawState struct { RBACRoles []*kong.RBACRole RBACEndpointPermissions []*kong.RBACEndpointPermission + + // Warnings are not Kong data. This field stores any warnings related to Kong data found while building state. + Warnings []string } // KonnectRawState contains all of Konnect resources. diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index a9ac8d8..1f1ed36 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -12,7 +12,6 @@ import ( "strings" "github.com/blang/semver/v4" - "github.com/kong/go-database-reconciler/pkg/cprint" "github.com/kong/go-kong/kong" ) @@ -237,13 +236,13 @@ func HasPathsWithRegex300AndAbove(route kong.Route) bool { } // PrintRouteRegexWarning prints out a warning about 3.x routes' path usage. -func PrintRouteRegexWarning(unsupportedRoutes []string) { +func PrintRouteRegexWarning(unsupportedRoutes []string) string { unsupportedRoutesLen := len(unsupportedRoutes) // do not consider more than 10 sample routes to print out. if unsupportedRoutesLen > 10 { unsupportedRoutes = unsupportedRoutes[:10] } - cprint.UpdatePrintf( + return fmt.Sprintf( "%d unsupported routes' paths format with Kong version 3.0\n"+ "or above were detected. Some of these routes are (not an exhaustive list):\n\n"+ "%s\n\n"+UpgradeMessage,