Support `--ca-certificate` in Buckler CLI
It has a `--ca-cert` alias for BOSH folks, and it can take either a path
to the CA Certificate (PEM) file, or the raw contents of that PEM file.
@@ -5,6 +5,7 @@ import (
"os"
"regexp"
"strconv"
+ "strings"
fmt "github.com/jhunt/go-ansi"
"github.com/jhunt/go-cli"
@@ -365,9 +366,21 @@ func main() {
cacert := ""
if opts.API.CACertificate != "" {
- /* try to parse it as a literal PEM */
- /* check for the file on-disk if no interior newlines */
- cacert = opts.API.CACertificate /* FIXME cheating */
+ if strings.Contains(opts.API.CACertificate, "\n") {
+ /* embedded newlines detected in option value;
+ assume this is a literal PEM blob, perhaps provided via
+
+ buckler api test https://shield.example.com \
+ --ca-certificate "$(vault read secret/ca/certs)"
+ */
+ cacert = opts.API.CACertificate
+ } else {
+ /* no embedded newlines in option value;
+ check for the file on-disk if no interior newlines */
+ b, err := ioutil.ReadFile(opts.API.CACertificate)
+ bail(err)
+ cacert = string(b)
+ }
}
/* validate the SHIELD */
@@ -376,6 +389,7 @@ func main() {
Debug: opts.Debug,
Trace: opts.Trace,
Session: "",
+ CACertificate: cacert,
}
nfo, err := c.Info()
bail(err)
@@ -401,6 +415,7 @@ func main() {
Debug: opts.Debug,
Trace: opts.Trace,
Session: config.Current.Session,
+ CACertificate: config.Current.CACertificate,
}
switch command {
