-
Notifications
You must be signed in to change notification settings - Fork 83
/
identity_provider_util.go
66 lines (56 loc) · 1.91 KB
/
identity_provider_util.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
//
// Copyright (c) 2019-2023 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package identityprovider
import (
"github.com/eclipse-che/che-operator/pkg/common/chetypes"
"github.com/eclipse-che/che-operator/pkg/common/constants"
"github.com/eclipse-che/che-operator/pkg/deploy"
oauth "github.com/openshift/api/oauth/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func GetOAuthClientSpec(
name string,
secret string,
redirectURIs []string,
accessTokenInactivityTimeoutSeconds *int32,
accessTokenMaxAgeSeconds *int32) *oauth.OAuthClient {
return &oauth.OAuthClient{
TypeMeta: metav1.TypeMeta{
Kind: "OAuthClient",
APIVersion: oauth.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{constants.KubernetesPartOfLabelKey: constants.CheEclipseOrg},
},
Secret: secret,
RedirectURIs: redirectURIs,
GrantMethod: oauth.GrantHandlerPrompt,
AccessTokenInactivityTimeoutSeconds: accessTokenInactivityTimeoutSeconds,
AccessTokenMaxAgeSeconds: accessTokenMaxAgeSeconds,
}
}
func GetOAuthClient(ctx *chetypes.DeployContext) (*oauth.OAuthClient, error) {
oAuthClientName := GetOAuthClientName(ctx)
oauthClient := &oauth.OAuthClient{}
exists, err := deploy.GetClusterObject(ctx, oAuthClientName, oauthClient)
if !exists {
return nil, err
}
return oauthClient, nil
}
func GetOAuthClientName(ctx *chetypes.DeployContext) string {
if ctx.CheCluster.Spec.Networking.Auth.OAuthClientName != "" {
return ctx.CheCluster.Spec.Networking.Auth.OAuthClientName
}
return ctx.CheCluster.Namespace + "-client"
}