2020-04-22 19:07:51 +05:30
< script >
2020-11-24 15:15:51 +05:30
/* eslint-disable vue/no-v-html */
2020-10-24 23:57:45 +05:30
import { GlButton , GlFormGroup , GlFormInput , GlModal , GlModalDirective } from '@gitlab/ui' ;
2020-04-22 19:07:51 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue' ;
import axios from '~/lib/utils/axios_utils' ;
import { _ _ , sprintf } from '~/locale' ;
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as createFlash } from '~/flash' ;
2020-04-22 19:07:51 +05:30
export default {
copyToClipboard : _ _ ( 'Copy' ) ,
components : {
2020-10-24 23:57:45 +05:30
GlButton ,
2020-04-22 19:07:51 +05:30
GlFormGroup ,
GlFormInput ,
GlModal ,
ClipboardButton ,
} ,
directives : {
'gl-modal' : GlModalDirective ,
} ,
props : {
initialAuthorizationKey : {
type : String ,
required : false ,
default : '' ,
} ,
changeKeyUrl : {
type : String ,
required : true ,
} ,
notifyUrl : {
type : String ,
required : true ,
} ,
learnMoreUrl : {
type : String ,
required : true ,
} ,
2020-07-28 23:09:34 +05:30
disabled : {
type : Boolean ,
required : false ,
default : false ,
} ,
2020-04-22 19:07:51 +05:30
} ,
data ( ) {
return {
authorizationKey : this . initialAuthorizationKey ,
sectionDescription : sprintf (
_ _ (
'To receive alerts from manually configured Prometheus services, add the following URL and Authorization key to your Prometheus webhook config file. Learn more about %{linkStart}configuring Prometheus%{linkEnd} to send alerts to GitLab.' ,
) ,
{
linkStart : ` <a href=" ${ this . learnMoreUrl } " target="_blank" rel="noopener noreferrer"> ` ,
linkEnd : '</a>' ,
} ,
false ,
) ,
} ;
} ,
methods : {
resetKey ( ) {
axios
. post ( this . changeKeyUrl )
. then ( res => {
this . authorizationKey = res . data . token ;
} )
. catch ( ( ) => {
createFlash ( _ _ ( 'Failed to reset key. Please try again.' ) ) ;
} ) ;
} ,
} ,
} ;
< / script >
< template >
< div class = "row py-4 border-top js-prometheus-alerts" >
< div class = "col-lg-3" >
< h4 class = "mt-0" >
{ { _ _ ( 'Alerts' ) } }
< / h4 >
< p >
{ { _ _ ( 'Receive alerts from manually configured Prometheus servers.' ) } }
< / p >
< / div >
< div class = "col-lg-9" >
< p v-html = "sectionDescription" > < / p >
< gl-form-group :label = "__('URL')" label -for = " notify -url " label -class = " label -bold " >
< div class = "input-group" >
< gl-form-input id = "notify-url" :readonly = "true" :value = "notifyUrl" / >
< span class = "input-group-append" >
2020-07-28 23:09:34 +05:30
< clipboard-button
: text = "notifyUrl"
: title = "$options.copyToClipboard"
: disabled = "disabled"
/ >
2020-04-22 19:07:51 +05:30
< / span >
< / div >
< / gl-form-group >
< gl-form-group
: label = "__('Authorization key')"
label - for = "authorization-key"
label - class = "label-bold"
>
< div class = "input-group" >
< gl-form-input id = "authorization-key" :readonly = "true" :value = "authorizationKey" / >
< span class = "input-group-append" >
2020-07-28 23:09:34 +05:30
< clipboard-button
: text = "authorizationKey"
: title = "$options.copyToClipboard"
: disabled = "disabled"
/ >
2020-04-22 19:07:51 +05:30
< / span >
< / div >
< / gl-form-group >
< template v-if = "authorizationKey.length > 0" >
< gl-modal
modal - id = "authKeyModal"
: title = "__('Reset authorization key?')"
: ok - title = "__('Reset authorization key')"
ok - variant = "danger"
@ ok = "resetKey"
>
{ {
_ _ (
'Resetting the authorization key will invalidate the previous key. Existing alert configurations will need to be updated with the new key.' ,
)
} }
< / gl-modal >
2020-10-24 23:57:45 +05:30
< gl-button v -gl -modal .authKeyModal class = "js-reset-auth-key" :disabled = "disabled" > { {
_ _ ( 'Reset key' )
} } < / gl-button >
2020-04-22 19:07:51 +05:30
< / template >
2020-10-24 23:57:45 +05:30
< gl-button v -else :disabled = "disabled" class = "js-reset-auth-key" @click ="resetKey" > {{
_ _ ( 'Generate key' )
} } < / gl-button >
2020-04-22 19:07:51 +05:30
< / div >
< / div >
< / template >