Skip to content

Be more graceful in handling a missing private key when generating licenses

Created by: flying-robot

This is pure papercut. When generating a license, all of the options except for private-key can provide a default value:

$ go run generate-license.go -h
Usage of /var/folders/6j/_hy6clp90sn9wd3f4l88q90m0000gn/T/go-build509168975/b001/exe/generate-license:
  -code-hosts uint
        maximum number of code hosts allowed by this license (0 = no limit)
  -expires duration
        time until license expires (0 = no expiration)
  -private-key string
        file containing private key to sign license
  -tags string
        comma-separated string tags to include in this license (e.g., "starter,dev")
  -users uint
        maximum number of users allowed by this license (0 = no limit)

The error state when running without that parameter set could be a tiny bit more user-friendly, since the output of that section should be the generated contents, but the error message is actually related to the missing input:

$ go run generate-license.go
# License info (encoded and signed in license key)
{
  "t": null,
  "u": 0,
  "h": 0,
  "e": "2020-10-20T12:05:25Z"
}

# License key
open : no such file or directory
exit status 1

Since the private key is required, maybe we could move a check for it to the top and bail out early? Or alternatively, just be a little more specific about what's happening if we want to always show the license info section etc.