I'm trying to process the output of the heroku certs command. Other commands in the heroku toolbelt write to STDOUT, but heroku certs and related commands like heroku certs:info do not appear to be written anywhere I would expect on ubuntu. Output when run normally:

$ heroku certs:info --app appname
Fetching SSL Endpoint changedname-3302.herokussl.com info for appname... done
Certificate details:
Common Name(s): *.domain.com
                domain.com

...etc

Output with attempts to redirect or pipe output:

$ heroku certs --app appname | grep ssl
$ heroku certs --app appname | cat
$ heroku certs:info --app appname | grep ssl
$ heroku certs:info --app appname 2>&1 | grep ssl
$ heroku certs:info --app appname &> /tmp/certs.info; cat /tmp/certs.info
$ heroku certs:info --app appname > /tmp/certs.info; cat /tmp/certs.info

Other heroku commands work as expected:

$ heroku ps --app appname | grep web
=== web (1X): `node www`
web.1: idle 2013/10/12 05:44:15 (~ 10h ago)

$ heroku status --app appname | grep -i status
=== Heroku Status

Is this a bug that should be reported or something I'm missing?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top