Skip to content

Commit

Permalink
Squash updates for v1 backwards porting
Browse files Browse the repository at this point in the history
Update LICENSE

Signed-off-by: Tai Groot <[email protected]>

resolve rebase error

runas error check

fixup all LSP wanrings (sans one TODO) in certs/tls

update licenses for v1 as well
  • Loading branch information
taigrr committed Sep 10, 2024
1 parent dfdc41d commit 174764f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go-licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- 'go.mod'
branches:
- master
- v1
- v2

workflow_dispatch:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (C) 2021-2023 by Tai Groot <[email protected]>
Copyright (C) 2023 by the grlx contributors (see https://github.com/gogrlx/grlx/graphs/contributors).
Copyright (C) 2024 by the grlx contributors (see https://github.com/gogrlx/grlx/graphs/contributors).

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
Expand Down
38 changes: 23 additions & 15 deletions certs/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
"os"
"time"

log "github.com/taigrr/log-socket/log"

"github.com/gogrlx/grlx/config"
log "github.com/taigrr/log-socket/log"
)

func publicKey(priv interface{}) interface{} {
Expand Down Expand Up @@ -49,6 +48,9 @@ func genCACert() {
}
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Panicf("Failed to generate serial number: %v", err)
}
caCert := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Expand Down Expand Up @@ -83,10 +85,10 @@ func genCACert() {
if err != nil {
log.Fatalf("%v", err)
}
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: caBytes}); err != nil {
if err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: caBytes}); err != nil {
log.Fatalf("%v", err)
}
if err := certOut.Close(); err != nil {
if err = certOut.Close(); err != nil {
log.Fatalf("%v", err)
}
log.Debugf("wrote %s", RootCA)
Expand Down Expand Up @@ -130,29 +132,35 @@ func GenCert() {
if statsErr != nil {
log.Panic(err)
}
var size int64 = stats.Size()
size := stats.Size()
bytes := make([]byte, size)
bufr := bufio.NewReader(file)
_, err = bufr.Read(bytes)
if err != nil {
log.Panic("could not read rootCA file into buffer", err)
}
block, _ := pem.Decode(bytes)
caCert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
log.Panic(err.Error())
}
file2, err := os.Open(config.RootCAPriv)
rootCAPrivFile, err := os.Open(config.RootCAPriv)
if err != nil {
log.Panic(err)
}
defer file2.Close()
stats, statsErr = file2.Stat()
defer rootCAPrivFile.Close()
stats, statsErr = rootCAPrivFile.Stat()
if statsErr != nil {
log.Panic(err)
}
size = stats.Size()
bytes2 := make([]byte, size)
bufr2 := bufio.NewReader(file2)
_, err = bufr2.Read(bytes2)
block2, _ := pem.Decode(bytes2)
rootCAPrivBytes := make([]byte, size)
bufr2 := bufio.NewReader(rootCAPrivFile)
_, err = bufr2.Read(rootCAPrivBytes)
if err != nil {
log.Panic("could not read rootCA private key file into buffer", err)
}
block2, _ := pem.Decode(rootCAPrivBytes)
caPriv, err := x509.ParsePKCS8PrivateKey(block2.Bytes)
if err != nil {
log.Panic(err.Error())
Expand All @@ -161,7 +169,7 @@ func GenCert() {
var priv interface{}
priv, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatalf("Failed to generate private key: %v", err)
log.Panicf("Failed to generate private key: %v", err)
}
// ECDSA, ED25519 and RSA subject keys should have the DigitalSignature
// KeyUsage bits set in the x509.Certificate template
Expand Down Expand Up @@ -200,10 +208,10 @@ func GenCert() {
if err != nil {
log.Fatalf("Failed to open cert.pem for writing: %v", err)
}
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
if err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
log.Fatalf("Failed to write data to cert.pem: %v", err)
}
if err := certOut.Close(); err != nil {
if err = certOut.Close(); err != nil {
log.Fatalf("Error closing cert.pem: %v", err)
}
log.Debug("wrote cert.pem")
Expand Down
2 changes: 1 addition & 1 deletion cmd/farmer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (

func main() {
config.LoadConfig("farmer")
fmt.Println(fmt.Sprintf("Starting Farmer with URL %s", config.FarmerBusURL))
fmt.Printf("Starting Farmer with URL %s\n", config.FarmerBusURL)
defer log.Flush()
log := log.CreateClient()
log.LogLevel = (config.LogLevel)
Expand Down
37 changes: 25 additions & 12 deletions ingredients/cmd/cmdRun.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,33 @@ func (c Cmd) run(ctx context.Context, test bool) (types.Result, error) {
timeout := ""
if runasInter, ok := c.params["runas"]; ok {
runas, ok = runasInter.(string)
if !ok {
return result, fmt.Errorf("invalid runas %v; must be a string", runasInter)
}
}
if pathInter, ok := c.params["path"]; ok {
path, ok = pathInter.(string)
if !ok {
return result, fmt.Errorf("invalid path %v; must be a string", pathInter)
}
}
if cwdInter, ok := c.params["cwd"]; ok {
cwd, ok = cwdInter.(string)
if !ok {
return result, fmt.Errorf("invalid cwd %v; must be a string", cwdInter)
}
}
if envInter, ok := c.params["env"]; ok {
env, ok = envInter.([]string)
if !ok {
return result, fmt.Errorf("invalid env %v; must be a string slice like `k=v`", envInter)
}
}
if timeoutInter, ok := c.params["timeout"]; ok {
timeout, ok = timeoutInter.(string)
if !ok {
return result, fmt.Errorf("invalid timeout %v; must be a string", timeoutInter)
}
}
// sanity check env vars
envVars := map[string]string{}
Expand All @@ -63,13 +78,13 @@ func (c Cmd) run(ctx context.Context, test bool) (types.Result, error) {
}
var command *exec.Cmd
if timeout != "" {
ttimeout, err := time.ParseDuration(timeout)
if err != nil {
ttimeout, parseErr := time.ParseDuration(timeout)
if parseErr != nil {
result.Succeeded = false
result.Failed = true
result.Changed = false
result.Notes = append(result.Notes, types.SimpleNote(fmt.Sprintf("invalid timeout %s; must be a valid duration", timeout)))
return result, errors.Join(err, fmt.Errorf("invalid timeout %s; must be a valid duration", timeout))
return result, errors.Join(parseErr, fmt.Errorf("invalid timeout %s; must be a valid duration", timeout))
}
timeoutCTX, cancel := context.WithTimeout(ctx, ttimeout)
defer cancel()
Expand All @@ -78,13 +93,13 @@ func (c Cmd) run(ctx context.Context, test bool) (types.Result, error) {
command = exec.CommandContext(ctx, splitCmd[0], args...)
}
if runas != "" && runtime.GOOS != "windows" {
u, err := user.Lookup(runas)
if err != nil {
return result, errors.Join(err, fmt.Errorf("invalid user %s; user must exist", runas))
u, lookupErr := user.Lookup(runas)
if lookupErr != nil {
return result, errors.Join(lookupErr, fmt.Errorf("invalid user %s; user must exist", runas))
}
uid64, err := strconv.Atoi(u.Uid)
if err != nil {
return result, errors.Join(err, fmt.Errorf("invalid user %s; user must exist", runas))
uid64, strNameErr := strconv.Atoi(u.Uid)
if strNameErr != nil {
return result, errors.Join(strNameErr, fmt.Errorf("invalid user %s; user must exist", runas))
}
if uid64 > math.MaxInt32 {
return result, fmt.Errorf("UID %d is invalid", uid64)
Expand All @@ -101,9 +116,7 @@ func (c Cmd) run(ctx context.Context, test bool) (types.Result, error) {
}
if len(envVars) > 0 {
command.Env = []string{}
for _, v := range env {
command.Env = append(command.Env, v)
}
command.Env = append(command.Env, env...)
}
if test {
result.Notes = append(result.Notes,
Expand Down

0 comments on commit 174764f

Please sign in to comment.