Skip to content

Commit d31c31a

Browse files
committed
move OIDCDiscoveryData to api/
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent 2a994be commit d31c31a

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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+
}

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77
"testing"
88

9+
"github.com/jetstack/preflight/api"
910
"k8s.io/client-go/discovery"
1011
"k8s.io/client-go/rest"
1112
)
@@ -55,7 +56,7 @@ func TestFetch_Success(t *testing.T) {
5556
t.Fatalf("expected count 1, got %d", count)
5657
}
5758

58-
res, ok := anyRes.(OIDCDiscoveryData)
59+
res, ok := anyRes.(api.OIDCDiscoveryData)
5960
if !ok {
6061
t.Fatalf("unexpected result type: %T", anyRes)
6162
}
@@ -99,7 +100,7 @@ func TestFetch_Errors(t *testing.T) {
99100
t.Fatalf("Fetch returned error: %v", err)
100101
}
101102

102-
res, ok := anyRes.(OIDCDiscoveryData)
103+
res, ok := anyRes.(api.OIDCDiscoveryData)
103104
if !ok {
104105
t.Fatalf("unexpected result type: %T", anyRes)
105106
}

0 commit comments

Comments
 (0)