I am similarly trying to capture the output of heroku certs
so that we can automate our DNS setup.
As you've also found, the Heroku toolbelt script won't redirect output for any of the certs
commands. Digging into the ruby implementation, it's in this overriding of the 'display' method:
def display(msg = "", new_line = true)
super if $stdout.tty?
end
(https://github.com/heroku/heroku/blob/master/lib/heroku/command/certs.rb#L188)
If it doesn't think its outputting to a /dev/tty, it won't print anything at all.
As a quick hack, I instead used a curl
equivalent as a drop-in replacement:
curl -n -s -X GET https://api.heroku.com/apps/my_app_name/ssl-endpoints -H "Accept: application/vnd.heroku+json; version=3"
The -n
option will get curl to use the ~/.netrc entry that the heroku
script already uses. The output is in JSON, along these lines.
[
{
"cname":"xxxx-xxxx.herokussl.com",
"id":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name":"xxxx-xxxx",
"warnings":[],
"ssl_cert":{
"ca_signed?":true,
"cert_domains":[
"*.xxxxxxxx.com",
"xxxxxxxx.com"
],
"expires_at":"xxxx",
"issuer":"xxxx",
"self_signed?":false,
"starts_at":"xxxx",
"subject":"xxxx"
},
"ssl_cert_prev":null
}
]
Depending on how you are wrapping the scripts, this may be even more parseable than the heroku
output.