diff --git a/.gitignore b/.gitignore index 097eadef..eb2d2797 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ test.json .idea/ *.iml .vscode/ + +# local test deployment-config +deployment-config.json diff --git a/CHANGES.md b/CHANGES.md index dd301a68..54c2366d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ # Release-Changelog ## TBD (TBD) +### Features +* Add option to register `SchemeHandlers` to deployment-config. See [deployment-config.md](docs/deployment-config.md). + ### Changes * Raise minimum golang requirement to 1.17 diff --git a/cmd/bundown/main.go b/cmd/bundown/main.go index a457b459..3a0e168c 100644 --- a/cmd/bundown/main.go +++ b/cmd/bundown/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -145,7 +144,7 @@ func isFolder(filePath string) bool { } func mustReaderForFile(filePath string) io.Reader { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fatalf("Could not read file \"%s\": %v", filePath, err) } diff --git a/cmd/echo_field/main.go b/cmd/echo_field/main.go index 3fbe60e1..bc17c01c 100644 --- a/cmd/echo_field/main.go +++ b/cmd/echo_field/main.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "github.com/setlog/trivrost/pkg/launcher/config" @@ -38,7 +37,7 @@ func parseFlags() { } func mustReaderForFile(filePath string) io.Reader { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fatalf("Could not read file \"%s\": %v", filePath, err) } diff --git a/cmd/installdown/main.go b/cmd/installdown/main.go index 5a5d293d..00e1a657 100644 --- a/cmd/installdown/main.go +++ b/cmd/installdown/main.go @@ -241,7 +241,7 @@ func configure() *wxsConfig { } func mustReaderForFile(filePath string) io.Reader { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fatalf("Could not read file \"%s\": %v", filePath, err) } diff --git a/cmd/launcher/launcher/install.go b/cmd/launcher/launcher/install.go index e3b0f41e..e3f88c0e 100644 --- a/cmd/launcher/launcher/install.go +++ b/cmd/launcher/launcher/install.go @@ -1,16 +1,18 @@ package launcher import ( + "github.com/setlog/systemuri" + "github.com/setlog/trivrost/cmd/launcher/flags" + "github.com/setlog/trivrost/cmd/launcher/resources" + "github.com/setlog/trivrost/pkg/launcher/config" "os/exec" "path/filepath" "runtime" + "sort" "strings" "sync" "time" - "github.com/setlog/trivrost/cmd/launcher/flags" - "github.com/setlog/trivrost/cmd/launcher/resources" - "github.com/setlog/trivrost/cmd/launcher/places" log "github.com/sirupsen/logrus" @@ -43,12 +45,12 @@ func IsInstanceInstalled() bool { return isInstalled } -// IsInstanceInstalledInSystemMode returns true iff we are in system mode. +// IsInstanceInstalledInSystemMode returns true if we are in system mode. func IsInstanceInstalledInSystemMode() bool { return system.FolderExists(places.GetSystemWideBundleFolderPath()) } -// IsInstanceInstalledForCurrentUser returns true iff the launcher's desired path under user files is occupied by the program running this code. +// IsInstanceInstalledForCurrentUser returns true if the launcher's desired path under user files is occupied by the program running this code. func IsInstanceInstalledForCurrentUser() bool { programPath := system.GetProgramPath() targetProgramPath := getTargetProgramPath() @@ -111,6 +113,8 @@ func Install(launcherFlags *flags.LauncherFlags) { InstallShortcuts(targetProgramPath, launcherFlags) + // Registering the scheme handlers had to happen in run.go, since we do not have the deployment config here, yet. + MustRestartWithInstalledBinary(launcherFlags) } @@ -124,6 +128,82 @@ func InstallShortcuts(targetProgramPath string, launcherFlags *flags.LauncherFla waitGroup.Wait() } +// RegisterSchemeHandlers registers the schemes defined in the deployment config +func RegisterSchemeHandlers(launcherFlags *flags.LauncherFlags, schemeHandlers []config.SchemeHandler) { + transmittingFlags := launcherFlags.GetTransmittingFlags() + for _, schemeHandler := range schemeHandlers { + // TODO: Create flag "-lockagnostic" (or such) to allow to eliminate all self-restarting behavior (when used in combination with "-skipselfupdate") to reduce UI flickering? + // TODO: Create and then always add flag "-skipschemehandlerregistry" (or such) here to prevent -extra-env from being added? + // TODO: systemuri does not presently implement %%-escapes according to deployment-config.md. + binaryPath := system.GetBinaryPath() + // We want to pass a few flags from the current execution (transmitting flags) as well, but only if they are not set in the passed arguments. + finalArguments := []string{} + finalArguments = removeFromList(transmittingFlags, extractArguments(schemeHandler.Arguments)) + finalArguments = filterWhitelistArguments(finalArguments) + + transmittingFlagsFiltered := removeFromList(transmittingFlags, finalArguments) + transmittingFlagsFiltered = []string{} // TODO: We actually want to create a whitelist here of flags that are okay to retain + + arguments := strings.Join(transmittingFlagsFiltered, " ") + schemeHandler.Arguments + err := systemuri.RegisterURLHandler(resources.LauncherConfig.BrandingName, schemeHandler.Scheme, binaryPath, arguments) + if err != nil { + log.Warnf("Registering the scheme \"%s\" failed: %v", schemeHandler.Scheme, err) + } + } +} + +// TODO: Make case insensitive +func filterWhitelistArguments(arguments []string) []string { + // slice of entries to allow in the arguments list + whitelist := []string{ + "debug", + "skipselfupdate", + "roaming", + "deployment-config", + "extra-env", + } + + var filteredArguments []string + + sort.Strings(whitelist) + for _, argument := range arguments { + if found := sort.SearchStrings(whitelist, argument); found < len(whitelist) && whitelist[found] == argument { + continue + } + filteredArguments = append(filteredArguments, argument) + } + + return filteredArguments +} + +// TODO: Make case insensitive +func removeFromList(sourceList []string, itemsToRemove []string) []string { + argSet := make(map[string]bool) + for _, item := range itemsToRemove { + argSet[item] = true + } + + var filteredSourceList []string + for _, item := range sourceList { + if _, ok := argSet[item]; !ok { + filteredSourceList = append(filteredSourceList, item) + } + } + return filteredSourceList +} + +func extractArguments(input string) []string { + words := strings.Fields(input) + var args []string + for _, w := range words { + if strings.HasPrefix(w, "-") || strings.HasPrefix(w, "--") { + arg := strings.SplitN(w, "=", 2)[0] + args = append(args, arg) + } + } + return args +} + func MustRestartWithInstalledBinary(launcherFlags *flags.LauncherFlags) { locking.RestartWithBinary(true, getTargetBinaryPath(), launcherFlags) } diff --git a/cmd/launcher/launcher/run.go b/cmd/launcher/launcher/run.go index dc99766f..0de2d681 100644 --- a/cmd/launcher/launcher/run.go +++ b/cmd/launcher/launcher/run.go @@ -2,14 +2,12 @@ package launcher import ( "context" - - "github.com/setlog/trivrost/pkg/launcher/config" - "github.com/setlog/trivrost/cmd/launcher/flags" "github.com/setlog/trivrost/cmd/launcher/gui" "github.com/setlog/trivrost/cmd/launcher/locking" "github.com/setlog/trivrost/cmd/launcher/places" "github.com/setlog/trivrost/cmd/launcher/resources" + "github.com/setlog/trivrost/pkg/launcher/config" "github.com/setlog/trivrost/pkg/fetching" "github.com/setlog/trivrost/pkg/logging" @@ -24,7 +22,7 @@ func Run(ctx context.Context, launcherFlags *flags.LauncherFlags) { updater := createUpdater(ctx, wireHandler(gui.NewGuiDownloadProgressHandler(fetching.MaxConcurrentDownloads))) gui.SetStage(gui.StageGetDeploymentConfig, 0) - updater.Prepare(resources.LauncherConfig.DeploymentConfigURL) + updater.ObtainDeploymentConfig(resources.LauncherConfig.DeploymentConfigURL) if !IsInstanceInstalledInSystemMode() && !launcherFlags.SkipSelfUpdate { updateLauncherToLatestVersion(updater, launcherFlags) @@ -33,6 +31,8 @@ func Run(ctx context.Context, launcherFlags *flags.LauncherFlags) { gui.SetStage(gui.StageLaunchApplication, 0) handleUpdateOmissions(ctx, updater) + // Registering the schema handlers here instead of install.go, since we have the updater (deployment config) here + RegisterSchemeHandlers(launcherFlags, updater.GetDeploymentConfig().SchemeHandlers) launch(ctx, updater.GetDeploymentConfig().Execution, launcherFlags) } diff --git a/cmd/launcher/launcher/uninstall.go b/cmd/launcher/launcher/uninstall.go index 7ee9a7e2..7397d4e9 100644 --- a/cmd/launcher/launcher/uninstall.go +++ b/cmd/launcher/launcher/uninstall.go @@ -7,6 +7,7 @@ import ( "regexp" "runtime" + "github.com/setlog/systemuri" "github.com/setlog/trivrost/cmd/launcher/locking" "github.com/setlog/trivrost/cmd/launcher/flags" @@ -38,11 +39,21 @@ func uninstall(launcherFlags *flags.LauncherFlags) { gui.ShowWaitDialog("Uninstalling "+brandingName, "Please wait as "+brandingName+" is uninstalling.") deletePlainFiles() deleteBundles() + unregisterSchemeHandlers() defer prepareProgramDeletionWithFinalizerFunc()() gui.HideWaitDialog() gui.BlockingDialog("Uninstallation complete", brandingName+" has been uninstalled.", []string{"Close"}, 0, launcherFlags.DismissGuiPrompts) } +// unregisterSchemeHandlers removes all handlers that are associated with this binary +func unregisterSchemeHandlers() { + binaryPath := system.GetBinaryPath() + err := systemuri.UnregisterURLHandlerByPath(binaryPath) + if err != nil { + log.Warnf("Unregistering the schemes for binary \"%s\" failed: %v", binaryPath, err) + } +} + func deletePlainFiles() { deleteDesktopShortcuts() if runtime.GOOS != system.OsMac { diff --git a/cmd/launcher/locking/signature_io.go b/cmd/launcher/locking/signature_io.go index 9f7c99b4..a4d95b3f 100644 --- a/cmd/launcher/locking/signature_io.go +++ b/cmd/launcher/locking/signature_io.go @@ -3,7 +3,6 @@ package locking import ( "encoding/json" "fmt" - "io/ioutil" "os" "github.com/setlog/trivrost/pkg/system" @@ -11,7 +10,7 @@ import ( ) func readProcessSignatureListFile(filePath string) (procSigs []system.ProcessSignature) { - bytes, err := ioutil.ReadFile(filePath) + bytes, err := os.ReadFile(filePath) if err != nil { if os.IsNotExist(err) { return nil @@ -36,7 +35,7 @@ func mustWriteProcessSignatureListFile(filePath string, procSigs []system.Proces if err != nil { panic(fmt.Sprintf("Could not marshal process signature slice of length %d: %v", len(procSigs), err)) } - err = ioutil.WriteFile(filePath, bytes, 0666) + err = os.WriteFile(filePath, bytes, 0666) if err != nil { panic(fmt.Sprintf("Could not write process signature list file \"%s\": %v", filePath, err)) } diff --git a/cmd/metawriter/main.go b/cmd/metawriter/main.go index d53dbe9e..e4ea1fad 100644 --- a/cmd/metawriter/main.go +++ b/cmd/metawriter/main.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "strconv" "strings" @@ -56,7 +55,7 @@ func replacePlaceholders(text string) string { func mustReadFile(filePath string) string { fmt.Printf("Metawriter: Reading \"%s\".\n", filePath) - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fatalf("Could not read \"%s\": %v", filePath, err) } @@ -65,7 +64,7 @@ func mustReadFile(filePath string) string { func mustWriteFile(filePath string, data []byte) { fmt.Printf("Metawriter: Writing \"%s\".\n", filePath) - err := ioutil.WriteFile(filePath, data, 0600) + err := os.WriteFile(filePath, data, 0600) if err != nil { fatalf("Could not open file \"%s\" for writing: %v", filePath, err) } @@ -108,7 +107,7 @@ func validateVariables() { } func mustReaderForFile(filePath string) io.Reader { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fatalf("Could not read file \"%s\": %v", filePath, err) } diff --git a/cmd/signer/main.go b/cmd/signer/main.go index fae8033f..9f7c8ef5 100644 --- a/cmd/signer/main.go +++ b/cmd/signer/main.go @@ -10,7 +10,6 @@ import ( "encoding/pem" "flag" "fmt" - "io/ioutil" "os" ) @@ -35,7 +34,8 @@ func createSignatures() { if err != nil { fatalf("Creating of a signature for the file %s failed: %v", targetFiles[i], err) } - if err = ioutil.WriteFile(targetFiles[i]+".signature", []byte(signature), 0644); err != nil { + + if err = os.WriteFile(targetFiles[i]+".signature", []byte(signature), 0644); err != nil { fatalf("Could not write a signature into the file %s.signature: %v", targetFiles[i], err) } } @@ -55,7 +55,7 @@ func createFileSignature(key *rsa.PrivateKey, fileContent []byte) (string, error } func readFile(fileName string) []byte { - content, err := ioutil.ReadFile(fileName) + content, err := os.ReadFile(fileName) if err != nil { fatalf("Could not read a file %s: %v", fileName, err) } diff --git a/cmd/validator/http.go b/cmd/validator/http.go index f17117c6..a87efb7e 100644 --- a/cmd/validator/http.go +++ b/cmd/validator/http.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "net/url" + "os" "time" ) @@ -12,9 +13,9 @@ func getFile(fileUrlString string) ([]byte, error) { fileUrl, err := url.Parse(fileUrlString) if err == nil && fileUrl.Scheme == "file" { fileUrl.Scheme = "" - return ioutil.ReadFile(fileUrl.String()) + return os.ReadFile(fileUrl.String()) } else if err != nil || fileUrl.Scheme == "" { - return ioutil.ReadFile(fileUrlString) + return os.ReadFile(fileUrlString) } client := &http.Client{} @@ -27,7 +28,7 @@ func getFile(fileUrlString string) ([]byte, error) { if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("received bad status code %s", resp.Status) } - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } func getHttpHeadResult(url string) (responseCode int, err error) { diff --git a/docs/deployment-config.md b/docs/deployment-config.md index a8849d14..2a83b388 100644 --- a/docs/deployment-config.md +++ b/docs/deployment-config.md @@ -5,6 +5,9 @@ The deployment-config is a JSON-file which is supposed to be hosted on a webserv ## Fields * **`Timestamp`** (string): A timestamp in the form `YYYY-MM-DD HH:mm:SS` which indicates when the deployment-config was last changed. This field protects trivrost against attacks. A utility script `script/insert_timestamp` is provided, which replaces a placeholder with a current timestamp. It can be called like this: `insert_timestamp "" …/deployment-config.json`. See [security.md](security.md) for more information. +* **`SchemeHandlers`** (array): An array of objects which define scheme handlers to be registered with the operating system to run this trivrost app with a specified command line. The idea is to use it in combination with the `--extra-env` commandline option to pass info to the launched application. See also the [exhaustive example](../examples/deployment-config.json.complex.example) of the deployment-config. + * **`Scheme`** (string): The scheme for which to register the handler, such as `mailto`. We recommend to use some sort of reverse-DNS scheme, e.g. `com.example.productname.customername`. + * **`Arguments`** (string): The arguments to pass. Any occurrences of the special string `%s` will be replaced with the operating system-specific template which receives the resource part of the URL (i.e. path, query and fragment). Any occurrences of `%%` will be replaced with `%` to allow for a literal string `%s` to be written (we do not recommend doing so). * **`LauncherUpdate`** (array): An array of objects which define bundle configurations for how trivrost updates itself. When trivrost runs, this list must boil down to either one single configuration, or no configurations, through filtering by `TargetPlatforms`. * **`BundleInfoURL`**, **`BaseURL`**, **`TargetPlatforms`**: See [Common fields](#Common-fields) below. * **`Bundles`** (array): An array of objects which define the bundles which trivrost should download and keep up to date. diff --git a/docs/glossary.md b/docs/glossary.md index 6cfac3cd..249acf4d 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -20,3 +20,6 @@ The deployment config tells trivrost where to check for updates to itself and it ## trivrost deployment artifact We occasionally need to differ between just trivrost's executable binary and its entire deployment artifact as a whole. On Windows and Linux these two concepts are the same thing. On MacOS however, the deployment artifact of trivrost actually is a `.app`-folder, which contains the binary at `Contents/MacOS/launcher`. + +## Transmitting flags +Whenever trivrost restarts itself as part of its exclusive lock and self-update mechanisms, it passes most of the command line arguments it was run with (such as `-skipselfupdate`) to the new instance as well. We refer to arguments affected by this as "transmitting flags". diff --git a/examples/deployment-config.json.complex.example b/examples/deployment-config.json.complex.example index 09c70926..6a765e79 100644 --- a/examples/deployment-config.json.complex.example +++ b/examples/deployment-config.json.complex.example @@ -1,5 +1,11 @@ { "Timestamp": "2019-02-07 14:53:17", + "SchemeHandlers": [ + { + "Scheme": "com.setlog.example", + "Arguments": "--extra-env=\"APP_LAUNCH_OPTIONS=%s\"" + } + ], "LauncherUpdate": [ { "BundleInfoURL": "https://example.com/windows/launcher/bundleinfo.json", diff --git a/go.mod b/go.mod index 17dd4def..2bee81cf 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gofrs/flock v0.8.1 github.com/mattn/go-ieproxy v0.0.1 github.com/prometheus/client_golang v1.15.1 + github.com/setlog/systemuri v0.0.0-20230602115055-b85b65c23a14 github.com/shirou/gopsutil v3.21.11+incompatible github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 19273a8b..361986c7 100644 --- a/go.sum +++ b/go.sum @@ -224,6 +224,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/setlog/systemuri v0.0.0-20230602115055-b85b65c23a14 h1:zXGZ+F63oO9+PreP40bNIUxmCNIS7+4XUxxu4kO7p4U= +github.com/setlog/systemuri v0.0.0-20230602115055-b85b65c23a14/go.mod h1:zKnFCdzySDBLqxRKu2vBU9okcVCYrhkiLtobnSkSEGg= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -243,6 +245,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tklauser/go-sysconf v0.3.4 h1:HT8SVixZd3IzLdfs/xlpq0jeSfTX57g1v6wB1EuzV7M= diff --git a/pkg/dummy/io_test.go b/pkg/dummy/io_test.go index 0ae4c62b..27ea8540 100644 --- a/pkg/dummy/io_test.go +++ b/pkg/dummy/io_test.go @@ -2,7 +2,7 @@ package dummy_test import ( "bytes" - "io/ioutil" + "io" "testing" "github.com/setlog/trivrost/pkg/dummy" @@ -12,7 +12,7 @@ import ( func TestReadCloser(t *testing.T) { data := []byte("super amazing data") rc := &dummy.ByteReadCloser{Buffer: bytes.NewBuffer(data)} - readData, err := ioutil.ReadAll(rc) + readData, err := io.ReadAll(rc) if err != nil { t.Fatalf("Error: %v", err) } @@ -24,7 +24,7 @@ func TestReadCloser(t *testing.T) { func TestReadCloserBigFile(t *testing.T) { data := []byte("hyper amazing data" + misc.MustGetRandomHexString(10000)) rc := &dummy.ByteReadCloser{Buffer: bytes.NewBuffer(data)} - readData, err := ioutil.ReadAll(rc) + readData, err := io.ReadAll(rc) if err != nil { t.Fatalf("Error: %v", err) } diff --git a/pkg/fetching/downloader.go b/pkg/fetching/downloader.go index 650477a4..8e0c434f 100644 --- a/pkg/fetching/downloader.go +++ b/pkg/fetching/downloader.go @@ -8,7 +8,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -141,12 +140,12 @@ func (downloader *Downloader) DownloadToRAM(fileMap config.FileInfoMap) (fileDat return fileData, downloader.DownloadResources(fileMap.FilePaths(), func(dl *Download) error { wantedFileInfo := fileMap[dl.url] hash := sha256.New() - data, err := ioutil.ReadAll(io.TeeReader(dl, hash)) + data, err := io.ReadAll(io.TeeReader(dl, hash)) if err != nil { if downloader.ctx.Err() != nil { return downloader.ctx.Err() } - return fmt.Errorf("ioutil.ReadAll failed: %v", err) + return fmt.Errorf("io.ReadAll failed: %v", err) } dlFileSha := hex.EncodeToString(hash.Sum(nil)) if wantedFileInfo.SHA256 != "" && !strings.EqualFold(wantedFileInfo.SHA256, dlFileSha) { diff --git a/pkg/fetching/downloader_test.go b/pkg/fetching/downloader_test.go index 8bac8974..83eb2d31 100644 --- a/pkg/fetching/downloader_test.go +++ b/pkg/fetching/downloader_test.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "io" "io/ioutil" "math/rand" "net/http" @@ -77,7 +78,7 @@ func (db *RiggedReader) Close() error { func (de *DummyEnvironment) TestDownload(t *testing.T, fromUrl string) { dl := NewDownload(context.Background(), fromUrl) - data, err := ioutil.ReadAll(dl) + data, err := io.ReadAll(dl) if err != nil { t.Fatalf("Download \"%s\" failed unexpectedly: %v", fromUrl, err) } @@ -94,7 +95,7 @@ func (de *DummyEnvironment) TestDownloadCancel(t *testing.T, fromUrl string, can t.Fatalf("Download \"%s\" could not deliver %d bytes: %v", fromUrl, cancelAfter, err) } cancelFunc() - data, err := ioutil.ReadAll(dl) + data, err := io.ReadAll(dl) if err != context.Canceled { t.Fatalf("Download \"%s\" did not fail with context.Canceled after %d bytes. Remainder: %d. Error: %v", fromUrl, cancelAfter, len(data), err) } @@ -102,7 +103,7 @@ func (de *DummyEnvironment) TestDownloadCancel(t *testing.T, fromUrl string, can func (de *DummyEnvironment) TestDownloadFailure(t *testing.T, fromUrl string) { dl := NewDownload(context.Background(), fromUrl) - _, err := ioutil.ReadAll(dl) + _, err := io.ReadAll(dl) if err == nil { t.Fatalf("Download \"%s\" succeeded unexpectedly", fromUrl) } @@ -174,7 +175,7 @@ func TestUpdateFile(t *testing.T) { t.Fatal(err) } defer os.Remove("testfile.txt") - diskData, err := ioutil.ReadFile("testfile.txt") + diskData, err := os.ReadFile("testfile.txt") if err != nil { t.Fatal(err) } diff --git a/pkg/launcher/bundle/updater.go b/pkg/launcher/bundle/updater.go index 467417ad..f886c278 100644 --- a/pkg/launcher/bundle/updater.go +++ b/pkg/launcher/bundle/updater.go @@ -68,8 +68,8 @@ func (u *Updater) announceStatus(status UpdaterStatus, progressTarget uint64) { } } -func (u *Updater) Prepare(deploymentConfigURL string) { - log.Infof("Downloading deployment config from \"%s\".", deploymentConfigURL) +func (u *Updater) ObtainDeploymentConfig(deploymentConfigURL string) { + log.Infof("Obtaining deployment config from \"%s\".", deploymentConfigURL) data, err := u.downloader.DownloadSignedResource(deploymentConfigURL, u.publicKeys) if err != nil { panic(err) diff --git a/pkg/launcher/config/bundleinfo.go b/pkg/launcher/config/bundleinfo.go index dd7124ef..40f60654 100644 --- a/pkg/launcher/config/bundleinfo.go +++ b/pkg/launcher/config/bundleinfo.go @@ -3,7 +3,8 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" + "io" + "os" "path/filepath" "strings" @@ -120,7 +121,7 @@ func (bundleFiles FileInfoMap) FilePaths() []string { } func ReadInfo(filePath string) *BundleInfo { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { panic(err) } @@ -128,7 +129,7 @@ func ReadInfo(filePath string) *BundleInfo { } func ReadInfoFromReader(reader *strings.Reader) *BundleInfo { - data, err := ioutil.ReadAll(reader) + data, err := io.ReadAll(reader) if err != nil { panic(err) } diff --git a/pkg/launcher/config/deployment_config.go b/pkg/launcher/config/deployment_config.go index be8c6db0..7f1ba010 100644 --- a/pkg/launcher/config/deployment_config.go +++ b/pkg/launcher/config/deployment_config.go @@ -12,11 +12,17 @@ import ( type DeploymentConfig struct { Timestamp string `json:"Timestamp,omitempty"` + SchemeHandlers []SchemeHandler `json:"SchemeHandlers,omitempty"` LauncherUpdate []LauncherUpdateConfig `json:"LauncherUpdate,omitempty"` Bundles []BundleConfig `json:"Bundles,omitempty"` Execution ExecutionConfig `json:"Execution,omitempty"` } +type SchemeHandler struct { + Scheme string `json:"Scheme,omitempty"` + Arguments string `json:"Arguments,omitempty"` +} + type HashDataConfig struct { BundleInfoURL string `json:"BundleInfoURL"` BaseURL string `json:"BaseURL,omitempty"` diff --git a/pkg/launcher/timestamps/timestamps.go b/pkg/launcher/timestamps/timestamps.go index a2b6baf4..184b5f11 100644 --- a/pkg/launcher/timestamps/timestamps.go +++ b/pkg/launcher/timestamps/timestamps.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "time" @@ -60,7 +59,7 @@ func (timestamps *Timestamps) write(filePath string) { } func ReadTimestampsFromReader(reader io.Reader) *Timestamps { - bytes, err := ioutil.ReadAll(reader) + bytes, err := io.ReadAll(reader) if err != nil { panic(fmt.Sprintf("Could not read from reader: %v", err)) } diff --git a/pkg/misc/must.go b/pkg/misc/must.go index 763c02a3..f2676818 100644 --- a/pkg/misc/must.go +++ b/pkg/misc/must.go @@ -3,11 +3,10 @@ package misc import ( "encoding/json" "io" - "io/ioutil" ) func MustReadAll(fromReader io.Reader) []byte { - data, err := ioutil.ReadAll(fromReader) + data, err := io.ReadAll(fromReader) if err != nil { panic(err) } diff --git a/pkg/system/file_system_funcs.go b/pkg/system/file_system_funcs.go index 02409bef..4fd7ddfd 100644 --- a/pkg/system/file_system_funcs.go +++ b/pkg/system/file_system_funcs.go @@ -99,7 +99,7 @@ func MustPutFile(localFilePath string, bytes []byte) { } func MustReadFile(filePath string) []byte { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { panic(&FileSystemError{fmt.Sprintf("Could not read file \"%s\"", filePath), err}) } @@ -107,7 +107,7 @@ func MustReadFile(filePath string) []byte { } func MustCopyFile(from, to string) { - data, err := ioutil.ReadFile(from) + data, err := os.ReadFile(from) if err != nil { panic(&FileSystemError{fmt.Sprintf("Could not read file \"%s\"", from), err}) } @@ -116,7 +116,7 @@ func MustCopyFile(from, to string) { panic(&FileSystemError{fmt.Sprintf("Could not stat file \"%s\"", from), err}) } log.Debugf(`Copying "%s" to "%s" with mode %s.`, from, to, strconv.FormatInt(int64(info.Mode()), 8)) - err = ioutil.WriteFile(to, data, info.Mode()) + err = os.WriteFile(to, data, info.Mode()) if err != nil { panic(&FileSystemError{fmt.Sprintf("Could not write file \"%s\"", to), err}) }