Skip to content

Commit 6ecd68a

Browse files
committed
backward compatibilty
1 parent 2f309da commit 6ecd68a

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

providers/os/resources/journald.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,49 @@ func (s *mqlJournaldConfig) sections(file *mqlFile) ([]any, error) {
137137
return s.Sections.Data, s.Sections.Error
138138
}
139139

140+
// params is deprecated, use sections instead
141+
func (s *mqlJournaldConfig) params(file *mqlFile) (map[string]any, error) {
142+
if err := s.parse(file); err != nil {
143+
return nil, err
144+
}
145+
146+
// For backward compatibility, return the [Journal] section's params as a map
147+
// Find the Journal section
148+
for _, sectionAny := range s.Sections.Data {
149+
section := sectionAny.(*mqlJournaldConfigSection)
150+
name := section.GetName()
151+
if name.Error != nil {
152+
continue
153+
}
154+
155+
// Only return params from the Journal section for backward compatibility
156+
if name.Data != "Journal" {
157+
continue
158+
}
159+
160+
params := section.GetParams()
161+
if params.Error != nil {
162+
return nil, params.Error
163+
}
164+
165+
// Convert params array to map[string]any
166+
// If there are duplicate keys, the last one wins
167+
result := make(map[string]any, len(params.Data))
168+
for _, paramAny := range params.Data {
169+
param := paramAny.(*mqlJournaldConfigSectionParam)
170+
paramName := param.GetName()
171+
paramValue := param.GetValue()
172+
if paramName.Error != nil || paramValue.Error != nil {
173+
continue
174+
}
175+
result[paramName.Data] = paramValue.Data
176+
}
177+
return result, nil
178+
}
179+
180+
return map[string]any{}, nil
181+
}
182+
140183
func (s *mqlJournaldConfigSection) id() (string, error) {
141184
name := s.GetName()
142185
if name.Error != nil {

providers/os/resources/journald_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@ func TestResource_JournaldConfig(t *testing.T) {
3737
assert.NoError(t, res[0].Data.Error)
3838
})
3939

40+
t.Run("backwards compatibility: journald is downcasing relevant params", func(t *testing.T) {
41+
res := x.TestQuery(t, "journald.config.params.Compress")
42+
assert.NotEmpty(t, res)
43+
assert.NoError(t, res[0].Data.Error)
44+
assert.Equal(t, "yes", res[0].Data.Value)
45+
})
46+
4047
t.Run("journald is downcasing relevant params", func(t *testing.T) {
4148
res := x.TestQuery(t, "journald.config.sections.where(name == 'Journal')[0].params.where(name == 'Compress')[0].value")
4249
assert.NotEmpty(t, res)
4350
assert.NoError(t, res[0].Data.Error)
4451
assert.Equal(t, "yes", res[0].Data.Value)
4552
})
4653

54+
t.Run("backwards compatibility: journald is NOT downcasing other params", func(t *testing.T) {
55+
res := x.TestQuery(t, "journald.config.params.Storage")
56+
assert.NotEmpty(t, res)
57+
assert.NoError(t, res[0].Data.Error)
58+
assert.Equal(t, "persistent", res[0].Data.Value)
59+
})
60+
4761
t.Run("journald is NOT downcasing other params", func(t *testing.T) {
4862
res := x.TestQuery(t, "journald.config.sections.where(name == 'Journal')[0].params.where(name == 'Storage')[0].value")
4963
assert.NotEmpty(t, res)

providers/os/resources/os.lr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ journald.config {
825825
init(path? string)
826826
// File of this journald configuration
827827
file() file
828+
// deprecated, use sections instead
829+
params(file) map[string]string
828830
// All sections in this journald configuration
829831
sections(file) []journald.config.section
830832
}

providers/os/resources/os.lr.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)