Alerting: Store sensitive settings encrypted for LINE notifier (#27157)

* encrypt token

* update docs
This commit is contained in:
Will Browne 2020-08-24 16:49:10 +02:00 committed by GitHub
parent ed6f0663c2
commit bbbbf9ac42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

@ -453,9 +453,9 @@ The following sections detail the supported settings and secure settings for eac
#### Alert notification `LINE` #### Alert notification `LINE`
| Name | | Name | Secure setting |
| ----- | | ----- | - |
| token | | token | yes |
#### Alert notification `pagerduty` #### Alert notification `pagerduty`

View File

@ -18,13 +18,23 @@ func init() {
Heading: "LINE notify settings", Heading: "LINE notify settings",
Factory: NewLINENotifier, Factory: NewLINENotifier,
OptionsTemplate: ` OptionsTemplate: `
<div class="gf-form-group"> <h3 class="page-heading">LINE notify settings</h3>
<h3 class="page-heading">LINE notify settings</h3> <div class="gf-form">
<div class="gf-form"> <label class="gf-form-label max-width-14">Token</label>
<span class="gf-form-label width-14">Token</span> <div class="gf-form gf-form--grow" ng-if="!ctrl.model.secureFields.token">
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.token" placeholder="LINE notify token key"></input> <input type="text"
</div> required
</div> class="gf-form-input max-width-22"
ng-init="ctrl.model.secureSettings.token = ctrl.model.settings.token || null; ctrl.model.settings.token = null;"
ng-model="ctrl.model.secureSettings.token"
data-placement="right">
</input>
</div>
<div class="gf-form" ng-if="ctrl.model.secureFields.token">
<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.token = false">reset</a>
</div>
</div>
`, `,
Options: []alerting.NotifierOption{ Options: []alerting.NotifierOption{
{ {
@ -44,7 +54,7 @@ const (
// NewLINENotifier is the constructor for the LINE notifier // NewLINENotifier is the constructor for the LINE notifier
func NewLINENotifier(model *models.AlertNotification) (alerting.Notifier, error) { func NewLINENotifier(model *models.AlertNotification) (alerting.Notifier, error) {
token := model.Settings.Get("token").MustString() token := model.DecryptedValue("token", model.Settings.Get("token").MustString())
if token == "" { if token == "" {
return nil, alerting.ValidationError{Reason: "Could not find token in settings"} return nil, alerting.ValidationError{Reason: "Could not find token in settings"}
} }