Skip to content

Commit

Permalink
Add deprecation message
Browse files Browse the repository at this point in the history
Signed-off-by: Pritesh Bandi <priteshbandi@gmail.com>
  • Loading branch information
priteshbandi committed Jan 15, 2024
1 parent 4a93375 commit 0eebc16
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 95 deletions.
23 changes: 11 additions & 12 deletions internal/mock/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
_ "embed"

"github.com/notaryproject/notation-core-go/signature"
"github.com/notaryproject/notation-go/plugin"
"github.com/notaryproject/notation-go/plugin/proto"
pluginframework "github.com/notaryproject/notation-plugin-framework-go/plugin"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
Expand Down Expand Up @@ -168,45 +167,45 @@ func (t Repository) PushSignature(ctx context.Context, mediaType string, blob []
}

type PluginMock struct {
Metadata proto.GetMetadataResponse
Metadata pluginframework.GetMetadataResponse
ExecuteResponse interface{}
ExecuteError error
}

func (p *PluginMock) GetMetadata(ctx context.Context, req *proto.GetMetadataRequest) (*proto.GetMetadataResponse, error) {
func (p *PluginMock) GetMetadata(ctx context.Context, req *pluginframework.GetMetadataRequest) (*pluginframework.GetMetadataResponse, error) {
return &p.Metadata, nil
}

func (p *PluginMock) VerifySignature(ctx context.Context, req *proto.VerifySignatureRequest) (*proto.VerifySignatureResponse, error) {
if resp, ok := p.ExecuteResponse.(*proto.VerifySignatureResponse); ok {
func (p *PluginMock) VerifySignature(ctx context.Context, req *pluginframework.VerifySignatureRequest) (*pluginframework.VerifySignatureResponse, error) {
if resp, ok := p.ExecuteResponse.(*pluginframework.VerifySignatureResponse); ok {
return resp, nil
}
return nil, p.ExecuteError
}

func (p *PluginMock) DescribeKey(ctx context.Context, req *proto.DescribeKeyRequest) (*proto.DescribeKeyResponse, error) {
func (p *PluginMock) DescribeKey(ctx context.Context, req *pluginframework.DescribeKeyRequest) (*pluginframework.DescribeKeyResponse, error) {
panic("not implemented") // TODO: Implement
}

func (p *PluginMock) GenerateSignature(ctx context.Context, req *proto.GenerateSignatureRequest) (*proto.GenerateSignatureResponse, error) {
func (p *PluginMock) GenerateSignature(ctx context.Context, req *pluginframework.GenerateSignatureRequest) (*pluginframework.GenerateSignatureResponse, error) {
panic("not implemented") // TODO: Implement
}

func (p *PluginMock) GenerateEnvelope(ctx context.Context, req *proto.GenerateEnvelopeRequest) (*proto.GenerateEnvelopeResponse, error) {
func (p *PluginMock) GenerateEnvelope(ctx context.Context, req *pluginframework.GenerateEnvelopeRequest) (*pluginframework.GenerateEnvelopeResponse, error) {
panic("not implemented") // TODO: Implement
}

type PluginManager struct {
PluginCapabilities []proto.Capability
PluginCapabilities []pluginframework.Capability
GetPluginError error
PluginRunnerLoadError error
PluginRunnerExecuteResponse interface{}
PluginRunnerExecuteError error
}

func (pm PluginManager) Get(ctx context.Context, name string) (plugin.Plugin, error) {
func (pm PluginManager) Get(ctx context.Context, name string) (pluginframework.Plugin, error) {
return &PluginMock{
Metadata: proto.GetMetadataResponse{
Metadata: pluginframework.GetMetadataResponse{
Name: "plugin-name",
Description: "for mocking in unit tests",
Version: "1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions plugin/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import (
"testing"

"github.com/notaryproject/notation-go/dir"
"github.com/notaryproject/notation-go/plugin/proto"
"github.com/notaryproject/notation-plugin-framework-go/plugin"
)

var exampleMetadata = proto.GetMetadataResponse{
var exampleMetadata = plugin.GetMetadataResponse{
Name: "foo",
Description: "friendly",
Version: "1",
URL: "example.com",
SupportedContractVersions: []string{"1.0"},
Capabilities: []proto.Capability{"cap"}}
Capabilities: []plugin.Capability{"cap"}}

func preparePlugin(t *testing.T) string {
root := t.TempDir()
Expand Down Expand Up @@ -87,11 +87,11 @@ func TestIntegration(t *testing.T) {
}

// validate and create
plugin, err := mgr.Get(context.Background(), "foo")
pl, err := mgr.Get(context.Background(), "foo")
if err != nil {
t.Fatal(err)
}
metadata, err := plugin.GetMetadata(context.Background(), &proto.GetMetadataRequest{})
metadata, err := pl.GetMetadata(context.Background(), &plugin.GetMetadataRequest{})
if err != nil {
t.Fatal(err)
}
Expand Down
14 changes: 7 additions & 7 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"github.com/notaryproject/notation-go/internal/file"
"github.com/notaryproject/notation-go/internal/semver"
"github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation-go/plugin/proto"
"github.com/notaryproject/notation-plugin-framework-go/plugin"
)

// Manager manages plugins installed on the system.
type Manager interface {
Get(ctx context.Context, name string) (Plugin, error)
Get(ctx context.Context, name string) (plugin.Plugin, error)
List(ctx context.Context) ([]string, error)
}

Expand All @@ -48,7 +48,7 @@ func NewCLIManager(pluginFS dir.SysFS) *CLIManager {
// Get returns a plugin on the system by its name.
//
// If the plugin is not found, the error is of type os.ErrNotExist.
func (m *CLIManager) Get(ctx context.Context, name string) (Plugin, error) {
func (m *CLIManager) Get(ctx context.Context, name string) (plugin.Plugin, error) {
pluginPath := path.Join(name, binName(name))
path, err := m.pluginFS.SysPath(pluginPath)
if err != nil {
Expand Down Expand Up @@ -113,7 +113,7 @@ type CLIInstallOptions struct {
//
// If overwrite is set, version check is skipped. If existing
// plugin is malfunctioning, it will be overwritten.
func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions) (*proto.GetMetadataResponse, *proto.GetMetadataResponse, error) {
func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions) (*plugin.GetMetadataResponse, *plugin.GetMetadataResponse, error) {
// initialization
logger := log.GetLogger(ctx)
overwrite := installOpts.Overwrite
Expand Down Expand Up @@ -148,20 +148,20 @@ func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions)
if err != nil {
return nil, nil, fmt.Errorf("failed to create new CLI plugin: %w", err)
}
newPluginMetadata, err := newPlugin.GetMetadata(ctx, &proto.GetMetadataRequest{})
newPluginMetadata, err := newPlugin.GetMetadata(ctx, &plugin.GetMetadataRequest{})
if err != nil {
return nil, nil, fmt.Errorf("failed to get metadata of new plugin: %w", err)
}
// check plugin existence and get existing plugin metadata
var existingPluginMetadata *proto.GetMetadataResponse
var existingPluginMetadata *plugin.GetMetadataResponse
existingPlugin, err := m.Get(ctx, pluginName)
if err != nil {
// fail only if overwrite is not set
if !errors.Is(err, os.ErrNotExist) && !overwrite {
return nil, nil, fmt.Errorf("failed to check plugin existence: %w", err)
}
} else { // plugin already exists
existingPluginMetadata, err = existingPlugin.GetMetadata(ctx, &proto.GetMetadataRequest{})
existingPluginMetadata, err = existingPlugin.GetMetadata(ctx, &plugin.GetMetadataRequest{})
if err != nil && !overwrite { // fail only if overwrite is not set
return nil, nil, fmt.Errorf("failed to get metadata of existing plugin: %w", err)
}
Expand Down
45 changes: 26 additions & 19 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package plugin provides the toolings to use the notation plugin.
// Package plugin provides the tooling to use the notation plugin.
//
// includes a CLIManager and a CLIPlugin implementation.
package plugin
Expand All @@ -34,16 +34,24 @@ import (

var executor commander = &execCommander{} // for unit test

// GenericPlugin is the base requirement to be an plugin.
// GenericPlugin is the base requirement to be a plugin.
// Deprecated: GenericPlugin exists for historical compatibility and should not be used.
// To access GenericPlugin, use the notation-plugin-framework-go's plugin.GenericPlugin type.
type GenericPlugin = plugin.GenericPlugin

// SignPlugin defines the required methods to be a SignPlugin.
// Deprecated: SignPlugin exists for historical compatibility and should not be used.
// To access SignPlugin, use the notation-plugin-framework-go's plugin.SignPlugin type.
type SignPlugin = plugin.SignPlugin

// VerifyPlugin defines the required method to be a VerifyPlugin.
// Deprecated: VerifyPlugin exists for historical compatibility and should not be used.
// To access VerifyPlugin, use the notation-plugin-framework-go's plugin.VerifyPlugin type.
type VerifyPlugin = plugin.VerifyPlugin

// Plugin defines required methods to be an Plugin.
// Plugin defines required methods to be a Plugin.
// Deprecated: Plugin exists for historical compatibility and should not be used.
// To access Plugin, use the notation-plugin-framework-go's plugin.Plugin type.
type Plugin = plugin.Plugin

// CLIPlugin implements Plugin interface to CLI plugins.
Expand All @@ -67,16 +75,15 @@ func NewCLIPlugin(ctx context.Context, name, path string) (*CLIPlugin, error) {
}

// generate plugin
plugin := CLIPlugin{
return &CLIPlugin{
name: name,
path: path,
}
return &plugin, nil
}, nil
}

// GetMetadata returns the metadata information of the plugin.
func (p *CLIPlugin) GetMetadata(ctx context.Context, req *proto.GetMetadataRequest) (*proto.GetMetadataResponse, error) {
var metadata proto.GetMetadataResponse
func (p *CLIPlugin) GetMetadata(ctx context.Context, req *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
var metadata plugin.GetMetadataResponse
err := run(ctx, p.name, p.path, req, &metadata)
if err != nil {
return nil, err
Expand All @@ -94,56 +101,56 @@ func (p *CLIPlugin) GetMetadata(ctx context.Context, req *proto.GetMetadataReque
// DescribeKey returns the KeySpec of a key.
//
// if ContractVersion is not set, it will be set by the function.
func (p *CLIPlugin) DescribeKey(ctx context.Context, req *proto.DescribeKeyRequest) (*proto.DescribeKeyResponse, error) {
func (p *CLIPlugin) DescribeKey(ctx context.Context, req *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
if req.ContractVersion == "" {
req.ContractVersion = proto.ContractVersion
}

var resp proto.DescribeKeyResponse
var resp plugin.DescribeKeyResponse
err := run(ctx, p.name, p.path, req, &resp)
return &resp, err
}

// GenerateSignature generates the raw signature based on the request.
//
// if ContractVersion is not set, it will be set by the function.
func (p *CLIPlugin) GenerateSignature(ctx context.Context, req *proto.GenerateSignatureRequest) (*proto.GenerateSignatureResponse, error) {
func (p *CLIPlugin) GenerateSignature(ctx context.Context, req *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
if req.ContractVersion == "" {
req.ContractVersion = proto.ContractVersion
}

var resp proto.GenerateSignatureResponse
var resp plugin.GenerateSignatureResponse
err := run(ctx, p.name, p.path, req, &resp)
return &resp, err
}

// GenerateEnvelope generates the Envelope with signature based on the request.
//
// if ContractVersion is not set, it will be set by the function.
func (p *CLIPlugin) GenerateEnvelope(ctx context.Context, req *proto.GenerateEnvelopeRequest) (*proto.GenerateEnvelopeResponse, error) {
func (p *CLIPlugin) GenerateEnvelope(ctx context.Context, req *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
if req.ContractVersion == "" {
req.ContractVersion = proto.ContractVersion
}

var resp proto.GenerateEnvelopeResponse
var resp plugin.GenerateEnvelopeResponse
err := run(ctx, p.name, p.path, req, &resp)
return &resp, err
}

// VerifySignature validates the signature based on the request.
//
// if ContractVersion is not set, it will be set by the function.
func (p *CLIPlugin) VerifySignature(ctx context.Context, req *proto.VerifySignatureRequest) (*proto.VerifySignatureResponse, error) {
func (p *CLIPlugin) VerifySignature(ctx context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
if req.ContractVersion == "" {
req.ContractVersion = proto.ContractVersion
}

var resp proto.VerifySignatureResponse
var resp plugin.VerifySignatureResponse
err := run(ctx, p.name, p.path, req, &resp)
return &resp, err
}

func run(ctx context.Context, pluginName string, pluginPath string, req proto.Request, resp interface{}) error {
func run(ctx context.Context, pluginName string, pluginPath string, req plugin.Request, resp interface{}) error {
logger := log.GetLogger(ctx)

// serialize request
Expand Down Expand Up @@ -179,7 +186,7 @@ func run(ctx context.Context, pluginName string, pluginPath string, req proto.Re

// commander is defined for mocking purposes.
type commander interface {
// Output runs the command, passing req to the its stdin.
// Output runs the command, passing req to the stdin.
// It only returns an error if the binary can't be executed.
// Returns stdout if err is nil, stderr if err is not nil.
Output(ctx context.Context, path string, command proto.Command, req []byte) (stdout []byte, stderr []byte, err error)
Expand All @@ -202,7 +209,7 @@ func (c execCommander) Output(ctx context.Context, name string, command proto.Co
}

// validate checks if the metadata is correctly populated.
func validate(metadata *proto.GetMetadataResponse) error {
func validate(metadata *plugin.GetMetadataResponse) error {
if metadata.Name == "" {
return errors.New("empty name")
}
Expand Down
18 changes: 12 additions & 6 deletions plugin/proto/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

// KeySpec is type of the signing algorithm, including algorithm and size.
// Deprecated: KeySpec exists for historical compatibility and should not be used.
// To access KeySpec, use the notation-plugin-framework-go's plugin.KeySpec type.
type KeySpec = plugin.KeySpec

// one of the following supported key spec names.
Expand All @@ -37,7 +39,7 @@ const (
)

// EncodeKeySpec returns the name of a keySpec according to the spec.
func EncodeKeySpec(k signature.KeySpec) (KeySpec, error) {
func EncodeKeySpec(k signature.KeySpec) (plugin.KeySpec, error) {
switch k.Type {
case signature.KeyTypeEC:
switch k.Size {
Expand All @@ -62,7 +64,7 @@ func EncodeKeySpec(k signature.KeySpec) (KeySpec, error) {
}

// DecodeKeySpec parses keySpec name to a signature.keySpec type.
func DecodeKeySpec(k KeySpec) (keySpec signature.KeySpec, err error) {
func DecodeKeySpec(k plugin.KeySpec) (keySpec signature.KeySpec, err error) {
switch k {
case KeySpecRSA2048:
keySpec.Size = 2048
Expand All @@ -89,7 +91,9 @@ func DecodeKeySpec(k KeySpec) (keySpec signature.KeySpec, err error) {
return
}

// HashAlgorithm is the type of a hash algorithm.
// HashAlgorithm is the type of hash algorithm.
// Deprecated: HashAlgorithm exists for historical compatibility and should not be used.
// To access HashAlgorithm, use the notation-plugin-framework-go's plugin.HashAlgorithm type.
type HashAlgorithm = plugin.HashAlgorithm

// one of the following supported hash algorithm names.
Expand All @@ -102,7 +106,7 @@ const (
)

// HashAlgorithmFromKeySpec returns the name of hash function according to the spec.
func HashAlgorithmFromKeySpec(k signature.KeySpec) (HashAlgorithm, error) {
func HashAlgorithmFromKeySpec(k signature.KeySpec) (plugin.HashAlgorithm, error) {
switch k.Type {
case signature.KeyTypeEC:
switch k.Size {
Expand All @@ -127,6 +131,8 @@ func HashAlgorithmFromKeySpec(k signature.KeySpec) (HashAlgorithm, error) {
}

// SignatureAlgorithm is the type of signature algorithm
// Deprecated: SignatureAlgorithm exists for historical compatibility and should not be used.
// To access SignatureAlgorithm, use the notation-plugin-framework-go's plugin.SignatureAlgorithm type.
type SignatureAlgorithm = plugin.SignatureAlgorithm

// one of the following supported signing algorithm names.
Expand All @@ -143,7 +149,7 @@ const (

// EncodeSigningAlgorithm returns the signing algorithm name of an algorithm
// according to the spec.
func EncodeSigningAlgorithm(alg signature.Algorithm) (SignatureAlgorithm, error) {
func EncodeSigningAlgorithm(alg signature.Algorithm) (plugin.SignatureAlgorithm, error) {
switch alg {
case signature.AlgorithmES256:
return SignatureAlgorithmECDSA_SHA256, nil
Expand All @@ -162,7 +168,7 @@ func EncodeSigningAlgorithm(alg signature.Algorithm) (SignatureAlgorithm, error)
}

// DecodeSigningAlgorithm parses the signing algorithm name from a given string.
func DecodeSigningAlgorithm(raw SignatureAlgorithm) (signature.Algorithm, error) {
func DecodeSigningAlgorithm(raw plugin.SignatureAlgorithm) (signature.Algorithm, error) {
switch raw {
case SignatureAlgorithmECDSA_SHA256:
return signature.AlgorithmES256, nil
Expand Down
5 changes: 3 additions & 2 deletions plugin/proto/algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"testing"

"github.com/notaryproject/notation-core-go/signature"
"github.com/notaryproject/notation-plugin-framework-go/plugin"
)

func TestEncodeKeySpec(t *testing.T) {
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestHashAlgorithmFromKeySpec(t *testing.T) {
tests := []struct {
name string
keySpec signature.KeySpec
expected HashAlgorithm
expected plugin.HashAlgorithm
}{
{
name: "EC 256",
Expand Down Expand Up @@ -228,7 +229,7 @@ func TestDecodeKeySpec(t *testing.T) {
},
{
name: "Unsupported key spec",
raw: "unsuppored",
raw: "unsupported",
expected: signature.KeySpec{},
expectErr: true,
},
Expand Down
Loading

0 comments on commit 0eebc16

Please sign in to comment.