Skip to content

Commit 9ff1891

Browse files
authored
chore: start using plugin-framework package (#372)
**Note:** we introduced a small breaking change; the type for `GenerateSignatureResponse#SigningAlgorithm` has been changed from `string` to `plugin.SignatureAlgorithm` --------- Signed-off-by: Pritesh Bandi <[email protected]>
1 parent 4606472 commit 9ff1891

18 files changed

+225
-296
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.20
55
require (
66
github.com/go-ldap/ldap/v3 v3.4.6
77
github.com/notaryproject/notation-core-go v1.0.2
8+
github.com/notaryproject/notation-plugin-framework-go v1.0.0
89
github.com/opencontainers/go-digest v1.0.0
910
github.com/opencontainers/image-spec v1.1.0-rc6
1011
github.com/veraison/go-cose v1.1.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
1717
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1818
github.com/notaryproject/notation-core-go v1.0.2 h1:VEt+mbsgdANd9b4jqgmx2C7U0DmwynOuD2Nhxh3bANw=
1919
github.com/notaryproject/notation-core-go v1.0.2/go.mod h1:2HkQzUwg08B3x9oVIztHsEh7Vil2Rj+tYgxH+JObLX4=
20+
github.com/notaryproject/notation-plugin-framework-go v1.0.0 h1:6Qzr7DGXoCgXEQN+1gTZWuJAZvxh3p8Lryjn5FaLzi4=
21+
github.com/notaryproject/notation-plugin-framework-go v1.0.0/go.mod h1:RqWSrTOtEASCrGOEffq0n8pSg2KOgKYiWqFWczRSics=
2022
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
2123
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
2224
github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU=

internal/mock/mocks.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import (
1818
_ "embed"
1919

2020
"github.com/notaryproject/notation-core-go/signature"
21-
"github.com/notaryproject/notation-go/plugin"
22-
"github.com/notaryproject/notation-go/plugin/proto"
21+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
2322
"github.com/opencontainers/go-digest"
2423
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2524
)
@@ -168,36 +167,36 @@ func (t Repository) PushSignature(ctx context.Context, mediaType string, blob []
168167
}
169168

170169
type PluginMock struct {
171-
Metadata proto.GetMetadataResponse
170+
Metadata plugin.GetMetadataResponse
172171
ExecuteResponse interface{}
173172
ExecuteError error
174173
}
175174

176-
func (p *PluginMock) GetMetadata(ctx context.Context, req *proto.GetMetadataRequest) (*proto.GetMetadataResponse, error) {
175+
func (p *PluginMock) GetMetadata(ctx context.Context, req *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
177176
return &p.Metadata, nil
178177
}
179178

180-
func (p *PluginMock) VerifySignature(ctx context.Context, req *proto.VerifySignatureRequest) (*proto.VerifySignatureResponse, error) {
181-
if resp, ok := p.ExecuteResponse.(*proto.VerifySignatureResponse); ok {
179+
func (p *PluginMock) VerifySignature(ctx context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
180+
if resp, ok := p.ExecuteResponse.(*plugin.VerifySignatureResponse); ok {
182181
return resp, nil
183182
}
184183
return nil, p.ExecuteError
185184
}
186185

187-
func (p *PluginMock) DescribeKey(ctx context.Context, req *proto.DescribeKeyRequest) (*proto.DescribeKeyResponse, error) {
186+
func (p *PluginMock) DescribeKey(ctx context.Context, req *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
188187
panic("not implemented") // TODO: Implement
189188
}
190189

191-
func (p *PluginMock) GenerateSignature(ctx context.Context, req *proto.GenerateSignatureRequest) (*proto.GenerateSignatureResponse, error) {
190+
func (p *PluginMock) GenerateSignature(ctx context.Context, req *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
192191
panic("not implemented") // TODO: Implement
193192
}
194193

195-
func (p *PluginMock) GenerateEnvelope(ctx context.Context, req *proto.GenerateEnvelopeRequest) (*proto.GenerateEnvelopeResponse, error) {
194+
func (p *PluginMock) GenerateEnvelope(ctx context.Context, req *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
196195
panic("not implemented") // TODO: Implement
197196
}
198197

199198
type PluginManager struct {
200-
PluginCapabilities []proto.Capability
199+
PluginCapabilities []plugin.Capability
201200
GetPluginError error
202201
PluginRunnerLoadError error
203202
PluginRunnerExecuteResponse interface{}
@@ -206,7 +205,7 @@ type PluginManager struct {
206205

207206
func (pm PluginManager) Get(ctx context.Context, name string) (plugin.Plugin, error) {
208207
return &PluginMock{
209-
Metadata: proto.GetMetadataResponse{
208+
Metadata: plugin.GetMetadataResponse{
210209
Name: "plugin-name",
211210
Description: "for mocking in unit tests",
212211
Version: "1.0.0",

plugin/integration_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ import (
2323
"testing"
2424

2525
"github.com/notaryproject/notation-go/dir"
26-
"github.com/notaryproject/notation-go/plugin/proto"
26+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
2727
)
2828

29-
var exampleMetadata = proto.GetMetadataResponse{
29+
var exampleMetadata = plugin.GetMetadataResponse{
3030
Name: "foo",
3131
Description: "friendly",
3232
Version: "1",
3333
URL: "example.com",
3434
SupportedContractVersions: []string{"1.0"},
35-
Capabilities: []proto.Capability{"cap"}}
35+
Capabilities: []plugin.Capability{"cap"}}
3636

3737
func preparePlugin(t *testing.T) string {
3838
root := t.TempDir()
@@ -87,11 +87,11 @@ func TestIntegration(t *testing.T) {
8787
}
8888

8989
// validate and create
90-
plugin, err := mgr.Get(context.Background(), "foo")
90+
pl, err := mgr.Get(context.Background(), "foo")
9191
if err != nil {
9292
t.Fatal(err)
9393
}
94-
metadata, err := plugin.GetMetadata(context.Background(), &proto.GetMetadataRequest{})
94+
metadata, err := pl.GetMetadata(context.Background(), &plugin.GetMetadataRequest{})
9595
if err != nil {
9696
t.Fatal(err)
9797
}

plugin/manager.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626
"github.com/notaryproject/notation-go/internal/file"
2727
"github.com/notaryproject/notation-go/internal/semver"
2828
"github.com/notaryproject/notation-go/log"
29-
"github.com/notaryproject/notation-go/plugin/proto"
29+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
3030
)
3131

3232
// Manager manages plugins installed on the system.
3333
type Manager interface {
34-
Get(ctx context.Context, name string) (Plugin, error)
34+
Get(ctx context.Context, name string) (plugin.Plugin, error)
3535
List(ctx context.Context) ([]string, error)
3636
}
3737

@@ -48,7 +48,7 @@ func NewCLIManager(pluginFS dir.SysFS) *CLIManager {
4848
// Get returns a plugin on the system by its name.
4949
//
5050
// If the plugin is not found, the error is of type os.ErrNotExist.
51-
func (m *CLIManager) Get(ctx context.Context, name string) (Plugin, error) {
51+
func (m *CLIManager) Get(ctx context.Context, name string) (plugin.Plugin, error) {
5252
pluginPath := path.Join(name, binName(name))
5353
path, err := m.pluginFS.SysPath(pluginPath)
5454
if err != nil {
@@ -118,7 +118,7 @@ type CLIInstallOptions struct {
118118
//
119119
// If overwrite is set, version check is skipped. If existing
120120
// plugin is malfunctioning, it will be overwritten.
121-
func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions) (*proto.GetMetadataResponse, *proto.GetMetadataResponse, error) {
121+
func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions) (*plugin.GetMetadataResponse, *plugin.GetMetadataResponse, error) {
122122
// initialization
123123
logger := log.GetLogger(ctx)
124124
overwrite := installOpts.Overwrite
@@ -153,20 +153,20 @@ func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions)
153153
if err != nil {
154154
return nil, nil, err
155155
}
156-
newPluginMetadata, err := newPlugin.GetMetadata(ctx, &proto.GetMetadataRequest{})
156+
newPluginMetadata, err := newPlugin.GetMetadata(ctx, &plugin.GetMetadataRequest{})
157157
if err != nil {
158158
return nil, nil, fmt.Errorf("failed to get metadata of new plugin: %w", err)
159159
}
160160
// check plugin existence and get existing plugin metadata
161-
var existingPluginMetadata *proto.GetMetadataResponse
161+
var existingPluginMetadata *plugin.GetMetadataResponse
162162
existingPlugin, err := m.Get(ctx, pluginName)
163163
if err != nil {
164164
// fail only if overwrite is not set
165165
if !errors.Is(err, os.ErrNotExist) && !overwrite {
166166
return nil, nil, fmt.Errorf("failed to check plugin existence: %w", err)
167167
}
168168
} else { // plugin already exists
169-
existingPluginMetadata, err = existingPlugin.GetMetadata(ctx, &proto.GetMetadataRequest{})
169+
existingPluginMetadata, err = existingPlugin.GetMetadata(ctx, &plugin.GetMetadataRequest{})
170170
if err != nil && !overwrite { // fail only if overwrite is not set
171171
return nil, nil, fmt.Errorf("failed to get metadata of existing plugin: %w", err)
172172
}

plugin/manager_unix.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"os"
2222
"strings"
2323

24-
"github.com/notaryproject/notation-go/plugin/proto"
24+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
2525
)
2626

2727
func binName(name string) string {
28-
return proto.Prefix + name
28+
return plugin.BinaryPrefix + name
2929
}
3030

3131
// isExecutableFile checks if a file at filePath is user executable
@@ -44,7 +44,7 @@ func isExecutableFile(filePath string) (bool, error) {
4444
// parsePluginName checks if fileName is a valid plugin file name
4545
// and gets plugin name from it based on spec: https://github.com/notaryproject/specifications/blob/main/specs/plugin-extensibility.md#installation
4646
func parsePluginName(fileName string) (string, error) {
47-
pluginName, found := strings.CutPrefix(fileName, proto.Prefix)
47+
pluginName, found := strings.CutPrefix(fileName, plugin.BinaryPrefix)
4848
if !found || pluginName == "" {
4949
return "", fmt.Errorf("invalid plugin executable file name. Plugin file name requires format notation-{plugin-name}, but got %s", fileName)
5050
}

plugin/manager_windows.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"strings"
2121

2222
"github.com/notaryproject/notation-go/internal/file"
23-
"github.com/notaryproject/notation-go/plugin/proto"
23+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
2424
)
2525

2626
func binName(name string) string {
27-
return proto.Prefix + name + ".exe"
27+
return plugin.BinaryPrefix + name + ".exe"
2828
}
2929

3030
// isExecutableFile checks if a file at filePath is executable
@@ -46,7 +46,7 @@ func parsePluginName(fileName string) (string, error) {
4646
return "", fmt.Errorf("invalid plugin executable file name. Plugin file name requires format notation-{plugin-name}.exe, but got %s", fileName)
4747
}
4848
fname := file.TrimFileExtension(fileName)
49-
pluginName, found := strings.CutPrefix(fname, proto.Prefix)
49+
pluginName, found := strings.CutPrefix(fname, plugin.BinaryPrefix)
5050
if !found || pluginName == "" {
5151
return "", fmt.Errorf("invalid plugin executable file name. Plugin file name requires format notation-{plugin-name}.exe, but got %s", fileName)
5252
}

0 commit comments

Comments
 (0)