-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Scott Nichols <[email protected]>
- Loading branch information
Showing
18 changed files
with
302 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Copyright 2021 The Sigstore 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 options | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
cremote "github.com/sigstore/cosign/pkg/cosign/remote" | ||
) | ||
|
||
// FilesOptions is the wrapper for the files. | ||
type FilesOptions struct { | ||
Files []string | ||
} | ||
|
||
var _ Interface = (*FilesOptions)(nil) | ||
|
||
func (o *FilesOptions) Parse() ([]cremote.File, error) { | ||
fs := cremote.FilesFromFlagList(o.Files) | ||
|
||
// If we have multiple files, each file must have a platform. | ||
if len(fs) > 1 { | ||
for _, f := range fs { | ||
if f.Platform() == nil { | ||
return nil, fmt.Errorf("each file must include a unique platform, %s had no platform", f.Path()) | ||
} | ||
} | ||
} | ||
|
||
return fs, nil | ||
} | ||
|
||
func (o *FilesOptions) String() string { | ||
return strings.Join(o.Files, ",") | ||
} | ||
|
||
// AddFlags implements Interface | ||
func (o *FilesOptions) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringSliceVarP(&o.Files, "files", "f", nil, | ||
"<filepath>:[platform/arch]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Copyright 2021 The Sigstore 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 options | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// UploadBlobOptions is the top level wrapper for the `upload blob` command. | ||
type UploadBlobOptions struct { | ||
ContentType string | ||
Files FilesOptions | ||
Registry RegistryOptions | ||
} | ||
|
||
var _ Interface = (*UploadBlobOptions)(nil) | ||
|
||
// AddFlags implements Interface | ||
func (o *UploadBlobOptions) AddFlags(cmd *cobra.Command) { | ||
o.Registry.AddFlags(cmd) | ||
o.Files.AddFlags(cmd) | ||
|
||
cmd.Flags().StringVar(&o.ContentType, "ct", "", | ||
"content type to set") | ||
} | ||
|
||
// UploadWASMOptions is the top level wrapper for the `upload wasm` command. | ||
type UploadWASMOptions struct { | ||
File string | ||
Registry RegistryOptions | ||
} | ||
|
||
var _ Interface = (*UploadWASMOptions)(nil) | ||
|
||
// AddFlags implements Interface | ||
func (o *UploadWASMOptions) AddFlags(cmd *cobra.Command) { | ||
o.Registry.AddFlags(cmd) | ||
|
||
cmd.Flags().StringVarP(&o.File, "file", "f", "", | ||
"path to the wasm file to upload") | ||
_ = cmd.MarkFlagRequired("file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// Copyright 2021 The Sigstore 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 cli | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/sigstore/cosign/cmd/cosign/cli/options" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/upload" | ||
) | ||
|
||
func addUpload(topLevel *cobra.Command) { | ||
cmd := &cobra.Command{ | ||
Use: "upload", | ||
Short: "Provides utilities for uploading artifacts to a registry", | ||
} | ||
|
||
cmd.AddCommand( | ||
uploadBlob(), | ||
uploadWASM(), | ||
) | ||
|
||
topLevel.AddCommand(cmd) | ||
} | ||
|
||
func uploadBlob() *cobra.Command { | ||
o := &options.UploadBlobOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "blob", | ||
Short: "Upload one or more blobs to the supplied container image address.", | ||
Long: "Upload one or more blobs to the supplied container image address.\ncosign upload blob -f <blob ref> <image uri>", | ||
Example: ` | ||
# upload a blob named foo to the location specified by <IMAGE> | ||
cosign upload blob -f foo <IMAGE> | ||
# upload a blob named foo to the location specified by <IMAGE>, setting the os field to "MYOS". | ||
cosign upload blob -f foo:MYOS <IMAGE> | ||
# upload a blob named foo to the location specified by <IMAGE>, setting the os field to "MYOS" and the platform field to "MYPLATFORM". | ||
cosign upload blob -f foo:MYOS/MYPLATFORM <IMAGE> | ||
# upload two blobs named foo-darwin and foo-linux to the location specified by <IMAGE>, setting the os fields | ||
cosign upload blob -f foo-darwin:darwin -f foo-linux:linux <IMAGE>`, | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if len(o.Files.Files) < 1 { | ||
return flag.ErrHelp | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
files, err := o.Files.Parse() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return upload.BlobCmd(cmd.Context(), o.Registry, files, o.ContentType, args[0]) | ||
}, | ||
} | ||
|
||
o.AddFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func uploadWASM() *cobra.Command { | ||
o := &options.UploadWASMOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "wasm", | ||
Short: "Upload a wasm module to the supplied container image reference", | ||
Long: "Upload a wasm module to the supplied container image reference", | ||
Example: "cosign upload wasm -f foo.wasm <image uri>", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return upload.WasmCmd(cmd.Context(), o.Registry, o.File, args[0]) | ||
}, | ||
} | ||
|
||
o.AddFlags(cmd) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.