diff --git a/.travis.yml b/.travis.yml index 3b3d44a..80d9f04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ install: - go get github.com/udhos/lockfile - go get github.com/udhos/equalfile - go get github.com/udhos/difflib - - go get gopkg.in/yaml.v2 + - go get gopkg.in/yaml.v3 - go get golang.org/x/crypto/ssh - go get github.com/aws/aws-sdk-go/aws diff --git a/README.md b/README.md index 58208f2..f143896 100644 --- a/README.md +++ b/README.md @@ -69,21 +69,13 @@ Quick Start - Short version This is how to boot up Jazigo very quickly: -## With Go Modules (starting from Go 1.11) - git clone https://github.com/udhos/jazigo ;# clone outside of GOPATH cd jazigo go install ./jazigo mkdir etc repo log JAZIGO_HOME=$PWD ~/go/bin/jazigo -## Without Go Modules (before Go 1.11) - - go get github.com/udhos/jazigo - cd ~/go/src/github.com/udhos/jazigo - ./build.sh - mkdir etc repo log - JAZIGO_HOME=$PWD ~/go/bin/jazigo +Open jazigo interface - http://localhost:8080/jazigo/ Quick Start - Detailed version ============================== @@ -92,34 +84,15 @@ Installation and usage are supposed to be dead simple. If you hit any surprising If you want to build from source code, start from step 1. -If you downloaded the executable binary file, start from step 5. - -1\. Setup GOPATH as usual - -Example: +If you downloaded the executable binary file, start from step 2. - #export GOPATH=~/go ;# starting from Go 1.8, GOPATH is no longer required - mkdir ~/go +1\. Build from source -2\. Get dependencies - - go get github.com/icza/gowut/gwu - go get github.com/udhos/lockfile - go get github.com/udhos/equalfile - go get github.com/udhos/difflib - go get gopkg.in/yaml.v2 - go get golang.org/x/crypto/ssh - go get github.com/aws/aws-sdk-go - -3\. Get source code - - go get github.com/udhos/jazigo - -4\. Compile and install - - go install github.com/udhos/jazigo/jazigo + git clone https://github.com/udhos/jazigo + cd jazigo + go install ./... -5\. Decide where to store config, backup, log and static www files +2\. Decide where to store config, backup, log and static www files Example: @@ -133,7 +106,7 @@ By default, Jazigo looks for directories 'etc', 'repo', 'log', and 'www' under $ If left undefined, JAZIGO_HOME defaults to /var/jazigo. See command line options to fine tune filesystem locations. -6\. Copy static files (CSS and images) to $JAZIGO_HOME/www +3\. Copy static files (CSS and images) to $JAZIGO_HOME/www Example: @@ -147,7 +120,7 @@ Example: wget https://raw.githubusercontent.com/udhos/jazigo/master/www/jazigo.css wget https://raw.githubusercontent.com/udhos/jazigo/master/www/GitHub-Mark-32px.png -7\. Run jazigo once (see -runOnce option) +4\. Run jazigo once (see -runOnce option) `$GOPATH/bin/jazigo -runOnce` @@ -155,11 +128,11 @@ Watch messages logged to standard output for errors. Hint: Since root privileges are usually not needed, run Jazigo as a regular user. -8\. Run jazigo forever +5\. Run jazigo forever `$GOPATH/bin/jazigo -disableStdoutLog` -9\. Open the web interface +6\. Open the web interface Point web browser at: [http://localhost:8080/jazigo](http://localhost:8080/jazigo) diff --git a/build.sh b/build.sh index 93ff0de..ddd6272 100755 --- a/build.sh +++ b/build.sh @@ -1,92 +1,23 @@ -#!/bin/sh +#!/bin/bash -step=0 +go install golang.org/x/vuln/cmd/govulncheck@latest -msg() { - step=$((step+1)) - echo >&2 $step. $* -} +gofmt -s -w . -get() { - i=$1 - msg fetching $i - go get $i - msg fetching $i - done -} +revive ./... -get github.com/icza/gowut/gwu -get github.com/udhos/difflib -get github.com/udhos/lockfile -get github.com/udhos/equalfile -get gopkg.in/yaml.v2 -get golang.org/x/crypto/ssh -get github.com/aws/aws-sdk-go -#get honnef.co/go/simple/cmd/gosimple -#get honnef.co/go/tools/cmd/staticcheck +#gocyclo -over 15 . -src=`find . -type f | egrep '\.go$'` +go mod tidy -msg fmt -gofmt -s -w $src -msg fix -go tool fix $src -msg vet -go tool vet . +govulncheck ./... -msg install -pkg=github.com/udhos/jazigo -go install $pkg/jazigo +go env -w CGO_ENABLED=1 -# go get honnef.co/go/simple/cmd/gosimple -s=$GOPATH/bin/gosimple -simple() { - msg simple - this is slow, please standby - # gosimple cant handle source files from multiple packages - $s jazigo/*.go - $s conf/*.go - $s dev/*.go - $s store/*.go - $s temp/*.go -} -[ -x "$s" ] && simple +go test -race ./... -# go get github.com/golang/lint/golint -l=$GOPATH/bin/golint -lint() { - msg lint - # golint cant handle source files from multiple packages - $l jazigo/*.go - $l conf/*.go - $l dev/*.go - $l store/*.go - $l temp/*.go -} -[ -x "$l" ] && lint +go env -w CGO_ENABLED=0 -# go get honnef.co/go/tools/cmd/staticcheck -sc=$GOPATH/bin/staticcheck -static() { - msg staticcheck - this is slow, please standby - # staticcheck cant handle source files from multiple packages - $sc jazigo/*.go - $sc conf/*.go - $sc dev/*.go - $sc store/*.go - $sc temp/*.go -} -[ -x "$sc" ] && static +go install ./... -msg test dev - this may take a while, please stand by -go test github.com/udhos/jazigo/dev - -msg test store -if [ -z "$JAZIGO_S3_REGION" ]; then - echo >&2 JAZIGO_S3_REGION undefined -- for S3 testing, set JAZIGO_S3_REGION=region -fi -if [ -z "$JAZIGO_S3_FOLDER" ]; then - echo >&2 JAZIGO_S3_FOLDER undefined -- for S3 testing, set JAZIGO_S3_FOLDER=bucket/folder -fi -go test github.com/udhos/jazigo/store - -msg test jazigo -go test github.com/udhos/jazigo/jazigo +go env -u CGO_ENABLED \ No newline at end of file diff --git a/conf/conf.go b/conf/conf.go index 032caf6..967d6af 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -1,9 +1,10 @@ +// Package conf handles configuration. package conf import ( "time" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/udhos/jazigo/store" ) diff --git a/dev/control.go b/dev/control.go index 37773ee..a89d4c8 100644 --- a/dev/control.go +++ b/dev/control.go @@ -1,3 +1,4 @@ +// Package dev provides access to multiple devices. package dev import ( diff --git a/dev/model_fortios.go b/dev/model_fortios.go index 12d95ed..c536188 100644 --- a/dev/model_fortios.go +++ b/dev/model_fortios.go @@ -22,9 +22,9 @@ func registerModelFortiOS(logger hasPrintf, t *DeviceTable) { "config system global", // enter config: valid only for vdom "config system console", // enter config: valid only for non-vdom "set output standard", // disable paging - "end", // exit config - "get system status", // system information - "show", // get configuration + "end", // exit config + "get system status", // system information + "show", // get configuration } promptPattern := `\S+\s#\s$` // "hostname # " diff --git a/go.mod b/go.mod index e679d6f..d8c2816 100644 --- a/go.mod +++ b/go.mod @@ -2,22 +2,25 @@ module github.com/udhos/jazigo require ( github.com/aws/aws-sdk-go v1.15.16 + github.com/icza/gowut v1.3.0 + github.com/udhos/difflib v0.0.0-20170223180222-9237ff6aafff + github.com/udhos/equalfile v0.0.0-20180725151512-a22d6261a8df + github.com/udhos/lockfile v0.0.0-20160928001432-1d49c987357a + golang.org/x/crypto v0.9.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-ini/ini v1.25.4 // indirect github.com/gopherjs/gopherjs v0.0.0-20180820052304-89baedc74dd7 // indirect - github.com/icza/gowut v1.3.0 + github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect github.com/stretchr/testify v1.2.2 // indirect - github.com/udhos/difflib v0.0.0-20170223180222-9237ff6aafff - github.com/udhos/equalfile v0.0.0-20180725151512-a22d6261a8df - github.com/udhos/lockfile v0.0.0-20160928001432-1d49c987357a - golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac - golang.org/x/net v0.0.0-20180821023952-922f4815f713 // indirect - golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339 // indirect - golang.org/x/text v0.3.0 // indirect - gopkg.in/yaml.v2 v2.2.1 + golang.org/x/sys v0.8.0 // indirect ) -go 1.13 +go 1.20 diff --git a/go.sum b/go.sum index 02e00d5..b8e41db 100644 --- a/go.sum +++ b/go.sum @@ -26,15 +26,14 @@ github.com/udhos/equalfile v0.0.0-20180725151512-a22d6261a8df h1:SDnf0lMzWQcbGOL github.com/udhos/equalfile v0.0.0-20180725151512-a22d6261a8df/go.mod h1:1LOX9HjdFMke7ryP3IPby09FkswyY5KzhhsT37wLz/Y= github.com/udhos/lockfile v0.0.0-20160928001432-1d49c987357a h1:286YGPLaLItW0JKx1IePghZEhuNLHNEGPOIsD+25Yx4= github.com/udhos/lockfile v0.0.0-20160928001432-1d49c987357a/go.mod h1:w5A2nWhTT88JgIVjPxgCNvD8yrXpXSckwYh924u8a0I= -golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac h1:7d7lG9fHOLdL6jZPtnV4LpI41SbohIJ1Atq7U991dMg= -golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/net v0.0.0-20180821023952-922f4815f713 h1:rMJUcaDGbG+X967I4zGKCq5laYqcGKJmpB+3jhpOhPw= -golang.org/x/net v0.0.0-20180821023952-922f4815f713/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339 h1:0w2EXzxbB03VAzqwe3csbadu4CPhMRtxCz/rjw9gkic= -golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/jazigo/doc.go b/jazigo/doc.go index 3bcb432..af77d45 100644 --- a/jazigo/doc.go +++ b/jazigo/doc.go @@ -6,49 +6,51 @@ Jazigo is a tool written in Go for retrieving configuration for multiple network See also: https://github.com/udhos/jazigo Usage: - jazigo [flag] + + jazigo [flag] Flags are: - -configPathPrefix string - configuration path prefix - -deviceDelete - delete devices specified in stdin - -deviceImport - import devices from stdin - -deviceList - list devices to stdout - -devicePurge - purge devices specified in stdin - -disableStdoutLog - disable logging to stdout - -logCheckInterval duration - interval for checking log file size - -logMaxFiles int - number of log files to keep - -logMaxSize int - size limit for log file - -logPathPrefix string - log path prefix - -repositoryPath string - repository path - -runOnce - exit after scanning all devices once - -s3region string - AWS S3 region - -webListen string - address:port for web UI - -wwwStaticPath string - directory for static www content + + -configPathPrefix string + configuration path prefix + -deviceDelete + delete devices specified in stdin + -deviceImport + import devices from stdin + -deviceList + list devices to stdout + -devicePurge + purge devices specified in stdin + -disableStdoutLog + disable logging to stdout + -logCheckInterval duration + interval for checking log file size + -logMaxFiles int + number of log files to keep + -logMaxSize int + size limit for log file + -logPathPrefix string + log path prefix + -repositoryPath string + repository path + -runOnce + exit after scanning all devices once + -s3region string + AWS S3 region + -webListen string + address:port for web UI + -wwwStaticPath string + directory for static www content By default, jazigo looks for these path prefixes under $JAZIGO_HOME: - etc/jazigo.conf. (can be overridden with -configPathPrefix) - log/jazigo.log. (can be overridden with -logPathPrefix) - repo (can be overridden with -repositoryPath) - www (can be overridden with -wwwStaticPath) + + etc/jazigo.conf. (can be overridden with -configPathPrefix) + log/jazigo.log. (can be overridden with -logPathPrefix) + repo (can be overridden with -repositoryPath) + www (can be overridden with -wwwStaticPath) If $JAZIGO_HOME is not defined, jazigo home defaults to /var/jazigo. Since root privileges are usually not needed, run the jazigo application as a regular user. - */ package main diff --git a/jazigo/main.go b/jazigo/main.go index d38f251..cc78d90 100644 --- a/jazigo/main.go +++ b/jazigo/main.go @@ -1,3 +1,4 @@ +// Package main implements the jazigo tool. package main import ( @@ -21,7 +22,7 @@ import ( ) const appName = "jazigo" -const appVersion = "0.11" +const appVersion = "0.11.0" type app struct { configPathPrefix string diff --git a/old-build.sh b/old-build.sh new file mode 100755 index 0000000..ddd6b69 --- /dev/null +++ b/old-build.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +step=0 + +msg() { + step=$((step+1)) + echo >&2 $step. $* +} + +get() { + i=$1 + msg fetching $i + go get $i + msg fetching $i - done +} + +get github.com/icza/gowut/gwu +get github.com/udhos/difflib +get github.com/udhos/lockfile +get github.com/udhos/equalfile +get gopkg.in/yaml.v3 +get golang.org/x/crypto/ssh +get github.com/aws/aws-sdk-go +#get honnef.co/go/simple/cmd/gosimple +#get honnef.co/go/tools/cmd/staticcheck + +src=`find . -type f | egrep '\.go$'` + +msg fmt +gofmt -s -w $src +msg fix +go tool fix $src +msg vet +go tool vet . + +msg install +pkg=github.com/udhos/jazigo +go install $pkg/jazigo + +# go get honnef.co/go/simple/cmd/gosimple +s=$GOPATH/bin/gosimple +simple() { + msg simple - this is slow, please standby + # gosimple cant handle source files from multiple packages + $s jazigo/*.go + $s conf/*.go + $s dev/*.go + $s store/*.go + $s temp/*.go +} +[ -x "$s" ] && simple + +# go get github.com/golang/lint/golint +l=$GOPATH/bin/golint +lint() { + msg lint + # golint cant handle source files from multiple packages + $l jazigo/*.go + $l conf/*.go + $l dev/*.go + $l store/*.go + $l temp/*.go +} +[ -x "$l" ] && lint + +# go get honnef.co/go/tools/cmd/staticcheck +sc=$GOPATH/bin/staticcheck +static() { + msg staticcheck - this is slow, please standby + # staticcheck cant handle source files from multiple packages + $sc jazigo/*.go + $sc conf/*.go + $sc dev/*.go + $sc store/*.go + $sc temp/*.go +} +[ -x "$sc" ] && static + +msg test dev - this may take a while, please stand by +go test github.com/udhos/jazigo/dev + +msg test store +if [ -z "$JAZIGO_S3_REGION" ]; then + echo >&2 JAZIGO_S3_REGION undefined -- for S3 testing, set JAZIGO_S3_REGION=region +fi +if [ -z "$JAZIGO_S3_FOLDER" ]; then + echo >&2 JAZIGO_S3_FOLDER undefined -- for S3 testing, set JAZIGO_S3_FOLDER=bucket/folder +fi +go test github.com/udhos/jazigo/store + +msg test jazigo +go test github.com/udhos/jazigo/jazigo diff --git a/store/mock_filesystem.go b/store/mock_filesystem.go index 09d0320..0f7568f 100644 --- a/store/mock_filesystem.go +++ b/store/mock_filesystem.go @@ -1,3 +1,4 @@ +// Package store abstracts a file system. package store import ( diff --git a/store/s3.go b/store/s3.go index efeeb88..f47d2a4 100644 --- a/store/s3.go +++ b/store/s3.go @@ -95,7 +95,8 @@ func s3path(path string) bool { return s3match } -// Input: "arn:aws:s3:region::bucket/folder/file.xxx" +// Input: "arn:aws:s3:region::bucket/folder/file.xxx" +// // Output: "region", "bucket", "folder/file.xxx" func s3parse(path string) (string, string, string) { s := strings.Split(path, ":") diff --git a/temp/temp.go b/temp/temp.go index b160122..b3ea39d 100644 --- a/temp/temp.go +++ b/temp/temp.go @@ -1,3 +1,4 @@ +// Package temp creates temporary repository. package temp import ( @@ -7,7 +8,7 @@ import ( const tempRepoPrefix = "/tmp/tmp-jazigo-repo" -// MakeTempRepo creates the remporary repository path, for testing. +// MakeTempRepo creates the temporary repository path, for testing. func MakeTempRepo() string { path := tempRepoPrefix if err := os.MkdirAll(path, 0700); err != nil { @@ -16,7 +17,7 @@ func MakeTempRepo() string { return path } -// CleanupTempRepo erases the remporary repository path. +// CleanupTempRepo erases the temporary repository path. func CleanupTempRepo() string { path := tempRepoPrefix if err := os.RemoveAll(path); err != nil {