github.com/openshift/installer@v1.4.17/pkg/asset/ignition/bootstrap/baremetal/ironic_creds.go (about) 1 package baremetal 2 3 import ( 4 "context" 5 "crypto/rand" 6 "math/big" 7 8 "github.com/openshift/installer/pkg/asset" 9 ) 10 11 // IronicCreds is the asset for the ironic user credentials 12 type IronicCreds struct { 13 Username string 14 Password string 15 } 16 17 var _ asset.Asset = (*IronicCreds)(nil) 18 19 // Dependencies returns no dependencies. 20 func (a *IronicCreds) Dependencies() []asset.Asset { 21 return nil 22 } 23 24 // Generate the ironic password 25 func (a *IronicCreds) Generate(context.Context, asset.Parents) error { 26 pw, err := generateRandomPassword() 27 if err != nil { 28 return err 29 } 30 a.Username = "bootstrap-user" 31 a.Password = pw 32 return nil 33 } 34 35 func generateRandomPassword() (string, error) { 36 chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 37 "abcdefghijklmnopqrstuvwxyz" + 38 "0123456789") 39 length := 16 40 buf := make([]rune, length) 41 numChars := big.NewInt(int64(len(chars))) 42 for i := range buf { 43 c, err := rand.Int(rand.Reader, numChars) 44 if err != nil { 45 return "", err 46 } 47 buf[i] = chars[c.Uint64()] 48 } 49 return string(buf), nil 50 } 51 52 // Name returns the human-friendly name of the asset. 53 func (a *IronicCreds) Name() string { 54 return "Ironic bootstrap credentials" 55 }