Skip to content

Commit 51dc4ab

Browse files
committed
mantle: math/rand -> crypto/rand
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. ```
1 parent aeb3423 commit 51dc4ab

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

mantle/platform/api/azure/api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package azure
1717

1818
import (
19+
"crypto/rand"
1920
"fmt"
20-
"math/rand"
2121
"os"
2222
"strings"
2323
"time"
@@ -27,10 +27,13 @@ import (
2727
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
2828
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
2929
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
30+
"github.com/coreos/pkg/capnslog"
3031

3132
"github.com/coreos/coreos-assembler/mantle/auth"
3233
)
3334

35+
var plog = capnslog.NewPackageLogger("github.com/coreos/coreos-assembler/mantle", "platform/api/azure")
36+
3437
type API struct {
3538
azIdCred *azidentity.DefaultAzureCredential
3639
rgClient *armresources.ResourceGroupsClient
@@ -116,7 +119,9 @@ func (a *API) SetupClients() error {
116119

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

mantle/platform/machine/azure/cluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
package azure
1616

1717
import (
18+
"crypto/rand"
1819
"errors"
1920
"fmt"
20-
"math/rand"
2121
"os"
2222
"path/filepath"
2323

@@ -35,7 +35,9 @@ type cluster struct {
3535

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

mantle/platform/machine/esx/cluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
package esx
1616

1717
import (
18+
"crypto/rand"
1819
"errors"
1920
"fmt"
20-
"math/rand"
2121
"os"
2222
"path/filepath"
2323

@@ -32,7 +32,9 @@ type cluster struct {
3232

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

0 commit comments

Comments
 (0)