mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Cleanup and rename version to channel
This commit is contained in:
parent
d97c4972f3
commit
c4a5785427
4 changed files with 24 additions and 17 deletions
|
|
@ -201,6 +201,8 @@ func main() {
|
|||
)
|
||||
}
|
||||
|
||||
options = append(options, osquery.WithFlags([]string{"--force"}))
|
||||
|
||||
if c.Bool("debug") {
|
||||
options = append(options,
|
||||
osquery.WithFlags([]string{"--verbose", "--tls_dump"}),
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ func WithEnv(env []string) func(*Runner) error {
|
|||
func WithShell() func(*Runner) error {
|
||||
return func(r *Runner) error {
|
||||
r.cmd.Args = append(r.cmd.Args, "-S")
|
||||
r.cmd.Stdout = os.Stdout
|
||||
r.cmd.Stderr = os.Stderr
|
||||
r.cmd.Stdin = os.Stdin
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,12 +38,18 @@ func CheckFileHash(meta *data.TargetFileMeta, localPath string) error {
|
|||
|
||||
// selectHashFunction returns the first matching hash function and expected
|
||||
// hash, otherwise returning an error if not matching hash can be found.
|
||||
//
|
||||
// SHA512 is preferred, and SHA256 is returned if 512 is not available.
|
||||
|
||||
func selectHashFunction(meta *data.TargetFileMeta) (hash.Hash, []byte, error) {
|
||||
for hashName, hashVal := range meta.Hashes {
|
||||
switch hashName {
|
||||
case "sha512":
|
||||
if hashName == "sha512" {
|
||||
return sha512.New(), hashVal, nil
|
||||
case "sha256":
|
||||
}
|
||||
}
|
||||
|
||||
for hashName, hashVal := range meta.Hashes {
|
||||
if hashName == "sha256" {
|
||||
return sha256.New(), hashVal, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,20 +115,20 @@ func (u *Updater) UpdateMetadata() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (u *Updater) RepoPath(name, version string) string {
|
||||
return path.Join(name, u.opt.Platform, version, name+constant.ExecutableExtension(u.opt.Platform))
|
||||
func (u *Updater) RepoPath(name, channel string) string {
|
||||
return path.Join(name, u.opt.Platform, channel, name+constant.ExecutableExtension(u.opt.Platform))
|
||||
}
|
||||
|
||||
func (u *Updater) LocalPath(name, version string) string {
|
||||
return u.pathFromRoot(filepath.Join(binDir, name, u.opt.Platform, version, name+constant.ExecutableExtension(u.opt.Platform)))
|
||||
func (u *Updater) LocalPath(name, channel string) string {
|
||||
return u.pathFromRoot(filepath.Join(binDir, name, u.opt.Platform, channel, name+constant.ExecutableExtension(u.opt.Platform)))
|
||||
}
|
||||
|
||||
// Lookup looks up the provided target in the local target metadata. This should
|
||||
// be called after UpdateMetadata.
|
||||
func (u *Updater) Lookup(name, version string) (*data.TargetFileMeta, error) {
|
||||
target, err := u.client.Target(u.RepoPath(name, version))
|
||||
func (u *Updater) Lookup(name, channel string) (*data.TargetFileMeta, error) {
|
||||
target, err := u.client.Target(u.RepoPath(name, channel))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lookup target %v", target)
|
||||
return nil, errors.Wrapf(err, "lookup %s@%s", name, channel)
|
||||
}
|
||||
|
||||
return &target, nil
|
||||
|
|
@ -146,9 +146,9 @@ func (u *Updater) Targets() (data.TargetFiles, error) {
|
|||
|
||||
// Get returns the local path to the specified target. The target is downloaded
|
||||
// if it does not yet exist locally or the hash does not match.
|
||||
func (u *Updater) Get(name, version string) (string, error) {
|
||||
localPath := u.LocalPath(name, version)
|
||||
repoPath := u.RepoPath(name, version)
|
||||
func (u *Updater) Get(name, channel string) (string, error) {
|
||||
localPath := u.LocalPath(name, channel)
|
||||
repoPath := u.RepoPath(name, channel)
|
||||
stat, err := os.Stat(localPath)
|
||||
if err != nil {
|
||||
log.Debug().Err(err).Msg("stat file")
|
||||
|
|
@ -158,7 +158,7 @@ func (u *Updater) Get(name, version string) (string, error) {
|
|||
return "", errors.Errorf("expected %s to be regular file", localPath)
|
||||
}
|
||||
|
||||
meta, err := u.Lookup(name, version)
|
||||
meta, err := u.Lookup(name, channel)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ func (u *Updater) Get(name, version string) (string, error) {
|
|||
return localPath, u.Download(repoPath, localPath)
|
||||
}
|
||||
|
||||
log.Debug().Str("path", localPath).Msg("found expected version locally")
|
||||
log.Debug().Str("path", localPath).Msg("found expected channel locally")
|
||||
|
||||
return localPath, nil
|
||||
}
|
||||
|
|
@ -189,6 +189,7 @@ func (u *Updater) Download(repoPath, localPath string) error {
|
|||
return errors.Wrap(err, "initialize download dir")
|
||||
}
|
||||
|
||||
// The go-tuf client handles checking of max size and hash.
|
||||
if err := u.client.Download(repoPath, &fileDestination{tmp}); err != nil {
|
||||
return errors.Wrapf(err, "download target %s", repoPath)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue