Skip to content

Commit 18c7aa9

Browse files
author
dlorenc
authored
Move cosign download to cosign download signature. (#392)
This is in preparation for other attachment types, like SBOMs and attestations. Signed-off-by: Dan Lorenc <[email protected]>
1 parent afd71a4 commit 18c7aa9

File tree

17 files changed

+79
-34
lines changed

17 files changed

+79
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* BREAKING: Move `cosign upload-blob` to `cosign upload blob`.
88
* BREAKING: Move `cosign upload` to `cosign attach signature`.
9+
* BREAKING: Move `cosign download` to `cosign download signature`.
910

1011
### Bug Fixes
1112

EXAMPLES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ cat gcpkms.sig | base64 | cosign attach signature -signature - us-central1-doc
1414
Now (on another machine) download the public key, payload, signatures and verify it!
1515

1616
```shell
17-
$ cosign download us-central1-docker.pkg.dev/dlorenc-vmtest2/test/taskrun > signatures.json
17+
$ cosign download signature us-central1-docker.pkg.dev/dlorenc-vmtest2/test/taskrun > signatures.json
1818
# There could be multiple signatures, let's pretend it's the last one.
1919
# Extract the payload and signature, base64 decoding them.
2020
$ cat signatures.json | tail -1 | jq -r .Payload | base64 -D > payload

USAGE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ invalid or missing annotation in claim: map[sig:original]
205205
Each signature is printed to stdout in a json format:
206206

207207
```
208-
$ cosign download us-central1-docker.pkg.dev/dlorenc-vmtest2/test/taskrun
208+
$ cosign download signature us-central1-docker.pkg.dev/dlorenc-vmtest2/test/taskrun
209209
{"Base64Signature":"Ejy6ipGJjUzMDoQFePWixqPBYF0iSnIvpMWps3mlcYNSEcRRZelL7GzimKXaMjxfhy5bshNGvDT5QoUJ0tqUAg==","Payload":"eyJDcml0aWNhbCI6eyJJZGVudGl0eSI6eyJkb2NrZXItcmVmZXJlbmNlIjoiIn0sIkltYWdlIjp7IkRvY2tlci1tYW5pZmVzdC1kaWdlc3QiOiI4N2VmNjBmNTU4YmFkNzliZWVhNjQyNWEzYjI4OTg5ZjAxZGQ0MTcxNjQxNTBhYjNiYWFiOThkY2JmMDRkZWY4In0sIlR5cGUiOiIifSwiT3B0aW9uYWwiOm51bGx9"}
210210
```
211211

cmd/cosign/cli/attach/sig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func SignatureCmd(ctx context.Context, sigRef, payloadRef, imageRef string) erro
8080
repo := ref.Context()
8181
img := repo.Digest(get.Digest.String())
8282

83-
sigRepo, err := cli.SignatureRepositoryForImage(ref)
83+
sigRepo, err := cli.TargetRepositoryForImage(ref)
8484
if err != nil {
8585
return err
8686
}

cmd/cosign/cli/clean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func CleanCmd(_ context.Context, imageRef string) error {
5858
return err
5959
}
6060

61-
sigRepo, err := SignatureRepositoryForImage(ref)
61+
sigRepo, err := TargetRepositoryForImage(ref)
6262
if err != nil {
6363
return err
6464
}

cmd/cosign/cli/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func CopyCmd(ctx context.Context, srcImg, dstImg string, sigOnly, force bool) er
7676
return err
7777
}
7878

79-
srcSigRepo, err := SignatureRepositoryForImage(srcRef)
79+
srcSigRepo, err := TargetRepositoryForImage(srcRef)
8080
if err != nil {
8181
return err
8282
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Copyright 2021 The Sigstore Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package download
17+
18+
import (
19+
"context"
20+
"flag"
21+
22+
"github.com/peterbourgon/ff/v3/ffcli"
23+
)
24+
25+
func Download() *ffcli.Command {
26+
var (
27+
flagset = flag.NewFlagSet("cosign download", flag.ExitOnError)
28+
)
29+
30+
return &ffcli.Command{
31+
Name: "download",
32+
ShortUsage: "cosign download",
33+
ShortHelp: "download contains tools to download artifacts and attached artifacts in a registry",
34+
FlagSet: flagset,
35+
Subcommands: []*ffcli.Command{Signature()},
36+
Exec: func(ctx context.Context, args []string) error {
37+
return flag.ErrHelp
38+
},
39+
}
40+
}

cmd/cosign/cli/download.go renamed to cmd/cosign/cli/download/signature.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
package cli
16+
package download
1717

1818
import (
1919
"context"
@@ -25,34 +25,34 @@ import (
2525
"github.com/google/go-containerregistry/pkg/name"
2626
"github.com/google/go-containerregistry/pkg/v1/remote"
2727
"github.com/peterbourgon/ff/v3/ffcli"
28-
28+
"github.com/sigstore/cosign/cmd/cosign/cli"
2929
"github.com/sigstore/cosign/pkg/cosign"
3030
)
3131

32-
func Download() *ffcli.Command {
32+
func Signature() *ffcli.Command {
3333
var (
34-
flagset = flag.NewFlagSet("cosign download", flag.ExitOnError)
34+
flagset = flag.NewFlagSet("cosign download signature", flag.ExitOnError)
3535
)
3636
return &ffcli.Command{
37-
Name: "download",
38-
ShortUsage: "cosign download <image uri>",
37+
Name: "signature",
38+
ShortUsage: "cosign download signature <image uri>",
3939
ShortHelp: "Download signatures from the supplied container image",
4040
FlagSet: flagset,
4141
Exec: func(ctx context.Context, args []string) error {
4242
if len(args) != 1 {
4343
return flag.ErrHelp
4444
}
45-
return DownloadCmd(ctx, args[0])
45+
return SignatureCmd(ctx, args[0])
4646
},
4747
}
4848
}
4949

50-
func DownloadCmd(ctx context.Context, imageRef string) error {
50+
func SignatureCmd(ctx context.Context, imageRef string) error {
5151
ref, err := name.ParseReference(imageRef)
5252
if err != nil {
5353
return err
5454
}
55-
sigRepo, err := SignatureRepositoryForImage(ref)
55+
sigRepo, err := cli.TargetRepositoryForImage(ref)
5656
if err != nil {
5757
return err
5858
}

cmd/cosign/cli/sign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func SignCmd(ctx context.Context, so SignOpts,
308308
continue
309309
}
310310

311-
sigRepo, err := SignatureRepositoryForImage(ref)
311+
sigRepo, err := TargetRepositoryForImage(ref)
312312
if err != nil {
313313
return err
314314
}

cmd/cosign/cli/triangulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func MungeCmd(_ context.Context, imageRef string) error {
5858
return err
5959
}
6060

61-
sigRepo, err := SignatureRepositoryForImage(ref)
61+
sigRepo, err := TargetRepositoryForImage(ref)
6262
if err != nil {
6363
return err
6464
}

0 commit comments

Comments
 (0)