refactoring: Tiny refactoring (#47)

* tiny refactoring name convention, and file name.

* added command line arguments files

* fix typo comment
This commit is contained in:
Mario Candela
2023-06-01 00:15:21 +02:00
committed by GitHub
parent 7d46c9544c
commit a7c69c8849
8 changed files with 38 additions and 27 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

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)

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