Ejemplo n.º 1
0
func (a *GenRandomAction) Run(s *State) error {
	if a.Length == 0 {
		a.Length = 16
	}
	data := interpolate(s, a.Data)
	if data == "" {
		switch a.Encoding {
		case "", "hex":
			data = random.Hex(a.Length)
		case "base64":
			data = base64.StdEncoding.EncodeToString(random.Bytes(a.Length))
		case "base64safe":
			data = random.Base64(a.Length)
		case "uuid":
			data = random.UUID()
		default:
			return fmt.Errorf("bootstrap: unknown random type: %q", a.Encoding)
		}
	}
	s.StepData[a.ID] = &RandomData{Data: data}
	if a.ControllerKey {
		s.SetControllerKey(data)
	}
	return nil
}
Ejemplo n.º 2
0
func createSuperuser(db *sql.DB) (password string) {
	log.Println("Creating superuser...")
	password = random.Base64(16)

	_, err := db.Exec("DROP USER IF EXISTS flynn")
	if err != nil {
		log.Fatalln("Error dropping user:"******"CREATE USER flynn WITH SUPERUSER CREATEDB CREATEROLE REPLICATION PASSWORD '" + password + "'")
	if err != nil {
		log.Fatalln("Error creating user:"******"Superuser created.")

	return
}