Skip to content

Commit

Permalink
[GH-236] Fail if parameter is empty and not populated in config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Jan 3, 2022
1 parent 941d2ef commit 7981e4a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.4.2] - 2021-01-03

### Fixed

- N3DR does not fail if parameter is empty and not populated in
`~/.n3dr/config.yml` reported by
[der-eismann](https://github.com/der-eismann).

## [6.4.1] - 2021-01-03

### Changed
Expand Down Expand Up @@ -604,7 +612,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Download all artifacts from a certain Nexus3 repository.

[Unreleased]: https://github.com/030/n3dr/compare/6.4.1...HEAD
[Unreleased]: https://github.com/030/n3dr/compare/6.4.2...HEAD
[6.4.2]: https://github.com/030/n3dr/compare/6.4.1...6.4.2
[6.4.1]: https://github.com/030/n3dr/compare/6.4.0...6.4.1
[6.4.0]: https://github.com/030/n3dr/compare/6.3.0...6.4.0
[6.3.0]: https://github.com/030/n3dr/compare/6.2.0...6.3.0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ n3dr config \
### Build

```bash
docker build -t utrecht/n3dr:6.4.1 .
docker build -t utrecht/n3dr:6.4.2 .
```

[![dockeri.co](https://dockeri.co/image/utrecht/n3dr)](https://hub.docker.com/r/utrecht/n3dr)
Expand All @@ -324,7 +324,7 @@ docker build -t utrecht/n3dr:6.4.1 .
```bash
docker run -it \
-v /home/${USER}/.n3dr:/root/.n3dr \
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.4.1
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.4.2
```

### Upload
Expand All @@ -333,7 +333,7 @@ docker run -it \
docker run -it \
--entrypoint=/bin/ash \
-v /home/${USER}/.n3dr:/root/.n3dr \
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.4.1
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.4.2
```

navigate to the repository folder, e.g. `/tmp/n3dr/download*/` and upload:
Expand Down
2 changes: 1 addition & 1 deletion build/package/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: n3dr
base: core20
version: 6.4.1
version: 6.4.2
summary: Nexus3 Disaster Recovery
description: |
Download all artifacts at once or migrate automatically from Nexus to Nexus.
Expand Down
29 changes: 23 additions & 6 deletions cmd/n3dr/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,39 @@ func initConfig() {
viper.AutomaticEnv()
}

func valueInConfigFile(key string) (string, error) {
conf := viper.ConfigFileUsed()
log.Infof("%s parameter empty. Reading it from config file: '%s'", key, conf)
value := viper.GetString(key)
if value == "" {
return "", fmt.Errorf("key: '%s' does not seem to contain a value. Check whether this key is populated in the config file: '%s'", key, conf)
}
return value, nil
}

func parseVarsFromConfig() {
var err error
if !anonymous {
if n3drUser == "" {
log.Infof("n3drUser empty. Reading if from '%v'", viper.ConfigFileUsed())
n3drUser = viper.GetString("n3drUser")
n3drUser, err = valueInConfigFile("n3drUser")
if err != nil {
log.Fatal(err)
}
}

if n3drPass == "" {
log.Infof("n3drPass empty. Reading if from '%v'", viper.ConfigFileUsed())
n3drPass = viper.GetString("n3drPass")
n3drPass, err = valueInConfigFile("n3drPass")
if err != nil {
log.Fatal(err)
}
}
}

if n3drURL == "" {
log.Infof("n3drURL empty. Reading if from '%v'", viper.ConfigFileUsed())
n3drURL = viper.GetString("n3drURL")
n3drURL, err = valueInConfigFile("n3drURL")
if err != nil {
log.Fatal(err)
}
}
}

Expand Down

0 comments on commit 7981e4a

Please sign in to comment.