Skip to content

Commit

Permalink
mantle: math/rand -> crypto/rand
Browse files Browse the repository at this point in the history
To appease golangci-lint:

```
Error: SA1019: rand.Read has been deprecated since Go 1.20 because
it shouldn't be used: For almost all use cases, [crypto/rand.Read]
is more appropriate.
```
  • Loading branch information
dustymabe committed Sep 13, 2024
1 parent aeb3423 commit 51dc4ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions mantle/platform/api/azure/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package azure

import (
"crypto/rand"
"fmt"
"math/rand"
"os"
"strings"
"time"
Expand All @@ -27,10 +27,13 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
"github.com/coreos/pkg/capnslog"

"github.com/coreos/coreos-assembler/mantle/auth"
)

var plog = capnslog.NewPackageLogger("github.com/coreos/coreos-assembler/mantle", "platform/api/azure")

type API struct {
azIdCred *azidentity.DefaultAzureCredential
rgClient *armresources.ResourceGroupsClient
Expand Down Expand Up @@ -116,7 +119,9 @@ func (a *API) SetupClients() error {

func randomName(prefix string) string {
b := make([]byte, 5)
rand.Read(b)
if _, err := rand.Read(b); err != nil {
plog.Errorf("randomName: failed to generate a random name: %v", err)
}
return fmt.Sprintf("%s-%x", prefix, b)
}

Expand Down
6 changes: 4 additions & 2 deletions mantle/platform/machine/azure/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package azure

import (
"crypto/rand"
"errors"
"fmt"
"math/rand"
"os"
"path/filepath"

Expand All @@ -35,7 +35,9 @@ type cluster struct {

func (ac *cluster) vmname() string {
b := make([]byte, 5)
rand.Read(b)
if _, err := rand.Read(b); err != nil {
plog.Errorf("failed to generate a random vmname: %v", err)
}
return fmt.Sprintf("%s-%x", ac.Name()[0:13], b)
}

Expand Down
6 changes: 4 additions & 2 deletions mantle/platform/machine/esx/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package esx

import (
"crypto/rand"
"errors"
"fmt"
"math/rand"
"os"
"path/filepath"

Expand All @@ -32,7 +32,9 @@ type cluster struct {

func (ec *cluster) vmname() string {
b := make([]byte, 5)
rand.Read(b)
if _, err := rand.Read(b); err != nil {
plog.Errorf("failed to generate a random vmname: %v", err)
}
return fmt.Sprintf("%s-%x", ec.Name(), b)
}

Expand Down

0 comments on commit 51dc4ab

Please sign in to comment.