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

* encrypt OpsGenie API key

* make whitespace consistent

* update docs
pull/27102/head
Will Browne 5 years ago committed by GitHub
parent 6b2d44416d
commit 9f2386a219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      docs/sources/administration/provisioning.md
  2. 19
      pkg/services/alerting/notifiers/opsgenie.go

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

@ -21,8 +21,21 @@ func init() {
OptionsTemplate: ` OptionsTemplate: `
<h3 class="page-heading">OpsGenie settings</h3> <h3 class="page-heading">OpsGenie settings</h3>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-14">API Key</span> <label class="gf-form-label max-width-14">API Key</label>
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.apiKey" placeholder="OpsGenie API Key"></input> <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>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-14">Alert API Url</span> <span class="gf-form-label width-14">Alert API Url</span>
@ -87,7 +100,7 @@ var (
func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) { func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
autoClose := model.Settings.Get("autoClose").MustBool(true) autoClose := model.Settings.Get("autoClose").MustBool(true)
overridePriority := model.Settings.Get("overridePriority").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() apiURL := model.Settings.Get("apiUrl").MustString()
if apiKey == "" { if apiKey == "" {
return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"} return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"}

Loading…
Cancel
Save