/
unmarshal.go
70 lines (59 loc) · 1.51 KB
/
unmarshal.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
62
63
64
65
66
67
68
69
70
// SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package token
import (
"github.com/xmidt-org/themis/config"
"github.com/xmidt-org/themis/key"
"github.com/xmidt-org/themis/random"
"github.com/xmidt-org/themis/xhttp/xhttpclient"
"go.uber.org/fx"
)
type TokenIn struct {
fx.In
Noncer random.Noncer `optional:"true"`
Keys key.Registry
Unmarshaller config.Unmarshaller
Client xhttpclient.Interface `optional:"true"`
}
type TokenOut struct {
fx.Out
ClaimBuilder ClaimBuilder
Factory Factory
IssueHandler IssueHandler
ClaimsHandler ClaimsHandler
}
// Unmarshal returns an uber/fx style factory that produces the relevant components for
// a single token factory.
func Unmarshal(configKey string, b ...RequestBuilder) func(TokenIn) (TokenOut, error) {
return func(in TokenIn) (TokenOut, error) {
var o Options
if err := in.Unmarshaller.UnmarshalKey(configKey, &o); err != nil {
return TokenOut{}, err
}
cb, err := NewClaimBuilders(in.Noncer, in.Client, o)
if err != nil {
return TokenOut{}, err
}
f, err := NewFactory(o, cb, in.Keys)
if err != nil {
return TokenOut{}, err
}
rb, err := NewRequestBuilders(o)
if err != nil {
return TokenOut{}, err
}
rb = append(rb, b...)
return TokenOut{
ClaimBuilder: cb,
Factory: f,
IssueHandler: NewIssueHandler(
NewIssueEndpoint(f),
rb,
),
ClaimsHandler: NewClaimsHandler(
NewClaimsEndpoint(cb),
rb,
),
}, nil
}
}