-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpledge.go
41 lines (34 loc) · 972 Bytes
/
pledge.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
package pledge
import (
"fmt"
)
// Config defines all the attributes required to set up pledge
type Config struct {
Issuer string `yaml:"issuer"`
PublicKeyPath string `yaml:"publickeypath"`
PrivateKeyPath string `yaml:"privatekeypath"`
}
var cfg *Config
// GetConfig returns pledge level configurations
func GetConfig() *Config {
return cfg
}
// SetConfig sets pledge level configurations
func SetConfig(conf *Config) {
cfg = conf
}
// Auth is generic interface for authentication
type Auth interface {
GenerateIdentitiy(interface{}) (interface{}, error)
VerifyIdentity(args ...interface{}) (interface{}, error)
}
// New provides an instance of implementation of Auth interface according to requested auth method
func New(method string, publisher bool, conf *Config) (Auth, error) {
SetConfig(conf)
switch method {
case AuthMethodJWT:
return newJWTAuth(publisher), nil
default:
return nil, fmt.Errorf(pledgeErrorStr, "Invalid method")
}
}