-
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.
Start to sketch
internal/oci/remote.SignedImage[Index]
.
This follows the pattern GGCR uses for functional `remote.Options`, and starts to define `SignedImage[Index]` methods, which build upon the `Signatures` implementation from a prior change. This also tries to start adopting this pattern a few places, which drops bits of boilerplate (or changes them to functional options). As part of this, I'm combining `FetchSignaturesForImage[Digest]` and tweaking it's signature a bit (no pun intended!), but I think long term we'll just want folks to consume the `remote` package directly themselves. Signed-off-by: Matt Moore <[email protected]>
- Loading branch information
Showing
9 changed files
with
288 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// 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 remote | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/google/go-containerregistry/pkg/authn" | ||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
) | ||
|
||
const ( | ||
SignatureTagSuffix = ".sig" | ||
SBOMTagSuffix = ".sbom" | ||
AttestationTagSuffix = ".att" | ||
|
||
RepoOverrideKey = "COSIGN_REPOSITORY" | ||
) | ||
|
||
// Option is a functional option for remote operations. | ||
type Option func(*options) error | ||
|
||
type options struct { | ||
signatureSuffix string | ||
attestationSuffix string | ||
sbomSuffix string | ||
targetRepository name.Repository | ||
ropt []remote.Option | ||
} | ||
|
||
func makeOptions(target name.Repository, opts ...Option) (*options, error) { | ||
o := &options{ | ||
signatureSuffix: SignatureTagSuffix, | ||
attestationSuffix: AttestationTagSuffix, | ||
sbomSuffix: SBOMTagSuffix, | ||
targetRepository: target, | ||
ropt: []remote.Option{ | ||
remote.WithAuthFromKeychain(authn.DefaultKeychain), | ||
// TODO(mattmoor): Incorporate user agent. | ||
}, | ||
} | ||
|
||
// Before applying options, allow the environment to override things. | ||
if ro := os.Getenv(RepoOverrideKey); ro != "" { | ||
repo, err := name.NewRepository(ro) | ||
if err != nil { | ||
return nil, err | ||
} | ||
o.targetRepository = repo | ||
} | ||
|
||
for _, option := range opts { | ||
if err := option(o); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return o, nil | ||
} | ||
|
||
// WithSignatureSuffix is a functional option for overriding the default | ||
// signature tag suffix. | ||
func WithSignatureSuffix(suffix string) Option { | ||
return func(o *options) error { | ||
o.signatureSuffix = suffix | ||
return nil | ||
} | ||
} | ||
|
||
// WithAttestationSuffix is a functional option for overriding the default | ||
// attestation tag suffix. | ||
func WithAttestationSuffix(suffix string) Option { | ||
return func(o *options) error { | ||
o.attestationSuffix = suffix | ||
return nil | ||
} | ||
} | ||
|
||
// WithSBOMSuffix is a functional option for overriding the default | ||
// SBOM tag suffix. | ||
func WithSBOMSuffix(suffix string) Option { | ||
return func(o *options) error { | ||
o.sbomSuffix = suffix | ||
return nil | ||
} | ||
} | ||
|
||
// WithRemoteOptions is a functional option for overriding the default | ||
// remote options passed to GGCR. | ||
func WithRemoteOptions(opts ...remote.Option) Option { | ||
return func(o *options) error { | ||
o.ropt = opts | ||
return nil | ||
} | ||
} | ||
|
||
// WithTargetRepository is a functional option for overriding the default | ||
// target repository hosting the signature and attestation tags. | ||
func WithTargetRepository(repo name.Repository) Option { | ||
return func(o *options) error { | ||
o.targetRepository = repo | ||
return nil | ||
} | ||
} |
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
Oops, something went wrong.