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

Load settings based on env variable #29

Merged
merged 3 commits into from
Jun 22, 2022
Merged

Load settings based on env variable #29

merged 3 commits into from
Jun 22, 2022

Conversation

v-p-b
Copy link

@v-p-b v-p-b commented Jun 21, 2022

If PIPER_CONFIG environment variable is set, Piper will try to load a configuration from the file specified by the variable.

Filenames ending with .yml or .yaml are interpreted as YAML configs, otherwise Protobuf is assumed.

If something goes wrong, Piper gracefully falls back to default config (user-specific saved settings are skipped).

@v-p-b
Copy link
Author

v-p-b commented Jun 21, 2022

1923d8e is a workaround to the 2) of #23 (comment)

} else if (serialized != null) {
return Piper.Config.parseFrom(decompress(unpad4(Z85.Z85Decoder(serialized))))
} else {
throw Exception("Fallback to default config")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the message? Since you catch it with a wildcard catch below, nobody will see this. Did you mean to print it to some console?

Copy link
Author

Choose a reason for hiding this comment

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

No, it's just meant to be a kind of self-documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if I understand it right, this will then just silently load the default config for any exception (e.g. YAML syntax error). Is this desired/planned behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this is intentional. A lot of things can go wrong during loading files alone, so my thinking was that if anything fails, we just go with the defaults. This would be an indication for the user about misconfiguration, but we may need some better signal.

@@ -578,13 +579,25 @@ class BurpExtender : IBurpExtender, ITab, ListDataListener, IHttpListener {

private fun loadConfig(): Piper.Config {
val serialized = callbacks.loadExtensionSetting(EXTENSION_SETTINGS_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why load it if you potentially will never use it anyway? I'd only load it if env is null, which would also make the code easier to read/follow.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! Resolved in 2754328

@dnet dnet merged commit 0e72ed5 into silentsignal:master Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants