Skip to content
Open
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
87 changes: 87 additions & 0 deletions cmd/soarca-conversion/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"os"
"soarca/internal/logger"
"soarca/pkg/conversion"
)

const banner = `
_____ ____ _____ _____
/ ____|/ __ \ /\ | __ \ / ____| /\
| (___ | | | | / \ | |__) | | / \
\___ \| | | |/ /\ \ | _ /| | / /\ \
____) | |__| / ____ \| | \ \| |____ / ____ \
|_____/ \____/_/ \_\_| \_\\_____/_/ \_\



`

var log *logger.Log

var (
Version string
Buildtime string
Host string
)

func init() {
log = logger.Logger("CONVERTER", logger.Info, "", logger.Json)
}

func print_help() {
fmt.Println("Usage: soarca-conversion -source=SOURCE_FILE [-target=TARGET_FILE] [-format=FORMAT] [-h]")
}

func main() {
fmt.Print(banner)
log.Info("Version: ", Version)
log.Info("Buildtime: ", Buildtime)
var (
source_filename string
target_filename string
format string
)
flag.StringVar(&source_filename, "source", "", "The source file to be converted")
flag.StringVar(&target_filename, "target", "", "The name of the converted filename")
flag.StringVar(&format, "format", "", "The format of the source file")
help := flag.Bool("help", false, "Print usage information")
flag.Parse()
if *help {
print_help()
return
}
if source_filename == "" {
log.Error("No source file given: -source=SOURCE_FILE is required")
print_help()
return
}
if target_filename == "" {
target_filename = fmt.Sprintf("%s.json", source_filename)
log.Infof("No target file given: defaulting to %s", target_filename)
}
source_content, err := os.ReadFile(source_filename)
if err != nil {
log.Errorf("Could not read source file")
return
}
target_content, err := conversion.PerformConversion(source_filename, source_content, format)
if err != nil {
log.Error(err)
return
}
output_str, err := json.Marshal(target_content)
if err != nil {
log.Error(err)
return
}
if err := os.WriteFile(target_filename, output_str, 0644); err != nil {
log.Error(err)
return
}

}
9 changes: 5 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all test integration-test ci-test clean build docker run pre-docker-build swagger sbom
.PHONY: all test integration-test ci-test clean build docker run pre-docker-build swagger sbom build

BINARY_NAME=soarca
DIRECTORY = $(sort $(dir $(wildcard ./test/*/)))
Expand All @@ -14,11 +14,12 @@ swagger:
swag init -g main.go -o api -d cmd/soarca/,api

lint: swagger

golangci-lint run --max-same-issues 0 --timeout 5m -v

build: swagger
CGO_ENABLED=0 go build -o ./build/soarca $(GOFLAGS) ./cmd/soarca/main.go
build: swagger build/soarca build/soarca-conversion

build/%: $(wildcard **/*.go)
CGO_ENABLED=0 go build -o $@ $(GOFLAGS) ./cmd/$(@F)/main.go

test: swagger
go test ./pkg/... -v
Expand Down
Loading