mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Orbit shell no longer ignores disable-updates (#32698)
For #32514 Fixed issue that caused orbit shell to ignore the 'disable-updates' flag.
This commit is contained in:
parent
cc04d2a459
commit
2081300c48
3 changed files with 58 additions and 12 deletions
1
orbit/changes/32514-orbit-shell-ignores-updates-disabled
Normal file
1
orbit/changes/32514-orbit-shell-ignores-updates-disabled
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fixed issue with `orbit shell` ignoring disable updates flag.
|
||||
|
|
@ -3,13 +3,14 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/fleetdm/fleet/v4/pkg/certificate"
|
||||
"github.com/fleetdm/fleet/v4/pkg/file"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/pkg/certificate"
|
||||
"github.com/fleetdm/fleet/v4/pkg/file"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
|
||||
"github.com/fleetdm/fleet/v4/orbit/pkg/osquery"
|
||||
"github.com/fleetdm/fleet/v4/orbit/pkg/update"
|
||||
|
|
@ -70,18 +71,28 @@ var shellCommand = &cli.Command{
|
|||
opt.LocalStore = localStore
|
||||
opt.InsecureTransport = c.Bool("insecure")
|
||||
|
||||
updater, err := update.NewUpdater(opt)
|
||||
disableUpdates := c.Bool("disable-updates")
|
||||
updater, err := getUpdater(disableUpdates, opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updater.UpdateMetadata(); err != nil {
|
||||
log.Info().Err(err).Msg("failed to update metadata. using saved metadata.")
|
||||
|
||||
var osquerydPath string
|
||||
if !disableUpdates {
|
||||
if err := updater.UpdateMetadata(); err != nil {
|
||||
log.Info().Err(err).Msg("failed to update metadata. using saved metadata.")
|
||||
}
|
||||
osquerydLocalTarget, err := updater.Get(constant.OsqueryTUFTargetName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
osquerydPath = osquerydLocalTarget.ExecPath
|
||||
} else {
|
||||
osquerydPath, err = updater.ExecutableLocalPath(constant.OsqueryTUFTargetName)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msgf("locate %s", constant.OsqueryTUFTargetName)
|
||||
}
|
||||
}
|
||||
osquerydLocalTarget, err := updater.Get(constant.OsqueryTUFTargetName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
osquerydPath := osquerydLocalTarget.ExecPath
|
||||
|
||||
var g run.Group
|
||||
|
||||
|
|
@ -177,3 +188,11 @@ func getCertPath(rootDir, fleetCertPath string) (string, error) {
|
|||
|
||||
return certPath, nil
|
||||
}
|
||||
|
||||
func getUpdater(disableUpdates bool, opt update.Options) (*update.Updater, error) {
|
||||
if disableUpdates {
|
||||
log.Info().Msg("running with auto updates disabled")
|
||||
return update.NewDisabled(opt), nil
|
||||
}
|
||||
return update.NewUpdater(opt)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/orbit/pkg/update"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ func TestGetCertPath(t *testing.T) {
|
|||
invalidCertPath := filepath.Join(invalidRoot, "invalid_cert.pem")
|
||||
require.NoError(t, os.WriteFile(invalidCertPath, []byte(`INVALID_CERT_CONTENT`), 0644))
|
||||
|
||||
tests := []struct {
|
||||
cases := []struct {
|
||||
name string
|
||||
rootDir string
|
||||
fleetCert string
|
||||
|
|
@ -65,7 +66,7 @@ func TestGetCertPath(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
path, err := getCertPath(tt.rootDir, tt.fleetCert)
|
||||
|
||||
|
|
@ -79,3 +80,28 @@ func TestGetCertPath(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUpdater(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
disableUpdates bool
|
||||
expectDisabled bool
|
||||
}{
|
||||
{"updates enabled", false, false},
|
||||
{"updates disabled", true, true},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
updater, err := getUpdater(c.disableUpdates, update.Options{})
|
||||
// A 'disabled' updater should never fail, even with invalid options.
|
||||
if c.expectDisabled {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, updater)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
require.Nil(t, updater)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue