forked from openshift/insights-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgather_cluster_oauth.go
56 lines (49 loc) · 1.51 KB
/
gather_cluster_oauth.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
// nolint: dupl
package clusterconfig
import (
"context"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openshift/insights-operator/pkg/record"
)
// GatherClusterOAuth Collects the cluster OAuth with cluster name.
//
// ### API Reference
// - https://github.com/openshift/client-go/blob/master/config/clientset/versioned/typed/config/v1/oauth.go#L50
// - https://docs.openshift.com/container-platform/4.3/rest_api/index.html#oauth-v1-config-openshift-io
//
// ### Sample data
// - docs/insights-archive-sample/config/oauth.json
//
// ### Location in archive
// - `config/oauth.json`
//
// ### Config ID
// `clusterconfig/oauths`
//
// ### Released version
// - 4.2.0
//
// ### Backported versions
// None
//
// ### Changes
// None
func (g *Gatherer) GatherClusterOAuth(ctx context.Context) ([]record.Record, []error) {
gatherConfigClient, err := configv1client.NewForConfig(g.gatherKubeConfig)
if err != nil {
return nil, []error{err}
}
return gatherClusterOAuth(ctx, gatherConfigClient)
}
func gatherClusterOAuth(ctx context.Context, configClient configv1client.ConfigV1Interface) ([]record.Record, []error) {
config, err := configClient.OAuths().Get(ctx, "cluster", metav1.GetOptions{})
if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, []error{err}
}
return []record.Record{{Name: "config/oauth", Item: record.ResourceMarshaller{Resource: config}}}, nil
}