| 1 | // Copyright The Notary Project Authors. |
| 2 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | // you may not use this file except in compliance with the License. |
| 4 | // You may obtain a copy of the License at |
| 5 | // |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | // |
| 8 | // Unless required by applicable law or agreed to in writing, software |
| 9 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | // See the License for the specific language governing permissions and |
| 12 | // limitations under the License. |
| 13 | |
| 14 | package plugin |
| 15 | |
| 16 | // GetMetadataRequest contains the parameters passed in a get-plugin-metadata |
| 17 | // request. |
| 18 | type GetMetadataRequest struct { |
| 19 | PluginConfig map[string]string `json:"pluginConfig,omitempty"` |
| 20 | } |
| 21 | |
| 22 | func (GetMetadataRequest) Command() Command { |
| 23 | return CommandGetMetadata |
| 24 | } |
| 25 | |
| 26 | // Validate validates GetMetadataRequest struct |
| 27 | func (GetMetadataRequest) Validate() error { |
| 28 | return nil |
| 29 | } |
| 30 | |
| 31 | // GetMetadataResponse provided by the plugin. |
| 32 | type GetMetadataResponse struct { |
| 33 | Name string `json:"name"` |
| 34 | Description string `json:"description"` |
| 35 | Version string `json:"version"` |
| 36 | URL string `json:"url"` |
| 37 | SupportedContractVersions []string `json:"supportedContractVersions,omitempty"` |
| 38 | Capabilities []Capability `json:"capabilities"` |
| 39 | } |
| 40 | |
| 41 | // HasCapability return true if the metadata states that the |
| 42 | // capability is supported. |
| 43 | // Returns true if capability is empty. |
| 44 | func (resp *GetMetadataResponse) HasCapability(capability Capability) bool { |
| 45 | if capability == "" { |
| 46 | return true |
| 47 | } |
| 48 | for _, c := range resp.Capabilities { |
| 49 | if c == capability { |
| 50 | return true |
| 51 | } |
| 52 | } |
| 53 | return false |
| 54 | } |