Skip to content

Instantly share code, notes, and snippets.

@kevinhillinger
kevinhillinger / azure-cli.sh
Created April 13, 2024 23:15
Managed identity and microsoft graph permission setup
func_name=<the name of the function app>
# global id for Microsoft Graph
graph_name=00000003-0000-0000-c000-000000000000
graph_id=$(az ad sp show --id 00000003-0000-0000-c000-000000000000 --query id -o tsv)
managed_identity=$(az ad sp list --display-name $func_name --query '[0]' -o json)
mi_object_id=$(echo $managed_identity | jq .id -r)
mi_app_id=$(echo $managed_identity | jq .appId -r)
@kevinhillinger
kevinhillinger / update_nic.py
Last active November 13, 2023 00:12
Azure Python SDK - Networking - Network Interface - updating nic
import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.network import NetworkManagementClient
subscription_id = os.environ.get(
'AZURE_SUBSCRIPTION_ID',
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
@kevinhillinger
kevinhillinger / commands.sh
Last active June 2, 2021 15:09
Azure App Services v2 - How to update authsettings
authsettingsv2_list_url="https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<group_name>/providers/Microsoft.Web/sites/<site_name>/config/authsettingsv2/list?api-version=2020-09-01"
authsettingsv2_url="https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<group_name>/providers/Microsoft.Web/sites/<site_name>/config/authsettingsv2?api-version=2020-09-01"
az rest --method GET --url $authsettings_list_url > authsettingsv2_list_url.json
// modify json
az rest --method PUT --url authsettingsv2_url --body @./authsettingsv2.json
@kevinhillinger
kevinhillinger / policies.xml
Created January 26, 2021 17:29
Front Door to APIM Restriction Policy
<policies>
<inbound>
<check-header name="X-Azure-FDID" failed-check-httpcode="403" failed-check-error-message="" ignore-case="true">
<value>475128ed-cf0a-494d-8178-cc2580e9e5d9</value>
</check-header>
</inbound>
<backend>
<forward-request />
</backend>
<outbound />
@kevinhillinger
kevinhillinger / template.json
Last active November 26, 2020 09:37
Resource Manager (ARM) Template with copyIndex variable to output
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageSettings": {
"type": "object",
"defaultValue": {
"count": 3,
"prefix": "baa"
}
@kevinhillinger
kevinhillinger / FileCacher.cs
Created April 10, 2017 20:04
Cache XML Files
class FileCacher
{
public Dictionary<string, byte[]> GetXmlFilesAsCache(IEnumerable<string> xmlFiles)
{
var cache = new Dictionary<string, byte[]>();
foreach (var file in xmlFiles)
{
cache.Add(file, GetBytes(file));
}
@kevinhillinger
kevinhillinger / sample.java
Created September 29, 2020 14:06
Cosmos Java SDK Client configuration
Duration twelveHourTimeout = Duration.ofHours(12);
DirectConnectionConfig connectionConfig = new DirectConnectionConfig();
connectionConfig.setIdleConnectionTimeout(twelveHourTimeout);
connectionConfig.setIdleEndpointTimeout(twelveHourTimeout);
client = new CosmosClientBuilder()
.endpoint(AccountSettings.HOST)
.key(AccountSettings.MASTER_KEY)
.consistencyLevel(ConsistencyLevel.EVENTUAL)
@kevinhillinger
kevinhillinger / internal-business.xml
Created September 17, 2020 16:00
rate limit for products
<policies>
<inbound>
<base />
<rate-limit calls="30" renewal-period="10" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
@kevinhillinger
kevinhillinger / apim.tf
Last active September 11, 2020 19:46
API Management Logging to Application Insights with Terraform
# Terraform version 0.13
# variables
variable "apis" {
type = map
default = {
conferenceApi = {
name = "conference-api"
}
}
javascript:(function() { function getText() { var text = $('textarea[data-id*=description]').text(); return text; }  function viewDescription() { var alertText = { text: getText(), title: "Description" }; var alertOptions = { height: '90%', width: '90%' }; Xrm.Navigation.openAlertDialog(alertText, alertOptions); setTimeout(() => $('span[id*=dialogMessageTextLine]').css('margin-top', '5px'), 300); }  viewDescription(); })();