forked from hamano/lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.go
61 lines (55 loc) · 1.04 KB
/
add.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"log"
"reflect"
"github.com/urfave/cli"
"github.com/satori/go.uuid"
)
type AddJob struct {
BaseJob
uuid bool
}
var addFlags = []cli.Flag {
cli.BoolFlag {
Name: "uuid",
Usage: "use UUID",
},
}
func Add(c *cli.Context) error {
runBenchmark(c, reflect.TypeOf(AddJob{}))
return nil
}
func (job *AddJob) Prep(c *cli.Context) bool {
if job.GetVerbose() >= 1 {
log.Printf("worker[%d]: prepare\n", job.wid)
}
job.uuid = c.Bool("uuid")
err := job.ldap.Bind(c.String("D"), c.String("w"))
if err != nil {
log.Fatal("bind error: ", err)
return false
}
return true
}
func (job *AddJob) Request() bool {
var cn string
if job.uuid {
cn = uuid.NewV1().String()
} else {
cn = fmt.Sprintf("%d-%d", job.wid, job.count)
}
dn := fmt.Sprintf("cn=%s,%s", cn, job.baseDN)
attrs := map[string][]string{
"objectClass": {"person"},
"cn": {cn},
"sn": {"sn"},
"userPassword": {"secret"},
}
err := job.ldap.Add(dn, attrs)
if err != nil {
log.Printf("add error: %s", err)
return false
}
return true
}