Debian Codegraph @

cli/cli.go

raw symbols SCIP
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 cli provides boilerplate code required to generate plugin executable.
15 // At high level it performs following tasks
16 // 1. Validate command arguments
17 // 2. Read and unmarshal input
18 // 3. Execute relevant plugin functions
19 // 4. marshals output
20 package cliscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/
21
22 import (
23 "contextscip-go gomod github.com/golang/go/src go1.20 context/"
24 "encoding/jsonscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/"
25 "errorsscip-go gomod github.com/golang/go/src go1.20 errors/"
26 "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/"
27 "osscip-go gomod github.com/golang/go/src go1.20 os/"
28 "reflectscip-go gomod github.com/golang/go/src go1.20 reflect/"
29
30 "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`/"
31 "github.com/notaryproject/notation-plugin-framework-go/logscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/"
32 "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`/"
33 )
34
35 // CLI struct is used to create an executable for plugin.
36 type CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI# struct {
37 plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl. pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Plugin#
38 loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger. logscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/.Loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#
39 }
40
41 // New creates a new CLI using given plugin
42 func Newscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/New().(pl pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Plugin#) (*CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#, error) {
43 return NewWithLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/NewWithLogger().(pl, &discardLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/discardLogger#{})
44 }
45
46 // NewWithLogger creates a new CLI using given plugin and logger
47 func NewWithLoggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/NewWithLogger().(pl pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Plugin#, l logscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/.Loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#) (*CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#, error) {
48 if pl == nil {
49 return nil, errorsscip-go gomod github.com/golang/go/src go1.20 errors/.Newscip-go gomod github.com/golang/go/src go1.20 errors/New().("plugin cannot be nil")
50 }
51
52 return &CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#{
53 plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.: pl,
54 loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger.: l,
55 }, nil
56 }
57
58 // Execute is main controller that reads/validates commands, parses input, executes relevant plugin functions
59 // and returns corresponding output.
60 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) Executescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#Execute().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#, args []string) {
61 c.validateArgsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#validateArgs().(ctx, args)
62
63 rescueStdOut := deferStdoutscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deferStdout().()
64 command := args[1]
65 var resp any
66 var err error
67 switch pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Commandscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Command#(command) {
68 case 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.:
69 var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GetMetadataRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataRequest#
70 err = c.unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request)
71 if err == nil {
72 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("executing %s plugin's GetMetadata function", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.))
73 resp, err = c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl..GetMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenericPlugin#GetMetadata.(ctx, &request)
74 }
75 case 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.:
76 var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GenerateEnvelopeRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateEnvelopeRequest#
77 err = c.unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request)
78 if err == nil {
79 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("executing %s plugin's GenerateEnvelope function", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.))
80 resp, err = c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl..GenerateEnvelopescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/SignPlugin#GenerateEnvelope.(ctx, &request)
81 }
82 case 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.:
83 var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#
84 err = c.unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request)
85 if err == nil {
86 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("executing %s plugin's VerifySignature function", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.))
87 resp, err = c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl..VerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifyPlugin#VerifySignature.(ctx, &request)
88 }
89 case 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.:
90 var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.DescribeKeyRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/DescribeKeyRequest#
91 err = c.unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request)
92 if err == nil {
93 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("executing %s plugin's DescribeKey function", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.))
94 resp, err = c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl..DescribeKeyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/SignPlugin#DescribeKey.(ctx, &request)
95 }
96 case 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.:
97 var request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GenerateSignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenerateSignatureRequest#
98 err = c.unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(&request)
99 if err == nil {
100 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("executing %s plugin's GenerateSignature function", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.))
101 resp, err = c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl..GenerateSignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/SignPlugin#GenerateSignature.(ctx, &request)
102 }
103 case 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.:
104 rescueStdOut()
105 c.printVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#printVersion().(ctx)
106 return
107 default:
108 // should never happen
109 rescueStdOut()
110 deliverErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deliverError().(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewGenericErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewGenericError().("something went wrong").Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().())
111 }
112
113 op, pluginErr := c.marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(resp, err)
114 rescueStdOut()
115 if pluginErr != nil {
116 deliverErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deliverError().(pluginErr.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().())
117 }
118 fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Printscip-go gomod github.com/golang/go/src go1.20 fmt/Print().(op)
119 }
120
121 // printVersion prints version of executable
122 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) printVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#printVersion().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#) {
123 md := c.getMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#getMetadata().(ctx, c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.)
124
125 fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Printfscip-go gomod github.com/golang/go/src go1.20 fmt/Printf().("%s - %s\nVersion: %s\n", md.Namescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Name., md.Descriptionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Description., md.Versionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataResponse#Version.)
126 }
127
128 // validateArgs validate commands/arguments passed to executable.
129 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) validateArgsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#validateArgs().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#, args []string) {
130 md := c.getMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#getMetadata().(ctx, c.plscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#pl.)
131 if !(len(args) == 2 && 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().(getValidArgsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/getValidArgs().(md), args[1])) {
132 deliverErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deliverError().(fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.20 fmt/Sprintf().("Invalid command, valid commands are: %s", getValidArgsStringscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/getValidArgsString().(md)))
133 }
134 }
135
136 // unmarshalRequest reads input from std.in and unmarshal it into given request struct
137 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) unmarshalRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#unmarshalRequest().(request pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Requestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Request#) error {
138 if err := jsonscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/NewDecoder().(osscip-go gomod github.com/golang/go/src go1.20 os/.Stdinscip-go gomod github.com/golang/go/src go1.20 os/Stdin.).Decodescip-go gomod github.com/golang/go/src go1.20 `encoding/json`/Decoder#Decode().(request); err != nil {
139 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Errorf.("%s unmarshalling error: %v", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(request), err)
140 return pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewJSONParsingErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewJSONParsingError().(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorMsgMalformedInputscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorMsgMalformedInput.)
141 }
142
143 if err := request.Validatescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Request#Validate.(); err != nil {
144 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Errorf.("%s validation error: %v", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(request), err)
145 var plError *pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#
146 if errorsscip-go gomod github.com/golang/go/src go1.20 errors/.Asscip-go gomod github.com/golang/go/src go1.20 errors/As().(err, &plError) {
147 return pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewValidationErrorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationErrorf().("%s: %s", pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorMsgMalformedInputscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorMsgMalformedInput., plError.Messagescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Message.)
148 }
149 return pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewValidationErrorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationErrorf().("%s", pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorMsgMalformedInputscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorMsgMalformedInput.)
150 }
151
152 return nil
153 }
154
155 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) getMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#getMetadata().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#, p pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Plugin#) *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# {
156 md, err := p.GetMetadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GenericPlugin#GetMetadata.(ctx, &pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.GetMetadataRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/GetMetadataRequest#{})
157 if err != nil {
158 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Errorf.("GetMetadataRequest error: %v", err)
159 deliverErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/deliverError().("Error: Failed to get plugin metadata.")
160 }
161 return md
162 }
163
164 // marshalResponse marshals the given response struct into json
165 func (c *CLIscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#) marshalResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#marshalResponse().(response any, err error) (string, *pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#) {
166 if err != nil {
167 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Errorf.("%s error: %v", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(response), err)
168 if plgErr, ok := err.(*pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#); ok {
169 return "", plgErr
170 }
171 return "", pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewGenericErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewGenericError().(err.Error())
172 }
173
174 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debug.("marshalling response")
175 jsonResponse, err := jsonscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/Marshal().(response)
176 if err != nil {
177 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Errorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Errorf.("%s marshalling error: %v", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(response), err)
178 return "", pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.NewGenericErrorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewGenericErrorf().(pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/.ErrorMsgMalformedOutputFmtscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorMsgMalformedOutputFmt., err.Error())
179 }
180
181 c.loggerscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/cli`/CLI#logger..Debugfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/log`/Logger#Debugf.("%s response: %s", reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.20 reflect/TypeOf().(response), jsonResponse)
182 return string(jsonResponse), nil
183 }