Files
nomad/helper/uuid/uuid.go
Luiz Aoqui 41277f823f license: fix some imports of BUSL-1.1 in MPL-2.0 (#19832)
Some packages licensed under MPL-2.0 were incorrectly importing code
from packages licensed under BUSL-1.1.

Not all imports are fixed here as they will require additional work to
untangle them. To help track progress this commit adds a Semgrep rule
that detects incorrect BUSL-1.1 imports in MPL-2.0 packages.
2024-01-29 12:04:12 -05:00

31 lines
556 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package uuid
import (
"fmt"
"github.com/hashicorp/nomad/helper/crypto"
)
// Generate is used to generate a random UUID.
func Generate() string {
buf, err := crypto.Bytes(16)
if err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
buf[0:4],
buf[4:6],
buf[6:8],
buf[8:10],
buf[10:16])
}
// Short is used to generate the first 8 characters of a UUID.
func Short() string {
return Generate()[0:8]
}