diff --git a/CHANGELOG.md b/CHANGELOG.md index c40f39a4..90e51b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] None +## [4.1.0] - 2020-07-19 +### Added +- Backup by anonymous users + +### Fixed +- Incorrect version in snapcraft + ## [4.0.0] - 2020-07-18 ### Added - Log the name of the n3dr backup zip @@ -201,7 +208,8 @@ None ### Added - Download all artifacts from a certain Nexus3 repository. -[Unreleased]: https://github.com/030/n3dr/compare/4.0.0...HEAD +[Unreleased]: https://github.com/030/n3dr/compare/4.1.0...HEAD +[4.1.0]: https://github.com/030/n3dr/compare/4.0.0...4.1.0 [4.0.0]: https://github.com/030/n3dr/compare/3.6.3...4.0.0 [3.6.3]: https://github.com/030/n3dr/compare/3.6.2...3.6.3 [3.6.2]: https://github.com/030/n3dr/compare/3.6.1...3.6.2 diff --git a/README.md b/README.md index 135feb72..2f98f3bc 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,11 @@ Flags: Use "n3dr [command] --help" for more information about a command. ``` +## Anonymous + +In order to download as a anonymous user, one has to omit the `n3drUser` and +`n3drPass` subcommands. + ## Store the password in a read-only file Define the password in `~/.n3dr.yaml`: diff --git a/cli/req.go b/cli/req.go index a13c65cc..5aa8a15f 100644 --- a/cli/req.go +++ b/cli/req.go @@ -1,28 +1,28 @@ package cli import ( - "errors" "fmt" - "github.com/hashicorp/go-retryablehttp" "io/ioutil" "net/http" "strconv" + "github.com/hashicorp/go-retryablehttp" + log "github.com/sirupsen/logrus" ) -func (n Nexus3) validatePassword() error { +func (n Nexus3) validate() { + if n.User == "" { + log.Debug("Empty user. Verify whether the the subcommand is specified or anonymous mode is used") + } if n.Pass == "" { - return errors.New("Empty password. Verify whether the 'n3drPass' has been defined in ~/.n3dr.yaml") + log.Debug("Empty password. Verify whether the 'n3drPass' has been defined in ~/.n3dr.yaml, the subcommand is specified or anonymous mode is used") } - return nil } func (n Nexus3) request(url string) ([]byte, string, error) { - err := n.validatePassword() - if err != nil { - return nil, "", err - } + n.validate() + log.WithFields(log.Fields{"URL": url, "User": n.User}).Debug("URL Request") req, err := http.NewRequest("GET", url, nil) diff --git a/cmd/root.go b/cmd/root.go index 62cfa0cb..645731af 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -67,9 +67,6 @@ func init() { if err := rootCmd.MarkPersistentFlagRequired("n3drURL"); err != nil { log.Fatal(err) } - if err := rootCmd.MarkPersistentFlagRequired("n3drUser"); err != nil { - log.Fatal(err) - } } // initConfig reads in config file and ENV variables if set. diff --git a/integration-tests.sh b/integration-tests.sh index 22c82349..6483374d 100755 --- a/integration-tests.sh +++ b/integration-tests.sh @@ -64,10 +64,7 @@ upload(){ echo } -backup(){ - echo "Testing backup..." - $TOOL backup -n http://localhost:9999 -u admin -p $PASSWORD -r maven-releases -v "${NEXUS_API_VERSION}" -z - +backupHelper(){ if [ "${NEXUS_VERSION}" == "3.9.0" ]; then count_downloads 300 test_zip 148 @@ -80,6 +77,18 @@ backup(){ cleanup_downloads } +anonymous(){ + echo "Testing backup by anonymous user..." + $TOOL backup -n http://localhost:9999 -r maven-releases -v "${NEXUS_API_VERSION}" -z + backupHelper +} + +backup(){ + echo "Testing backup..." + $TOOL backup -n http://localhost:9999 -u admin -p $PASSWORD -r maven-releases -v "${NEXUS_API_VERSION}" -z + backupHelper +} + regex(){ echo "Testing backup regex..." $TOOL backup -n http://localhost:9999 -u admin -p $PASSWORD -r maven-releases -v "${NEXUS_API_VERSION}" -x 'some/group42' -z @@ -158,6 +167,7 @@ main(){ password files upload + anonymous backup repositories regex diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index ce563086..a675483e 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: n3dr # you probably want to 'snapcraft register ' base: core18 # the base snap is the execution environment for this snap -version: '3.6.3' # just for humans, typically '1.2+git' or '1.3.2' +version: '4.1.0' # just for humans, typically '1.2+git' or '1.3.2' summary: Nexus3 Disaster Recovery # 79 char long summary description: | Download all artifacts at once or migrate automatically from Nexus to Nexus. @@ -28,7 +28,7 @@ parts: source: . go-importpath: github.com/030/n3dr override-build: | - GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-X n3dr/cmd.Version=3.6.2" -o $SNAPCRAFT_PART_INSTALL/n3dr + GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-X n3dr/cmd.Version=${SNAPCRAFT_PROJECT_VERSION}" -o $SNAPCRAFT_PART_INSTALL/n3dr $SNAPCRAFT_PART_INSTALL/n3dr --version stage: - "n3dr" diff --git a/tests.bats b/tests.bats index e684461d..a4ffe9f0 100644 --- a/tests.bats +++ b/tests.bats @@ -6,12 +6,10 @@ [[ "$output" =~ $regex ]] } -@test "invoking n3dr without password specification prints an error" { - echo 'n3drPass: admin123' > ${HOME}/.n3dr.yaml - sed -i "s|n3drPass|nhihidrPass|" ~/.n3dr.yaml - run go run main.go repositories -n http://localhost:9999 -u admin -b +@test "invoking n3dr with unreachable URL exists after 6 attempts" { + run go run main.go repositories -n http://localhost:99999 -u admin -p INCORRECT_PASSWORD -b [ "$status" -eq 1 ] echo $output - regex='.*Empty password. Verify whether the .n3drPass..*has been defined in ~/.n3dr.yaml' + regex='.*http://localhost:99999/service/rest/v1/repositories giving up after 6 attempts' [[ "$output" =~ $regex ]] } \ No newline at end of file