| 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 cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/ |
| 15 | |
| 16 | import ( |
| 17 | "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/" |
| 18 | "osscip-go gomod github.com/golang/go/src go1.20 os/" |
| 19 | "sortscip-go gomod github.com/golang/go/src go1.20 sort/" |
| 20 | "stringsscip-go gomod github.com/golang/go/src go1.20 strings/" |
| 21 | |
| 22 | "github.com/notaryproject/notation-plugin-framework-go/internal/slicesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/" |
| 23 | "github.com/notaryproject/notation-plugin-framework-go/pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/" |
| 24 | ) |
| 25 | |
| 26 | func getValidArgsStringscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/getValidArgsString().(md *pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GetMetadataResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#) string { |
| 27 | return fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.20 fmt/Sprintf().(`<%s>`, stringsscip-go gomod github.com/golang/go/src go1.20 strings/.Joinscip-go gomod github.com/golang/go/src go1.20 strings/Join().(getValidArgsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/getValidArgs().(md), "|")) |
| 28 | } |
| 29 | |
| 30 | // getValidArgs returns list of valid arguments depending upon the plugin capabilities |
| 31 | func getValidArgsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/getValidArgs().(md *pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GetMetadataResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#) []string { |
| 32 | args := []string{ |
| 33 | string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGetMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGetMetadata.), string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Versionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Version.), |
| 34 | } |
| 35 | |
| 36 | if slicesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/.Containsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/Contains().(md.Capabilitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Capabilities., pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CapabilitySignatureGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilitySignatureGenerator.) { |
| 37 | args = append(args, string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGenerateSignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGenerateSignature.), string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandDescribeKeyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandDescribeKey.)) |
| 38 | } |
| 39 | |
| 40 | if slicesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/.Containsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/Contains().(md.Capabilitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Capabilities., pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CapabilityEnvelopeGeneratorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilityEnvelopeGenerator.) { |
| 41 | args = append(args, string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandGenerateEnvelopescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandGenerateEnvelope.)) |
| 42 | } |
| 43 | |
| 44 | if slicesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/.Containsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/Contains().(md.Capabilitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Capabilities., pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CapabilityTrustedIdentityVerifierscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilityTrustedIdentityVerifier.) || slicesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/.Containsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/internal/slices`/Contains().(md.Capabilitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Capabilities., pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CapabilityRevocationCheckVerifierscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CapabilityRevocationCheckVerifier.) { |
| 45 | args = append(args, string(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.CommandVerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandVerifySignature.)) |
| 46 | } |
| 47 | |
| 48 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(args) |
| 49 | return args |
| 50 | } |
| 51 | |
| 52 | // deliverError print to standard error and then return nonzero exit code |
| 53 | func deliverErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deliverError().(message string) { |
| 54 | _, _ = fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.20 fmt/Fprint().(osscip-go gomod github.com/golang/go/src go1.20 os/.Stderrscip-go gomod github.com/golang/go/src go1.20 os/Stderr., message) |
| 55 | osscip-go gomod github.com/golang/go/src go1.20 os/.Exitscip-go gomod github.com/golang/go/src go1.20 os/Exit().(1) |
| 56 | } |
| 57 | |
| 58 | // deferStdout is used to make sure that nothing get emitted to stdout and stderr until intentionally rescued. |
| 59 | // This is required to make sure that the plugin or its dependency doesn't interfere with notation <-> plugin communication |
| 60 | func deferStdoutscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deferStdout().() func() { |
| 61 | // Ignoring error because we don't want plugin to fail if `os.DevNull` is misconfigured. |
| 62 | null, _ := osscip-go gomod github.com/golang/go/src go1.20 os/.Openscip-go gomod github.com/golang/go/src go1.20 os/Open().(osscip-go gomod github.com/golang/go/src go1.20 os/.DevNullscip-go gomod github.com/golang/go/src go1.20 os/DevNull.) |
| 63 | sout := osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. |
| 64 | serr := osscip-go gomod github.com/golang/go/src go1.20 os/.Stderrscip-go gomod github.com/golang/go/src go1.20 os/Stderr. |
| 65 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. = null |
| 66 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stderrscip-go gomod github.com/golang/go/src go1.20 os/Stderr. = null |
| 67 | |
| 68 | return func() { |
| 69 | err := null.Closescip-go gomod github.com/golang/go/src go1.20 os/File#Close().() |
| 70 | if err != nil { |
| 71 | return |
| 72 | } |
| 73 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stdoutscip-go gomod github.com/golang/go/src go1.20 os/Stdout. = sout |
| 74 | osscip-go gomod github.com/golang/go/src go1.20 os/.Stderrscip-go gomod github.com/golang/go/src go1.20 os/Stderr. = serr |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // discardLogger implements Logger but logs nothing. It is used when user |
| 79 | // disenabled logging option in notation, i.e. loggerKey is not in the context. |
| 80 | type discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger# struct{} |
| 81 | |
| 82 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Debugscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Debug().(_ ...interface{}) { |
| 83 | } |
| 84 | |
| 85 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Debugf().(_ string, _ ...interface{}) { |
| 86 | } |
| 87 | |
| 88 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Debuglnscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Debugln().(_ ...interface{}) { |
| 89 | } |
| 90 | |
| 91 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Infoscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Info().(_ ...interface{}) { |
| 92 | } |
| 93 | |
| 94 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Infofscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Infof().(_ string, _ ...interface{}) { |
| 95 | } |
| 96 | |
| 97 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Infolnscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Infoln().(_ ...interface{}) { |
| 98 | } |
| 99 | |
| 100 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Warnscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Warn().(_ ...interface{}) { |
| 101 | } |
| 102 | |
| 103 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Warnfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Warnf().(_ string, _ ...interface{}) { |
| 104 | } |
| 105 | |
| 106 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Warnlnscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Warnln().(_ ...interface{}) { |
| 107 | } |
| 108 | |
| 109 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Error().(_ ...interface{}) { |
| 110 | } |
| 111 | |
| 112 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Errorf().(_ string, _ ...interface{}) { |
| 113 | } |
| 114 | |
| 115 | func (dl *discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#) Errorlnscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#Errorln().(_ ...interface{}) { |
| 116 | } |