Pragmatism in the real world

Passing secrets to your OpenWhisk action

There is only one way to pass data into your OpenWhisk action: parameters. Your function receives a dictionary of parameters and returns one. Let's explore how you can set these parameters. Parameters passed to the action You can see this by creating this action: test.swift func main(args: [String:Any]) -> [String:Any] { return args } Add the action to OpenWhisk with: wsk action update params params.swift -a web-export true and test: $ wsk action invoke -b… continue reading.

Quick tip: OpenWhisk autocompletion

I've just discovered how to enable Bash autocompletion for the wsk command line tool! $ cd /usr/local/bin $ wsk sdk install bashauto This will create a file called wsk_cli_bash_completion.sh in your /usr/local/bin directory. Now, source this file within your .bash_profile or equivalent: $ echo -e "\n# OpenWhisk autocompletion\nsource ~/bin/wsk_cli_bash_completion.sh" >> ~/.bash_profile Start a new terminal window, (or source ~/.bash_profile in your current one) and you can now press the tab key after typing wsk to… continue reading.

Error handling in OpenWhisk actions

With a standard OpenWhisk action, we return a dictionary of the data and let OpenWhisk deal with converting it to JSON etc. OpenWhisk will also set the correct 200 status code. How do we handle an error though? It turns out that if there is a key called "error" in our returned dictionary, then all the other data is ignored and an error is sent back. To show this, consider this action: func main(args: [String:Any])… continue reading.

Using ngrok to test on a mobile

To test a website that you're developing on your local computer on a mobile device such as a phone or tablet use ngrok. This is the way to do it: Start up ngrok: $ ngrok http my-dev-site.local:80 This will start up ngrok and give you a "Forwarding" URL such as http://24f55bf5.ngrok.io. In this case, it will direct all traffic to that URL to http://my-dev-site.local. If you run your website on a different port, such as… continue reading.

OpenWhisk web actions

The first way that you learn to call your OpenWhisk action over HTTP is a POST request that is authenticated using your API key. This key allows all sorts of write access to your account, so you never release it. If you want to access the action over HTTP without the API key, you have two choices: Web Actions or API Gateway. This article discusses how to use Web Actions as they are very useful… continue reading.

Serverless Swift on OpenWhisk

I'm interested in serverless computing and as I write Swift, the OpenWhisk platform comes up high when you Google. This turns out to be a really good choice as OpenWhisk is Open Source so I can read the source code (and have done!). In principle, I can also run my own instance of it if I need to to for regulatory reasons, or just to avoid vendor lock-in. Commercially, the whole point of Serverless (aka… continue reading.

Keyboard shortcut to resize Finder columns

I like to use Finder in Column mode (⌘+3). i.e. this view: One feature of this view is that you can resize all the columns to fit by alt+double clicking on the move handle between each column. There doesn't appear to be a keyboard shortcut for this operation though, so I created one using Keyboard Maestro. Keyboard Maestro can move the mouse around the screen and click with it which is exactly what I need.… continue reading.

Stand-alone usage of Zend-InputFilter

Any data that you receive needs to be checked and validated. There are number of ways to do this including PHP's filter_var, but I prefer Zend-InputFilter. This is how to use it as a stand-alone component. Installation Firstly, we install it using Composer: $ composer require zendframework/zend-inputfilter $ composer require zendframework/zend-servicemanager You don't have to have ServiceManager, but it makes working with InputFilter much easier, so it's worth installing. Create the InputFilter The easiest way… continue reading.

Rendering problem details in Slim

As I've already noted, in the project I'm currently building, I'm rendering errors in my Slim Framework API using RFC 7807: Problem Details for HTTP APIs via Larry Garfield's ApiProblem component and rka-content-type-renderer. One place where we need to integrate this approach into Slim is in the error handlers. Let's look at NotFound. To ensure that we return a response in the right format, we need to implement our own NotFound handler: src/App/Handler/NotFound.php: <?php namespace… continue reading.

Rendering ApiProblem with PSR-7

In the API I'm currently building, I'm rendering errors using RFC 7807: Problem Details for HTTP APIs. As this is a Slim Framework project, it uses PSR-7, so I updated rka-content-type-renderer to support problem. RFC 7807 defines a standard for sending details of an error in an HTTP response message. It supports both XML and JSON formats. From the RFC, an example response is: HTTP/1.1 403 Forbidden Content-Type: application/problem+json Content-Language: en { "type": "https://example.com/probs/out-of-credit", "title":… continue reading.