This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
forked from containers/image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stubs.NoSignatures and stubs.AlwaysSupportsSignatures, use them i…
…n transports Should not change behavior. Signed-off-by: Miloslav Trmač <[email protected]>
- Loading branch information
Showing
7 changed files
with
58 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package stubs | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/opencontainers/go-digest" | ||
) | ||
|
||
// NoSignaturesInitialize implements parts of private.ImageDestination | ||
// for transports that don’t support storing signatures. | ||
// See NoSignatures() below. | ||
type NoSignaturesInitialize struct { | ||
message string | ||
} | ||
|
||
// NoSignatures creates a NoSignaturesInitialize, failing with message. | ||
func NoSignatures(message string) NoSignaturesInitialize { | ||
return NoSignaturesInitialize{ | ||
message: message, | ||
} | ||
} | ||
|
||
// SupportsSignatures returns an error (to be displayed to the user) if the destination certainly can't store signatures. | ||
// Note: It is still possible for PutSignatures to fail if SupportsSignatures returns nil. | ||
func (stub NoSignaturesInitialize) SupportsSignatures(ctx context.Context) error { | ||
return errors.New(stub.message) | ||
} | ||
|
||
// PutSignatures writes a set of signatures to the destination. | ||
// If instanceDigest is not nil, it contains a digest of the specific manifest instance to write or overwrite the signatures for | ||
// (when the primary manifest is a manifest list); this should always be nil if the primary manifest is not a manifest list. | ||
// MUST be called after PutManifest (signatures may reference manifest contents). | ||
func (stub NoSignaturesInitialize) PutSignatures(ctx context.Context, signatures [][]byte, instanceDigest *digest.Digest) error { | ||
if len(signatures) != 0 { | ||
return errors.New(stub.message) | ||
} | ||
return nil | ||
} | ||
|
||
// SupportsSignatures implements SupportsSignatures() that returns nil. | ||
// Note that it might be even more useful to return a value dynamically detected based on | ||
type AlwaysSupportsSignatures struct{} | ||
|
||
// SupportsSignatures returns an error (to be displayed to the user) if the destination certainly can't store signatures. | ||
// Note: It is still possible for PutSignatures to fail if SupportsSignatures returns nil. | ||
func (stub AlwaysSupportsSignatures) SupportsSignatures(ctx context.Context) error { | ||
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
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