minimal implementation for pmg

This commit is contained in:
Sahilb315
2025-04-09 23:27:46 +05:30
parent 4805f443f5
commit ed8f9b6d53
13 changed files with 188 additions and 68 deletions
+21
View File
@@ -0,0 +1,21 @@
package utils
import (
"bytes"
"fmt"
"os/exec"
)
func ExecCmd(name string, args []string) error {
cmd := exec.Command(name, args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running cmd %s: %s\nStderr: %s", name,
err.Error(), stderr.String())
}
return nil
}
+11
View File
@@ -0,0 +1,11 @@
package utils
import "os"
func ApiKey() string {
return os.Getenv("SAFEDEP_API_KEY")
}
func TenantDomain() string {
return os.Getenv("SAFEDEP_TENANT_ID")
}
+14
View File
@@ -0,0 +1,14 @@
package utils
import (
"fmt"
"os/exec"
)
func GetInterpreterPath(name string) (string, error) {
path, err := exec.LookPath(name)
if err != nil {
return "", fmt.Errorf("interpreter '%s' not found in PATH: %s", name, err.Error())
}
return path, nil
}
+30
View File
@@ -0,0 +1,30 @@
package utils
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/safedep/dry/log"
)
func ConfirmInstallation(maliciousPkgs map[string]string) bool {
fmt.Printf("\nWARNING: %d potentially malicious packages detected!\n", len(maliciousPkgs))
fmt.Println("The following packages have been flagged:")
for name, reason := range maliciousPkgs {
fmt.Printf("- %s: %s\n", name, reason)
}
fmt.Print("\nDo you want to continue with installation? (y/N): ")
reader := bufio.NewReader(os.Stdin)
response, err := reader.ReadString('\n')
if err != nil {
log.Errorf("Failed to read user input: %v", err)
return false
}
response = strings.ToLower(strings.TrimSpace(response))
return response == "y" || response == "yes"
}