mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
Add nolint:gosec comments to address security-related linter warnings where the behavior is intentional: - G302/G306: Executable and public file permissions (0755, 0644) - G304: File inclusion from controlled app data directories - G204: Subprocess execution for known binaries - G107: HTTP requests to trusted/local endpoints - G404: Non-crypto random for temp identifiers - G115: Bounded integer conversions - G301: Directory permissions for log/data directories - G507: Legacy ripemd160 for address derivation These patterns are intentional and necessary for CLI functionality.
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/luxfi/cli/tests/e2e/utils"
|
|
"github.com/onsi/gomega"
|
|
)
|
|
|
|
const strTrue = "true"
|
|
|
|
// ConfigureBlockchain configures a blockchain with the given flags
|
|
func ConfigureBlockchain(blockchainName string, flags utils.TestFlags) (string, error) {
|
|
// Convert flags to args
|
|
args := []string{"blockchain", "configure", blockchainName}
|
|
for flag, value := range flags {
|
|
args = append(args, "--"+flag, fmt.Sprintf("%v", value))
|
|
}
|
|
|
|
// Run the command
|
|
/* #nosec G204 */
|
|
cmd := exec.Command(CLIBinary, args...)
|
|
output, err := cmd.CombinedOutput()
|
|
return string(output), err
|
|
}
|
|
|
|
// DeployBlockchain deploys a blockchain with the given flags
|
|
func DeployBlockchain(blockchainName string, flags utils.TestFlags) (string, error) {
|
|
// Convert flags to args
|
|
args := []string{"blockchain", "deploy", blockchainName}
|
|
for flag, value := range flags {
|
|
strValue := fmt.Sprintf("%v", value)
|
|
switch {
|
|
case flag == "local" && strValue == strTrue:
|
|
args = append(args, "--local")
|
|
case flag == "skip-warp-deploy" && strValue == strTrue:
|
|
args = append(args, "--skip-warp-deploy")
|
|
case flag == "skip-update-check" && strValue == strTrue:
|
|
args = append(args, "--skip-update-check")
|
|
default:
|
|
args = append(args, "--"+flag, strValue)
|
|
}
|
|
}
|
|
|
|
// Run the command
|
|
/* #nosec G204 */
|
|
cmd := exec.Command(CLIBinary, args...)
|
|
output, err := cmd.CombinedOutput()
|
|
return string(output), err
|
|
}
|
|
|
|
// CreateBlockchain creates a blockchain with the given VM type and version
|
|
func CreateBlockchain(blockchainName string, vmType string, version string) (string, error) {
|
|
args := []string{"blockchain", "create", blockchainName, "--vm", vmType}
|
|
if version != "" {
|
|
args = append(args, "--version", version)
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
cmd := exec.Command(CLIBinary, args...)
|
|
output, err := cmd.CombinedOutput()
|
|
return string(output), err
|
|
}
|
|
|
|
// DeleteBlockchain deletes a blockchain
|
|
func DeleteBlockchain(blockchainName string) error {
|
|
exists, err := utils.BlockchainConfigExists(blockchainName)
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
if !exists {
|
|
return nil
|
|
}
|
|
|
|
args := []string{"blockchain", "delete", blockchainName, "--force"}
|
|
/* #nosec G204 */
|
|
cmd := exec.Command(CLIBinary, args...)
|
|
_, err = cmd.CombinedOutput()
|
|
return err
|
|
}
|
|
|
|
// BlockchainStatus gets the status of a blockchain
|
|
func BlockchainStatus(blockchainName string) (string, error) {
|
|
args := []string{"blockchain", "status", blockchainName}
|
|
/* #nosec G204 */
|
|
cmd := exec.Command(CLIBinary, args...)
|
|
output, err := cmd.CombinedOutput()
|
|
return string(output), err
|
|
}
|