/
output_jwks.go
67 lines (55 loc) · 1.25 KB
/
output_jwks.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
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"fmt"
hydra "github.com/ory/hydra-client-go/v2"
)
type (
outputJsonWebKey struct {
Set string `json:"set"`
hydra.JsonWebKey
}
outputJSONWebKeyCollection struct {
Set string `json:"set"`
Keys []hydra.JsonWebKey `json:"keys"`
}
)
func (outputJsonWebKey) Header() []string {
return []string{"SET ID", "KEY ID", "ALGORITHM", "USE"}
}
func (i outputJsonWebKey) Columns() []string {
data := [7]string{
i.Set,
i.Kid,
i.Alg,
i.Use,
}
return data[:]
}
func (i outputJsonWebKey) Interface() interface{} {
return i
}
func (outputJSONWebKeyCollection) Header() []string {
return outputJsonWebKey{}.Header()
}
func (c outputJSONWebKeyCollection) Table() [][]string {
rows := make([][]string, len(c.Keys))
for i, key := range c.Keys {
rows[i] = outputJsonWebKey{Set: c.Set, JsonWebKey: key}.Columns()
}
return rows
}
func (c outputJSONWebKeyCollection) Interface() interface{} {
return c
}
func (c outputJSONWebKeyCollection) Len() int {
return len(c.Keys)
}
func (c outputJSONWebKeyCollection) IDs() []string {
ids := make([]string, len(c.Keys))
for i, client := range c.Keys {
ids[i] = fmt.Sprintf("%v", client.Kid)
}
return ids
}