Correlations: Add CreateCorrelation HTTP API (#51630)
* Correlations: add migration
* Correlations: Add CreateCorrelation API
* Correlations: Make correlations work with provisioning
* Handle version changes
* Fix lining error
* lint fixes
* rebuild betterer results
* add a UID to each correlation
* Fix lint errors
* add docs
* better wording in API docs
* remove leftover comment
* handle ds updates
* Fix error message typo
* add bad data test
* make correlations a separate table
* skip readonly check when provisioning correlations
* delete stale correlations when datasources are deleted
* restore provisioned readonly ds
* publish deletion event with full data
* generate swagger and HTTP API docs
* apply source datasource permission to create correlation API
* Fix tests & lint errors
* ignore empty deletion events
* fix last lint errors
* fix more lint error
* Only publish deletion event if datasource was actually deleted
* delete DS provisioning deletes correlations, added & fixed tests
* Fix unmarshalling tests
* Fix linting errors
* Fix deltion event tests
* fix small linting error
* fix lint errors
* update betterer
* fix test
* make path singular
* Revert "make path singular"
This reverts commit 420c3d315e.
* add integration tests
* remove unneeded id from correlations table
* update spec
* update leftover references to CorrelationDTO
* fix tests
* cleanup tests
* fix lint error
This commit is contained in:
@@ -188,6 +188,47 @@ func (val *StringMapValue) Value() map[string]string {
|
||||
return val.value
|
||||
}
|
||||
|
||||
// JSONSliceValue represents a slice value in a YAML
|
||||
// config that can be overridden by environment variables
|
||||
|
||||
type JSONSliceValue struct {
|
||||
value []map[string]interface{}
|
||||
Raw []map[string]interface{}
|
||||
}
|
||||
|
||||
// UnmarshalYAML converts YAML into an *JSONSliceValue
|
||||
func (val *JSONSliceValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
unmarshaled := make([]interface{}, 0)
|
||||
err := unmarshal(&unmarshaled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
interpolated := make([]map[string]interface{}, 0)
|
||||
raw := make([]map[string]interface{}, 0)
|
||||
|
||||
for _, v := range unmarshaled {
|
||||
i := make(map[string]interface{})
|
||||
r := make(map[string]interface{})
|
||||
for key, val := range v.(map[interface{}]interface{}) {
|
||||
i[key.(string)], r[key.(string)], err = transformInterface(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
interpolated = append(interpolated, i)
|
||||
raw = append(raw, r)
|
||||
}
|
||||
|
||||
val.Raw = raw
|
||||
val.value = interpolated
|
||||
return err
|
||||
}
|
||||
|
||||
// Value returns the wrapped []interface{} value
|
||||
func (val *JSONSliceValue) Value() []map[string]interface{} {
|
||||
return val.value
|
||||
}
|
||||
|
||||
// transformInterface tries to transform any interface type into proper value with env expansion. It traverses maps and
|
||||
// slices and the actual interpolation is done on all simple string values in the structure. It returns a copy of any
|
||||
// map or slice value instead of modifying them in place and also return value without interpolation but with converted
|
||||
|
||||
@@ -220,6 +220,54 @@ func TestValues(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("JSONSliceValue", func(t *testing.T) {
|
||||
type Data struct {
|
||||
Val JSONSliceValue `yaml:"val"`
|
||||
}
|
||||
d := &Data{}
|
||||
|
||||
t.Run("Should unmarshal top-level slices and nested structures", func(t *testing.T) {
|
||||
doc := `
|
||||
val:
|
||||
- interpolatedString: $STRING
|
||||
interpolatedInt: $INT
|
||||
string: "just a string"
|
||||
- interpolatedString: $STRING
|
||||
interpolatedInt: $INT
|
||||
string: "just a string"
|
||||
`
|
||||
unmarshalingTest(t, doc, d)
|
||||
|
||||
type stringMap = map[string]interface{}
|
||||
|
||||
require.Equal(t, []stringMap{
|
||||
{
|
||||
"interpolatedString": "test",
|
||||
"interpolatedInt": "1",
|
||||
"string": "just a string",
|
||||
},
|
||||
{
|
||||
"interpolatedString": "test",
|
||||
"interpolatedInt": "1",
|
||||
"string": "just a string",
|
||||
},
|
||||
}, d.Val.Value())
|
||||
|
||||
require.Equal(t, []stringMap{
|
||||
{
|
||||
"interpolatedString": "$STRING",
|
||||
"interpolatedInt": "$INT",
|
||||
"string": "just a string",
|
||||
},
|
||||
{
|
||||
"interpolatedString": "$STRING",
|
||||
"interpolatedInt": "$INT",
|
||||
"string": "just a string",
|
||||
},
|
||||
}, d.Val.Raw)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("StringMapValue", func(t *testing.T) {
|
||||
type Data struct {
|
||||
Val StringMapValue `yaml:"val"`
|
||||
|
||||
Reference in New Issue
Block a user