Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions cli/certs/generate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"os"
"path/filepath"

"github.com/alecthomas/kingpin/v2"
"github.com/harness/godotenv/v3"
"github.com/harness/lite-engine/config"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)

const certPermissions = os.FileMode(0600)
Expand All @@ -26,35 +25,35 @@ type certCommand struct {
func generateCert(serverName, relPath string) error {
ca, err := GenerateCA()
if err != nil {
return errors.Wrap(err, "failed to generate ca certificate")
return fmt.Errorf("failed to generate ca certificate: %w", err)
}

tlsCert, err := GenerateCert(serverName, ca)
if err != nil {
return errors.Wrap(err, "failed to generate certificate")
return fmt.Errorf("failed to generate certificate: %w", err)
}

err = os.MkdirAll(relPath, os.ModePerm)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to create directory at path: %s", relPath))
return fmt.Errorf("failed to create directory at path: %s: %w", relPath, err)
}

caCertFilePath := filepath.Join(relPath, "ca-cert.pem")
caKeyFilePath := filepath.Join(relPath, "ca-key.pem")
if err := os.WriteFile(caCertFilePath, ca.Cert, certPermissions); err != nil {
return errors.Wrap(err, "failed to write CA cert file")
return fmt.Errorf("failed to write CA cert file: %w", err)
}
if err := os.WriteFile(caKeyFilePath, ca.Key, certPermissions); err != nil {
return errors.Wrap(err, "failed to write CA key file")
return fmt.Errorf("failed to write CA key file: %w", err)
}

certFilePath := filepath.Join(relPath, "server-cert.pem")
keyFilePath := filepath.Join(relPath, "server-key.pem")
if err := os.WriteFile(certFilePath, tlsCert.Cert, certPermissions); err != nil {
return errors.Wrap(err, "failed to write server cert file")
return fmt.Errorf("failed to write server cert file: %w", err)
}
if err := os.WriteFile(keyFilePath, tlsCert.Key, certPermissions); err != nil {
return errors.Wrap(err, "failed to write server key file")
return fmt.Errorf("failed to write server key file: %w", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/harness/lite-engine/cli/server"
"github.com/harness/lite-engine/version"

"gopkg.in/alecthomas/kingpin.v2"
"github.com/alecthomas/kingpin/v2"
)

// Command parses the command line arguments and then executes a
Expand Down
7 changes: 3 additions & 4 deletions cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import (
"github.com/harness/lite-engine/engine/spec"
"github.com/harness/lite-engine/logger"

"github.com/alecthomas/kingpin/v2"
"github.com/harness/godotenv/v3"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)

type Client interface {
Expand Down Expand Up @@ -86,7 +85,7 @@ func (c *clientCommand) run(*kingpin.ParseContext) error {
if err != nil {
logrus.WithError(err).
Errorln("failed to create client")
return errors.Wrap(err, "failed to create client")
return fmt.Errorf("failed to create client: %w", err)
}
}

Expand All @@ -103,7 +102,7 @@ func checkServerHealth(client Client) error {
if healthErr != nil {
logrus.WithError(healthErr).
Errorln("cannot check the health of the server")
return errors.Wrap(healthErr, "cannot check the health of the server")
return fmt.Errorf("cannot check the health of the server: %w", healthErr)
}
logrus.WithField("response", response).Info("health check")
return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/harness/lite-engine/server"
"github.com/harness/lite-engine/setup"

"github.com/alecthomas/kingpin/v2"
"github.com/harness/godotenv/v3"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)

type serverCommand struct {
Expand Down
46 changes: 18 additions & 28 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/harness/lite-engine/engine/spec"
"github.com/harness/lite-engine/logstream"
"github.com/harness/lite-engine/pipeline"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -58,8 +57,7 @@ func NewEnv(opts docker.Opts) (*Engine, error) {
func setupHelper(pipelineConfig *spec.PipelineConfig) error {
// create global files and folders
if err := createFiles(pipelineConfig.Files); err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to create files/folders for pipeline %v", pipelineConfig.Files))
return fmt.Errorf("failed to create files/folders for pipeline %v: %w", pipelineConfig.Files, err)
}
// create volumes
for _, vol := range pipelineConfig.Volumes {
Expand All @@ -75,16 +73,15 @@ func setupHelper(pipelineConfig *spec.PipelineConfig) error {
}

if err := os.MkdirAll(path, permissions); err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to create directory for host volume path: %q", path))
return fmt.Errorf("failed to create directory for host volume path: %q: %w", path, err)
}
_ = os.Chmod(path, permissions)
}

// create mTLS certs and set environment variable if successful
certsWritten, err := createMtlsCerts(pipelineConfig.MtlsConfig)
if err != nil {
return errors.Wrap(err, "failed to create mTLS certificates")
return fmt.Errorf("failed to create mTLS certificates: %w", err)
}
if certsWritten {
// This can be used by STO and SSCA plugins to support mTLS
Expand All @@ -109,34 +106,32 @@ func createMtlsCerts(mtlsConfig spec.MtlsConfig) (bool, error) {

// Create the mTLS directory
if err := os.MkdirAll(mtlsConfig.ClientCertDirPath, permissions); err != nil {
return false, errors.Wrap(err, "failed to create mTLS directory")
return false, fmt.Errorf("failed to create mTLS directory: %w", err)
}

// Decode and write certificate
certPath := filepath.Join(mtlsConfig.ClientCertDirPath, "client.crt")
if err := writeBase64ToFile(certPath, mtlsConfig.ClientCert); err != nil {
return false, errors.Wrap(err, "failed to write mTLS certificate")
return false, fmt.Errorf("failed to write mTLS certificate: %w", err)
}

// Set 0777 permissions for the certificate
if _, err := os.Stat(certPath); err == nil {
if err := os.Chmod(certPath, permissions); err != nil {
logrus.Error(errors.Wrap(err,
fmt.Sprintf("Failed to set permissions %o for file on host path: %q", permissions, certPath)))
logrus.Errorf("Failed to set permissions %o for file on host path: %q: %v", permissions, certPath, err)
}
}

// Decode and write key
keyPath := filepath.Join(mtlsConfig.ClientCertDirPath, "client.key")
if err := writeBase64ToFile(keyPath, mtlsConfig.ClientCertKey); err != nil {
return false, errors.Wrap(err, "failed to write mTLS key")
return false, fmt.Errorf("failed to write mTLS key: %w", err)
}

// Set 0777 permissions for the key
if _, err := os.Stat(keyPath); err == nil {
if err := os.Chmod(keyPath, permissions); err != nil {
logrus.Error(errors.Wrap(err,
fmt.Sprintf("Failed to set permissions %o for file on host path: %q", permissions, certPath)))
logrus.Errorf("Failed to set permissions %o for file on host path: %q: %v", permissions, keyPath, err)
}
}

Expand All @@ -154,7 +149,7 @@ func loadSanitizePatternsIntoRuntime(sanitizeConfig spec.SanitizeConfig) error {
// Decode Base64 content
data, err := base64.StdEncoding.DecodeString(sanitizeConfig.SanitizePatternsContent)
if err != nil {
return errors.Wrap(err, "failed to decode sanitize patterns from Base64")
return fmt.Errorf("failed to decode sanitize patterns from Base64: %w", err)
}

// Load patterns directly from decoded string content (in-memory)
Expand All @@ -170,7 +165,7 @@ func loadSanitizePatternsIntoRuntime(sanitizeConfig spec.SanitizeConfig) error {
}

if err := logstream.LoadCustomPatternsFromString(content); err != nil {
return errors.Wrap(err, "failed to load sanitize patterns into runtime")
return fmt.Errorf("failed to load sanitize patterns into runtime: %w", err)
}

logrus.WithField("pattern_count", patternCount).Info("successfully loaded sanitize patterns from delegate into runtime (in-memory)")
Expand All @@ -181,11 +176,11 @@ func loadSanitizePatternsIntoRuntime(sanitizeConfig spec.SanitizeConfig) error {
func writeBase64ToFile(filePath, base64Data string) error {
data, err := base64.StdEncoding.DecodeString(base64Data)
if err != nil {
return errors.Wrap(err, "failed to decode base64 data")
return fmt.Errorf("failed to decode base64 data: %w", err)
}

if err := os.WriteFile(filePath, data, permissions); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to write to file: %s", filePath))
return fmt.Errorf("failed to write to file: %s: %w", filePath, err)
}

return nil
Expand Down Expand Up @@ -354,17 +349,15 @@ func createFiles(paths []*spec.File) error {
// make the file writable (if it exists)
if _, err := os.Stat(path); err == nil {
if err = os.Chmod(path, defaultFilePermissions); err != nil {
logrus.Error(errors.Wrap(err,
fmt.Sprintf("failed to set permissions for file on host path: %q", path)))
logrus.Errorf("failed to set permissions for file on host path: %q: %v", path, err)
continue
}
}

if f.IsDir {
// create a folder
if err := os.MkdirAll(path, fs.FileMode(f.Mode)); err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to create directory for host path: %q", path))
return fmt.Errorf("failed to create directory for host path: %q: %w", path, err)
}
continue
}
Expand All @@ -373,28 +366,25 @@ func createFiles(paths []*spec.File) error {
dir := filepath.Dir(path)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, fs.FileMode(permissions)); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to create directory: for path %q", path))
return fmt.Errorf("failed to create directory for path %q: %w", path, err)
}
}

// Create (or overwrite) the file
file, err := os.Create(path)
if err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to create file for host path: %q", path))
return fmt.Errorf("failed to create file for host path: %q: %w", path, err)
}

if _, err = file.WriteString(f.Data); err != nil {
_ = file.Close()
return errors.Wrap(err,
fmt.Sprintf("failed to write file for host path: %q", path))
return fmt.Errorf("failed to write file for host path: %q: %w", path, err)
}

_ = file.Close()

if err = os.Chmod(path, fs.FileMode(f.Mode)); err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to change permissions for file on host path: %q", path))
return fmt.Errorf("failed to change permissions for file on host path: %q: %w", path, err)
}
}
return nil
Expand Down
44 changes: 21 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,47 @@ go 1.24.0
toolchain go1.24.12

require (
github.com/bmatcuk/doublestar v1.3.4
github.com/cenkalti/backoff/v4 v4.2.0
github.com/docker/distribution v2.8.1+incompatible
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/cenkalti/backoff/v4 v4.3.0
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v28.0.2+incompatible
github.com/docker/go-connections v0.4.0
github.com/drone/drone-go v1.7.1
github.com/drone/runner-go v1.12.0
github.com/go-chi/chi/v5 v5.0.8
github.com/gofrs/uuid v4.4.0+incompatible
github.com/golang/mock v1.6.0
github.com/drone/runner-go v1.13.0
github.com/go-chi/chi/v5 v5.2.4
github.com/harness/ti-client v0.0.0-20260106231425-06bf65d965b0
github.com/hashicorp/go-multierror v1.1.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/linkedin/goavro/v2 v2.12.0
github.com/mattn/go-zglob v0.0.4
github.com/mholt/archives v0.1.5
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/sirupsen/logrus v1.9.4
github.com/stretchr/testify v1.11.1
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
golang.org/x/sync v0.17.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
golang.org/x/sync v0.18.0
)

require (
github.com/bmatcuk/doublestar/v4 v4.10.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/dgryski/go-lttb v0.0.0-20230207170358-f8fc36cdbff1
github.com/google/uuid v1.6.0
github.com/harness/godotenv/v2 v2.0.0
github.com/harness/godotenv/v3 v3.0.1
github.com/harness/godotenv/v4 v4.0.2
github.com/shirou/gopsutil/v3 v3.23.5
github.com/wings-software/dlite v1.0.0-rc.13
golang.org/x/net v0.43.0
golang.org/x/sys v0.35.0
github.com/wings-software/dlite v1.0.0-rc.15
go.uber.org/mock v0.6.0
golang.org/x/net v0.47.0
golang.org/x/sys v0.40.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/STARRY-S/zip v0.2.3 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/bodgit/plumbing v1.3.0 // indirect
Expand All @@ -62,12 +61,12 @@ require (
github.com/drone/envsubst v1.0.3 // indirect
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/klauspost/compress v1.18.0 // indirect
Expand All @@ -84,6 +83,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
Expand All @@ -92,6 +92,7 @@ require (
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/ulikunitz/xz v0.5.15 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.mongodb.org/mongo-driver v1.17.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
Expand All @@ -101,14 +102,11 @@ require (
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/exp v0.0.0-20220927162542-c76eaa363f9d // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.36.0 // indirect
golang.org/x/tools v0.38.0 // indirect
google.golang.org/genproto v0.0.0-20230320184635-7606e756e683 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.2 // indirect
)
Loading