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' ;
2021-09-04 01:27:46 +05:30
import createFlash from '~/flash' ;
2020-04-22 19:07:51 +05:30
import axios from '~/lib/utils/axios_utils' ;
import { _ _ , sprintf } from '~/locale' ;
2021-03-11 19:13:27 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue' ;
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 )
2021-03-08 18:12:59 +05:30
. then ( ( res ) => {
2020-04-22 19:07:51 +05:30
this . authorizationKey = res . data . token ;
} )
. catch ( ( ) => {
2021-09-04 01:27:46 +05:30
createFlash ( {
message : _ _ ( 'Failed to reset key. Please try again.' ) ,
} ) ;
2020-04-22 19:07:51 +05:30
} ) ;
} ,
} ,
} ;
< / 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 >