Alerting: Store sensitive settings encrypted for OpsGenie notifier (#27074)

* encrypt OpsGenie API key

* make whitespace consistent

* update docs
This commit is contained in:
Will Browne 2020-08-20 16:05:48 +02:00 committed by GitHub
parent 6b2d44416d
commit 9f2386a219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 34 deletions

View File

@ -511,12 +511,12 @@ The following sections detail the supported settings and secure settings for eac
#### Alert notification `opsgenie`
| Name |
| ---------------- |
| apiKey |
| apiUrl |
| autoClose |
| overridePriority |
| Name | Secure setting |
| ---------------- | - |
| apiKey | yes |
| apiUrl | |
| autoClose | |
| overridePriority | |
#### Alert notification `telegram`

View File

@ -21,8 +21,21 @@ func init() {
OptionsTemplate: `
<h3 class="page-heading">OpsGenie settings</h3>
<div class="gf-form">
<span class="gf-form-label width-14">API Key</span>
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.apiKey" placeholder="OpsGenie API Key"></input>
<label class="gf-form-label max-width-14">API Key</label>
<div class="gf-form gf-form--grow" ng-if="!ctrl.model.secureFields.apiKey">
<input type="text"
required
class="gf-form-input max-width-22"
ng-init="ctrl.model.secureSettings.apiKey = ctrl.model.settings.apiKey || null; ctrl.model.settings.apiKey = null;"
ng-model="ctrl.model.secureSettings.apiKey"
placeholder="OpsGenie API Key"
data-placement="right">
</input>
</div>
<div class="gf-form" ng-if="ctrl.model.secureFields.apiKey">
<input type="text" class="gf-form-input max-width-18" disabled="disabled" value="configured" />
<a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.model.secureFields.apiKey = false">reset</a>
</div>
</div>
<div class="gf-form">
<span class="gf-form-label width-14">Alert API Url</span>
@ -87,7 +100,7 @@ var (
func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
autoClose := model.Settings.Get("autoClose").MustBool(true)
overridePriority := model.Settings.Get("overridePriority").MustBool(true)
apiKey := model.Settings.Get("apiKey").MustString()
apiKey := model.DecryptedValue("apiKey", model.Settings.Get("apiKey").MustString())
apiURL := model.Settings.Get("apiUrl").MustString()
if apiKey == "" {
return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"}