From d7e7b2579d33f95ed22e0e42be1313ae9a6a4550 Mon Sep 17 00:00:00 2001 From: Damian ONeill Date: Mon, 18 Nov 2019 11:06:43 +0000 Subject: [PATCH] added asciinema video, cleanup test --- README.md | 2 ++ cmd/extract_installation.go | 16 ++++++++++------ cmd/extract_installation_test.go | 18 ++++++++++++++++-- cmd/testdata/devices.json | 24 ++++++++++++++++++++++++ docs/h7t.md | 2 +- docs/h7t_completion.md | 2 +- docs/h7t_configure.md | 2 +- docs/h7t_configure_devices.md | 2 +- docs/h7t_docs.md | 2 +- docs/h7t_extract.md | 2 +- docs/h7t_extract_device-groups.md | 2 +- docs/h7t_extract_devices.md | 2 +- docs/h7t_extract_installation.md | 2 +- docs/h7t_load.md | 2 +- docs/h7t_load_device-groups.md | 2 +- docs/h7t_load_devices.md | 2 +- docs/h7t_load_helper-files.md | 2 +- docs/h7t_summarise.md | 2 +- docs/h7t_summarise_installation.md | 2 +- docs/h7t_transform.md | 2 +- docs/h7t_transform_devices.md | 2 +- docs/h7t_version.md | 2 +- go.sum | 2 -- 23 files changed, 70 insertions(+), 28 deletions(-) create mode 100644 cmd/testdata/devices.json diff --git a/README.md b/README.md index 18d3fff..021d45f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ A command line tool for interacting with [Juniper Healthbot](https://www.juniper > Note Device Group functionality is limited currently, this will be updated after Healthbot 2.1 is released. +[![asciicast](https://asciinema.org/a/FsdPZpORfIuciQ70rTgGvtf4M.svg)](https://asciinema.org/a/FsdPZpORfIuciQ70rTgGvtf4M) + ## Synopsis A tool for interacting with Healthbot over the REST API. diff --git a/cmd/extract_installation.go b/cmd/extract_installation.go index c8131c9..2390f1b 100644 --- a/cmd/extract_installation.go +++ b/cmd/extract_installation.go @@ -12,18 +12,22 @@ import ( "gopkg.in/resty.v1" ) -func appendResourceBody(backup *[]byte, responseBody []byte) (err error) { +func removeBracketsFromJSONObject(src []byte) (bare []byte, err error) { // remove all whitespace / carriage returns, etc. buffer := new(bytes.Buffer) - err = json.Compact(buffer, responseBody) + err = json.Compact(buffer, src) if err != nil { return } - // remove outer brackets - by := bytes.TrimPrefix(buffer.Bytes(), []byte("{")) - by = bytes.TrimSuffix(by, []byte("}")) + bare = bytes.TrimPrefix(buffer.Bytes(), []byte("{")) + bare = bytes.TrimSuffix(bare, []byte("}")) + return +} + +func appendResourceBody(backup *[]byte, responseBody []byte) (err error) { + b, err := removeBracketsFromJSONObject(responseBody) // append to main json object and add comma in advance of next object being added - *backup = append(*backup, by...) + *backup = append(*backup, b...) *backup = append(*backup, ',') return } diff --git a/cmd/extract_installation_test.go b/cmd/extract_installation_test.go index 44d5bdc..bd41c7c 100644 --- a/cmd/extract_installation_test.go +++ b/cmd/extract_installation_test.go @@ -1,8 +1,11 @@ package cmd -import "testing" +import ( + "strings" + "testing" -import "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/assert" +) func Test_appendResourceBody(t *testing.T) { // fugly test @@ -14,3 +17,14 @@ func Test_appendResourceBody(t *testing.T) { assert.Nil(t, err, "Should not return an error %v", err) assert.Equal(t, expected, backup, "should start with { and end with , and separate objects with a comma") } + +func Test_removeBracketsFromJSONObject(t *testing.T) { + b, err := removeBracketsFromJSONObject(HelperLoadBytes(t, "devices.json")) + if err != nil { + t.Errorf("removeBracketsFromJSONObject() error = %v", err) + return + } + got := string(b) + assert.True(t, strings.HasPrefix(got, "\"device\":"), "Should start with device colon") + assert.True(t, strings.HasSuffix(got, "]"), "Should end with square bracket") +} diff --git a/cmd/testdata/devices.json b/cmd/testdata/devices.json new file mode 100644 index 0000000..0a5a5c4 --- /dev/null +++ b/cmd/testdata/devices.json @@ -0,0 +1,24 @@ +{ + "device": [ + { + "authentication": { + "password": { + "password": "$9$rgFlWXJZjq.5YgoGjif51RESKMX7-", + "username": "doneill" + } + }, + "device-id": "mmx960-1", + "host": "172.30.177.102" + }, + { + "authentication": { + "password": { + "password": "$9$TQ6CrlMXxdRhSeMW-dHq.fFnCtu", + "username": "doneill" + } + }, + "device-id": "mmx960-3", + "host": "172.30.177.113" + } + ] +} diff --git a/docs/h7t.md b/docs/h7t.md index 9ce6c86..3e3ad78 100644 --- a/docs/h7t.md +++ b/docs/h7t.md @@ -30,4 +30,4 @@ The intent with this tool is to provide bulk or aggregate functions, that simpli * [h7t transform](h7t_transform.md) - Transform things from proprietary formats into Healthbot dsl format * [h7t version](h7t_version.md) - Output the current build information -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_completion.md b/docs/h7t_completion.md index 3d92900..2e5c539 100644 --- a/docs/h7t_completion.md +++ b/docs/h7t_completion.md @@ -54,4 +54,4 @@ h7t completion [flags] * [h7t](h7t.md) - Healthbot Command Line Interface -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_configure.md b/docs/h7t_configure.md index 17571ec..81304ac 100644 --- a/docs/h7t_configure.md +++ b/docs/h7t_configure.md @@ -31,4 +31,4 @@ h7t configure [flags] * [h7t](h7t.md) - Healthbot Command Line Interface * [h7t configure devices](h7t_configure_devices.md) - Load Devices with configuration -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_configure_devices.md b/docs/h7t_configure_devices.md index d6f60f9..a770cad 100644 --- a/docs/h7t_configure_devices.md +++ b/docs/h7t_configure_devices.md @@ -56,4 +56,4 @@ h7t configure devices [flags] * [h7t configure](h7t_configure.md) - Configure information relating to a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_docs.md b/docs/h7t_docs.md index 00d3a12..ebb1e61 100644 --- a/docs/h7t_docs.md +++ b/docs/h7t_docs.md @@ -30,4 +30,4 @@ h7t docs [flags] * [h7t](h7t.md) - Healthbot Command Line Interface -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_extract.md b/docs/h7t_extract.md index 7e6cce6..03198f7 100644 --- a/docs/h7t_extract.md +++ b/docs/h7t_extract.md @@ -34,4 +34,4 @@ h7t extract [flags] * [h7t extract devices](h7t_extract_devices.md) - Extract Device configuration * [h7t extract installation](h7t_extract_installation.md) - Extract installation configuration -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_extract_device-groups.md b/docs/h7t_extract_device-groups.md index 7f88719..c33eb72 100644 --- a/docs/h7t_extract_device-groups.md +++ b/docs/h7t_extract_device-groups.md @@ -31,4 +31,4 @@ h7t extract device-groups [flags] * [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_extract_devices.md b/docs/h7t_extract_devices.md index e868fda..afe5de7 100644 --- a/docs/h7t_extract_devices.md +++ b/docs/h7t_extract_devices.md @@ -31,4 +31,4 @@ h7t extract devices [flags] * [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_extract_installation.md b/docs/h7t_extract_installation.md index 9b009fc..32feeeb 100644 --- a/docs/h7t_extract_installation.md +++ b/docs/h7t_extract_installation.md @@ -31,4 +31,4 @@ h7t extract installation [flags] * [h7t extract](h7t_extract.md) - Extract information from a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_load.md b/docs/h7t_load.md index 3d7b9fc..76b2838 100644 --- a/docs/h7t_load.md +++ b/docs/h7t_load.md @@ -37,4 +37,4 @@ h7t load [flags] * [h7t load devices](h7t_load_devices.md) - Load Device configuration * [h7t load helper-files](h7t_load_helper-files.md) - Load Helper Files -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_load_device-groups.md b/docs/h7t_load_device-groups.md index 63a5767..1df9290 100644 --- a/docs/h7t_load_device-groups.md +++ b/docs/h7t_load_device-groups.md @@ -32,4 +32,4 @@ h7t load device-groups [flags] * [h7t load](h7t_load.md) - Load information into a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_load_devices.md b/docs/h7t_load_devices.md index f29b4dd..302f85b 100644 --- a/docs/h7t_load_devices.md +++ b/docs/h7t_load_devices.md @@ -32,4 +32,4 @@ h7t load devices [flags] * [h7t load](h7t_load.md) - Load information into a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_load_helper-files.md b/docs/h7t_load_helper-files.md index c2eb7e3..d980319 100644 --- a/docs/h7t_load_helper-files.md +++ b/docs/h7t_load_helper-files.md @@ -32,4 +32,4 @@ h7t load helper-files [flags] * [h7t load](h7t_load.md) - Load information into a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_summarise.md b/docs/h7t_summarise.md index f9ee3a3..06496f4 100644 --- a/docs/h7t_summarise.md +++ b/docs/h7t_summarise.md @@ -31,4 +31,4 @@ h7t summarise [flags] * [h7t](h7t.md) - Healthbot Command Line Interface * [h7t summarise installation](h7t_summarise_installation.md) - Summarise information collected from a Healthbot installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_summarise_installation.md b/docs/h7t_summarise_installation.md index e7a045b..4e58236 100644 --- a/docs/h7t_summarise_installation.md +++ b/docs/h7t_summarise_installation.md @@ -30,4 +30,4 @@ h7t summarise installation [flags] * [h7t summarise](h7t_summarise.md) - Summarise information from a Healthbot Installation -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_transform.md b/docs/h7t_transform.md index 43121da..def302d 100644 --- a/docs/h7t_transform.md +++ b/docs/h7t_transform.md @@ -36,4 +36,4 @@ h7t transform [flags] * [h7t](h7t.md) - Healthbot Command Line Interface * [h7t transform devices](h7t_transform_devices.md) - Transform Devices configuration -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_transform_devices.md b/docs/h7t_transform_devices.md index 8463bb2..aea022d 100644 --- a/docs/h7t_transform_devices.md +++ b/docs/h7t_transform_devices.md @@ -33,4 +33,4 @@ h7t transform devices [flags] * [h7t transform](h7t_transform.md) - Transform things from proprietary formats into Healthbot dsl format -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/docs/h7t_version.md b/docs/h7t_version.md index 3b365bb..761d535 100644 --- a/docs/h7t_version.md +++ b/docs/h7t_version.md @@ -30,4 +30,4 @@ h7t version [flags] * [h7t](h7t.md) - Healthbot Command Line Interface -###### Auto generated by spf13/cobra on 15-Nov-2019 +###### Auto generated by spf13/cobra on 18-Nov-2019 diff --git a/go.sum b/go.sum index 0da676a..9e517a5 100644 --- a/go.sum +++ b/go.sum @@ -203,8 +203,6 @@ github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/goreleaser/goreleaser v0.121.0 h1:CeOa4lqMI1TlPXral4PeMxWoRQv+fq0JTPUUVsl+P4Y= -github.com/goreleaser/goreleaser v0.121.0/go.mod h1:Acn33/psgsNrPClBfaYjaqmtfK4ilOIWQWYEls6nOPs= github.com/goreleaser/goreleaser v0.122.0 h1:83xV9cUrXErdvIVnIAXYZkmZFdY139RvihqxrwswxrY= github.com/goreleaser/goreleaser v0.122.0/go.mod h1:Acn33/psgsNrPClBfaYjaqmtfK4ilOIWQWYEls6nOPs= github.com/goreleaser/nfpm v1.1.5 h1:bjVIflQl0b3lNQvO/b++cKMKXW+INL70AdGR+zDXWps=