Skip to content

Commit

Permalink
feat: replace prints with state warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Dec 15, 2023
1 parent 78f4f43 commit f7027d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 12 additions & 2 deletions pkg/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sync"

"github.com/blang/semver/v4"
"github.com/kong/go-database-reconciler/pkg/konnect"
Expand All @@ -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
Expand All @@ -37,6 +42,8 @@ type stateBuilder struct {

checkRoutePaths bool

warnBasicAuth sync.Once

isConsumerGroupScopedPluginSupported bool

err error
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f7027d7

Please sign in to comment.