mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a7c69c8849 | |||
7d46c9544c | |||
10d16d7dd1 | |||
48489e0abb | |||
ca51e076b6 |
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -39,8 +39,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "Quality Gate: checking test coverage is above threshold ..."
|
echo "Quality Gate: checking test coverage is above threshold ..."
|
||||||
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
|
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
|
||||||
# Excluded the concrete strategy from the coverage calculation, because tested by integration tests
|
# Excluded the concrete strategy from the unit test coverage, because covered by integration tests
|
||||||
cat coverage.tmp.out | grep -v "secureShellStrategy.go" | grep -v "hypertextTransferProtocolStrategy.go" | grep -v "transmissionControlProtocolStrategy.go" > coverage.out
|
cat coverage.tmp.out | grep -v "ssh.go" | grep -v "http.go" | grep -v "tcp.go" > coverage.out
|
||||||
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
||||||
echo "Current test coverage : $totalCoverage %"
|
echo "Current test coverage : $totalCoverage %"
|
||||||
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
|
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
|
||||||
|
10
Makefile
10
Makefile
@ -4,27 +4,35 @@ ifeq (${DOCKER_COMPOSE},)
|
|||||||
DOCKER_COMPOSE = docker compose
|
DOCKER_COMPOSE = docker compose
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY: beelzebub.start
|
||||||
beelzebub.start:
|
beelzebub.start:
|
||||||
${DOCKER_COMPOSE} build;
|
${DOCKER_COMPOSE} build;
|
||||||
${DOCKER_COMPOSE} up -d;
|
${DOCKER_COMPOSE} up -d;
|
||||||
|
|
||||||
|
.PHONY: beelzebub.stop
|
||||||
beelzebub.stop:
|
beelzebub.stop:
|
||||||
${DOCKER_COMPOSE} down;
|
${DOCKER_COMPOSE} down;
|
||||||
|
|
||||||
|
.PHONY: test.unit
|
||||||
test.unit:
|
test.unit:
|
||||||
go test ./...
|
go test ./...
|
||||||
|
|
||||||
|
.PHONY: test.unit.verbose
|
||||||
test.unit.verbose:
|
test.unit.verbose:
|
||||||
go test ./... -v
|
go test ./... -v
|
||||||
|
|
||||||
|
.PHONY: test.dependencies.start
|
||||||
test.dependencies.start:
|
test.dependencies.start:
|
||||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml up -d
|
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml up -d
|
||||||
|
|
||||||
|
.PHONY: test.dependencies.down
|
||||||
test.dependencies.down:
|
test.dependencies.down:
|
||||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml down
|
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml down
|
||||||
|
|
||||||
|
.PHONY: test.integration
|
||||||
test.integration:
|
test.integration:
|
||||||
INTEGRATION=1 go test ./...
|
INTEGRATION=1 go test ./...
|
||||||
|
|
||||||
|
.PHONY: test.integration.verbose
|
||||||
test.integration.verbose:
|
test.integration.verbose:
|
||||||
INTEGRATION=1 go test ./... -v
|
INTEGRATION=1 go test ./... -v
|
||||||
|
@ -97,9 +97,9 @@ func (b *Builder) Run() error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Init Protocol strategies
|
// Init Protocol strategies
|
||||||
secureShellStrategy := &strategies.SecureShellStrategy{}
|
secureShellStrategy := &strategies.SSHStrategy{}
|
||||||
hypertextTransferProtocolStrategy := &strategies.HypertextTransferProtocolStrategy{}
|
hypertextTransferProtocolStrategy := &strategies.HTTPStrategy{}
|
||||||
transmissionControlProtocolStrategy := &strategies.TransmissionControlProtocolStrategy{}
|
transmissionControlProtocolStrategy := &strategies.TCPStrategy{}
|
||||||
|
|
||||||
// Init Tracer strategies, and set the trace strategy default HTTP
|
// Init Tracer strategies, and set the trace strategy default HTTP
|
||||||
protocolManager := protocols.InitProtocolManager(b.traceStrategy, hypertextTransferProtocolStrategy)
|
protocolManager := protocols.InitProtocolManager(b.traceStrategy, hypertextTransferProtocolStrategy)
|
||||||
|
4
go.mod
4
go.mod
@ -10,8 +10,8 @@ require (
|
|||||||
github.com/melbahja/goph v1.3.1
|
github.com/melbahja/goph v1.3.1
|
||||||
github.com/prometheus/client_golang v1.15.1
|
github.com/prometheus/client_golang v1.15.1
|
||||||
github.com/rabbitmq/amqp091-go v1.8.1
|
github.com/rabbitmq/amqp091-go v1.8.1
|
||||||
github.com/sirupsen/logrus v1.9.1
|
github.com/sirupsen/logrus v1.9.2
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.4
|
||||||
golang.org/x/crypto v0.9.0
|
golang.org/x/crypto v0.9.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
9
go.sum
9
go.sum
@ -52,16 +52,15 @@ github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0
|
|||||||
github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
|
github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
|
||||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/sirupsen/logrus v1.9.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
|
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
|
||||||
github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
|
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
|
||||||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
||||||
|
22
main.go
22
main.go
@ -3,14 +3,23 @@ package main
|
|||||||
import (
|
import (
|
||||||
"beelzebub/builder"
|
"beelzebub/builder"
|
||||||
"beelzebub/parser"
|
"beelzebub/parser"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var quit = make(chan struct{})
|
var quit = make(chan struct{})
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parser := parser.Init("./configurations/beelzebub.yaml", "./configurations/services/")
|
var configurationsCorePath string
|
||||||
|
var configurationsServicesDirectory string
|
||||||
|
|
||||||
|
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
|
||||||
|
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
|
||||||
|
|
||||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
||||||
@ -23,14 +32,11 @@ func main() {
|
|||||||
director := builder.NewDirector(beelzebubBuilder)
|
director := builder.NewDirector(beelzebubBuilder)
|
||||||
|
|
||||||
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
||||||
if err != nil {
|
failOnError(err, fmt.Sprintf("Error during BuildBeelzebub: "))
|
||||||
log.Fatal(err)
|
|
||||||
}
|
err = beelzebubBuilder.Run()
|
||||||
|
failOnError(err, fmt.Sprintf("Error during run beelzebub core: "))
|
||||||
|
|
||||||
if err := beelzebubBuilder.Run(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer beelzebubBuilder.Close()
|
defer beelzebubBuilder.Close()
|
||||||
|
|
||||||
<-quit
|
<-quit
|
||||||
|
@ -4,8 +4,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
|
const ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
|
||||||
@ -104,7 +107,7 @@ func (openAIGPTVirtualTerminal *OpenAIGPTVirtualTerminal) GetCompletions(command
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
log.Debug(response)
|
||||||
if len(response.Result().(*gptResponse).Choices) == 0 {
|
if len(response.Result().(*gptResponse).Choices) == 0 {
|
||||||
return "", errors.New("no choices")
|
return "", errors.New("no choices")
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,20 @@ import (
|
|||||||
"beelzebub/parser"
|
"beelzebub/parser"
|
||||||
"beelzebub/tracer"
|
"beelzebub/tracer"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HypertextTransferProtocolStrategy struct {
|
type HTTPStrategy struct {
|
||||||
beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration
|
beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (httpStrategy HypertextTransferProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
func (httpStrategy HTTPStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||||
httpStrategy.beelzebubServiceConfiguration = beelzebubServiceConfiguration
|
httpStrategy.beelzebubServiceConfiguration = beelzebubServiceConfiguration
|
||||||
serverMux := http.NewServeMux()
|
serverMux := http.NewServeMux()
|
||||||
|
|
@ -15,10 +15,10 @@ import (
|
|||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SecureShellStrategy struct {
|
type SSHStrategy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||||
go func() {
|
go func() {
|
||||||
server := &ssh.Server{
|
server := &ssh.Server{
|
||||||
Addr: beelzebubServiceConfiguration.Address,
|
Addr: beelzebubServiceConfiguration.Address,
|
@ -4,16 +4,17 @@ import (
|
|||||||
"beelzebub/parser"
|
"beelzebub/parser"
|
||||||
"beelzebub/tracer"
|
"beelzebub/tracer"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransmissionControlProtocolStrategy struct {
|
type TCPStrategy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TCPStrategy *TransmissionControlProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
func (tcpStrategy *TCPStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||||
listen, err := net.Listen("tcp", beelzebubServiceConfiguration.Address)
|
listen, err := net.Listen("tcp", beelzebubServiceConfiguration.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error during init TCP Protocol: %s", err.Error())
|
log.Errorf("Error during init TCP Protocol: %s", err.Error())
|
Reference in New Issue
Block a user