-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cd3042
commit 2f8e68d
Showing
9 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package clients | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/crossplane/upjet/pkg/terraform" | ||
"github.com/keycloak/terraform-provider-keycloak/keycloak" | ||
) | ||
|
||
func NewKeycloakClient(ctx context.Context, terraformProviderConfig map[string]any) (*keycloak.KeycloakClient, error) { | ||
config := terraformProviderConfig["configuration"].(terraform.ProviderConfiguration) | ||
|
||
url := tryGetString(config, "url", "") | ||
basePath := tryGetString(config, "base_path", "") | ||
clientId := tryGetString(config, "client_id", "") | ||
clientSecret := tryGetString(config, "client_secret", "") | ||
username := tryGetString(config, "username", "") | ||
password := tryGetString(config, "password", "") | ||
realm := tryGetString(config, "realm", "master") | ||
initialLogin := tryGetBool(config, "initial_login", true) | ||
clientTimeout := tryGetInt(config, "client_timeout", 15) | ||
tlsInsecureSkipVerify := tryGetBool(config, "tls_insecure_skip_verify", false) | ||
rootCaCertificate := tryGetString(config, "root_ca_certificate", "") | ||
redHatSSO := tryGetBool(config, "initial_login", false) | ||
additionalHeaders := tryGetMap(config, "additional_headers") | ||
userAgent := fmt.Sprintf("Crossplane Keycloak Provider") | ||
|
||
keycloakClient, err := keycloak.NewKeycloakClient(ctx, url, basePath, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout, rootCaCertificate, tlsInsecureSkipVerify, userAgent, redHatSSO, additionalHeaders) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return keycloakClient, nil | ||
|
||
} | ||
|
||
func tryGetString(m map[string]any, key string, defaultValue string) string { | ||
value, ok := m[key] | ||
if ok { | ||
return value.(string) | ||
} | ||
return defaultValue | ||
} | ||
|
||
func tryGetBool(m map[string]any, key string, defaultValue bool) bool { | ||
value, ok := m[key] | ||
if ok { | ||
return value.(bool) | ||
} | ||
return defaultValue | ||
} | ||
|
||
func tryGetInt(m map[string]any, key string, defaultValue int) int { | ||
value, ok := m[key] | ||
if ok { | ||
return value.(int) | ||
} | ||
return defaultValue | ||
} | ||
|
||
func tryGetMap(m map[string]any, key string) map[string]string { | ||
value, ok := m[key] | ||
result := make(map[string]string) | ||
if ok { | ||
for k, v := range value.(map[string]interface{}) { | ||
result[k] = v.(string) | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
apiVersion: keycloak.crossplane.io/v1beta1 | ||
kind: ProviderConfig | ||
metadata: | ||
name: keycloak-provider-config | ||
namespace: upbound-system | ||
spec: | ||
credentials: | ||
source: Secret | ||
secretRef: | ||
name: keycloak-credentials | ||
key: credentials | ||
namespace: upbound-system |
4 changes: 4 additions & 0 deletions
4
local-deploy/manifests/keycloak-provider-deployment-runtime-config.patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
spec: | ||
deploymentTemplate: | ||
spec: | ||
replicas: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: keycloak-credentials | ||
namespace: upbound-system | ||
labels: | ||
type: provider-credentials | ||
type: Opaque | ||
stringData: | ||
credentials: | | ||
{ | ||
"client_id":"admin-cli", | ||
"username": "<username>", | ||
"password": "<password>", | ||
"url": "http://<host>:<port>", | ||
"base_path": "/", | ||
"realm": "master" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
apiVersion: role.keycloak.crossplane.io/v1alpha1 | ||
kind: Role | ||
metadata: | ||
name: test-client | ||
namespace: upbound-system | ||
spec: | ||
forProvider: | ||
realmId: "master" # The realm to which this user belongs | ||
name: "abc" # The username for this user | ||
clientId: "terraform" | ||
description: "abc" | ||
providerConfigRef: | ||
name: "keycloak-provider-config" # Reference to the provider configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
apiVersion: role.keycloak.crossplane.io/v1alpha1 | ||
kind: Role | ||
metadata: | ||
name: test | ||
namespace: upbound-system | ||
spec: | ||
forProvider: | ||
realmId: "master" # The realm to which this user belongs | ||
name: "abc" # The username for this user | ||
description: "abc" | ||
providerConfigRef: | ||
name: "keycloak-provider-config" # Reference to the provider configuration |