mantl / consul-cli

Command line interface to Consul HTTP API
Apache License 2.0
251 stars 67 forks source link

Add a `--header` flag to `check register` and `service register` commands #59

Closed sbryant closed 6 years ago

sbryant commented 6 years ago

I'm using consul-cli to register services and wanted to add some headers to the http checks. The current solution was to use --raw and throw some json at it:

      consul-cli service register --raw - <<JSON
      {
        "name": "example-service",
        "port": 1337,
        "check": {
          "http": "http://localhost:1337/_ping",
          "header": { "Host": [ "example-service" ] },
          "interval": "15s"
        }
      }
JSON

Rather tossing JSON around it would be nice to add --header "Header: Val" flag support.

This PR adds stringSlice support to the mapValue Value implementation. Currently the string slice is serializes to CSV to work the existing implementation.

Added the ability turn off CSV reading when setting up a stringSliceValue.

With those out of the way the header flag implementation is pretty straight forward. The flag can be specified multiple times. These headers will be parsed and passed along as to the onsulapi.AgentServiceCheck structs.

Added some command tests to make it easier to verify the implementation.

$ GOCACHE=off make test
go test $(glide nv)  -timeout=30s -parallel=4
ok      github.com/mantl/consul-cli/action  0.011s
ok      github.com/mantl/consul-cli/commands    3.628s
?       github.com/mantl/consul-cli [no test files]
go vet $(glide nv)
sbryant commented 6 years ago

Small update, I've updated the CI to use 1.8.x, 1.10.x and tip. The consul testutils package requires an updated testing package. The travis CI setup will now download a consul binary and use that for the integration tests.

Theaxiom commented 6 years ago

@sbryant Merged, thanks for your contribution and hard work!