diff --git a/cmd/catalog-importer/cmd/sync.go b/cmd/catalog-importer/cmd/sync.go index 3dc4b83..84fc424 100644 --- a/cmd/catalog-importer/cmd/sync.go +++ b/cmd/catalog-importer/cmd/sync.go @@ -473,7 +473,7 @@ func (opt *SyncOptions) Run(ctx context.Context, logger kitlog.Logger, cfg *conf logger.Log("msg", "reconciling catalog entries", "output", outputType.TypeName) catalogType := catalogTypesByOutput[outputType.TypeName] - err = reconcile.Entries(ctx, logger, entriesClient, catalogType, entryModels, newEntriesProgress(!opt.DryRun)) + err = reconcile.Entries(ctx, logger, entriesClient, outputType, catalogType, entryModels, newEntriesProgress(!opt.DryRun)) if err != nil { return errors.Wrap(err, fmt.Sprintf("outputs (type_name = '%s'): reconciling catalog entries", outputType.TypeName)) } @@ -509,7 +509,7 @@ func (opt *SyncOptions) Run(ctx context.Context, logger kitlog.Logger, cfg *conf OUT("\n ↻ %s (enum)", enumModel.TypeName) catalogType := catalogTypesByOutput[enumModel.TypeName] - err := reconcile.Entries(ctx, logger, entriesClient, catalogType, enumModels, newEntriesProgress(!opt.DryRun)) + err := reconcile.Entries(ctx, logger, entriesClient, outputType, catalogType, enumModels, newEntriesProgress(!opt.DryRun)) if err != nil { return errors.Wrap(err, fmt.Sprintf("outputs (type_name = '%s'): enum for attribute (id = '%s'): %s: reconciling catalog entries", diff --git a/config/reference.jsonnet b/config/reference.jsonnet index b438902..7755948 100644 --- a/config/reference.jsonnet +++ b/config/reference.jsonnet @@ -228,6 +228,12 @@ // // Will default to the id of this attribute. source: '$.metadata.description', + + // If true we will only create the attribute in the schema and won't sync + // the value of the attribute. This is useful when you want to specify the + // schema but leave this field available to be controlled from the dashboard + // manually, separately from the importer. + schema_only: false, }, // Most of the time you can be much less verbose, as source will diff --git a/output/output.go b/output/output.go index 36df0ec..52fc9ef 100644 --- a/output/output.go +++ b/output/output.go @@ -57,6 +57,7 @@ type Attribute struct { Enum *AttributeEnum `json:"enum"` BacklinkAttribute null.String `json:"backlink_attribute"` Path []string `json:"path"` + SchemaOnly bool `json:"schema_only"` } func (a Attribute) Validate() error { diff --git a/reconcile/entries.go b/reconcile/entries.go index f12b8ac..bad6c0b 100644 --- a/reconcile/entries.go +++ b/reconcile/entries.go @@ -64,7 +64,7 @@ type EntriesProgress struct { OnUpdateProgress func() } -func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, catalogType *client.CatalogTypeV2, entryModels []*output.CatalogEntryModel, progress *EntriesProgress) error { +func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, outputType *output.Output, catalogType *client.CatalogTypeV2, entryModels []*output.CatalogEntryModel, progress *EntriesProgress) error { logger = kitlog.With(logger, "catalog_type_id", catalogType.Id, "catalog_type_name", catalogType.TypeName, @@ -197,6 +197,15 @@ func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, catalo } } + // Identify the attributes that are schema-only, as we want to preserve the existing + // value instead of setting it outselves. + schemaOnlyAttributes := []*output.Attribute{} + for _, attr := range outputType.Attributes { + if attr.SchemaOnly { + schemaOnlyAttributes = append(schemaOnlyAttributes, attr) + } + } + { toUpdate := []*output.CatalogEntryModel{} eachPayload: @@ -238,6 +247,12 @@ func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, catalo currentBindings[attributeID] = current } + // For any of the schema only attributes, preserve the existing value when + // performing an update. + for _, attr := range schemaOnlyAttributes { + model.AttributeValues[attr.ID] = currentBindings[attr.ID] + } + if isSame && reflect.DeepEqual(model.AttributeValues, currentBindings) { logger.Log("msg", "catalog entry has not changed, not updating", "entry_id", entry.Id) continue eachPayload