github.com/wolfi-dev/wolfictl@v0.16.11/pkg/configs/advisory/v2/section_updaters.go (about)

     1  package v2
     2  
     3  import "github.com/wolfi-dev/wolfictl/pkg/configs"
     4  
     5  func NewSchemaVersionSectionUpdater(newSchemaVersion string) configs.EntryUpdater[Document] {
     6  	updater := func(_ Document) (string, error) {
     7  		return newSchemaVersion, nil
     8  	}
     9  
    10  	yamlASTMutater := configs.NewTargetedYAMLASTMutater[string, Document](
    11  		"schema-version",
    12  		updater,
    13  		func(doc Document, data string) Document {
    14  			doc.SchemaVersion = data
    15  			return doc
    16  		},
    17  	)
    18  
    19  	return configs.NewYAMLUpdateFunc[Document](yamlASTMutater)
    20  }
    21  
    22  func NewAdvisoriesSectionUpdater(
    23  	updater configs.SectionUpdater[Advisories, Document],
    24  ) configs.EntryUpdater[Document] {
    25  	yamlASTMutater := configs.NewTargetedYAMLASTMutater[Advisories, Document](
    26  		"advisories",
    27  		updater,
    28  		func(doc Document, data Advisories) Document {
    29  			doc.Advisories = data
    30  
    31  			// Since we're using _this_ version of wolfictl to update the document, we
    32  			// should update the schema version, which ensures that any features of the
    33  			// current schema being used in this document update are accounted for in the
    34  			// document's expressed schema version.
    35  			doc.SchemaVersion = SchemaVersion
    36  
    37  			return doc
    38  		},
    39  	)
    40  
    41  	return configs.NewYAMLUpdateFunc[Document](yamlASTMutater)
    42  }