| 296 | } |
| 297 | |
| 298 | func randomUUID() string { |
| 299 | var b [16]byte |
| 300 | if _, err := rand.Read(b[:]); err != nil { |
| 301 | // crypto/rand on Linux reads from getrandom()/urandom; on Windows |
| 302 | // from CryptGenRandom. Only way this fails is catastrophic OS |
| 303 | // breakage. Panic loudly so the user doesn't ship an all-zero UUID. |
| 304 | panic("crypto/rand failed: " + err.Error()) |
| 305 | } |
| 306 | // v4 format |
| 307 | b[6] = (b[6] & 0x0f) | 0x40 |
| 308 | b[8] = (b[8] & 0x3f) | 0x80 |
| 309 | s := hex.EncodeToString(b[:]) |
| 310 | return s[0:8] + "-" + s[8:12] + "-" + s[12:16] + "-" + s[16:20] + "-" + s[20:] |
| 311 | } |
| 312 | |
| 313 | func writeConfigYAML(path string, cfg *config.Config) error { |
| 314 | if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |