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

support env vars for options in server config #364

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions config/policy-bot.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ server:
logging:
# If true, logs are printed in human-readable form. We recommend using
# "false" to output JSON-formatted logs in production
# Can also be set by the POLICYBOT_LOG_PRETTY environment variable.
text: false
# Set a minimum logging level threshold
# Choose from: debug, info, warn, error
# Can also be set by the POLICYBOT_LOG_LEVEL environment variable.
level: debug

# Options for the GitHub response cache. When the cache reaches max_size, the
Expand Down Expand Up @@ -78,17 +80,21 @@ sessions:
# Options for application behavior. The defaults are shown below.
#
# options:
# # The path to the policy file in a repository.
# # The path to the policy file in a repository. Can also be set by the
# # POLICYBOT_POLICY_PATH environment variable.
# policy_path: .policy.yml
#
# # The name of an organization repository to look in for a shared policy if
# # a repository does not define a policy file.
# # a repository does not define a policy file. Can also be set by the
# # POLICYBOT_SHARED_REPOSITORY environment variable.
# shared_repository: .github
#
# # The path to the policy file in the shared organization repository.
# # Can also be set by the POLICYBOT_SHARED_POLICY_PATH environment variable.
# shared_policy_path: policy.yml
#
# # The context prefix for status checks created by the bot.
# # The context prefix for status checks created by the bot. Can also be set by the
# # POLICYBOT_STATUS_CHECK_CONTEXT environment variable.
# status_check_context: policy-bot

# Options for locating the frontend files. By default, the server uses appropriate
Expand Down
14 changes: 14 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,22 @@ func ParseConfig(bytes []byte) (*Config, error) {
return nil, errors.Wrapf(err, "failed unmarshalling yaml")
}

if v, ok := os.LookupEnv("POLICYBOT_POLICY_PATH"); ok {
c.Options.PolicyPath = v
}
if v, ok := os.LookupEnv("POLICYBOT_SHARED_REPOSITORY"); ok {
c.Options.SharedRepository = v
}
if v, ok := os.LookupEnv("POLICYBOT_SHARED_POLICY_PATH"); ok {
c.Options.SharedPolicyPath = v
}
if v, ok := os.LookupEnv("POLICYBOT_STATUS_CHECK_CONTEXT"); ok {
c.Options.StatusCheckContext = v
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would work right? @bluekeyes

c.Options.FillDefaults()

c.Server.SetValuesFromEnv("POLICYBOT_")

c.Github.SetValuesFromEnv("")

if v, ok := os.LookupEnv("POLICYBOT_SESSIONS_KEY"); ok {
Expand Down