Skip to content

Commit

Permalink
Merge pull request #4 from aydinnyunus/fix_auth_error
Browse files Browse the repository at this point in the history
Fix auth error
  • Loading branch information
aydinnyunus authored Jun 21, 2024
2 parents 689f6b0 + 89a6fa5 commit 760bd40
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bitcoin-to-neo4jdash
Submodule bitcoin-to-neo4jdash added at 34bb57
83 changes: 60 additions & 23 deletions cli/command/neodash/start.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package neodash

import (
"fmt"
"github.com/aydinnyunus/wallet-tracker/domain/cli"
models "github.com/aydinnyunus/wallet-tracker/domain/repository"
"github.com/fatih/color"
"github.com/go-git/go-git/v5"
"github.com/k0kubun/pp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"os"
"os/exec"
"path/filepath"
"strconv"

models "github.com/aydinnyunus/wallet-tracker/domain/repository"
"github.com/go-git/go-git/v5"
)

// global constants for file
Expand Down Expand Up @@ -95,44 +96,80 @@ func startNeoDash(cmd *cobra.Command, _ []string) error {
}

func CreateNeodash(args models.ScammerQueryArgs) ([]byte, error) {
_, err := git.PlainClone(mydir+"/bitcoin-to-neo4jdash", false, &git.CloneOptions{
URL: "https://github.com/tomasonjo/bitcoin-to-neo4jdash",
Progress: os.Stdout,
})
repoDir := filepath.Join(mydir, "bitcoin-to-neo4jdash")
// Check if directory exists
if _, err := os.Stat(repoDir); os.IsNotExist(err) {
// Directory does not exist, clone the repository
_, err := git.PlainClone(repoDir, false, &git.CloneOptions{
URL: "https://github.com/tomasonjo/bitcoin-to-neo4jdash",
Progress: os.Stdout,
})
if err != nil {
log.Fatal(err)
return nil, err
}
color.Yellow("Repository cloned successfully")

if err != nil {
log.Fatal(err)
return nil, err
color.Yellow("Define Schema is starting")
_, err = DefineSchema(args)
if err != nil {
log.Fatal(err)
return nil, err
}
color.Yellow("Define Schema is finished")
}

color.Yellow("Define Schema is starting")
_, err2 := DefineSchema(args)
if err2 != nil {
return nil, err2
}
color.Yellow("Define Schema is finished")
err := checkBinaryExists("docker")
// Check if Docker Compose is running
if err == nil {
cmd := exec.Command("docker", "compose", "ps", "-q")
cmd.Dir = repoDir
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
return nil, err
}

color.Yellow("Builds, (re)creates, starts, and attaches to containers for a service.")
if len(out) == 0 {
// Docker Compose is not running, start it
color.Yellow("Builds, (re)creates, starts, and attaches to containers for a service.")
out, err = DockerComposeUp(args)
if err != nil {
log.Fatal(err)
return nil, err
}
color.Yellow("docker-compose up finished. http://localhost:80")
} else {
color.Yellow("Docker Compose is already running")
}

out, err := DockerComposeUp(args)
if err != nil {
return out, err
} else {
color.Red("Docker is not installed.")
return nil, err
}
color.Yellow("docker-compose up finished. http://localhost:80")

return out, err
}

// DefineSchema is a temporary method to satisfy the authentication process.
func DefineSchema(args models.ScammerQueryArgs) ([]byte, error) {
cmdStr := "sudo sh " + mydir + "/bitcoin-to-neo4jdash/define_schema.sh"
out, _ := exec.Command("/bin/sh", "-c", cmdStr).Output()
color.Yellow(string(out))
return out, nil
}

func DockerComposeUp(args models.ScammerQueryArgs) ([]byte, error) {
cmdStr := "sudo docker-compose -f " + mydir + "/bitcoin-to-neo4jdash/docker-compose.yml up"
cmdStr := "sudo docker compose -f " + mydir + "/bitcoin-to-neo4jdash/docker-compose.yml up -d"
out, _ := exec.Command("/bin/sh", "-c", cmdStr).Output()

color.Yellow(string(out))
return out, nil
}

func checkBinaryExists(binaryName string) error {
_, err := exec.LookPath(binaryName)
if err != nil {
return fmt.Errorf("%s binary not found", binaryName)
}
return nil
}

0 comments on commit 760bd40

Please sign in to comment.