A Clockwork Engineer

The Star Wars API

The Star Wars API

Paul Hallett developed a web api called SWAPI which consists of the data from the universe of Star Wars.

You can find all the planets, spaceships, vehicles, characters from the six original movies. This is a nice dataset to practice coding or for an assessment. I wrote an api client SharpTrooper with C# to support this project in 2015. You know Storm Troopers are famous with their lack of targeting skills.


Automate Microsoft Login

Selenium Webdriver With Javascript

If you have a protected website by Azure Active Directory, you need to pass Microsoft login first to run your functional UI tests.

I used both id and name locators for the elements and they have some weird naming. I am not sure but maybe the purpose is to prevent any bot attacks. We need to use driver.wait() method of the webdriver to wait until the element is found but with a timeout limit in milliseconds.

It is not a good practice to have animations on web but Microsoft Online login has some sliding animations. This causes another bad practice like sleeping the driver for the animation to be completed. Please, keep in mind never let the driver sleep(), but let her wait(). We do not have anything to wait for at this step, so I used driver.sleep() for 1 second. It is not preferred because it will add that duration to your test run no matter what.

module.exports = {

    elements: {
        usernameInput: by.id('i0116'),
        passwordInput: by.name('passwd'),
        submitButton: by.id('idSIButton9')
    },

    /**
     * Sign in to Azure AD with the given credentials
     * @param {string} username
     * @param {string} password
     */
    signin: function (username, password) {
        var locateTimeout = 1000; //in milliseconds

        var usernameElement = driver.wait(until.elementLocated(elements.usernameInput), locateTimeout);
        usernameElement.sendKeys(username);
        usernameElement.sendKeys(selenium.Key.ENTER);

        var passwordElement = driver.wait(until.elementLocated(elements.passwordInput), locateTimeout);
        passwordElement.sendKeys(password);

        driver.sleep(1000); //bad bad bad

        var submitButtonElement = driver.wait(until.elementLocated(elements.submitButton), locateTimeout);
        submitButtonElement.click();

        var staySignedInButtonElement = driver.wait(until.elementLocated(elements.submitButton), locateTimeout);
        staySignedInButtonElement.click();
    }
};


A personal summary of 2020

A personal summary of 2020

We experienced a year like never before. I tried to do what I could and stayed at home as much as possible while keeping my health and sanity well. I focused on self development and sharing the knowledge with others. Thanks to all healthcare and essential workers, they made it possible to do the stuff in the list below;

  • Finished an awesome course Harvard Introduction to Computer Science. It was mostly back to basics for me but a lot of fun and a few nice little details in programming. There are some updates in the course so I think I will do it again.

  • Wrote 6 new blog posts as you can see below. It is not much but still better than previous years.

  • Organized an online meetup Hacktoberfest Istanbul. I always wanted to do it but I was far from the community. I did not miss the chance to make it online.


Follow A Link To A New Tab

Selenium Webdriver With Javascript

This will tell about my age but back then we did not have tabs on an internet browser. We only had windows. When you click a link on a webpage with the target attribute set as _blank, it was openning a new window. Now, it opens a new tab. Even folders on a file explorer were openning a new window on Windows 95.

Moving formard, we had a test scenario to check contents of a webpage that opens on a new tab. We had to follow a link from our parent website, to the target but Selenium Webdriver was not doing it by default. So the code below helped us to track new tabs on the browser. If there is a new tab, just switch the driver to continue on that one.

//Get all the tab handles first
var windowHandles = await driver.getAllWindowHandles()

//Click that anchor with target=_blank
await driver.findElement(By.id('externalLink')).click()

//Never ever let the driver sleep, because they may crash
//But there is not any change on the parent page to wait for
await driver.sleep(20000) //in milliseconds

//Keep the previous handles
const handlesThen = windowHandles

//Get the current handles
const handlesNow = await driver.getAllWindowHandles()

//If there are new handles in our list, that must be our target
var newWindow
if (handlesNow.length > handlesThen.length) {
    newWindow = handlesNow.find(handle => (!handlesThen.includes(handle)))
}

//Switch the driver, the previous one was already sleepy
await driver.switchTo().window(newWindow)


BlazorBin

BlazorBin

Yet another request bin

