-
Notifications
You must be signed in to change notification settings - Fork 45
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
e86b59e
commit 107bb74
Showing
13 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,22 @@ | ||
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">] | ||
(https://unskript.com/assets/favicon.png) | ||
<h1>Get Keycloak audit report</h1> | ||
|
||
## Description | ||
Fetches the audit events from Keycloak. | ||
|
||
## Lego Details | ||
keycloak_get_audit_report(handle): | ||
handle: Handle object containing the KeycloakAdmin instance. | ||
|
||
|
||
## Lego Input | ||
This Lego takes inputs handle. | ||
|
||
## Lego Output | ||
Here is a sample output. | ||
<img src="./1.png"> | ||
|
||
## See it in Action | ||
|
||
You can see this Lego in action following this link [unSkript Live](https://us.app.unskript.io) |
Empty file.
12 changes: 12 additions & 0 deletions
12
Keycloak/legos/keycloak_get_audit_report/keycloak_get_audit_report.json
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,12 @@ | ||
{ | ||
"action_title": "Get Keycloak audit report", | ||
"action_description": "Fetches the audit events from Keycloak.", | ||
"action_type": "LEGO_TYPE_KEYCLOAK", | ||
"action_entry_function": "keycloak_get_audit_report", | ||
"action_needs_credential": true, | ||
"action_output_type": "ACTION_OUTPUT_TYPE_LIST", | ||
"action_is_check": false, | ||
"action_supports_iteration": true, | ||
"action_supports_poll": true, | ||
"action_categories":["CATEGORY_TYPE_SRE","CATEGORY_TYPE_KEYCLOAK"] | ||
} |
53 changes: 53 additions & 0 deletions
53
Keycloak/legos/keycloak_get_audit_report/keycloak_get_audit_report.py
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,53 @@ | ||
# | ||
# Copyright (c) 2023 unSkript.com | ||
# All rights reserved. | ||
# | ||
from typing import List | ||
from tabulate import tabulate | ||
from pydantic import BaseModel | ||
|
||
|
||
class InputSchema(BaseModel): | ||
pass | ||
|
||
|
||
def keycloak_get_audit_report_printer(output): | ||
if not output: | ||
print("No audit events found.") | ||
return | ||
|
||
# Extract relevant event data for tabulation | ||
table_data = [] | ||
for event in output: | ||
table_data.append({ | ||
"Time": event['time'], | ||
"Type": event['type'], | ||
"User ID": event['userId'], | ||
"Client ID": event['clientId'], | ||
"IP Address": event['ipAddress'], | ||
"Error": event.get('error', '') | ||
}) | ||
|
||
# Convert list of dictionaries to tabulated format | ||
headers = ["Time", "Type", "User ID", "Client ID", "IP Address", "Error"] | ||
print(tabulate(table_data, headers=headers, tablefmt="grid")) | ||
|
||
|
||
def keycloak_get_audit_report(handle) -> List: | ||
""" | ||
keycloak_get_audit_report fetches the audit events from Keycloak. | ||
:type handle: KeycloakAdmin | ||
:param handle: Handle containing the KeycloakAdmin instance. | ||
:rtype: List of dictionaries representing the audit events. | ||
""" | ||
try: | ||
# Fetch the events | ||
events = handle.get_events() | ||
return events if events else [] | ||
|
||
except Exception as e: | ||
raise e | ||
|
||
|
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,25 @@ | ||
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">](https://unskript.com/assets/favicon.png) | ||
<h2>Get Keycloak Handle</h2> | ||
|
||
<br> | ||
|
||
## Description | ||
This Lego Get Keycloak Handle. | ||
|
||
|
||
## Lego Details | ||
|
||
keycloak_get_handle(handle: object) | ||
|
||
handle: Object of type unSkript Keycloak Connector | ||
|
||
## Lego Input | ||
This Lego take one input handle. | ||
|
||
## Lego Output | ||
Here is a sample output. | ||
|
||
|
||
## See it in Action | ||
|
||
You can see this Lego in action following this link [unSkript Live](https://us.app.unskript.io) |
Empty file.
11 changes: 11 additions & 0 deletions
11
Keycloak/legos/keycloak_get_handle/keycloak_get_handle.json
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,11 @@ | ||
{ | ||
"action_title": "Keycloak Get Handle", | ||
"action_description": "Get Keycloak Handle", | ||
"action_type": "LEGO_TYPE_KEYCLOAK", | ||
"action_entry_function": "keycloak_get_handle", | ||
"action_needs_credential": true, | ||
"action_supports_poll": false, | ||
"action_supports_iteration": false, | ||
"action_output_type": "ACTION_OUTPUT_TYPE_LIST" | ||
} | ||
|
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,17 @@ | ||
## | ||
## Copyright (c) 2023 unSkript, Inc | ||
## All rights reserved. | ||
## | ||
from pydantic import BaseModel | ||
|
||
|
||
class InputSchema(BaseModel): | ||
pass | ||
|
||
|
||
def keycloak_get_handle(handle): | ||
"""keycloak_get_handle returns the Keycloak handle. | ||
:rtype: Keycloak handle. | ||
""" | ||
return handle |
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,22 @@ | ||
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">] | ||
(https://unskript.com/assets/favicon.png) | ||
<h1>Get Keycloak service health</h1> | ||
|
||
## Description | ||
Fetches the health of the Keycloak service by trying to list available realms. | ||
|
||
## Lego Details | ||
keycloak_get_service_health fetches the health of the Keycloak service by trying to list available realms. | ||
handle: Handle containing the KeycloakAdmin instance. | ||
|
||
|
||
## Lego Input | ||
This Lego takes inputs handle. | ||
|
||
## Lego Output | ||
Here is a sample output. | ||
<img src="./1.png"> | ||
|
||
## See it in Action | ||
|
||
You can see this Lego in action following this link [unSkript Live](https://us.app.unskript.io) |
Empty file.
16 changes: 16 additions & 0 deletions
16
Keycloak/legos/keycloak_get_service_health/keycloak_get_service_health.json
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,16 @@ | ||
{ | ||
"action_title": "Get Keycloak service health", | ||
"action_description": "Fetches the health of the Keycloak service by trying to list available realms.", | ||
"action_type": "LEGO_TYPE_KEYCLOAK", | ||
"action_entry_function": "keycloak_get_service_health", | ||
"action_needs_credential": true, | ||
"action_output_type": "ACTION_OUTPUT_TYPE_LIST", | ||
"action_is_check": true, | ||
"action_next_hop": [ | ||
"" | ||
], | ||
"action_next_hop_parameter_mapping": {}, | ||
"action_supports_iteration": true, | ||
"action_supports_poll": true, | ||
"action_categories":["CATEGORY_TYPE_SRE","CATEGORY_TYPE_KEYCLOAK"] | ||
} |
44 changes: 44 additions & 0 deletions
44
Keycloak/legos/keycloak_get_service_health/keycloak_get_service_health.py
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,44 @@ | ||
# | ||
# Copyright (c) 2023 unSkript.com | ||
# All rights reserved. | ||
# | ||
|
||
from typing import Tuple | ||
from pydantic import BaseModel | ||
|
||
|
||
class InputSchema(BaseModel): | ||
pass | ||
|
||
def keycloak_get_service_health(handle) -> Tuple: | ||
""" | ||
keycloak_get_service_health fetches the health of the Keycloak service by trying to list available realms. | ||
:type handle: object | ||
:param handle: Handle containing the KeycloakAdmin instance. | ||
:rtype: Tuple indicating if the service is healthy and a list of available realms (or None if healthy). | ||
""" | ||
try: | ||
realms = handle.get_realms() | ||
available_realms = [realm["realm"] for realm in realms] | ||
|
||
if not available_realms: | ||
return (False, available_realms) | ||
|
||
return (True, None) | ||
|
||
except Exception as e: | ||
raise e | ||
|
||
def keycloak_get_service_health_printer(output): | ||
is_healthy, realms = output | ||
|
||
if is_healthy: | ||
print("Keycloak Service is Healthy.") | ||
else: | ||
print("Keycloak Service is Unhealthy.") | ||
if realms: | ||
print("\nUnavailable Realms:") | ||
for realm in realms: | ||
print(f" - {realm}") |