Compare commits

..

5 Commits

Author SHA1 Message Date
a7c69c8849 refactoring: Tiny refactoring (#47)
* tiny refactoring name convention, and file name.

* added command line arguments files

* fix typo comment
2023-06-01 00:15:21 +02:00
7d46c9544c Bump github.com/stretchr/testify from 1.8.3 to 1.8.4 (#46)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.3...v1.8.4)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-31 09:23:42 +02:00
10d16d7dd1 update: add .PHONY notation to Makefile commands (#45)
* update: add .PHONY notation to Makefile commands

* patch: Makefile according to style guide

Signed-off-by: Mario Candela <m4r10.php@gmail.com>

---------

Signed-off-by: Mario Candela <m4r10.php@gmail.com>
Co-authored-by: v0id <v0id@TheLab>
Co-authored-by: Mario Candela <m4r10.php@gmail.com>
2023-05-25 15:30:40 +02:00
48489e0abb Bump github.com/stretchr/testify from 1.8.2 to 1.8.3 (#44)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-19 10:10:15 +02:00
ca51e076b6 Bump github.com/sirupsen/logrus from 1.9.1 to 1.9.2 (#43)
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.1 to 1.9.2.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.9.1...v1.9.2)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-18 09:33:37 +02:00
11 changed files with 53 additions and 35 deletions

View File

@ -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

View File

@ -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

File diff suppressed because one or more lines are too long

View File

@ -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
View File

@ -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
View File

@ -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
View File

@ -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

View File

@ -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")
} }

View File

@ -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()

View File

@ -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,

View File

@ -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())