Skip to content

Commit

Permalink
Merge pull request #600 from Security-Onion-Solutions/jertel/force
Browse files Browse the repository at this point in the history
remove extended setting toggle
  • Loading branch information
jertel authored Jul 31, 2024
2 parents b6020a3 + 045f842 commit 394ce93
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 108 deletions.
1 change: 0 additions & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,6 @@ <h2 v-text="i18n.configTitle"></h2>
<v-expansion-panel>
<v-expansion-panel-header id="configOptionsHeader">{{i18n.options}}</v-expansion-panel-header>
<v-expansion-panel-content>
<v-switch id="option-extended" :disabled="$root.loading" v-model="extended" dense class="my-0" :label="i18n.settingsExtended" :hint="i18n.settingsExtendedHelp" persistent-hint data-aid="config_option_extended_toggle"></v-switch>
<v-switch id="option-advanced" :disabled="$root.loading" v-model="advanced" dense class="my-0" :label="i18n.settingsAdvanced" :hint="i18n.settingsAdvancedHelp" persistent-hint data-aid="config_option_advanced_toggle"></v-switch>
<v-btn id="option-synchronize" @click.stop="sync()" class="mt-6 mb-1" data-aid="config_option_synchronize_toggle">
{{ i18n.settingsSynchronize }}
Expand Down
5 changes: 1 addition & 4 deletions html/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ const i18n = {
completed: 'Completed',
config: 'Configuration',
configAdvancedTag: 'adv',
configExtendedTag: 'ext',
configTitle: 'Grid Configuration',
configQLGridTitle: 'Grid Administration Quick Links',
configQLElasticsearchCold: 'Cold Phase',
Expand Down Expand Up @@ -773,10 +772,8 @@ const i18n = {
settingHideDefault: 'Hide Default',
settingValidationFailed: 'The specified value is not valid.',
settings: 'Settings',
settingsAdvanced: 'Show all configurable settings, including advanced settings.',
settingsAdvanced: 'Show advanced settings. Screen refresh will take significantly longer.',
settingsAdvancedHelp: 'CAUTION! Changing advanced settings is unsupported and could result in requiring a full cluster re-installation.',
settingsExtended: 'Show extended settings, including index settings.',
settingsExtendedHelp: 'Including the extended settings will cause the configuration screen to take longer to load. These are customized less often, and therefore excluded by default.',
settingsInvalid: 'Unable to save settings: ',
settingsCustomized: 'Modified: ',
settingsTitle: 'User Settings',
Expand Down
18 changes: 4 additions & 14 deletions html/js/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ routes.push({ path: '/config', name: 'config', component: {
resetNodeId: null,
confirmResetDialog: false,
treeVisible: true,
extended: false,
}},
mounted() {
this.processRouteParameters();
this.loadData();
},
watch: {
"active": "selectSetting",
"advanced": "refreshTree",
"extended": "loadData",
"advanced": "loadData",
},
computed: {
selected() {
Expand All @@ -69,9 +67,6 @@ routes.push({ path: '/config', name: 'config', component: {
if (this.$route.query.a == "1") {
this.advanced = true;
}
if (this.$route.query.x == "1") {
this.extended = true;
}
if (this.$route.query.f) {
this.search = this.$route.query.f;
}
Expand Down Expand Up @@ -156,10 +151,8 @@ routes.push({ path: '/config', name: 'config', component: {
settings.forEach((setting) => {
try {
path = setting.id.split(".");
if ((setting.description && !setting.advanced) || this.advanced) {
this.addToNode(root, "", path, setting);
this.settingsAvailable++;
}
this.addToNode(root, "", path, setting);
this.settingsAvailable++;
} catch(e) {
route.$root.showError(route.i18n.settingMalformed + " (" + setting.id + "): " + e);
}
Expand Down Expand Up @@ -255,7 +248,7 @@ routes.push({ path: '/config', name: 'config', component: {
var response = await this.$root.papi.get('gridmembers/');
this.nodes = response.data;

response = await this.$root.papi.get('config/', {params: { extended: this.extended }});
response = await this.$root.papi.get('config/', {params: { advanced: this.advanced }});
this.settings = [];
response.data.forEach((setting) => {
const existing = this.settings.find(s => s.id == setting.id);
Expand Down Expand Up @@ -313,9 +306,6 @@ routes.push({ path: '/config', name: 'config', component: {
if (setting.advanced) {
modifiers.push(this.i18n.configAdvancedTag);
}
if (setting.extended) {
modifiers.push(this.i18n.configExtendedTag);
}
if (modifiers.length > 0) {
breadcrumbs = breadcrumbs + " [" + modifiers.join(", ") + "]";
}
Expand Down
14 changes: 4 additions & 10 deletions html/js/routes/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test('loadData', async () => {
comp.settings = [];
await comp.loadData();
expect(loadmock).toHaveBeenCalledWith('gridmembers/');
expect(mock).toHaveBeenCalledWith('config/', {params: { extended: false }});
expect(mock).toHaveBeenCalledWith('config/', {params: { advanced: false }});

expect(comp.nodes).toBe(loaddata);

Expand Down Expand Up @@ -686,19 +686,13 @@ test('processRouteParameters', () => {
});

test('getSettingBreadcrumbs', () => {
setting = { id: "foo.bar.car", advanced: false, extended: false };
setting = { id: "foo.bar.car", advanced: false };
expect(comp.getSettingBreadcrumbs(setting)).toBe("foo > bar > car");

setting = { id: "foo.bar.car", advanced: false, extended: false, title: "Carbine" };
setting = { id: "foo.bar.car", advanced: false, title: "Carbine" };
expect(comp.getSettingBreadcrumbs(setting)).toBe("foo > bar > Carbine");

setting = { id: "foo.bar.car", advanced: false, extended: true };
expect(comp.getSettingBreadcrumbs(setting)).toBe("foo > bar > car [ext]");

setting = { id: "foo.bar.car", advanced: true, extended: false };
setting = { id: "foo.bar.car", advanced: true };
expect(comp.getSettingBreadcrumbs(setting)).toBe("foo > bar > car [adv]");

var setting = { id: "foo.bar.car", advanced: true, extended: true };
expect(comp.getSettingBreadcrumbs(setting)).toBe("foo > bar > car [adv, ext]");

});
12 changes: 0 additions & 12 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package model

import (
"regexp"
"strings"
)

type Setting struct {
Expand All @@ -33,7 +32,6 @@ type Setting struct {
Syntax string `json:"syntax"`
ForcedType string `json:"forcedType"`
Duplicates bool `json:"duplicates"`
Extended bool `json:"extended"`
}

func NewSetting(id string) *Setting {
Expand All @@ -44,16 +42,6 @@ func NewSetting(id string) *Setting {

func (setting *Setting) SetId(id string) {
setting.Id = id
setting.Extended = IsExtendedSetting(setting)
}

func IsExtendedSetting(setting *Setting) bool {
extended := false
extended = extended || strings.HasPrefix(setting.Id, "elasticsearch.index_settings.")
extended = extended || strings.HasPrefix(setting.Id, "docker.containers.")
extended = extended || strings.HasPrefix(setting.Id, "firewall.role.")
extended = extended || strings.HasPrefix(setting.Id, "strelka.backend.")
return extended
}

func IsValidMinionId(id string) bool {
Expand Down
10 changes: 1 addition & 9 deletions model/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ import (
func TestStringId(tester *testing.T) {
setting := NewSetting("MyId")
assert.Equal(tester, "MyId", setting.Id)
assert.False(tester, setting.Extended)
}

func TestExtendedSetting(tester *testing.T) {
assert.True(tester, NewSetting("elasticsearch.index_settings.foo").Extended)
assert.True(tester, NewSetting("docker.containers.foo").Extended)
assert.True(tester, NewSetting("firewall.role.foo").Extended)
assert.True(tester, NewSetting("strelka.backend.foo").Extended)
assert.False(tester, NewSetting("something.else.foo").Extended)
assert.False(tester, setting.Advanced)
}

func TestIsValidMinionId(tester *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions server/confighandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func (h *ConfigHandler) configEnabled(next http.Handler) http.Handler {
func (h *ConfigHandler) getConfig(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

extended, err := strconv.ParseBool(r.URL.Query().Get("extended"))
advanced, err := strconv.ParseBool(r.URL.Query().Get("advanced"))
if err != nil {
extended = false
advanced = false
}
settings, err := h.server.Configstore.GetSettings(ctx, extended)
settings, err := h.server.Configstore.GetSettings(ctx, advanced)
if err != nil {
web.Respond(w, r, http.StatusBadRequest, err)
return
Expand Down
2 changes: 1 addition & 1 deletion server/configstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Configstore interface {
GetSettings(ctx context.Context, extended bool) ([]*model.Setting, error)
GetSettings(ctx context.Context, advanced bool) ([]*model.Setting, error)
UpdateSetting(ctx context.Context, setting *model.Setting, remove bool) error
SyncSettings(ctx context.Context) error
}
2 changes: 1 addition & 1 deletion server/memconfigstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewMemConfigStore(settings []*model.Setting) *MemConfigStore {
}
}

func (m *MemConfigStore) GetSettings(ctx context.Context, extended bool) ([]*model.Setting, error) {
func (m *MemConfigStore) GetSettings(ctx context.Context, advanced bool) ([]*model.Setting, error) {
return m.settings, nil
}

Expand Down
10 changes: 5 additions & 5 deletions server/memconfigstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMemConfigStoreNew(t *testing.T) {

ctx := context.Background()

set, err := mCfgStore.GetSettings(ctx, false)
set, err := mCfgStore.GetSettings(ctx, true)
assert.NoError(t, err)
assert.Same(t, &origSettings[0], &set[0])
}
Expand All @@ -44,7 +44,7 @@ func TestMemConfigStoreUpdate(t *testing.T) {
err := mCfgStore.UpdateSetting(ctx, &model.Setting{Id: "1", Value: "new"}, false)
assert.NoError(t, err)

set, err := mCfgStore.GetSettings(ctx, false)
set, err := mCfgStore.GetSettings(ctx, true)
assert.NoError(t, err)
assert.Len(t, set, 3)

Expand All @@ -68,7 +68,7 @@ func TestMemConfigStoreUpdateAdd(t *testing.T) {
err := mCfgStore.UpdateSetting(ctx, &model.Setting{Id: "4", Value: "four"}, false)
assert.NoError(t, err)

set, err := mCfgStore.GetSettings(ctx, false)
set, err := mCfgStore.GetSettings(ctx, true)
assert.NoError(t, err)
assert.Len(t, set, 4)

Expand All @@ -92,14 +92,14 @@ func TestMemConfigStoreUpdateRemove(t *testing.T) {
err := mCfgStore.UpdateSetting(ctx, &model.Setting{Id: "4"}, true)
assert.NoError(t, err)

set, err := mCfgStore.GetSettings(ctx, false)
set, err := mCfgStore.GetSettings(ctx, true)
assert.NoError(t, err)
assert.Len(t, set, 3)

err = mCfgStore.UpdateSetting(ctx, &model.Setting{Id: "2"}, true)
assert.NoError(t, err)

set, err = mCfgStore.GetSettings(ctx, false)
set, err = mCfgStore.GetSettings(ctx, true)
assert.NoError(t, err)
assert.Len(t, set, 2)

Expand Down
32 changes: 23 additions & 9 deletions server/modules/salt/saltstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (store *Saltstore) GetSetting(settings []*model.Setting, id string) *model.
return nil
}

func (store *Saltstore) GetSettings(ctx context.Context, extended bool) ([]*model.Setting, error) {
func (store *Saltstore) GetSettings(ctx context.Context, advanced bool) ([]*model.Setting, error) {
var err error
if err = store.server.CheckAuthorized(ctx, "read", "config"); err != nil {
return nil, err
Expand Down Expand Up @@ -227,16 +227,28 @@ func (store *Saltstore) GetSettings(ctx context.Context, extended bool) ([]*mode
})
}

return store.sortSettings(store.filterExtended(settings, extended)), err
store.markAdvanced(settings)

return store.sortSettings(store.filter(settings, advanced)), err
}

func (store *Saltstore) filterExtended(settings []*model.Setting, extended bool) []*model.Setting {
if !extended {
settings = slices.DeleteFunc(settings, func(setting *model.Setting) bool {
return setting.Extended
})
func (store *Saltstore) markAdvanced(settings []*model.Setting) {
// Mark all settings missing descriptions as advanced
for _, setting := range settings {
if len(setting.Description) == 0 {
setting.Advanced = true
}
}
return settings
}

func (store *Saltstore) filter(settings []*model.Setting, advanced bool) []*model.Setting {
if advanced {
// No need to filter anything, caller wants everything
return settings
}
return slices.DeleteFunc(settings, func(setting *model.Setting) bool {
return setting.Advanced
})
}

func (store *Saltstore) sortSettings(settings []*model.Setting) []*model.Setting {
Expand Down Expand Up @@ -634,7 +646,9 @@ func (store *Saltstore) UpdateSetting(ctx context.Context, setting *model.Settin
return errors.New("Invalid setting id: " + setting.Id)
}

settings, err := store.GetSettings(ctx, model.IsExtendedSetting(setting))
// always pull advanced settings on update since incoming setting may not be properly flagged as advanced
advanced := true
settings, err := store.GetSettings(ctx, advanced)
if err != nil {
return err
} else {
Expand Down
Loading

0 comments on commit 394ce93

Please sign in to comment.