-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbackend.go
More file actions
84 lines (66 loc) · 1.66 KB
/
backend.go
File metadata and controls
84 lines (66 loc) · 1.66 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package keycloak
import (
"context"
"fmt"
"strings"
"sync"
"github.com/Serviceware/vault-plugin-secrets-keycloak/keycloak"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
log "github.com/hashicorp/go-hclog"
)
type backend struct {
*framework.Backend
KeycloakServiceFactory keycloak.ServiceFactoryFunc
logger log.Logger
jwtMutex sync.Mutex
jwt map[ConnectionConfig]*keycloak.JWT
}
var _ logical.Factory = Factory
// Factory configures and returns Keycloak backends
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b, err := newBackend(conf)
if err != nil {
return nil, err
}
if conf == nil {
return nil, fmt.Errorf("configuration passed into backend is nil")
}
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
func newBackend(conf *logical.BackendConfig) (*backend, error) {
b := &backend{
jwt: make(map[ConnectionConfig]*keycloak.JWT),
}
b.Backend = &framework.Backend{
Help: strings.TrimSpace(keycloakHelp),
BackendType: logical.TypeLogical,
PathsSpecial: &logical.Paths{
SealWrapStorage: []string{
"config/connection",
},
},
Paths: framework.PathAppend(
b.paths(),
),
}
b.KeycloakServiceFactory = keycloak.NewGocloakClient
b.logger = conf.Logger
return b, nil
}
func (b *backend) paths() []*framework.Path {
return []*framework.Path{
pathConfigConnection(b),
pathConfigConnectionOfRealm(b),
pathClientSecretDeprecated(b),
pathClientSecret(b),
pathRealmClientSecret(b),
pathRealmClientOptionalSecret(b),
}
}
const keycloakHelp = `
The Keycloak backend is retrieves secrets from keycloak.
`