Did you know that you can navigate the posts by swiping left and right?

How YAML ruined my day...

25 Aug 2017 . job hunt diary . Comments #diary, jobhunt, paypal, app, web development, SSL, ENV, environment variable, figaro, application.yml, Rails, Ruby

Hi All:

Over the past few days I’ve been focussed on getting the development done on Robot Combat Events to incorporate Paypal. If you haven’t visited the site yet, it’s designed to list upcoming events around the world for everyone to see, provide a means for roboteers to organize events and enthusiasts to register their bots for combat. I was recently requested to incorporate Paypal as a way for participants to pay the organizers their registration fees. And so the war began…

First, I used my excellent Google-Fu skills to find a great series of vlogs by Ryan Bates on his site RailsCasts concerning Paypal. He did a very thorough and detailed description and even though it is over eight years old, it still works. One thing he didn’t include, however, was how to use the required security certificates generated with OpenSSl as environment variables. Environment variables are added to web apps so that we can configure programs slightly different when they are run in ‘development’ from when they are in ‘production.’ Think of it like using a fake credit card to make test payments here on my machine vs. the real deal when someone tries to register for an upcoming competition.

Unfortunately, what seemed to me this morning like a no-brainer cut and paste sort of problem, turned into a day long ordeal involving much gnashing of teeth and pulling of hair. I searched high and low on Stack Overflow but found almost nothing on this problem. Eventually, I pieced together a solution from several locations that allowed me to move the data out of a security certificate, reformat it and save it as an environment variable in YAML format.

For any aficionados out there, here is the solution I finally discovered:

The data in a certificate file like: SSL_KEY.PEM

-----BEGIN CERTIFICATE-----
MIIDkDCCAvmgAwIBAgIJAPgi1tTi2nWDMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD
VQQGEwJBVTERMA8GA1UECBMIVmljdG9yaWExFzAVBgNVBAcTDldlcnJpYmVlIFNv
o2ogew==
-----END CERTIFICATE-----

Had to be turned into a single line, which included line breaks (\n) for every line, including the last.

-----BEGIN CERTIFICATE-----\nMIIDkDCCAvmgAwIBAgIJAPgi1tTi2nWDMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD\nVQQGEwJBVTERMA8GA1UECBMIVmljdG9yaWExFzAVBgNVBAcTDldlcnJpYmVlIFNv\no2ogew==\n-----END CERTIFICATE-----\n

Miss one of the line feeds, leave it formatted with multiple lines, forget the last line feed and no dice. Sure, security certificates are meant to be, well, secure. But, there has to be a better way. Perhaps I’ll find the time to write up a little script that does this automatically. For now though, it’s BEER O’CLOCK!

Cheers,

Brendan