diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c402ca5..e0391e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,8 +39,8 @@ jobs: run: | echo "Quality Gate: checking test coverage is above threshold ..." echo "Threshold : $TESTCOVERAGE_THRESHOLD %" - # Excluded the concrete strategy from the coverage calculation, because tested by integration tests - cat coverage.tmp.out | grep -v "secureShellStrategy.go" | grep -v "hypertextTransferProtocolStrategy.go" | grep -v "transmissionControlProtocolStrategy.go" > coverage.out + # Excluded the concrete strategy from the unit test coverage, because covered by integration tests + 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]+'` echo "Current test coverage : $totalCoverage %" if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then diff --git a/README.md b/README.md index 8e7e665..b4a7ee5 100644 --- a/README.md +++ b/README.md @@ -73,14 +73,14 @@ address: ":80" description: "Wordpress 6.0" commands: - regex: "index.php" - handler: "test – Just another WordPress site
" + handler: "" headers: - "Content-Type: text/html" - "Server: Apache/2.4.53 (Debian)" - "X-Powered-By: PHP/7.4.29" statusCode: 200 - regex: "^(wp-login.php|/wp-admin)$" - handler: "Log In ‹ test — WordPress

Powered by WordPress

Lost your password?

← Go to test

" + handler: "" headers: - "Content-Type: text/html" - "Server: Apache/2.4.53 (Debian)" diff --git a/builder/builder.go b/builder/builder.go index 81cad1c..fc97eaa 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -97,9 +97,9 @@ func (b *Builder) Run() error { }() // Init Protocol strategies - secureShellStrategy := &strategies.SecureShellStrategy{} - hypertextTransferProtocolStrategy := &strategies.HypertextTransferProtocolStrategy{} - transmissionControlProtocolStrategy := &strategies.TransmissionControlProtocolStrategy{} + secureShellStrategy := &strategies.SSHStrategy{} + hypertextTransferProtocolStrategy := &strategies.HTTPStrategy{} + transmissionControlProtocolStrategy := &strategies.TCPStrategy{} // Init Tracer strategies, and set the trace strategy default HTTP protocolManager := protocols.InitProtocolManager(b.traceStrategy, hypertextTransferProtocolStrategy) diff --git a/main.go b/main.go index eb8ffc5..7ec4c88 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,23 @@ package main import ( "beelzebub/builder" "beelzebub/parser" + "flag" "fmt" + log "github.com/sirupsen/logrus" ) var quit = make(chan struct{}) 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() failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: ")) @@ -23,14 +32,11 @@ func main() { director := builder.NewDirector(beelzebubBuilder) beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration) - if err != nil { - log.Fatal(err) - } + failOnError(err, fmt.Sprintf("Error during BuildBeelzebub: ")) + + 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() <-quit diff --git a/plugins/openai-gpt.go b/plugins/openai-gpt.go index e6558ca..7fe7aae 100644 --- a/plugins/openai-gpt.go +++ b/plugins/openai-gpt.go @@ -4,8 +4,11 @@ import ( "encoding/json" "errors" "fmt" - "github.com/go-resty/resty/v2" "strings" + + log "github.com/sirupsen/logrus" + + "github.com/go-resty/resty/v2" ) const ChatGPTPluginName = "OpenAIGPTLinuxTerminal" @@ -104,7 +107,7 @@ func (openAIGPTVirtualTerminal *OpenAIGPTVirtualTerminal) GetCompletions(command if err != nil { return "", err } - + log.Debug(response) if len(response.Result().(*gptResponse).Choices) == 0 { return "", errors.New("no choices") } diff --git a/protocols/strategies/hypertext_transfer_protocol.go b/protocols/strategies/http.go similarity index 93% rename from protocols/strategies/hypertext_transfer_protocol.go rename to protocols/strategies/http.go index 121867f..63b9262 100644 --- a/protocols/strategies/hypertext_transfer_protocol.go +++ b/protocols/strategies/http.go @@ -4,19 +4,20 @@ import ( "beelzebub/parser" "beelzebub/tracer" "fmt" - "github.com/google/uuid" - log "github.com/sirupsen/logrus" "io" "net/http" "regexp" "strings" + + "github.com/google/uuid" + log "github.com/sirupsen/logrus" ) -type HypertextTransferProtocolStrategy struct { +type HTTPStrategy struct { 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 serverMux := http.NewServeMux() diff --git a/protocols/strategies/secure_shell.go b/protocols/strategies/ssh.go similarity index 96% rename from protocols/strategies/secure_shell.go rename to protocols/strategies/ssh.go index 5bef19c..494d0c0 100644 --- a/protocols/strategies/secure_shell.go +++ b/protocols/strategies/ssh.go @@ -15,10 +15,10 @@ import ( "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() { server := &ssh.Server{ Addr: beelzebubServiceConfiguration.Address, diff --git a/protocols/strategies/transmission_control_protocol.go b/protocols/strategies/tcp.go similarity index 86% rename from protocols/strategies/transmission_control_protocol.go rename to protocols/strategies/tcp.go index cdc47eb..ade0568 100644 --- a/protocols/strategies/transmission_control_protocol.go +++ b/protocols/strategies/tcp.go @@ -4,16 +4,17 @@ import ( "beelzebub/parser" "beelzebub/tracer" "fmt" - "github.com/google/uuid" - log "github.com/sirupsen/logrus" "net" "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) if err != nil { log.Errorf("Error during init TCP Protocol: %s", err.Error())