-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef953b3
commit 5f2bcdf
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/ditatompel/xmr-remote-nodes/internal/database" | ||
"github.com/ditatompel/xmr-remote-nodes/internal/monero" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var nodeCmd = &cobra.Command{ | ||
Use: "node", | ||
Short: "[Server] Administer monitored nodes", | ||
Long: `Command to administer monitored nodes. | ||
This command should only be run on the server which directly connect to the MySQL database. | ||
`, | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
if err := cmd.Help(); err != nil { | ||
slog.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
var deleteNodeCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete node", | ||
Long: `Delete node identified by ID. | ||
This command delete node and it's associated probe logs (if exists). | ||
To find out the node ID, visit frontend UI or from "/api/v1/nodes" endpoint. | ||
`, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
if err := database.ConnectDB(); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
nodeID, err := strconv.Atoi(stringPrompt("Node ID:")) | ||
if err != nil { | ||
fmt.Println("Invalid ID:", err) | ||
return | ||
} | ||
|
||
moneroRepo := monero.New() | ||
err = moneroRepo.Delete(uint(nodeID)) | ||
if err != nil { | ||
fmt.Println("Failed to delete node:", err) | ||
return | ||
} | ||
|
||
fmt.Printf("Node ID %d deleted\n", nodeID) | ||
}, | ||
} |