Skip to content

Instantly share code, notes, and snippets.

@ErikAndreas
ErikAndreas / sql.md
Last active February 5, 2022 15:41
Azure function using Azure Active Directory managed identity to authenticate with Azure SQLServer in Azure and working transparently locally. Using Dapper as ORM.

"Your account control strategy should rely on identity systems for controlling access rather than relying on network controls or direct use of cryptographic keys" - Microsoft Well Architected framework Security pillar

Context and steps

  1. Create Azure SQLServer and database, only allow AAD auth
  2. Set AAD admin, preferably a group account and add whoever needs admin access
  3. Set firewall rules
  4. Test connection with e.g. SSMS using AAD - universal with mfa login
  5. Create a table ('test' is used here)
  6. Create function app, http triggered VS 2022, copy code from here
@ErikAndreas
ErikAndreas / DatePeriod.cs
Last active September 14, 2021 11:39
Get DateTimes relative Now from Parsing text period, e.g. "Sun 18:00 - Mon 06:00" provided current datetime
using System;
using System.Globalization;
public class Program
{
public static void Main()
{
//string inputStr = "Tue 18:00-Wed 06:00";
string inputStr = "Sat 18:00-Mon 06:00";
var now = DateTime.Parse("2021-08-30 06:01:00");
@ErikAndreas
ErikAndreas / client.js
Created March 21, 2019 08:40
Azure Functions SignalR service authentication using imperative ("dynamic") binding of userId for negotiate, assuming jwt is set from client using accessTokenFactory. Use case when not using app service authentication.
const connection = new signalR.HubConnectionBuilder()
.withUrl('http://localhost:7071/api/v1.0/messages/binding',
{ accessTokenFactory: () => "aJwtToken" })
.build();
@ErikAndreas
ErikAndreas / build.yml
Created March 13, 2019 09:02
.net core 2 azure functions function app Azure pipeline deploy to Azure function app, also see https://medium.com/microsoftazure/serverless-devops-and-ci-cd-part-2-b6e0a6d05530
pool:
vmImage: Hosted Ubuntu 1604
steps:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '$(Parameters.RestoreBuildProjects)'
@ErikAndreas
ErikAndreas / build.yml
Last active April 18, 2021 20:59
Static angular site Azure DevOps pipeline Static web site deploy to Azure blob GPv2. Define variables (jsonpath) for file transform
pool:
vmImage: Hosted Ubuntu 1604
demands: npm
steps:
- task: Npm@1
displayName: 'npm install'
inputs:
verbose: false
@ErikAndreas
ErikAndreas / choco.md
Created August 14, 2018 09:03
Chocolatey

Install chocolatey per instructions on site

cinst packages.config -y

@ErikAndreas
ErikAndreas / azure-functions.md
Last active March 27, 2018 08:59
Serverless, FaaS

Azure Functions (release 2, beta)

PROS

  • the only "big" provider supporting node.js LTS 8 (aws and gcp still on 6.x)
  • automated deploy using git (tested w bitbucket), use different function apps per env (dev, stage, prod etc) and map against branches
  • local dev environment

CONS

  • cli deploy very unstable
  • "function host not running" errors
@ErikAndreas
ErikAndreas / ProcessUrlListController.cs
Last active October 30, 2017 11:57
.net core static httpclient async send multiple requests with auth token
private static HttpClient client = new HttpClient();
// send off reqs as fast as possible, then process them, arbitrary Item's, each having a Url to process
public async Task<ActionResult> ProcessUrlList(List<Item> items, string token)
{
var reqs = new List<Task<HttpResponseMessage>>();
foreach(var item in items)
{
reqs.Add(Req(item.Url, token));
}
@ErikAndreas
ErikAndreas / page.md
Created May 3, 2017 12:43
https via Cloudflare with github pages on custom domain with redirect to www
  1. assuming you already have your domain, will use domain.com as example and you have your github pages, will use username.github.io as example
  2. register for cloudflare account
  3. get cloudflare nameservers for your domain, e.g xxx.ns.cloudflare.com and yyy.ns.cloudflare.com
  4. update dns settings for your domain with the cloudflare nameservers and check status (might take a while)
  5. cloudflare dns settings -> add 2 A records; name: domain.com, value 192.30.252.153 and value 192.30.252.154 as per github pages instructions
  6. cloudflare dns settings -> add cname record; name www, value (is an alias of) username.github.io
  7. cloudflare page rules -> domain.com/* forwarding URL https://www.domain.com/$1 301 permanent redirect
  8. cloudflare page rules -> http://www.domain.com/* Always use https
  9. settings on your github pages repo -> custom domain 'www.domain.com'
@ErikAndreas
ErikAndreas / iso.md
Last active August 29, 2015 14:01
Isomorphic Javascript