Skip to content

Instantly share code, notes, and snippets.

View deangrant's full-sized avatar

Dean Grant deangrant

View GitHub Profile
@deangrant
deangrant / cache-ispn-jdbc-ping.xml
Created November 10, 2022 20:45
Example configuration for running a Keycloak cluster with an external infinispan cluster
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
@deangrant
deangrant / az_keyvault_set_multiline_secret.sh
Created August 15, 2022 20:04
Azure CLI to store a multi-line secret such as a JSON file or RSA private key using the file parameter.
VAULT_NAME = {{ vault_name }}
SECRET_NAME = {{ secret_name }}
FILENAME = {{ filename }}
az keyvault secret set --vault-name $VAULT_NAME --name $SECRET_NAME --file $FILENAME
@deangrant
deangrant / docker-compose.yml
Created August 12, 2022 10:34
Configure a check that’s run to determine whether or not a Keycloak containers is healthy
# Healthcheck for strict HTTPS
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8443/health"]
interval: 10s
timeout: 5s
retries: 5
# Healthcheck for HTTP enabled
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
@deangrant
deangrant / docker-compose.yml
Last active August 12, 2022 10:31
Configure a check that’s run to determine whether or not a PostgreSQL containers for this service are healthy
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
@deangrant
deangrant / azure_ad_create_service_principal.sh
Created August 11, 2022 12:17
Create a service principal compatible with SDK authentication and configure its access to Azure resources
SERVICE_PRINCIPAL = {{ service_principal_name }}
az ad sp create-for-rbac --name $SERVICE_PRINCIPAL --sdk-auth
@deangrant
deangrant / swagger_bearer_token_example.yaml
Created August 2, 2022 13:45
Example YAML block for configuring Swagger 2.0 with Bearer security definition for authentication
swagger: 2.0
securityDefinitions:
Bearer:
type: apiKey
in: header
name: Authorization
paths:
/auth:
post:
summary: Get a bearer token
@deangrant
deangrant / __init__.py
Last active August 3, 2022 10:38
Contains code blocks from script files to initialize Flask-OIDC to add OpenID Connect based authentication
# /app/__init__.py
import json
from flask import (
Flask
)
from flask_oidc import (
OpenIDConnect
)
@deangrant
deangrant / unit_test_case_ordered.py
Last active July 27, 2022 06:04
Template code for running test cases in order using the python unit testing framwork
import unittest
# User defined funtion to compare method names when sorting them in order
# to be executed in the unit test.
def unit_test_order():
order = {}
def ordered(f):
order[f.__name__] = len(order)
return f
@deangrant
deangrant / test_keycloak_auth_token.sh
Last active July 26, 2022 16:03
Test shell script to return access token as from Keycloak
export USERNAME={{ username }}
export PASSWORD={{ password }}
export CLIENT_ID={{ client_id }}
export CLIENT_SECRET={{ client_secret }}
export HOSTNAME={{ hostname }}
export REALM={{ realm }}
export AUTH_TOKEN=`curl -s -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" \
-d "username=$USERNAME" -d "password=$PASSWORD" -d "grant_type=$PASSWORD" \
"https://$HOSTNAME:8443/auth/realms/$REALM/protocol/openid-connect/token" | jq -r '.access_token'`
@deangrant
deangrant / timezone_finder_l.py
Created July 25, 2022 15:55
Returns light version of TimeZoneFinder class and load all binary files into memory. Shows example of applying time zone to coordinates returned in a GeoJSON FeatureCollection.
from timezonefinder import TimezoneFinderL
def timezone_finder_l():
return TimeZoneFinderL(in_memory=True)
# Initialize class and load binary files into memory.
get_timezone = timezone_finder_l()
# Return timezone for coordinates based on precomputed shortcuts.
get_timezone.timezone_at(