Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar
🏠
Working from home

Patrick Kalkman PatrickKalkman

🏠
Working from home
View GitHub Profile
public List<ContentValues> parseMedia(JSONArray videoArray) throws JSONException {
List<ContentValues> videosToInsert = new ArrayList<>();
for (int j = 0; j < videoArray.length(); j++) {
JSONObject video = videoArray.getJSONObject(j);
String videoUrl = video.optString(TAG_URL);
String titleId = video.optString(TAG_TITLE_ID);
if (videoUrl.isEmpty()) {
if (!titleId.isEmpty()) {
<#
.SYNOPSIS
Get the ip address from the ip-addresses.json and give these access to all the
app services in the given resource group.
.DESCRIPTION
Get the ip address from the ip-addresses.json and give these access to all the
app services in the given resource group.
.PARAMETER JsonFilename
function Add-AccessRestrictionToAppService([string] $ResourceGroupName, [string] $Name, [string] $IpFilterRuleName, [string] $IpAddress, [string] $Priority)
{
Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and $Priority access to $Name"
Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress
Update-AzWebAppAccessRestrictionConfig -Name $appService.Name -ResourceGroupName $ResourceGroupName -ScmSiteUseMainSiteRestrictionConfig
# Also add the access restriction to the staging slots
$allSlots = Get-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name
Foreach ($slot in $allSlots)
{
:nextAppService Foreach ($appService in $allAppServices)
{
$appServiceName = $appService.Name
Foreach ($appServiceToExclude in $AppServicesToExclude)
{
if($appServiceToExclude.ToLower().Contains($appServiceName.ToLower()))
{
Write-Output "Skipped app service $appServiceName as it is in the exclude list"
continue nextAppService
function Add-AccessRestrictionsToAppServices([string] $ResourceGroupName,
[string] $JsonFilename,
[bool] $RemoveExistingRules,
[string[]] $AppServicesToExclude)
{
Write-Information "Retrieving all app services in $ResourceGroupName"
$allAppServices = Get-AzWebApp -ResourceGroupName $ResourceGroupName
$confirmAppServicesToExclude = Confirm-AppServicesToExclude -AllAppServices $allAppServices -AppServicesToExclude $AppServicesToExclude
if (!$confirmAppServicesToExclude)
@PatrickKalkman
PatrickKalkman / rules.json
Created January 21, 2022 09:25
A file with rules to set as access restrictions on app services
[
{ "rulename": "gateway", "ipaddress": "213.46.145.111", "priority": "200" },
{ "rulename": "vpn", "ipaddress": "210.46.145.111", "priority": "300" },
{ "rulename": "test", "ipaddress": "215.46.145.111", "priority": "400" }
]
<#
.SYNOPSIS
Remove all access restrictions from the app services in the given resource group
.DESCRIPTION
The Remove-AccessRestrictions.ps1 script removes all access restrictions from
the app services in the given resource group
.PARAMETER resourceGroupName
The resource group with the app services to remove the access restrictions
function Remove-AccessRestrictionsFromAppService([string] $ResourceGroupName, [string] $Name) {
$config = Get-AzWebAppAccessRestrictionConfig -ResourceGroupName $ResourceGroupName -Name $Name
Write-Information "Removing existing access restrictions on $Name"
Foreach ($accessRestriction in $config.MainSiteAccessRestrictions) {
$ruleName = $accessRestriction.RuleName
Write-Debug "Removing rule $ruleName"
Remove-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $accessRestriction.RuleName
}
# Also remove all the access restriction from the staging slots
function Remove-AllAccessRestrictionsFromAppServices([string] $ResourceGroupName) {
Write-Information "Retrieving all app services in $ResourceGroupName"
$allAppServices = Get-AzWebApp -ResourceGroupName $ResourceGroupName
Foreach ($appService in $allAppServices) {
Remove-AccessRestrictionsFromAppService -ResourceGroupName $ResourceGroupName -Name $appService.Name
}
}
@PatrickKalkman
PatrickKalkman / two-factor-registration.js
Created January 16, 2022 15:25
Enable two factor authentication temple
<template>
<div>
<h3>Two Factor Registration</h3>
<img v-bind:src="qr" />
<form @submit.prevent="validateToken">
<label for="token">
Enter token to enable two factor authentication:
</label>
<input v-model="token" type="text" name="token" value />
<button type="submit" name="button">validate</button>