Skip to content

Commit

Permalink
Embed SignOptions in RemoteSignOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Byron Chien <chienb@amazon.com>
  • Loading branch information
Byron Chien committed Jan 19, 2023
1 parent c98f90a commit ffaf954
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
7 changes: 3 additions & 4 deletions example_remoteSign_test.go
Expand Up @@ -46,10 +46,9 @@ func Example_remoteSign() {
exampleRepo := registry.NewRepository(remoteRepo)

// exampleSignOptions is an example of notation.SignOptions.
exampleSignOptions := notation.RemoteSignOptions{
ArtifactReference: exampleArtifactReference,
SignatureMediaType: exampleSignatureMediaType,
}
exampleSignOptions := notation.RemoteSignOptions{}
exampleSignOptions.ArtifactReference = exampleArtifactReference
exampleSignOptions.SignatureMediaType = exampleSignatureMediaType

// remote sign core process
// upon successful signing, descriptor of the sign content is returned and
Expand Down
33 changes: 8 additions & 25 deletions notation.go
Expand Up @@ -26,8 +26,8 @@ const annotationX509ChainThumbprint = "io.cncf.notary.x509chain.thumbprint#S256"
var errDoneVerification = errors.New("done verification")
var reservedAnnotationPrefixes = [...]string{"io.cncf.notary"}

// RemoteSignOptions contains parameters for notation.Sign.
type RemoteSignOptions struct {
// SignOptions contains parameters for Signer.Sign.
type SignOptions struct {
// ArtifactReference sets the reference of the artifact that needs to be signed.
ArtifactReference string

Expand All @@ -43,32 +43,16 @@ type RemoteSignOptions struct {
// PluginConfig sets or overrides the plugin configuration.
PluginConfig map[string]string

// UserMetadata contains key-value pairs that are added to the signature payload
UserMetadata map[string]string

// SigningAgent sets the signing agent name
SigningAgent string
}

// SignOptions contains parameters for Signer.Sign.
type SignOptions struct {
// ArtifactReference sets the reference of the artifact that needs to be signed.
ArtifactReference string

// SignatureMediaType is the envelope type of the signature.
// Currently both `application/jose+json` and `application/cose` are
// supported.
SignatureMediaType string

// ExpiryDuration identifies the expiry duration of the resulted signature. Zero value
// represents no expiry duration.
ExpiryDuration time.Duration

// PluginConfig sets or overrides the plugin configuration.
PluginConfig map[string]string
// RemoteSignOptions contains parameters for notation.Sign.
type RemoteSignOptions struct {
SignOptions

// SigningAgent sets the signing agent name
SigningAgent string
// UserMetadata contains key-value pairs that are added to the signature payload
UserMetadata map[string]string
}

// Signer is a generic interface for signing an artifact.
Expand Down Expand Up @@ -317,8 +301,7 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, re
errExceededMaxVerificationLimit := ErrorVerificationFailed{Msg: fmt.Sprintf("total number of signatures associated with an artifact should be less than: %d", remoteOpts.MaxSignatureAttempts)}
numOfSignatureProcessed := 0

var verificationFailedErr error
verificationFailedErr = ErrorVerificationFailed{}
var verificationFailedErr error = ErrorVerificationFailed{}

// get signature manifests
logger.Debug("Fetching signature manifests using referrers API")
Expand Down
21 changes: 12 additions & 9 deletions notation_test.go
Expand Up @@ -28,10 +28,10 @@ func TestSignSuccess(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(b *testing.T) {
opts := RemoteSignOptions{
ExpiryDuration: tc.dur,
ArtifactReference: mock.SampleArtifactUri,
}
opts := RemoteSignOptions{}
opts.ExpiryDuration = tc.dur
opts.ArtifactReference = mock.SampleArtifactUri

_, err := Sign(context.Background(), &dummySigner{}, repo, opts)
if err != nil {
b.Fatalf("Sign failed with error: %v", err)
Expand All @@ -42,10 +42,10 @@ func TestSignSuccess(t *testing.T) {

func TestSignSuccessWithUserMetadata(t *testing.T) {
repo := mock.NewRepository()
opts := RemoteSignOptions{
ArtifactReference: mock.SampleArtifactUri,
UserMetadata: expectedMetadata,
}
opts := RemoteSignOptions{}
opts.ArtifactReference = mock.SampleArtifactUri
opts.UserMetadata = expectedMetadata

_, err := Sign(context.Background(), &verifyMetadataSigner{}, repo, opts)
if err != nil {
t.Fatalf("error: %v", err)
Expand All @@ -63,7 +63,10 @@ func TestSignWithInvalidExpiry(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(b *testing.T) {
_, err := Sign(context.Background(), &dummySigner{}, repo, RemoteSignOptions{ExpiryDuration: tc.dur})
opts := RemoteSignOptions{}
opts.ExpiryDuration = tc.dur

_, err := Sign(context.Background(), &dummySigner{}, repo, opts)
if err == nil {
b.Fatalf("Expected error but not found")
}
Expand Down

0 comments on commit ffaf954

Please sign in to comment.