Debian Codegraph @

api/v0/auth/sasl/mech/plugins.go

raw symbols SCIP
1 package mech
2
3 import (
4 "fmt"
5 "sync"
6
7 log "github.com/golang/glog"
8 )
9
10 var (
11 mechLock sync.Mutex
12 supportedMechs = make(map[string]Factory)
13 )
14
15 func Register(name string, f Factory) error {
16 mechLock.Lock()
17 defer mechLock.Unlock()
18
19 if _, found := supportedMechs[name]; found {
20 return fmt.Errorf("Mechanism registered twice: %s", name)
21 }
22 supportedMechs[name] = f
23 log.V(1).Infof("Registered mechanism %s", name)
24 return nil
25 }
26
27 func ListSupported() (list []string) {
28 mechLock.Lock()
29 defer mechLock.Unlock()
30
31 for mechname := range supportedMechs {
32 list = append(list, mechname)
33 }
34 return list
35 }
36
37 func SelectSupported(mechanisms []string) (selectedMech string, factory Factory) {
38 mechLock.Lock()
39 defer mechLock.Unlock()
40
41 for _, m := range mechanisms {
42 if f, ok := supportedMechs[m]; ok {
43 selectedMech = m
44 factory = f
45 break
46 }
47 }
48 return
49 }