Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Backport of core/app_build: Fix panic where Waypoint plugin missing AccessInfoFunc into release/0.6.x #2553

Merged
4 changes: 4 additions & 0 deletions .changelog/2532.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
core: Fix a panic where a custom Waypoint plugin would panic if the plugin
did not properly implement a Registry component with AccessInfoFunc()
```
2 changes: 2 additions & 0 deletions builtin/aws/ecr/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,5 @@ registry {
}

var _ component.Documented = (*Registry)(nil)
var _ component.Registry = (*Registry)(nil)
var _ component.RegistryAccess = (*Registry)(nil)
4 changes: 4 additions & 0 deletions builtin/docker/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/waypoint-plugin-sdk/component"
"github.com/hashicorp/waypoint-plugin-sdk/docs"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -226,3 +227,6 @@ build {

return doc, nil
}

var _ component.Registry = (*Registry)(nil)
var _ component.RegistryAccess = (*Registry)(nil)
8 changes: 7 additions & 1 deletion internal/core/app_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (op *buildOperation) Do(ctx context.Context, log hclog.Logger, app *App, _

// If there is a registry defined and it implements RegistryAccess...
if op.Registry != nil {
if ra, ok := op.Registry.Value.(component.RegistryAccess); ok {
if ra, ok := op.Registry.Value.(component.RegistryAccess); ok && ra.AccessInfoFunc() != nil {
raw, err := app.callDynamicFunc(ctx, log, nil, op.Component, ra.AccessInfoFunc())
if err == nil {
args = append(args, argmapper.Typed(raw))
Expand All @@ -176,6 +176,12 @@ func (op *buildOperation) Do(ctx context.Context, log hclog.Logger, app *App, _
log.Error("error calling dynamic func", "error", err)
return nil, err
}
} else {
if ok && ra != nil && ra.AccessInfoFunc() == nil {
return nil, status.Error(codes.Internal, "The plugin requested does not "+
"define an AccessInfoFunc() in its Registry plugin. This is an internal "+
"error and should be reported to the author of the plugin.")
}
}
}

Expand Down