-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add Identity Provider Factory and Interface scripts #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Aravinda-HWK
wants to merge
3
commits into
LSFLK:main
Choose a base branch
from
Aravinda-HWK:255-feature-create-identity-provider-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,140 @@ | ||
| #!/bin/bash | ||
|
|
||
|
|
||
| # ============================================ | ||
| # Identity Provider Factory | ||
| # ============================================ | ||
| # | ||
| # This factory creates and returns the appropriate Identity Provider | ||
| # based on the configuration in silver.yaml | ||
| # | ||
| # Usage: | ||
| # source "$(dirname "$0")/../idp/idp-factory.sh" | ||
| # create_idp_provider "thunder" | ||
| # # Now you can call: thunder_initialize, thunder_wait_for_ready, etc. | ||
|
|
||
|
|
||
| # Get the directory where this script is located | ||
| IDP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PROVIDERS_DIR="${IDP_DIR}/providers" | ||
|
|
||
|
|
||
| # Source the interface | ||
| source "${IDP_DIR}/idp-interface.sh" | ||
|
|
||
|
|
||
| # ============================================ | ||
| # Function: Create IdP Provider | ||
| # ============================================ | ||
| # Creates and initializes the specified Identity Provider | ||
| # | ||
| # Arguments: | ||
| # $1 - Provider name (thunder, keycloak, etc.) | ||
| # | ||
| # Returns: | ||
| # 0 on success, 1 on failure | ||
| # | ||
| # Exports: | ||
| # IDP_PROVIDER - The name of the loaded provider | ||
| # IDP_INITIALIZE - Function name for initialize | ||
| # IDP_WAIT_FOR_READY - Function name for wait_for_ready | ||
| # IDP_CONFIGURE - Function name for configure | ||
| # IDP_GET_COMPOSE_FILE - Function name for get_compose_file | ||
| # IDP_CLEANUP - Function name for cleanup | ||
| # ============================================ | ||
| create_idp_provider() { | ||
| local provider_name="$1" | ||
|
|
||
|
|
||
| if [ -z "$provider_name" ]; then | ||
| echo -e "${RED}β Provider name is required${NC}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
|
|
||
| # Convert to lowercase | ||
| provider_name=$(echo "$provider_name" | tr '[:upper:]' '[:lower:]') | ||
|
|
||
|
|
||
| echo -e "${CYAN}Loading Identity Provider: ${provider_name}${NC}" | ||
|
|
||
|
|
||
| # Load the appropriate provider implementation | ||
| case "$provider_name" in | ||
| thunder|keycloak) | ||
| local provider_script="${PROVIDERS_DIR}/${provider_name}-idp.sh" | ||
| if [ ! -f "$provider_script" ]; then | ||
| echo -e "${RED}β ${provider_name^} provider not found at ${provider_script}${NC}" >&2 | ||
| return 1 | ||
| fi | ||
| source "$provider_script" | ||
| ;; | ||
| *) | ||
| echo -e "${RED}β Unknown identity provider: ${provider_name}${NC}" >&2 | ||
| echo -e "${YELLOW}Supported providers: thunder, keycloak${NC}" >&2 | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
|
|
||
| # Validate that the provider implements all required functions | ||
| if ! validate_provider_implementation "$provider_name"; then | ||
| echo -e "${RED}β Provider '${provider_name}' does not implement the required interface${NC}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
|
|
||
| # Export provider information | ||
| export IDP_PROVIDER="$provider_name" | ||
| export IDP_INITIALIZE="${provider_name}_initialize" | ||
| export IDP_WAIT_FOR_READY="${provider_name}_wait_for_ready" | ||
| export IDP_CONFIGURE="${provider_name}_configure" | ||
| export IDP_GET_COMPOSE_FILE="${provider_name}_get_compose_file" | ||
| export IDP_CLEANUP="${provider_name}_cleanup" | ||
|
|
||
|
|
||
| echo -e "${GREEN}β Identity Provider '${provider_name}' loaded successfully${NC}" | ||
| return 0 | ||
| } | ||
|
|
||
|
|
||
| # ============================================ | ||
| # Function: Get Provider from Config | ||
| # ============================================ | ||
| # Reads the provider name from silver.yaml | ||
| # | ||
| # Arguments: | ||
| # $1 - Path to silver.yaml config file | ||
| # | ||
| # Returns: | ||
| # Provider name (stdout), empty if not found | ||
| # ============================================ | ||
| get_provider_from_config() { | ||
| local config_file="$1" | ||
|
|
||
|
|
||
| if [ ! -f "$config_file" ]; then | ||
| echo -e "${RED}β Configuration file not found: ${config_file}${NC}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
|
|
||
| # Extract provider from YAML (simple grep-based parsing) | ||
| # Looking for: identity: | ||
| # provider: thunder | ||
| local provider=$(grep -A 1 '^identity:' "$config_file" | grep 'provider:' | sed 's/.*provider:\s*//' | xargs) | ||
Aravinda-HWK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| if [ -z "$provider" ]; then | ||
| echo -e "${YELLOW}β No identity provider configured in ${config_file}${NC}" >&2 | ||
| echo -e "${YELLOW} Defaulting to 'thunder'${NC}" >&2 | ||
| echo "thunder" | ||
| else | ||
| echo "$provider" | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| # Export functions | ||
| export -f create_idp_provider | ||
| export -f get_provider_from_config | ||
This file contains hidden or 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,157 @@ | ||
| #!/bin/bash | ||
|
|
||
| # ============================================ | ||
| # Identity Provider Interface Contract | ||
| # ============================================ | ||
| # | ||
| # This file defines the interface that all Identity Provider | ||
| # implementations must follow. It serves as a contract for the | ||
| # Strategy pattern. | ||
| # | ||
| # Each IdP provider must implement these functions: | ||
| # - <provider>_initialize() | ||
| # - <provider>_wait_for_ready() | ||
| # - <provider>_configure() | ||
| # - <provider>_get_compose_file() | ||
| # - <provider>_cleanup() | ||
| # | ||
| # Where <provider> is the name of the provider (e.g., thunder, keycloak) | ||
|
|
||
| # Colors for output | ||
| CYAN="\033[0;36m" | ||
| GREEN="\033[0;32m" | ||
| YELLOW="\033[1;33m" | ||
| RED="\033[0;31m" | ||
| NC="\033[0m" # No Color | ||
|
|
||
| # ============================================ | ||
| # Interface: initialize | ||
| # ============================================ | ||
| # Starts the Identity Provider service | ||
| # | ||
| # Arguments: | ||
| # $1 - Mail domain | ||
| # | ||
| # Returns: | ||
| # 0 on success, 1 on failure | ||
| # | ||
| # Example: | ||
| # thunder_initialize "example.com" | ||
| # keycloak_initialize "example.com" | ||
| # ============================================ | ||
|
|
||
| # ============================================ | ||
| # Interface: wait_for_ready | ||
| # ============================================ | ||
| # Waits for the Identity Provider to be healthy and ready | ||
| # | ||
| # Arguments: | ||
| # $1 - IdP host | ||
| # $2 - IdP port | ||
| # | ||
| # Returns: | ||
| # 0 on success, 1 on timeout/failure | ||
| # | ||
| # Example: | ||
| # thunder_wait_for_ready "example.com" "8090" | ||
| # keycloak_wait_for_ready "example.com" "8080" | ||
| # ============================================ | ||
|
|
||
| # ============================================ | ||
| # Interface: configure | ||
| # ============================================ | ||
| # Configures the Identity Provider with necessary settings | ||
| # This includes creating realms, clients, schemas, etc. | ||
| # | ||
| # Arguments: | ||
| # $1 - Mail domain | ||
| # | ||
| # Returns: | ||
| # 0 on success, 1 on failure | ||
| # | ||
| # Example: | ||
| # thunder_configure "example.com" | ||
| # keycloak_configure "example.com" | ||
| # ============================================ | ||
|
|
||
| # ============================================ | ||
| # Interface: get_compose_file | ||
| # ============================================ | ||
| # Returns the path to the docker-compose file for this provider | ||
| # | ||
| # Arguments: | ||
| # None | ||
| # | ||
| # Returns: | ||
| # Path to docker-compose file (stdout) | ||
| # | ||
| # Example: | ||
| # compose_file=$(thunder_get_compose_file) | ||
| # compose_file=$(keycloak_get_compose_file) | ||
| # ============================================ | ||
|
|
||
| # ============================================ | ||
| # Interface: cleanup | ||
| # ============================================ | ||
| # Cleans up and stops the Identity Provider service | ||
| # | ||
| # Arguments: | ||
| # None | ||
| # | ||
| # Returns: | ||
| # 0 on success, 1 on failure | ||
| # | ||
| # Example: | ||
| # thunder_cleanup | ||
| # keycloak_cleanup | ||
| # ============================================ | ||
|
|
||
| # ============================================ | ||
| # Helper: Validate Provider Implementation | ||
| # ============================================ | ||
| # Validates that a provider implements all required functions | ||
| # | ||
| # Arguments: | ||
| # $1 - Provider name (e.g., "thunder", "keycloak") | ||
| # | ||
| # Returns: | ||
| # 0 if valid, 1 if missing functions | ||
| # ============================================ | ||
| validate_provider_implementation() { | ||
| local provider_name="$1" | ||
|
|
||
| if [ -z "$provider_name" ]; then | ||
| echo -e "${RED}β Provider name is required for validation${NC}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| local required_functions=( | ||
| "${provider_name}_initialize" | ||
| "${provider_name}_wait_for_ready" | ||
| "${provider_name}_configure" | ||
| "${provider_name}_get_compose_file" | ||
| "${provider_name}_cleanup" | ||
| ) | ||
|
|
||
| local missing_functions=() | ||
|
|
||
| for func in "${required_functions[@]}"; do | ||
| if ! declare -f "$func" > /dev/null 2>&1; then | ||
| missing_functions+=("$func") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#missing_functions[@]} -gt 0 ]; then | ||
| echo -e "${RED}β Provider '${provider_name}' is missing required functions:${NC}" >&2 | ||
| for func in "${missing_functions[@]}"; do | ||
| echo -e "${RED} - ${func}${NC}" >&2 | ||
| done | ||
| return 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}β Provider '${provider_name}' implements all required functions${NC}" | ||
| return 0 | ||
| } | ||
|
|
||
| # Export validation function | ||
| export -f validate_provider_implementation |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.