Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Marc Bruins MarcBruins

View GitHub Profile
View gist:99c1c7c6d77de0aced1db19056f53cb3
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
@MarcBruins
MarcBruins / Dockerfile
Last active Apr 10, 2019
Plain functions dockerfile dotnet
View Dockerfile
FROM microsoft/dotnet:2.2-sdk AS installer-env
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
View gistnukeeper.cs
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using NuKeeper.Abstractions.Inspections.Files;
using Paket;
namespace NuKeeper.Inspection.RepositoryInspection
{
@MarcBruins
MarcBruins / keyvault-secrets-from-appconfig.cs
Last active Jan 9, 2019
Read keyvault secrets from app config json
View keyvault-secrets-from-appconfig.cs
//1. Create a file for both classes
//2. Replace the IKeyVaultAccessClient with a concrete keyvault implementation
//3. Add it to the builder: builder.Add(new ReplaceTokensConfigurationSource(configuration, logger, client));
//4. Add secrets placeholder to the appsetings.json with the following pattern __secret__
/// <summary>
/// A JSON configuration source that replaces values from JSON that are tokenized with a value from Azure Key Vault,
/// using the tokenized value as lookup key.
/// </summary>
public sealed class ReplaceTokensConfigurationProvider : ConfigurationProvider, IDisposable
@MarcBruins
MarcBruins / AzureServicesAuthConnectionString.txt
Created Jan 7, 2019
AzureServicesAuthConnectionString sample
View AzureServicesAuthConnectionString.txt
AzureServicesAuthConnectionString RunAs=App;AppId=YOURAPPID;TenantId=YOURTENANTID;AppKey=OPTIONALAPPKEY
View pwd.cs
private string DbPassword = "MySuperSecretPassword";
View callingkeyvault.cs
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var secret = await keyVaultClient.GetSecretAsync("https://YOURKEYVAULT.azure.net/secrets/sqlAzure--AdminPassword").ConfigureAwait(false);
@MarcBruins
MarcBruins / possiblederefenceofnull.cs
Last active Jan 4, 2019
Possible dereference of a null reference sample
View possiblederefenceofnull.cs
public async Task<SearchCodeResult> Search(SearchCodeRequest search)
{
foreach (var repo in search.Repos)
{
//do search stuff
}
}
class SearchCodeRequest{
public IList<string>? Repos { get; set; }
@MarcBruins
MarcBruins / returningforuri.cs
Created Dec 16, 2018
Return value for uri trailing slash
View returningforuri.cs
public static Uri EnsureTrailingSlash(Uri uri)
{
return new Uri(uri.ToString() + "/");
}
//OR
public static Uri EnsureTrailingSlash(Uri? uri)
{
if(uri == null)
@MarcBruins
MarcBruins / returnullfornull.cs
Created Dec 16, 2018
Returning null for null Uri
View returnullfornull.cs
public static Uri EnsureTrailingSlash(Uri uri)
{
if (uri == null)
return null;
return new Uri(uri.ToString() + "/");
}
You can’t perform that action at this time.