Validate published output declarations
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -66,7 +65,7 @@ func (l RemoteLock) Validate() error {
|
||||
if l.FormatVersion != RemoteLockFormatVersion {
|
||||
return fmt.Errorf("unsupported remote lock format version %d", l.FormatVersion)
|
||||
}
|
||||
if err := validateRemoteLockSource(l.Source); err != nil {
|
||||
if err := validateCanonicalPublishSource(l.Source); err != nil {
|
||||
return fmt.Errorf("remote lock source: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(l.Reason) != l.Reason {
|
||||
@@ -137,7 +136,7 @@ func RemoteLockKey(sessionPrefix, source string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := validateRemoteLockSource(source); err != nil {
|
||||
if err := validateCanonicalPublishSource(source); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return locksPrefix + remoteLockDigest(source) + ".lock", nil
|
||||
@@ -267,17 +266,6 @@ func lookupRemoteLockAtKey(ctx context.Context, store storage.ObjectStore, key,
|
||||
return RemoteLockLookup{Lock: lock, Present: true, Generation: info.ETag}, nil
|
||||
}
|
||||
|
||||
func validateRemoteLockSource(source string) error {
|
||||
classified, err := artifactpolicy.ClassifySource(source)
|
||||
if err != nil || classified.Kind == artifactpolicy.SourceKindPreviousArtifact {
|
||||
return fmt.Errorf("source %q is not a supported publish source", source)
|
||||
}
|
||||
if classified.ID != source {
|
||||
return fmt.Errorf("source %q is not canonical", source)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func remoteLocksPrefix(sessionPrefix string) (string, error) {
|
||||
if err := validateRemoteLockSessionPrefix(sessionPrefix); err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user