Skip to content

Instantly share code, notes, and snippets.

View bruceharrison1984's full-sized avatar
🔥

Bruce Harrison bruceharrison1984

🔥
View GitHub Profile
public override void Configure(IFunctionsHostBuilder builder)
{
...
builder.Services.AddLogging();
//workaround azure functions not handling nested arrays by default
builder.Services.AddTransient<IConfigureOptions<MvcOptions>, MvcJsonMvcOptionsSetup>();
builder.Services.AddTransient<BaseValidator<Widget>, WidgetValidator>(o => new WidgetValidator());
builder.Services.AddTransient<BaseValidator<User>, UserValidator>(o => new UserValidator());
$Fields = @{
grant_type = "client_credentials"
client_id = "<service-principal-id>"
resource = "<resource-id-to-auth-for-or-url>"
client_secret = "<service-principal-secret>"
};
$response = Invoke-RestMethod `
-Uri "https://login.microsoftonline.com/<azure-tenant-id>/oauth2/token" `
-ContentType "application/x-www-form-urlencoded" `
-Method POST `
@bruceharrison1984
bruceharrison1984 / error-output.sh
Last active May 19, 2020 12:40
Running Sqlpackage v150 on DevOps
2020-05-01T19:06:05.0948538Z ##[error]Publishing to database '****' on server '***.database.windows.net,1433'.
Initializing deployment (Start)
Initializing deployment (Failed)
Time elapsed 00:00:06.91
*** An error occurred during deployment plan generation. Deployment cannot continue. The Element class SqlColumnStoreIndex does not contain the Relationship class OrderedColumns.
@bruceharrison1984
bruceharrison1984 / get_terraform_outputs.ps1
Last active July 17, 2020 22:04
Get outputs from terraform.io
param(
[string]$workspaceName = $(throw "Please specify a workspace name"),
[string]$organizationName = $(throw "Please specify an organization name"),
[string]$terraformIoToken = $(throw "Please specify a terraform Io Token")
)
$ErrorActionPreference = "Stop"
$baseUri = "https://app.terraform.io/"
$authHeader = @{ Authorization = "Bearer $terraformIoToken" }
@bruceharrison1984
bruceharrison1984 / azure-synapse-online-status.cs
Last active November 4, 2020 18:25
Check if Azure Synapse is Online
using Azure.Identity;
using Azure.ResourceManager.Resources;
using MyFunctionProject.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@bruceharrison1984
bruceharrison1984 / WebApi-Error-Middleware.cs
Created January 16, 2021 20:33
Example of how to implement global error handling in WebApi
using System;
using FluentValidation;
using System.Text.Json;
using System.Threading.Tasks;
using Logic.Exceptions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using System.Linq;
using System.Collections.Generic;
@bruceharrison1984
bruceharrison1984 / aws-secrets-manager-terraform.tf
Last active March 2, 2021 15:42
Bulk save AWS Secrets with Terraform
variable "base_name" {
description = "The prefix on created resources"
}
variable "secret_map" {
description = "A Key/Value map of secrets that will be added to AWS Secrets"
type = map(string)
}
variable "default_tags" {
@bruceharrison1984
bruceharrison1984 / aws-secrets-manager-terraform-usage.tf
Last active March 2, 2021 15:43
Usage of aws-secrets-manager-terraform.tf
module "secrets" {
source = "./secrets"
base_name = local.base_name
default_tags = local.default_tags
secret_map = {
"shared/bastion/ssh/public_pem" = tls_private_key.bastion.public_key_openssh
"shared/bastion/ssh/private_pem" = tls_private_key.bastion.private_key_pem
"shared/bastion/ssh/username" = random_pet.bastion_username.id
}
resource "aws_ecs_task_definition" "bastion" {
family = "${var.base_name}-bastion-task"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 256
memory = 512
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
container_definitions = jsonencode([{
name = "bastion"
using Microsoft.EntityFrameworkCore.Diagnostics;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
// copied from https://github.com/aws/aws-xray-sdk-dotnet/blob/master/sdk/src/Handlers/EntityFramework/EFInterceptor.cs
// Xray doesn't support EF5 OOTB right now, so this lets us hack it back in.
// All we did was change all the Task<> to ValueTask<>
namespace MyProject.Data