Skip to content

Commit f765740

Browse files
authored
Merge pull request #763 from jetstack/oidc_datagatherer
Move OIDCDiscoveryData to api/
2 parents ded0ff7 + e114701 commit f765740

5 files changed

Lines changed: 23 additions & 22 deletions

File tree

api/datareading.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ func (v *GatheredResource) UnmarshalJSON(data []byte) error {
130130
return nil
131131
}
132132

133-
// DynamicData is the DataReading.Data returned by the k8s.DataGathererDynamic
133+
// DynamicData is the DataReading.Data returned by the k8sdynamic.DataGathererDynamic
134134
// gatherer
135135
type DynamicData struct {
136136
// Items is a list of GatheredResource
137137
Items []*GatheredResource `json:"items"`
138138
}
139139

140-
// DiscoveryData is the DataReading.Data returned by the k8s.ConfigDiscovery
140+
// DiscoveryData is the DataReading.Data returned by the k8sdiscovery.DataGathererDiscovery
141141
// gatherer
142142
type DiscoveryData struct {
143143
// ClusterID is the unique ID of the Kubernetes cluster which this snapshot was taken from.
@@ -149,3 +149,18 @@ type DiscoveryData struct {
149149
// See https://godoc.org/k8s.io/apimachinery/pkg/version#Info
150150
ServerVersion *version.Info `json:"server_version"`
151151
}
152+
153+
// OIDCDiscoveryData is the DataReading.Data returned by the oidc.OIDCDiscovery
154+
// gatherer
155+
type OIDCDiscoveryData struct {
156+
// OIDCConfig contains OIDC configuration data from the API server's
157+
// `/.well-known/openid-configuration` endpoint
158+
OIDCConfig map[string]any `json:"openid_configuration,omitempty"`
159+
// OIDCConfigError contains any error encountered while fetching the OIDC configuration
160+
OIDCConfigError string `json:"openid_configuration_error,omitempty"`
161+
162+
// JWKS contains JWKS data from the API server's `/openid/v1/jwks` endpoint
163+
JWKS map[string]any `json:"jwks,omitempty"`
164+
// JWKSError contains any error encountered while fetching the JWKS
165+
JWKSError string `json:"jwks_error,omitempty"`
166+
}

deploy/charts/disco-agent/templates/configmap.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ data:
1919
{{- . | toYaml | nindent 6 }}
2020
{{- end }}
2121
data-gatherers:
22-
- kind: oidc
23-
name: ark/oidc
2422
- kind: k8s-discovery
2523
name: ark/discovery
2624
- kind: k8s-dynamic

deploy/charts/disco-agent/tests/__snapshot__/configmap_test.yaml.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ custom-cluster-description:
77
cluster_description: "A cloud hosted Kubernetes cluster hosting production workloads.\n\nteam: team-1\nemail: team-1@example.com\npurpose: Production workloads\n"
88
period: "12h0m0s"
99
data-gatherers:
10-
- kind: oidc
11-
name: ark/oidc
1210
- kind: k8s-discovery
1311
name: ark/discovery
1412
- kind: k8s-dynamic
@@ -116,8 +114,6 @@ custom-cluster-name:
116114
cluster_description: ""
117115
period: "12h0m0s"
118116
data-gatherers:
119-
- kind: oidc
120-
name: ark/oidc
121117
- kind: k8s-discovery
122118
name: ark/discovery
123119
- kind: k8s-dynamic
@@ -225,8 +221,6 @@ custom-period:
225221
cluster_description: ""
226222
period: "1m"
227223
data-gatherers:
228-
- kind: oidc
229-
name: ark/oidc
230224
- kind: k8s-discovery
231225
name: ark/discovery
232226
- kind: k8s-dynamic
@@ -334,8 +328,6 @@ defaults:
334328
cluster_description: ""
335329
period: "12h0m0s"
336330
data-gatherers:
337-
- kind: oidc
338-
name: ark/oidc
339331
- kind: k8s-discovery
340332
name: ark/discovery
341333
- kind: k8s-dynamic

pkg/datagatherer/oidc/oidc.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"k8s.io/client-go/rest"
99

10+
"github.com/jetstack/preflight/api"
1011
"github.com/jetstack/preflight/pkg/datagatherer"
1112
"github.com/jetstack/preflight/pkg/kubeconfig"
1213
)
@@ -73,21 +74,14 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) {
7374
return ""
7475
}
7576

76-
return OIDCDiscoveryData{
77+
return api.OIDCDiscoveryData{
7778
OIDCConfig: oidcResponse,
7879
OIDCConfigError: errToString(oidcErr),
7980
JWKS: jwksResponse,
8081
JWKSError: errToString(jwksErr),
8182
}, 1 /* we have 1 result, so return 1 as count */, nil
8283
}
8384

84-
type OIDCDiscoveryData struct {
85-
OIDCConfig map[string]any `json:"openid_configuration,omitempty"`
86-
OIDCConfigError string `json:"openid_configuration_error,omitempty"`
87-
JWKS map[string]any `json:"jwks,omitempty"`
88-
JWKSError string `json:"jwks_error,omitempty"`
89-
}
90-
9185
func (g *DataGathererOIDC) fetchOIDCConfig(ctx context.Context) (map[string]any, error) {
9286
// Fetch the OIDC discovery document from the well-known endpoint.
9387
bytes, err := g.cl.Get().AbsPath("/.well-known/openid-configuration").Do(ctx).Raw()

pkg/datagatherer/oidc/oidc_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
"k8s.io/client-go/discovery"
1010
"k8s.io/client-go/rest"
11+
12+
"github.com/jetstack/preflight/api"
1113
)
1214

1315
func makeRESTClient(t *testing.T, ts *httptest.Server) rest.Interface {
@@ -55,7 +57,7 @@ func TestFetch_Success(t *testing.T) {
5557
t.Fatalf("expected count 1, got %d", count)
5658
}
5759

58-
res, ok := anyRes.(OIDCDiscoveryData)
60+
res, ok := anyRes.(api.OIDCDiscoveryData)
5961
if !ok {
6062
t.Fatalf("unexpected result type: %T", anyRes)
6163
}
@@ -99,7 +101,7 @@ func TestFetch_Errors(t *testing.T) {
99101
t.Fatalf("Fetch returned error: %v", err)
100102
}
101103

102-
res, ok := anyRes.(OIDCDiscoveryData)
104+
res, ok := anyRes.(api.OIDCDiscoveryData)
103105
if !ok {
104106
t.Fatalf("unexpected result type: %T", anyRes)
105107
}

0 commit comments

Comments
 (0)