-
Notifications
You must be signed in to change notification settings - Fork 458
/
plugintypes.go
106 lines (93 loc) · 2.36 KB
/
plugintypes.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package jwtkey
import (
apitypes "github.com/spiffe/spire-api-sdk/proto/spire/api/types"
plugintypes "github.com/spiffe/spire-plugin-sdk/proto/spire/plugin/types"
"github.com/spiffe/spire/proto/spire/common"
)
func FromPluginProto(pb *plugintypes.JWTKey) (JWTKey, error) {
return fromProtoFields(pb.KeyId, pb.PublicKey, pb.ExpiresAt)
}
func FromPluginProtos(pbs []*plugintypes.JWTKey) ([]JWTKey, error) {
if pbs == nil {
return nil, nil
}
jwtKeys := make([]JWTKey, 0, len(pbs))
for _, pb := range pbs {
jwtKey, err := FromPluginProto(pb)
if err != nil {
return nil, err
}
jwtKeys = append(jwtKeys, jwtKey)
}
return jwtKeys, nil
}
func ToPluginProto(jwtKey JWTKey) (*plugintypes.JWTKey, error) {
id, publicKey, expiresAt, err := toProtoFields(jwtKey)
if err != nil {
return nil, err
}
return &plugintypes.JWTKey{
KeyId: id,
PublicKey: publicKey,
ExpiresAt: expiresAt,
}, nil
}
func ToPluginProtos(jwtKeys []JWTKey) ([]*plugintypes.JWTKey, error) {
if jwtKeys == nil {
return nil, nil
}
pbs := make([]*plugintypes.JWTKey, 0, len(jwtKeys))
for _, jwtKey := range jwtKeys {
pb, err := ToPluginProto(jwtKey)
if err != nil {
return nil, err
}
pbs = append(pbs, pb)
}
return pbs, nil
}
func ToPluginFromCommonProto(pb *common.PublicKey) (*plugintypes.JWTKey, error) {
jwtKey, err := FromCommonProto(pb)
if err != nil {
return nil, err
}
return ToPluginProto(jwtKey)
}
func ToPluginFromCommonProtos(pbs []*common.PublicKey) ([]*plugintypes.JWTKey, error) {
if pbs == nil {
return nil, nil
}
jwtKeys := make([]*plugintypes.JWTKey, 0, len(pbs))
for _, pb := range pbs {
jwtKey, err := ToPluginFromCommonProto(pb)
if err != nil {
return nil, err
}
jwtKeys = append(jwtKeys, jwtKey)
}
return jwtKeys, nil
}
func ToPluginFromAPIProto(pb *apitypes.JWTKey) (*plugintypes.JWTKey, error) {
if pb == nil {
return nil, nil
}
jwtKey, err := fromProtoFields(pb.KeyId, pb.PublicKey, pb.ExpiresAt)
if err != nil {
return nil, err
}
return ToPluginProto(jwtKey)
}
func ToPluginFromAPIProtos(pbs []*apitypes.JWTKey) ([]*plugintypes.JWTKey, error) {
if pbs == nil {
return nil, nil
}
jwtAuthorities := make([]*plugintypes.JWTKey, 0, len(pbs))
for _, pb := range pbs {
jwtKey, err := ToPluginFromAPIProto(pb)
if err != nil {
return nil, err
}
jwtAuthorities = append(jwtAuthorities, jwtKey)
}
return jwtAuthorities, nil
}