Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Feb 25, 2025
1 parent c2da048 commit 928fc1d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
15 changes: 0 additions & 15 deletions cmd/notation/internal/option/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// copied and adopted from https://github.com/oras-project/oras with
// modification
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package option

import (
Expand Down
7 changes: 5 additions & 2 deletions cmd/notation/internal/option/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ package option

const userMetadataFlag = "user-metadata"

// userMetadata is user metadata flag values
// userMetadata defines a type for user-metadata flag.
//
// the userMetadata was used in both option.Signer and option.Verifier with
// different flag messages.
type userMetadata []string

// UserMetadataMap parses user-metadata flag into a map.
// UserMetadataMap parses user-metadata value into a map.
func (m *userMetadata) ToMap() (map[string]string, error) {
return parseFlagMap(*m, userMetadataFlag)
}
7 changes: 5 additions & 2 deletions cmd/notation/internal/option/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ func (opts *Plugin) ApplyFlags(cmd *cobra.Command) {
cmd.MarkFlagsRequiredTogether("id", "plugin")
}

// pluginConfig is a plugin config option.
// pluginConfig defines a type for plugin-config flag.
//
// the pluginConfig was used in both option.Plugin and option.Verifier with
// different flag messages.
type pluginConfig []string

// ToMap parses plugin-config flag value into a map.
// ToMap parses plugin-config value into a map.
func (c *pluginConfig) ToMap() (map[string]string, error) {
return parseFlagMap(*c, pluginConfigFlag)
}
6 changes: 4 additions & 2 deletions cmd/notation/internal/option/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/spf13/pflag"
)

const timestampURLFlag = "timestamp-url"

// Timestamp contains timestamp-related flag values
type Timestamp struct {
// ServerURL is the URL of the Timestamping Authority (TSA) server.
Expand All @@ -31,13 +33,13 @@ type Timestamp struct {

// ApplyFlags apply flags and their default values for Timestamp flags.
func (opts *Timestamp) ApplyFlags(fs *pflag.FlagSet) {
fs.StringVar(&opts.ServerURL, "timestamp-url", "", "RFC 3161 Timestamping Authority (TSA) server URL")
fs.StringVar(&opts.ServerURL, timestampURLFlag, "", "RFC 3161 Timestamping Authority (TSA) server URL")
fs.StringVar(&opts.RootCertificatePath, "timestamp-root-cert", "", "filepath of timestamp authority root certificate")
}

// Validate validates Timestamp flags.
func (opts *Timestamp) Validate(cmd *cobra.Command) error {
if cmd.Flags().Changed("timestamp-url") {
if cmd.Flags().Changed(timestampURLFlag) {
if opts.ServerURL == "" {
return errors.New("timestamping: tsa url cannot be empty")
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/notation/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,24 @@ Example - [Experimental] Sign an OCI artifact identified by a tag and referenced
return command
}

func runSign(command *cobra.Command, opts *signOpts) error {
func runSign(command *cobra.Command, cmdOpts *signOpts) error {
// set log level
ctx := opts.Logging.InitializeLogger(command.Context())
ctx := cmdOpts.Logging.InitializeLogger(command.Context())

// initialize
signer, err := signer.GetSigner(ctx, &opts.Signer)
signer, err := signer.GetSigner(ctx, &cmdOpts.Signer)
if err != nil {
return err
}
sigRepo, err := getRepository(ctx, opts.inputType, opts.reference, &opts.SecureRegistry, opts.forceReferrersTag)
sigRepo, err := getRepository(ctx, cmdOpts.inputType, cmdOpts.reference, &cmdOpts.SecureRegistry, cmdOpts.forceReferrersTag)
if err != nil {
return err
}
signOpts, err := prepareSigningOpts(ctx, opts)
signOpts, err := prepareSigningOpts(ctx, cmdOpts)
if err != nil {
return err
}
manifestDesc, resolvedRef, err := resolveReference(ctx, opts.inputType, opts.reference, sigRepo, func(ref string, manifestDesc ocispec.Descriptor) {
manifestDesc, resolvedRef, err := resolveReference(ctx, cmdOpts.inputType, cmdOpts.reference, sigRepo, func(ref string, manifestDesc ocispec.Descriptor) {
fmt.Fprintf(os.Stderr, "Warning: Always sign the artifact using digest(@sha256:...) rather than a tag(:%s) because tags are mutable and a tag reference can point to a different artifact than the one signed.\n", ref)
})
if err != nil {
Expand Down

0 comments on commit 928fc1d

Please sign in to comment.