Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD Integration & Refactor & AI #45

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
37 changes: 22 additions & 15 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]

jobs:

Fleet:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: 1.23.x

- name: Check Go environment
run: go version

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.x
- name: Install dependencies
run: go get -v -t -d ./...

- name: Build
run: go build -v ./...
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

- name: Run golangci-lint
run: golangci-lint run ./...

- name: Build
run: go build -o resq
11 changes: 7 additions & 4 deletions CLI/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
package cli

import (
"fleet/ai"
"fleet/handlers"
"fleet/handlers/list"
"fmt"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -58,15 +61,15 @@ func Command() *cobra.Command {
},
},
&cobra.Command{
Use: "update [package]",
Short: "Update a package",
Use: "ai [question]",
Short: "AI assistant",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// handlers.Update(args[0])
result := ai.ResponseAi(args[0])
fmt.Println(result)
},
},
)

return rootCmd
}

6 changes: 3 additions & 3 deletions Formulas/aircrack-ng.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func downloadFile(filepath string, url string) error {
return err
}


func unzip(src string, dest string) error {
r, err := zip.OpenReader(src)
if err != nil {
Expand All @@ -105,7 +104,9 @@ func unzip(src string, dest string) error {
for _, f := range r.File {
fPath := filepath.Join(dest, f.Name)
if f.FileInfo().IsDir() {
os.MkdirAll(fPath, os.ModePerm)
if err := os.MkdirAll(fPath, os.ModePerm); err != nil {
return err
}
continue
}

Expand Down Expand Up @@ -140,4 +141,3 @@ func runCommand(name string, args ...string) error {
cmd.Stderr = os.Stderr
return cmd.Run()
}

36 changes: 23 additions & 13 deletions Formulas/bat.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,34 @@ package formulas

import (
"fmt"
"os"
"os/exec"
"runtime"
)

func InstallBat() {

func InstallBat(){
switch runtime.GOOS {
case "darwin":
installBazelMac()
default:
fmt.Println("OS No Support")
}

switch runtime.GOOS {
case "darwin":
installBazelMac()
default:
fmt.Println("OS No Support")
}

}

func InstallBatMac(){
url := "https://github.com/sharkdp/bat/releases/download/v0.24.0/bat-v0.24.0-x86_64-apple-darwin.tar.gz"
download := exec.Command("curl", "-L", url, "-o", "bat.tar.gz")
download.Run()
}
func InstallBatMac() {
url := "https://github.com/sharkdp/bat/releases/download/v0.24.0/bat-v0.24.0-x86_64-apple-darwin.tar.gz"
download := exec.Command("curl", "-L", url, "-o", "bat.tar.gz")
if err := download.Run(); err != nil {
fmt.Println("Error downloading bat:", err)
return
}
defer os.Remove("bat.tar.gz")

extract := exec.Command("tar", "-xzf", "bat.tar.gz")
if err := extract.Run(); err != nil {
fmt.Println("Error extracting bat:", err)
return
}
}
28 changes: 16 additions & 12 deletions Formulas/burpsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
package formulas

import (
"runtime"
"os/exec"
"fmt"
"os/exec"
"runtime"
)

func InstallBurpSuite(){
switch runtime.GOARCH{
case "arm64":
InstallBurpSuiteMac("https://portswigger.net/burp/releases/community/latest")
case "amd64":
InstallBurpSuiteMac("https://portswigger.net/burp/releases/community/latest")
}
func InstallBurpSuite() {
switch runtime.GOARCH {
case "arm64":
InstallBurpSuiteMac("https://portswigger.net/burp/releases/community/latest")
case "amd64":
InstallBurpSuiteMac("https://portswigger.net/burp/releases/community/latest")
}
}

func InstallBurpSuiteMac(url string){
download := exec.Command("curl", "-L", url)
download.Run()
func InstallBurpSuiteMac(url string) {
download := exec.Command("curl", "-L", url)
if err := download.Run(); err != nil {
fmt.Println("Error downloading burpsuite:", err)
return
}
}
5 changes: 4 additions & 1 deletion Formulas/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func installDockerMac(url string) {
install := exec.Command("sudo", "/Volumes/Docker/Docker.app/Contents/MacOS/install")
if err := install.Run(); err != nil {
redBold.Println("Error installing Docker:", err)
exec.Command("hdiutil", "detach", "/Volumes/Docker").Run() // Desmontar en caso de error
if err := exec.Command("sudo", "rm", "-rf", "/Volumes/Docker").Run(); err != nil {
redBold.Println("Error cleaning up the disk image:", err)
return
}
return
}

Expand Down
46 changes: 42 additions & 4 deletions Formulas/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package formulas

import (
"os"
"os/exec"
"runtime"
)
Expand Down Expand Up @@ -50,18 +51,55 @@ func installGitMac() {
pkgPath := "/Volumes/Git 2.2.1 Mavericks Intel Universal/git-2.2.1-intel-universal-mavericks.pkg"
if err := exec.Command("test", "-f", pkgPath).Run(); err != nil {
redBold.Println("Error finding the .pkg file:", err)
exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Intel Universal Mavericks").Run() // Desmontar en caso de error
if err := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/").Run(); err != nil {
redBold.Println("Error detaching the disk image:", err)
return
}
return
}

yellow.Println("Installing Git from the package...")
install := exec.Command("sudo", "installer", "-pkg", pkgPath, "-target", "/")
if err := install.Run(); err != nil {
if err := exec.Command("sudo", "installer", "-pkg", pkgPath, "-target", "/").Run(); err != nil {
redBold.Println("Error installing Git:", err)
exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Intel Universal Mavericks").Run() // Desmontar en caso de error
if err := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/").Run(); err != nil {
redBold.Println("Error detaching the disk image:", err)
return
}
return
}

zipFile := "git.zip"
download = exec.Command("curl", "-L", "https://github.com/git-for-windows/git/releases/download/v2.38.1.windows.1/Git-2.38.1-64-bit.zip", "-o", zipFile)
if err := download.Run(); err != nil {
redBold.Println("Error downloading Git:", err)
if err := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/").Run(); err != nil {
redBold.Println("Error detaching the disk image:", err)
return
}
return
}
defer os.Remove(zipFile)

yellow.Println("Extracting Git...")
unzip := exec.Command("unzip", zipFile)
if err := unzip.Run(); err != nil {
redBold.Println("Error extracting Git:", err)
if err := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/").Run(); err != nil {
redBold.Println("Error detaching the disk image:", err)
return
}
return
}

install := exec.Command("sudo", "installer", "-pkg", "/Volumes/Git/Git.app/Contents/Resources/git-installer.pkg", "-target", "/")
if err := install.Run(); err != nil {
redBold.Println("Error installing Git:", err)
if err := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/").Run(); err != nil {
redBold.Println("Error detaching the disk image:", err)
return
}
}

yellow.Println("Unmounting the disk image...")
detach := exec.Command("hdiutil", "detach", "/Volumes/Git 2.2.1 Mavericks Intel Universal/")
if err := detach.Run(); err != nil {
Expand Down
28 changes: 11 additions & 17 deletions ai/ai.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ai


// This functionality is not available yet, it is not ready and it has bugs
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"text/tabwriter"
Expand All @@ -15,7 +13,7 @@ import (

type Message struct {
Content string `json:"content"`
ID string `json:"id"`
ID string `json:"id"`
Role string `json:"role"`
CreatedAt string `json:"createdAt"`
}
Expand Down Expand Up @@ -64,7 +62,7 @@ func wrapText(text string, width int) string {
return buf.String()
}

func ResponseAi(question string) {
func ResponseAi(question string) error {
url := "https://www.blackbox.ai/api/chat"

messages := []Message{
Expand All @@ -88,32 +86,28 @@ func ResponseAi(question string) {

jsonData, err := json.Marshal(requestBody)
if err != nil {
fmt.Println("Error converting to JSON:", err)
return
return fmt.Errorf("error converting to JSON: %w", err)
}

resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error making request:", err)
return
return fmt.Errorf("error making request: %w", err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body) // Reemplazado ioutil.ReadAll con io.ReadAll
if err != nil {
fmt.Println("Error reading response:", err)
return
return fmt.Errorf("error reading response: %w", err)
}

responseStr := string(body)

parts := strings.Split(responseStr, "$@$")
if len(parts) > 2 {
responseStr = parts[2]
} else {
responseStr = responseStr
}

typingAnimation(wrapText(responseStr, 20), 13*time.Millisecond)
}
fmt.Println("\nAI is typing...")
typingAnimation(wrapText(responseStr, 60), 30*time.Millisecond)

return nil
}
Loading
Loading