Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration system for knoxite #120

Merged
merged 15 commits into from Aug 9, 2020
Merged

Configuration system for knoxite #120

merged 15 commits into from Aug 9, 2020

Conversation

penguwin
Copy link
Member

This PR adds the first draft for a configuration which support multiple config file backend system in knoxite. This brings support for multiple config file backends to make it easier to implement other backends (encrypted, networked, etc). Fixes #72

The knoxite commands will respect the values stored in the config but you're still able to overwrite them via command line flags. You can specify which configuration configbackend you want to use and the path to the file with the new -C | --configURL flag .

To create a new shorthand for an repository configuration with the new repo alias command:

$ knoxite repo alias fort -r /knox

You can use the new subcommand config to manage your configuration:

$ knoxite config --help
The config command manages the knoxite configuration

Usage:
  knoxite config [command]

Available Commands:
  cat         display the configuration file on stdout
  info        display information about the configuration file on stdout
  init        initialize a new configuration
  set         set configuration values for an alias

For example with the set command you can tweak configuration values:

$ knoxite config set fort.encryption aes --configURL "crypto://test@/path/to/knoxite.conf"

cmd/knoxite/config.go Outdated Show resolved Hide resolved
return fmt.Errorf("set needs to know which option to set")
}
if len(args) < 2 {
return fmt.Errorf("set needs to know which value to set")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be the wrong position to critizise this here, since we're doing this in every command - but shouldn't we just print the help text of this command reather than a specific help text? I often had the situation where i typed just the second argument of a command requiring two arguments and was confused when reading that the second argument was missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's keep this discussion in a separate issue / ticket.

cmd/knoxite/config.go Outdated Show resolved Hide resolved
cmd/knoxite/config.go Outdated Show resolved Hide resolved
cmd/knoxite/repository.go Outdated Show resolved Hide resolved
cfg/config.go Outdated Show resolved Hide resolved
cfg/config.go Outdated Show resolved Hide resolved
cfg/config.go Outdated Show resolved Hide resolved
cfg/config.go Outdated Show resolved Hide resolved
cfg/aesbackend.go Outdated Show resolved Hide resolved
@penguwin penguwin marked this pull request as ready for review July 7, 2020 18:30
@penguwin penguwin requested a review from craftamap July 7, 2020 18:30
Copy link
Member

@muesli muesli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome-sauce. Just a few changes required!

cmd/knoxite/store.go Outdated Show resolved Hide resolved
cmd/knoxite/store.go Outdated Show resolved Hide resolved
utils/utils.go Show resolved Hide resolved
Copy link
Member

@ma-hartma ma-hartma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the requested changes, this looks good to me! Great contribution! <3

- Move CompressionTypeFromString() to utils.go
- Move CompressionText to utils.go
- Also move ErrCompressionUnkown to utils.go
- Move EncryptionTypeFromString to utils.go
- Move EncryptionText to utils.go
- Move ErrEncryptionUnkown to utils.go
@penguwin penguwin force-pushed the configuration branch 2 times, most recently from f188205 to 21a686f Compare August 3, 2020 12:16
@penguwin
Copy link
Member Author

penguwin commented Aug 3, 2020

Applied the changes as requested and splitted up the commits a bit more.
Also note that the config command now also provides the alias subcommand (as requested by @craftamap):

$ knoxite config --help
The config command manages the knoxite configuration

Usage:
  knoxite config [command]

Available Commands:
  alias       Set an alias for the storage backend url to a repository
  cat         display the configuration file on stdout
  info        display information about the configuration file on stdout
  init        initialize a new configuration
  set         set configuration values for an alias

- move readPassword and readPasswordTwice to utils.go
- moved ErrPasswordMismatch to utils.go
cfg/config.go Outdated Show resolved Hide resolved
cfg/aesbackend_test.go Outdated Show resolved Hide resolved
This commits adds a configuration system backend to knoxite.
The code is heavily inspired by the configuration backend for beehive written
by rubiojr so all your credits are belong to him:
muesli/beehive@5f810ab

The main difference is ofc the adjustments to work with/for knoxite.
I also modified the password system as I'm not feeling safe setting the password
for the config file in an environment variable. It'll prompt the user once when
there's no password specified in the url.
Our main.go file will now initialize a cfg.Config object for us.
This object can be used to in further commands to read out the corresponding
values.
The path to the configfile can be specified via an URL. For example to use an
aes encrypted configuration file you can pass an url like this:

    ./knoxite config init --ConfigURL "crypto:///path/to/config.conf"

You can also pass you encryption password via the url:

    ./knoxite config init --ConfigURL "crypto://password@/path/to/config.conf"

Also updated dependencies
The config command can be used to manage and tweak the configuration
This subcommand helps to set specific values in the configuration file
These commands will output the config to stdout
With the config alias command you can declare shorthands for your repository
configurations.
This will implement and use the values specified in the configuration file and
provided by the configuration system for store command in knoxite
This will implement and use the values specified in the configuration file and
provided by the configuration system for the clone command in knoxite
This will implement and use the values specified in the configuration file for
the repopath(s) and provided by the configuration system for the repository
command in knoxite
The first check for the redundancy amount should be checked as int. After that
convert the tolerance-value to uiunt for further use in snapshot.Add
@muesli muesli merged commit 4c87305 into master Aug 9, 2020
@penguwin penguwin deleted the configuration branch August 10, 2020 17:08
@penguwin penguwin restored the configuration branch August 13, 2020 11:56
@penguwin penguwin deleted the configuration branch August 13, 2020 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Configurable repositories and backends
4 participants