init commit for coverting to podman
This commit is contained in:
29
internal/podman/errors/errors.go
Normal file
29
internal/podman/errors/errors.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package errors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TrimExtraInfo is a helper function that trims extra information
|
||||
// from a Docker error. Specifically, on Windows, this can expose
|
||||
// environment variables and other sensitive data.
|
||||
func TrimExtraInfo(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
s := err.Error()
|
||||
i := strings.Index(s, "extra info:")
|
||||
if i > 0 {
|
||||
s = s[:i]
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.TrimSuffix(s, "(0x2)")
|
||||
s = strings.TrimSpace(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
return err
|
||||
}
|
||||
22
internal/podman/errors/errors_test.go
Normal file
22
internal/podman/errors/errors_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package errors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrimExtraInfo(t *testing.T) {
|
||||
const (
|
||||
before = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: { "User":"ContainerUser" }`
|
||||
after = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.`
|
||||
)
|
||||
errBefore := errors.New(before)
|
||||
errAfter := TrimExtraInfo(errBefore)
|
||||
if errAfter.Error() != after {
|
||||
t.Errorf("Expect trimmed image")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user