@@ -59,8 +59,28 @@ func NewProposedEntry(ctx context.Context, kind, version string, props ArtifactP
5959 return nil , fmt .Errorf ("could not create entry for kind '%v'" , kind )
6060}
6161
62- // NewEntry returns the specific instance for the type and version specified in the doc
63- func NewEntry (pe models.ProposedEntry ) (EntryImpl , error ) {
62+ // CreateVersionedEntry returns the specific instance for the type and version specified in the doc
63+ // This method should be used on the insertion flow, which validates that the specific version proposed
64+ // is permitted to be entered into the log.
65+ func CreateVersionedEntry (pe models.ProposedEntry ) (EntryImpl , error ) {
66+ ei , err := UnmarshalEntry (pe )
67+ if err != nil {
68+ return nil , err
69+ }
70+ kind := pe .Kind ()
71+ if tf , found := TypeMap .Load (kind ); found {
72+ if ! tf .(func () TypeImpl )().IsSupportedVersion (ei .APIVersion ()) {
73+ return nil , fmt .Errorf ("entry kind '%v' does not support inserting entries of version '%v'" , kind , ei .APIVersion ())
74+ }
75+ }
76+
77+ return ei , nil
78+ }
79+
80+ // UnmarshalEntry returns the specific instance for the type and version specified in the doc
81+ // This method does not check for whether the version of the entry could be currently inserted into the log,
82+ // and is useful when dealing with entries that have been persisted to the log.
83+ func UnmarshalEntry (pe models.ProposedEntry ) (EntryImpl , error ) {
6484 if pe == nil {
6585 return nil , errors .New ("proposed entry cannot be nil" )
6686 }
@@ -73,7 +93,7 @@ func NewEntry(pe models.ProposedEntry) (EntryImpl, error) {
7393 }
7494 return t .UnmarshalEntry (pe )
7595 }
76- return nil , fmt .Errorf ("could not create entry for kind '%v'" , kind )
96+ return nil , fmt .Errorf ("could not unmarshal entry for kind '%v'" , kind )
7797}
7898
7999// DecodeEntry maps the (abstract) input structure into the specific entry implementation class;
0 commit comments