-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add environment variable configuration for storage #42
Changes from all commits
990e8d5
a6cd803
b05a84e
de65051
66c26c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ package s3 | |
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
const ( | ||
|
@@ -50,6 +51,9 @@ func NewConfig() *Config { | |
ForcePathStyle: true, | ||
MaxRetries: defaultMaxRetries, | ||
MaxPartSize: defaultMaxPartSize, | ||
Bucket: os.Getenv("STORAGE_S3_BUCKET_NAME"), | ||
Region: os.Getenv("STORAGE_S3_BUCKET_REGION"), | ||
Prefix: os.Getenv("STORAGE_S3_BUCKET_PREFIX"), | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi! Greenmask employs Viper and Cobra frameworks for managing the configuration. This means you should not hardcode Have a look at an example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wwoytenko I see, while investigating the code further I realized that Viper would take care of the configuration. As I understand, I believe that it was supposed to load all the configuration from environment variables automatically since However, I can't seem to make it work using any environment variables following Viper's docummentation (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wwoytenko it seems I was able to fix it, it was simply the lack of the separator replacer. I opened a new PR #43 with the change. On a side note I would like to propose a couple of other changes (and I'm unsure where would be the ideal location to communicate those, so I'm just adding them here):
I can work on all of those if you agree, I've tested a few of those changes locally already and they are really simple, the first one being the most impactful for my use case. To give you some context of my use case: I'm planning to run greenmask once a day as a ECS container inside a VPC in AWS, export dumps to S3 and also use it in Github actions to restore the dump to a postgres database so we can run database migration tests in our CI. So, having all the configurations as environment variables would be ideal, even the transformer configurations for the dump operation (which I still haven't tested yet). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joao-zanutto sure you can start doing it with all the listed fixes/features. Kindly remind you to review the documentation according to the changes will make. Thank you! |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to implement the configuration in the next way:
We should introduce the
storage.type
parameter and depending on the type provided you can use either S3 config or Directory.Keep in mind that the env vars mapping should be done via viper/cobra usage here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important now, because
AutomaticEnv
does not work when we provide the variableSTORAGE_DIRECTORY_PATH=/tmp
. The default config file assembles the S3 storage (not the Directory). It would be fine to introduce the next keys in the config:Then the variables will be dynamically working using the next variable naming:
STORAGE_DIRECTORY_PATH=/tmp
STORAGE_S3_BUCKET=testbucket