Skip to content

Commit

Permalink
cloudapi: lint fixes + just use crypto/rand
Browse files Browse the repository at this point in the history
Some leftover lint fixes and just move to crypto/rand for the idempotency
token.

Part of #769
  • Loading branch information
mstoykov committed Apr 4, 2024
1 parent 1e5bb9d commit b80ad9f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
8 changes: 1 addition & 7 deletions cloudapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cloudapi

import (
"bytes"
"crypto/rand"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"net/http"
"time"

Expand Down Expand Up @@ -230,15 +230,9 @@ func shouldAddIdempotencyKey(req *http.Request) bool {

// randomStrHex returns a hex string which can be used
// for session token id or idempotency key.
//
//nolint:gosec
func randomStrHex() string {
// 16 hex characters
b := make([]byte, 8)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}

func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
2 changes: 1 addition & 1 deletion cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewConfig() Config {

// Apply saves config non-zero config values from the passed config in the receiver.
//
//nolint:funlen,gocognit,cyclop
//nolint:cyclop
func (c Config) Apply(cfg Config) Config {
if cfg.Token.Valid {
c.Token = cfg.Token
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestConfigApply(t *testing.T) {
TracesEnabled: null.NewBool(true, true),
TracesHost: null.NewString("TracesHost", true),
TracesPushInterval: types.NewNullDuration(10*time.Second, true),
TracesPushConcurrency: null.NewInt(6, true),
TracesPushConcurrency: null.NewInt(6, true),
}

assert.Equal(t, full, full.Apply(empty))
Expand Down

0 comments on commit b80ad9f

Please sign in to comment.