github.com/Jeffail/benthos/v3@v3.65.0/lib/manager/docs.go (about)

     1  package manager
     2  
     3  import (
     4  	"github.com/Jeffail/benthos/v3/internal/docs"
     5  	"github.com/Jeffail/gabs/v2"
     6  )
     7  
     8  func lintResource(ctx docs.LintContext, line, col int, v interface{}) []docs.Lint {
     9  	if _, ok := v.(map[string]interface{}); !ok {
    10  		return nil
    11  	}
    12  	gObj := gabs.Wrap(v)
    13  	label, _ := gObj.S("label").Data().(string)
    14  	if label == "" {
    15  		return []docs.Lint{
    16  			docs.NewLintError(line, "The label field for resources must be unique and not empty"),
    17  		}
    18  	}
    19  	return nil
    20  }
    21  
    22  // Spec returns a field spec for the manager configuration.
    23  func Spec() docs.FieldSpecs {
    24  	return docs.FieldSpecs{
    25  		docs.FieldDeprecated(
    26  			"resources", "A map of components identified by unique names that can be referenced throughout a Benthos config.",
    27  		).WithChildren(
    28  			docs.FieldCommon("inputs", "A map of inputs.").Map().HasType(docs.FieldTypeInput),
    29  			docs.FieldCommon("conditions", "A map of conditions.").Map().HasType(docs.FieldTypeCondition),
    30  			docs.FieldCommon("processors", "A map of processors.").Map().HasType(docs.FieldTypeProcessor),
    31  			docs.FieldCommon("outputs", "A map of outputs.").Map().HasType(docs.FieldTypeOutput),
    32  			docs.FieldCommon("caches", "A map of caches.").Map().HasType(docs.FieldTypeCache),
    33  			docs.FieldCommon("rate_limits", "A map of rate limits.").Map().HasType(docs.FieldTypeRateLimit),
    34  			docs.FieldAdvanced("plugins", "A map of resource plugins.").Map().WithChildren(
    35  				docs.FieldString("type", "The type of the plugin.").HasDefault(""),
    36  				docs.FieldCommon("plugin", "The config fields of the plugin type.").HasType(docs.FieldTypeUnknown).HasDefault(nil),
    37  			),
    38  		).OmitWhen(func(field, parent interface{}) (string, bool) {
    39  			if len(gabs.Wrap(field).ChildrenMap()) == 0 {
    40  				return "resources should be omitted when empty", true
    41  			}
    42  			return "", false
    43  		}),
    44  
    45  		docs.FieldCommon(
    46  			"input_resources", "A list of input resources, each must have a unique label.",
    47  		).Array().HasType(docs.FieldTypeInput).Linter(lintResource),
    48  
    49  		docs.FieldCommon(
    50  			"processor_resources", "A list of processor resources, each must have a unique label.",
    51  		).Array().HasType(docs.FieldTypeProcessor).Linter(lintResource),
    52  
    53  		docs.FieldCommon(
    54  			"output_resources", "A list of output resources, each must have a unique label.",
    55  		).Array().HasType(docs.FieldTypeOutput).Linter(lintResource),
    56  
    57  		docs.FieldCommon(
    58  			"cache_resources", "A list of cache resources, each must have a unique label.",
    59  		).Array().HasType(docs.FieldTypeCache).Linter(lintResource),
    60  
    61  		docs.FieldCommon(
    62  			"rate_limit_resources", "A list of rate limit resources, each must have a unique label.",
    63  		).Array().HasType(docs.FieldTypeRateLimit).Linter(lintResource),
    64  	}
    65  }