-
Notifications
You must be signed in to change notification settings - Fork 127
Enable developer extensions #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abcc19f
f73f014
2d37a58
e171718
da62c11
6e5b0ff
2d30443
5f35552
bb01462
ea3ef8f
44ddd57
d30c2e6
a03e750
38c5980
8536cf8
562ca51
5afc1a9
e6b5851
311d25d
49d5b86
e9011b6
ebd27d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| type: integration | ||
| version: 0.0.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,9 @@ import ( | |
| "gopkg.in/yaml.v3" | ||
|
|
||
| "github.com/elastic/elastic-package/internal/common" | ||
| "github.com/elastic/elastic-package/internal/logger" | ||
| "github.com/elastic/elastic-package/internal/multierror" | ||
| "github.com/elastic/elastic-package/internal/packages" | ||
| "github.com/elastic/elastic-package/internal/packages/buildmanifest" | ||
| ) | ||
|
|
||
|
|
@@ -39,7 +41,7 @@ type Validator struct { | |
| allowedCIDRs []*net.IPNet | ||
| } | ||
|
|
||
| // ValidatorOption represents an optional flag that can be passed to CreateValidatorForDataStream. | ||
| // ValidatorOption represents an optional flag that can be passed to CreateValidatorForDirectory. | ||
| type ValidatorOption func(*Validator) error | ||
|
|
||
| // WithDefaultNumericConversion configures the validator to accept defined keyword (or constant_keyword) fields as numeric-type. | ||
|
|
@@ -78,8 +80,8 @@ func WithEnabledAllowedIPCheck() ValidatorOption { | |
| } | ||
| } | ||
|
|
||
| // CreateValidatorForDataStream function creates a validator for the data stream. | ||
| func CreateValidatorForDataStream(dataStreamRootPath string, opts ...ValidatorOption) (v *Validator, err error) { | ||
| // CreateValidatorForDirectory function creates a validator for the directory. | ||
| func CreateValidatorForDirectory(fieldsParentDir string, opts ...ValidatorOption) (v *Validator, err error) { | ||
| v = new(Validator) | ||
| for _, opt := range opts { | ||
| if err := opt(v); err != nil { | ||
|
|
@@ -89,16 +91,28 @@ func CreateValidatorForDataStream(dataStreamRootPath string, opts ...ValidatorOp | |
|
|
||
| v.allowedCIDRs = initializeAllowedCIDRsList() | ||
|
|
||
| v.Schema, err = loadFieldsForDataStream(dataStreamRootPath) | ||
| fieldsDir := filepath.Join(fieldsParentDir, "fields") | ||
| v.Schema, err = loadFieldsFromDir(fieldsDir) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "can't load fields for data stream (path: %s)", dataStreamRootPath) | ||
| return nil, errors.Wrapf(err, "can't load fields from directory (path: %s)", fieldsDir) | ||
| } | ||
|
|
||
| if v.disabledDependencyManagement { | ||
| return v, nil | ||
| } | ||
|
|
||
| packageRoot := filepath.Dir(filepath.Dir(dataStreamRootPath)) | ||
| packageRoot, found, err := packages.FindPackageRoot() | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "can't find package root") | ||
| } | ||
| // As every command starts with approximating where is the package root, it isn't required to return an error in case the root is missing. | ||
| // This is also useful for testing purposes, where we don't have a real package, but just "fields" directory. The package root is always absent. | ||
| if !found { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this hide problems with malformed packages? On what cases is it ok to not find the package root? Could you add a comment here about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment, let me know what do you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, we can revisit this if found to be problematic at some point. Would it make sense to add a debug message here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
| logger.Debug("Package root not found, dependency management will be disabled.") | ||
| v.disabledDependencyManagement = true | ||
| return v, nil | ||
| } | ||
|
|
||
| bm, ok, err := buildmanifest.ReadBuildManifest(packageRoot) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "can't read build manifest") | ||
|
|
@@ -132,8 +146,7 @@ func initializeAllowedCIDRsList() (cidrs []*net.IPNet) { | |
| return cidrs | ||
| } | ||
|
|
||
| func loadFieldsForDataStream(dataStreamRootPath string) ([]FieldDefinition, error) { | ||
| fieldsDir := filepath.Join(dataStreamRootPath, "fields") | ||
| func loadFieldsFromDir(fieldsDir string) ([]FieldDefinition, error) { | ||
| files, err := filepath.Glob(filepath.Join(fieldsDir, "*.yml")) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "reading directory with fields failed (path: %s)", fieldsDir) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dependencies: | ||
| ecs: | ||
| reference: git@v8.2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # SQL Input | ||
|
|
||
| Hello from the SQL input package! | ||
|
|
||
| {{fields}} |
Uh oh!
There was an error while loading. Please reload this page.