Skip to content

Commit

Permalink
gha fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Jun 14, 2024
1 parent a130fb7 commit 676c250
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1cd6cde4277dd30deb5a533446e516649fb9fbce:environments/local/local_test.go:generic-api-key:96
10 changes: 4 additions & 6 deletions cmd/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package cmd

import (
"fmt"
"github.com/vechain/networkhub/environments/docker"

"github.com/vechain/networkhub/hub"
"github.com/vechain/networkhub/preset"

"github.com/spf13/cobra"
"github.com/vechain/networkhub/entrypoint/api"
"github.com/vechain/networkhub/environments/docker"
"github.com/vechain/networkhub/environments/local"

"github.com/spf13/cobra"
"github.com/vechain/networkhub/hub"
"github.com/vechain/networkhub/preset"
)

var apiCmd = &cobra.Command{
Expand Down
8 changes: 3 additions & 5 deletions cmd/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package cmd

import (
"fmt"
"github.com/vechain/networkhub/environments/docker"
"io/ioutil"
"log/slog"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/spf13/cobra"
"github.com/vechain/networkhub/environments/docker"
"github.com/vechain/networkhub/environments/local"
"github.com/vechain/networkhub/hub"
"github.com/vechain/networkhub/preset"

"github.com/spf13/cobra"

cmdentrypoint "github.com/vechain/networkhub/entrypoint/cmd"
)

Expand Down Expand Up @@ -89,7 +87,7 @@ var configureCmd = &cobra.Command{
cmdManager := setup()

// Read from the specified file
data, err := ioutil.ReadFile(args[0])
data, err := os.ReadFile(args[0])
if err != nil {
fmt.Printf("Error reading config file: %v\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion entrypoint/api/http_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestStartStopHandler(t *testing.T) {
{
name: "Load existing preset network",
target: "/preset/noop-network",
payload: "{ \"artifactPath\": \"noop/dir\" }",
payload: "{ \"artifactPath\": \"noop/dir\", \"environment\":\"noop\" }",
method: http.MethodPost,
wantStatus: http.StatusOK,
wantBody: "{\"networkId\": \"noop\"}",
Expand Down
1 change: 1 addition & 0 deletions entrypoint/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"

"github.com/vechain/networkhub/hub"
"github.com/vechain/networkhub/network"
"github.com/vechain/networkhub/preset"
Expand Down
8 changes: 4 additions & 4 deletions entrypoint/cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/vechain/networkhub/network"
"io/ioutil"
"log/slog"
"os"

"github.com/vechain/networkhub/network"
)

type StorageJson struct {
Expand All @@ -33,7 +33,7 @@ func (s *Storage) Store(networkID string, net *network.Network) error {
}

// Write the updated data back to file
err = ioutil.WriteFile(s.path, data, 0644)
err = os.WriteFile(s.path, data, 0644)
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func (s *Storage) LoadExistingNetworks() (map[string]*network.Network, error) {
// Check if file exists
if _, err := os.Stat(s.path); err == nil {
// File exists, load the current data
fileData, err := ioutil.ReadFile(s.path)
fileData, err := os.ReadFile(s.path)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions environments/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package docker
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"log/slog"
"strconv"
"strings"

"github.com/docker/docker/client"
"github.com/vechain/networkhub/environments"
"github.com/vechain/networkhub/network"
"log/slog"

dockernetwork "github.com/docker/docker/api/types/network"
)
Expand Down Expand Up @@ -127,7 +126,7 @@ func (d *Docker) checkOrCreateNetwork(networkName, subnet string) error {
defer cli.Close()

// List existing networks
networks, err := cli.NetworkList(context.Background(), types.NetworkListOptions{})
networks, err := cli.NetworkList(context.Background(), dockernetwork.ListOptions{})
if err != nil {
return fmt.Errorf("could not list Docker networks: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion environments/docker/docker_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/vechain/networkhub/network/node"
"strings"
)

// NewDockerNode initializes a new DockerNode
Expand Down
5 changes: 3 additions & 2 deletions environments/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package docker_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/vechain/networkhub/environments/docker"
"github.com/vechain/networkhub/network"
"github.com/vechain/networkhub/network/node"
"github.com/vechain/networkhub/preset"
"testing"
"time"
)

func TestDockerNetwork(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion environments/docker/ip_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type IpManager struct {
}

func NewIPManagerRandom() *IpManager {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
// Generate random octets for a Class C subnet
a := rand.Intn(128)
b := rand.Intn(256)
Expand Down
4 changes: 3 additions & 1 deletion environments/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package local
import (
"encoding/json"
"fmt"
"github.com/vechain/networkhub/preset"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/vechain/networkhub/network"
"github.com/vechain/networkhub/preset"
"github.com/vechain/networkhub/utils/client"
"github.com/vechain/networkhub/utils/datagen"
)
Expand Down Expand Up @@ -128,6 +128,8 @@ func TestLocalInvalidExecArtifact(t *testing.T) {
)
require.NoError(t, err)

networkCfg.Nodes[0].ExecArtifact = "/some_fake_dir"

localEnv := NewLocalEnv()
_, err = localEnv.LoadConfig(networkCfg)
require.Error(t, err)
Expand Down
1 change: 1 addition & 0 deletions hub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hub

import (
"fmt"

"github.com/vechain/networkhub/environments"
"github.com/vechain/networkhub/network"
)
Expand Down
1 change: 1 addition & 0 deletions network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package node

import (
"fmt"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/vechain/thor/v2/genesis"
Expand Down
6 changes: 3 additions & 3 deletions preset/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package preset
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"github.com/vechain/thor/v2/genesis"
"math/big"
"testing"

"github.com/stretchr/testify/require"
"github.com/vechain/thor/v2/genesis"
)

func TestGenesisUnmarshal(t *testing.T) {

type derp struct {
Hex *genesis.HexOrDecimal256
}
Expand Down

0 comments on commit 676c250

Please sign in to comment.