Skip to main content

Posts

Add Git Commit Hash and Build Number to a Static React Website using Azure DevOps

While working on a React based static website recently, there was a need to see exactly what was deployed in the Dev/Test environments to reduce confusion amongst teams. I wanted to show something like this: A quick look at the site's footer should show the Git Commit Hash and Build Number which was deployed and click through to actual commits and build results. Let's see how we achieved this using Azure DevOps. Git Commit Hash Azure DevOps exposes a variable called  $(Build.SourceVersion) which contains the hash of the commit. So I defined a variable in the Build Pipeline using it. Build Id and Build Number Azure DevOps also exposes two release time variables  $(Build.BuildId) and  $(Build.BuildNumber) which can be used to define custom variables in the pipeline. So we have a total of 3 variables defined: Next we use these variables in our React App. I created 3 global variables in index.html and assigned a token value to them. < script   type = "text/JavaScri...

Azure Application Insights Logging and EF Core in a Domain Driven Design

Logging is one of the core pillars of application development. .NET Core has fantastic support for rich contextual logging which spans across distributed system using its Activity API . Azure Application Insights SDK offers extensive logging out of the box without writing a single line of code. Just wire up the SDK and you are good to go. However there may be situations where you may want more fine grained control over the logging experience. Fortunately, its as simple as writing: Activity activity = new Activity("Test Message"); var operation = telemetryClient.StartOperation<DependencyTelemetry>(activity); This TelemetryClient is injected in your application when you wire up Application Insights. services.AddApplicationInsightsTelemetry(options => options.InstrumentationKey = "YOUR_AI_KEY"); This works seamlessly till you hit the road block of Domain Driven Design and Entity Framework Core. In DDD, entities represent a real-world business object and perf...

Use Azure App Configuration To Store Hierarchical Data

.NET Core has first class support for parsing hierarchical configuration data . If you have a JSON configuration like this,  { "rootObject": [ { "level1": "l1v1", "level2": "l1v2" }, { "level1": "l2v1", "level2": "l2v2" } ] } then you can easily target individual values with " rootObject:[0]:level1 ". However to store this JSON, you have to either use a File System or some kind of database. The problem with this approach is that you have to modify the entire document when you want to change a value of any field. If you are not careful, you may end up corrupting the JSON and thus breaking your system. This is where Azure App Configuration comes in the picture. Azure App Configuration is nothing but a key-value store. We can use that to store the hierarchical values like this: Once you inject this Azure App Configuration in your .NET Core project and call C...

CPU Cycles Are Cheap!

Modern CPUs have gotten so ridiculously fast that for most business applications we don't need to worry about optimizing the code we are writing. On the other hand, network calls like getting a record from database consume an eternity of CPU cycles. For example consider the following code example: foreach (var item in itemList) {     var data = MakeANetworkCallToDatabaseAndGetData(item.Id);     Process(data); } On the face of it, there is nothing wrong with this. The code works and even performs fine when the items in the list are less. But you will start to see things slow down when the item list grows. So how to solve this problem? var allIds = itemList.Select(x => x.Id).ToList(); var dataList = MakeANetworkCallToDatabaseAndGetData(allIds); foreach (var data in dataList) {    Process(data); } As you can see in above code, we have reduced the network call to just one and process it once we have everything in memory. Things are much faster now! Obvious...

Benchmarking Azure Key Vault Decryption

Azure Key Vault is used to store Keys, Certificates and Secrets and make them available to applications safely. It can create and store asymmetric (RSA and EC) keys. These keys expose their public key material but the private key remains stored within Key Vault. For decryption, the application needs to make a REST call to the Key Vault which will then return the decrypted result. There are libraries available for various languages and frameworks (including .NET) which enable developers to do this seamlessly. Integrating Azure Key Vault with .NET applications is a straight-forward process although  not documented widely . One of the frequently recommended technique for securing data is to use Envelope Encryption . This requires use Key Encryption Key (KEK) which is typically a RSA key stored in Azure Key Vault. The Data Encryption Key (DEK) is generated for each piece of data and is then used to encrypt the data using symmetric algorithms like AES. DEK is then itself encrypted using...