func()

in server/internal/server/CreateStorageAccount.go [25:46]


func (s *Server) generateUniqueStorageAccountName() (string, error) {
	maxIterations := 10
	delayMilliseconds := 100
	name := ""
	for i := 0; i < maxIterations; i++ {
		name = "sa" + generateID()
		res, checkErr := s.AccountsClient.CheckNameAvailability(context.Background(), armstorage.AccountCheckNameAvailabilityParameters{
			Name: to.Ptr(name),
			Type: to.Ptr("Microsoft.Storage/storageAccounts"),
		}, nil)
		if checkErr != nil {
			return "", checkErr
		}
		if *res.NameAvailable {
			return name, nil
		}

		// Add a delay to avoid hitting the server too fast
		time.Sleep(time.Duration(delayMilliseconds) * time.Millisecond)
	}
	return "", status.Errorf(codes.AlreadyExists, "Storage account name ("+name+") already exists")
}