-
Notifications
You must be signed in to change notification settings - Fork 459
/
identityprovider.go
44 lines (34 loc) · 1.02 KB
/
identityprovider.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
package fakeidentityprovider
import (
"context"
"errors"
"sync"
identityproviderv1 "github.com/spiffe/spire-plugin-sdk/proto/spire/hostservice/server/identityprovider/v1"
plugintypes "github.com/spiffe/spire-plugin-sdk/proto/spire/plugin/types"
)
type IdentityProvider struct {
identityproviderv1.UnsafeIdentityProviderServer
mu sync.Mutex
bundles []*plugintypes.Bundle
}
func New() *IdentityProvider {
return &IdentityProvider{}
}
func (c *IdentityProvider) FetchX509Identity(context.Context, *identityproviderv1.FetchX509IdentityRequest) (*identityproviderv1.FetchX509IdentityResponse, error) {
c.mu.Lock()
defer c.mu.Unlock()
if len(c.bundles) == 0 {
return nil, errors.New("no bundle")
}
bundle := c.bundles[0]
c.bundles = c.bundles[1:]
// TODO: support sending back the identity
return &identityproviderv1.FetchX509IdentityResponse{
Bundle: bundle,
}, nil
}
func (c *IdentityProvider) AppendBundle(bundle *plugintypes.Bundle) {
c.mu.Lock()
defer c.mu.Unlock()
c.bundles = append(c.bundles, bundle)
}