Password-less access from pipeline to database
The goal
The goal is to be able to run database migrations as part of a Azure DevOps Pipeline with using a stored secret anywhere. The databases are Azure Sql Databases, connected to a VNET, with no public access. There are two major problems to solve:
- Network access
- Authentication
Background
My current project is at a company with a software solution that has been in development for more than 20 years. Traditionally it ran on-premise, that is at the customer’s site. This is still the case for a few customers, but most customers are now using the service served from a cloud-hosted solution - Software-as-a-Service - SaaS
Generate a sequence of DateOnly in F#
For a hobby project I had to generate a sequence of DateTime (a.k.a. IEnumerable<DateTime>).
Generating a sequence from simple types is easy:
let seqOfInt (start: int) (end: int) =
seq { start .. end }
But we cannot use range operator with DateOnly:
// Not valid code!
let badSeqOfDateTime (startDate: DateOnly) (endDate: DateOnly) =
seq { startDate .. endDate }
In my first attempt at this (and current code as of today), I ended up with a while loop and a mutable:
Query Azure Table Storage using F#
When looking at the signature of the TableClient.QueryAsync method in Azure.Data.Tables SDK, it is not clear how to use it. It returns a AsyncPageable<T>. Fortunately that again implements the IAsyncEnumerable<T>, which means that we can use the Fsharp.Control.TaskSeq library to get the resulting entities.
-
Install FSharp.Control.TaskSeq NuGet-package to your project.
-
open FSharp.Control -
Write your code using the
TaskSeqmodule
let getPartitionRows (tableClient: TableClient) (partition: string) =
task {
return!
tableClient.QueryAsync<TableEntity>(filter = $"PartitionKey eq '{partition}'")
|> TaskSeq.map fromEntity
|> TaskSeq.toArrayAsync
}
This is written as a reminder to myself, so that I can easily find it again