|
5 | 5 | _ "embed"
|
6 | 6 |
|
7 | 7 | "github.com/notaryproject/notation-core-go/signature"
|
8 |
| - "github.com/notaryproject/notation-go/internal/plugin" |
9 |
| - "github.com/notaryproject/notation-go/internal/plugin/manager" |
| 8 | + "github.com/notaryproject/notation-go/plugin" |
| 9 | + "github.com/notaryproject/notation-go/plugin/proto" |
10 | 10 | "github.com/opencontainers/go-digest"
|
11 | 11 | ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
12 | 12 | )
|
@@ -101,40 +101,58 @@ func (t Repository) PushSignature(ctx context.Context, mediaType string, blob []
|
101 | 101 | return ocispec.Descriptor{}, ocispec.Descriptor{}, nil
|
102 | 102 | }
|
103 | 103 |
|
| 104 | +type PluginMock struct { |
| 105 | + Metadata proto.GetMetadataResponse |
| 106 | + ExecuteResponse interface{} |
| 107 | + ExecuteError error |
| 108 | +} |
| 109 | + |
| 110 | +func (p *PluginMock) GetMetadata(ctx context.Context, req *proto.GetMetadataRequest) (*proto.GetMetadataResponse, error) { |
| 111 | + return &p.Metadata, nil |
| 112 | +} |
| 113 | + |
| 114 | +func (p *PluginMock) VerifySignature(ctx context.Context, req *proto.VerifySignatureRequest) (*proto.VerifySignatureResponse, error) { |
| 115 | + if resp, ok := p.ExecuteResponse.(*proto.VerifySignatureResponse); ok { |
| 116 | + return resp, nil |
| 117 | + } |
| 118 | + return nil, p.ExecuteError |
| 119 | +} |
| 120 | + |
| 121 | +func (p *PluginMock) DescribeKey(ctx context.Context, req *proto.DescribeKeyRequest) (*proto.DescribeKeyResponse, error) { |
| 122 | + panic("not implemented") // TODO: Implement |
| 123 | +} |
| 124 | + |
| 125 | +func (p *PluginMock) GenerateSignature(ctx context.Context, req *proto.GenerateSignatureRequest) (*proto.GenerateSignatureResponse, error) { |
| 126 | + panic("not implemented") // TODO: Implement |
| 127 | +} |
| 128 | + |
| 129 | +func (p *PluginMock) GenerateEnvelope(ctx context.Context, req *proto.GenerateEnvelopeRequest) (*proto.GenerateEnvelopeResponse, error) { |
| 130 | + panic("not implemented") // TODO: Implement |
| 131 | +} |
| 132 | + |
104 | 133 | type PluginManager struct {
|
105 |
| - PluginCapabilities []plugin.Capability |
| 134 | + PluginCapabilities []proto.Capability |
106 | 135 | GetPluginError error
|
107 | 136 | PluginRunnerLoadError error
|
108 | 137 | PluginRunnerExecuteResponse interface{}
|
109 | 138 | PluginRunnerExecuteError error
|
110 | 139 | }
|
111 | 140 |
|
112 |
| -type PluginRunner struct { |
113 |
| - Response interface{} |
114 |
| - Error error |
115 |
| -} |
116 |
| - |
117 |
| -func (pr PluginRunner) Run(ctx context.Context, req plugin.Request) (interface{}, error) { |
118 |
| - return pr.Response, pr.Error |
119 |
| -} |
120 |
| - |
121 |
| -func (pm PluginManager) Get(ctx context.Context, name string) (*manager.Plugin, error) { |
122 |
| - return &manager.Plugin{ |
123 |
| - Metadata: plugin.Metadata{ |
| 141 | +func (pm PluginManager) Get(ctx context.Context, name string) (plugin.Plugin, error) { |
| 142 | + return &PluginMock{ |
| 143 | + Metadata: proto.GetMetadataResponse{ |
124 | 144 | Name: "plugin-name",
|
125 | 145 | Description: "for mocking in unit tests",
|
126 | 146 | Version: "1.0.0",
|
127 | 147 | URL: ".",
|
128 | 148 | SupportedContractVersions: []string{"1.0"},
|
129 | 149 | Capabilities: pm.PluginCapabilities,
|
130 | 150 | },
|
131 |
| - Path: ".", |
132 |
| - Err: nil, |
| 151 | + ExecuteResponse: pm.PluginRunnerExecuteResponse, |
| 152 | + ExecuteError: pm.PluginRunnerExecuteError, |
133 | 153 | }, pm.GetPluginError
|
134 | 154 | }
|
135 |
| -func (pm PluginManager) Runner(name string) (plugin.Runner, error) { |
136 |
| - return PluginRunner{ |
137 |
| - Response: pm.PluginRunnerExecuteResponse, |
138 |
| - Error: pm.PluginRunnerExecuteError, |
139 |
| - }, pm.PluginRunnerLoadError |
| 155 | + |
| 156 | +func (pm PluginManager) List(ctx context.Context) ([]string, error) { |
| 157 | + panic("not implemented") |
140 | 158 | }
|
0 commit comments