Yet another request bin but made with Blazor this time. When you build serverless apps or functions, your system depends on webhooks a lot. There are request bin tools on web which provides you unique endpoints so you can send requests from your system and see what is coming in the payload.

When I saw Blazor WebAssembly 3.2.0 Preview 1 release now available article on ASP.NET Blog, I decided to give it a try to work with Azure SignalR Service.

BlazorBin is on Azure and can be accessed by blazorbin.azurewebsites.net/. This service does not continue because of a billing issue. A new endpoint to an Azure Function, will be created when you visit the website. When a request comes to the endpoint, it will be listed on the left-hand-side menu as the method name. You can see the details of that request by clicking on the menu item.


Azure Durable Functions

Azure Durable Functions

Architect serverless solutions in Azure

Durable Functions is an extension of Azure Functions that enables you to perform long-lasting, stateful operations in Azure. Azure provides the infrastructure for maintaining state information. You can use Durable Functions to orchestrate a long-running workflow. Using this approach, you get all the benefits of a serverless hosting model, while letting the Durable Functions framework take care of activity monitoring, synchronization, and runtime concerns.

Suppose your e-commerce company has a warehouse and there is a staff to ship products. We want to automate the process, but still involve humans. We can implement human interaction pattern by using an orchestrator function. The orchestrator uses a durable timer to request approval. The orchestrator escalates if timeout occurs. The orchestrator waits for an external event, such as a notification that’s generated by a human interaction.


Azure Functions

Azure Functions

Architect serverless solutions in Azure

Serverless, as the name suggests, is computing without managing a server. You would not care about any server specification to process your data. The server should already be provided by a cloud platform as a PaaS (platform as a service) or as a FaaS (function as a service). The two common approaches on Azure are Logic Apps and Functions.

Is serverless computing right for my business needs?

No, it is not. You need to create clear requirements for your business needs then develop your application. You can answer this question only by analyzing your telemetry results from production. The serverless computing is a technical solution for a better infrastructure allocation and event driven design. There is not any engineer who can calculate necessacities without any data.

For example, functions have a timeout of 10 minutes maximum. If it is triggered by an HTTP request then it lowers to 2.5 minutes. Even if it responds in seconds, there is still a probability that it is executed continuously. In this case, it would be more expensive than having an app service or a VM.

How serverless can help me?

You will be working only on your business logic code in the technology stack of your choice (.NET Core, Node.js, Python, Java and PowerShell Core). No more hassle about infrastucture, scaling up or down. Most importantly, you are charged based on what is used.


Wildcard For Azure Devops Branch Policies

Wildcard For Azure Devops Branch Policies

We use GitFlow as our branching model on Azure Devops. When we create a new Release branch, we want it to be protected by default. By protection I mean, preventing unreviewed code changes.

This is not like setting a branch policy for an existing branch, it would be a wildcard for future branches. You need to do one extra step to access the correct page for a wildcard and this is not documented yet.


Architect Azure API Management service

Architect Azure API Management service

Architect serverless solutions in Azure

Let’s setup an API gateway using the Azure API Management service with a nice architecture.

An API gateway is positioned between your APIs and the Internet. You can control how the APIs are exposed or limit the usage per subscription through the Azure portal.

Why would I use the Azure API Management service?

It is a native Azure SaaS (software as a service) which brings nice pros;

  • API documentation
  • Rate limiting access
  • Health monitoring
  • Modern formats like JSON
  • Connections to any API
  • Analytics
  • Security
  • Built-in caching
  • Network tracing

Is there any trade-off?

Yes, the circuit breaker policy is not implemented yet. You can build your own API gateway with a circuit breaker using third-party libraries like Ocelot and Polly with Quality of Service configured but does it worth to go down to a PaaS (platform as a service) instead of a SaaS?


Hacking with Python

Hacking with Python

As software developers, we need to know any software vulnerability to prevent them before they happen. Every software developer should act or think like a hacker at some point. It is like asking what would a thief do to infiltrate our house and taking precautions. On the other side, hackers are evolving. They are getting better and faster tools.

Karen from comparitech has contacted me about her colleague’s article about ethical hacking by using Python. Please, have a look at this 6 best online courses for ethical hackers guide. It has a wide range of courses even including one for non-coders.

Image: Monty Python and the Holy Grail (1975)