(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[534],{95756:(R,b,a)=>{"use strict";a.d(b,{d:()=>E});var l=a(68404),e=a(5916),u=a(81764),m=a(30810);const E=f=>{const{labelWidth:S,editorProps:o,showCACert:g,showKeyPair:D=!0}=f,{secureJsonFields:d}=o.options;return l.createElement(l.Fragment,null,D?l.createElement(u._,{tooltip:l.createElement("span",null,"To authenticate with an TLS/SSL client certificate, provide the client certificate here."),labelWidth:S,label:"TLS/SSL Client Certificate"},l.createElement(m.Zk,{placeholder:"Begins with -----BEGIN CERTIFICATE-----",cols:45,rows:7,isConfigured:d&&d.tlsClientCert,onChange:(0,e.fi)(o,"tlsClientCert"),onReset:()=>{(0,e.Mf)(o,"tlsClientCert")}})):null,g?l.createElement(u._,{tooltip:l.createElement("span",null,"If the selected TLS/SSL mode requires a server root certificate, provide it here."),labelWidth:S,label:"TLS/SSL Root Certificate"},l.createElement(m.Zk,{placeholder:"Begins with -----BEGIN CERTIFICATE-----",cols:45,rows:7,isConfigured:d&&d.tlsCACert,onChange:(0,e.fi)(o,"tlsCACert"),onReset:()=>{(0,e.Mf)(o,"tlsCACert")}})):null,D?l.createElement(u._,{tooltip:l.createElement("span",null,"To authenticate with a client TLS/SSL certificate, provide the key here."),labelWidth:S,label:"TLS/SSL Client Key"},l.createElement(m.Zk,{placeholder:"Begins with -----BEGIN RSA PRIVATE KEY-----",cols:45,rows:7,isConfigured:d&&d.tlsClientKey,onChange:(0,e.fi)(o,"tlsClientKey"),onReset:()=>{(0,e.Mf)(o,"tlsClientKey")}})):null)}},50992:(R,b,a)=>{"use strict";a.r(b),a.d(b,{plugin:()=>fe});var l=a(7238),e=a(68404),u=a(44674);const m={isDatasetSelectorHidden:!0};function E(t){return e.createElement(u.M,{...t,queryHeaderProps:m})}var f=a(5916),S=a(13393),o=a(81764),g=a(46967),D=a(11543),d=a(52953),y=a(53217),M=a(8944),w=a(45253),Q=a(29460),K=a(16705),$=a(95756),G=a(59024),v=(t=>(t.disable="disable",t.require="require",t.verifyCA="verify-ca",t.verifyFull="verify-full",t))(v||{}),I=(t=>(t.filePath="file-path",t.fileContent="file-content",t))(I||{}),N=a(88771),H=a(54899),U=a(91162),Z=a(25748),z=a(13930),J=a(71208),Y=a(67090);class q{constructor(r,n,i){this.target=(0,Y.Y)(r||{refId:"A"}),this.templateSrv=n,this.scopedVars=i}interpolate(){return this.templateSrv?.replace(this.target.rawSql,this.scopedVars,J.Q.sqlString)||""}quoteLiteral(r){return"'"+r.replace(/'/g,"''")+"'"}}function X(){return"SELECT current_setting('server_version_num')::int/100 as version"}function k(){return"SELECT extversion FROM pg_extension WHERE extname = 'timescaledb'"}function _(){return`select quote_ident(table_name) as "table" from information_schema.tables
    where quote_ident(table_schema) not in ('information_schema',
                             'pg_catalog',
                             '_timescaledb_cache',
                             '_timescaledb_catalog',
                             '_timescaledb_internal',
                             '_timescaledb_config',
                             'timescaledb_information',
                             'timescaledb_experimental')
      and table_type = 'BASE TABLE' and ${te()}`}function ee(t){return`select quote_ident(column_name) as "column", data_type as "type"
    from information_schema.columns
    where quote_ident(table_name) = '${t}'`}function te(){return`
          quote_ident(table_schema) IN (
          SELECT
            CASE WHEN trim(s[i]) = '"$user"' THEN user ELSE trim(s[i]) END
          FROM
            generate_series(
              array_lower(string_to_array(current_setting('search_path'),','),1),
              array_upper(string_to_array(current_setting('search_path'),','),1)
            ) as i,
            string_to_array(current_setting('search_path'),',') s
          )`}var ae=a(26418);const re=({getColumns:t,getTables:r})=>(n,i)=>({...i&&(0,ae.getStandardSQLCompletionProvider)(n,i),tables:{resolve:async()=>await r.current()},columns:{resolve:async s=>await t.current({table:s?.table,refId:"A"})}});async function ne(t,r){const n=await t.fields(r);return n.length>0?n.map(i=>({name:i.value,type:i.value,description:i.value})):[]}async function le(t){return await t.lookup?.()||[]}var ie=a(82897),V=a(12936);function se(t){switch(t){case"boolean":return{raqbFieldType:"boolean",icon:"toggle-off"};case"bit":case"bit varying":case"character":case"character varying":case"text":return{raqbFieldType:"text",icon:"text"};case"smallint":case"integer":case"bigint":case"decimal":case"numeric":case"real":case"double precision":case"serial":case"bigserial":case"smallserial":return{raqbFieldType:"number",icon:"calculator-alt"};case"date":return{raqbFieldType:"date",icon:"clock-nine"};case"time":case"time with time zone":case"time without time zone":case"interval":return{raqbFieldType:"time",icon:"clock-nine"};case"timestamp":case"timestamp with time zone":case"timestamp without time zone":return{raqbFieldType:"datetime",icon:"clock-nine"};default:return{raqbFieldType:"text",icon:"text"}}}function oe({sql:t,table:r}){let n="";if(!t||!(0,V.IC)(t.columns))return n;if(n+=(0,V.zE)(t.columns),r&&(n+=`FROM ${r} `),t.whereString&&(n+=`WHERE ${t.whereString} `),t.groupBy?.[0]?.property.name){const i=t.groupBy.map(s=>s.property.name).filter(s=>!(0,ie.isEmpty)(s));n+=`GROUP BY ${i.join(", ")} `}return t.orderBy?.property.name&&(n+=`ORDER BY ${t.orderBy.property.name} `),t.orderBy?.property.name&&t.orderByDirection&&(n+=`${t.orderByDirection} `),t.limit!==void 0&&t.limit>=0&&(n+=`LIMIT ${t.limit} `),n}class j extends Z.D{constructor(r){super(r),this.sqlLanguageDefinition=void 0}getQueryModel(r,n,i){return new q(r,n,i)}async getVersion(){return(await this.runSql(X())).fields.version.values.toArray()[0].toString()}async getTimescaleDBVersion(){return(await this.runSql(k())).fields.extversion.values.toArray()[0]}async fetchTables(){return(await this.runSql(_(),{refId:"tables"})).fields.table.values.toArray().flat()}getSqlLanguageDefinition(r){if(this.sqlLanguageDefinition!==void 0)return this.sqlLanguageDefinition;const n={getColumns:{current:i=>ne(r,i)},getTables:{current:()=>le(r)}};return this.sqlLanguageDefinition={id:"pgsql",completionProvider:re(n),formatter:z._},this.sqlLanguageDefinition}async fetchFields(r){const n=await this.runSql(ee(r.table),{refId:"columns"}),i=[];for(let s=0;s<n.length;s++){const c=n.fields.column.values.get(s),F=n.fields.type.values.get(s);i.push({label:c,value:c,type:F,...se(F)})}return i}getDB(){return this.db!==void 0?this.db:{init:()=>Promise.resolve(!0),datasets:()=>Promise.resolve([]),tables:()=>this.fetchTables(),getEditorLanguageDefinition:()=>this.getSqlLanguageDefinition(this.db),fields:async r=>r?.table?this.fetchFields(r):[],validateQuery:r=>Promise.resolve({isError:!1,isValid:!0,query:r,error:"",rawSql:r.rawSql}),dsID:()=>this.id,toRawSql:oe,lookup:async()=>(await this.fetchTables()).map(n=>({name:n,completion:n}))}}}function ce({props:t,setVersionOptions:r}){const[n,i]=(0,e.useState)(!1),{options:s,onOptionsChange:c}=t;(0,N.Z)(()=>{const F=async()=>{if(n){const C=await(0,U.ak)().loadDatasource(s.name);if(C instanceof j){const W=await C.getVersion(),h=parseInt(W,10);h>=906&&!s.jsonData.timescaledb&&await C.getTimescaleDBVersion()&&(0,f.tp)({options:s,onOptionsChange:c},"timescaledb",!0);const B=Math.trunc(h/100),O=h%100;let L=String(B);h<1e3&&(L=String(B)+"."+String(O)),x.find(p=>p.value===h)||r(p=>[...p,{label:L,value:h}]),(s.jsonData.postgresVersion===void 0||s.jsonData.postgresVersion!==h)&&(0,f.tp)({options:s,onOptionsChange:c},"postgresVersion",h)}}else{const C=await(0,H.i)().put(`/api/datasources/${s.id}`,s);i(!0),(0,f.fd)({options:s,onOptionsChange:c},"version",C.datasource.version)}};ue(s)&&F()},[s,n,r])}function ue(t){return t.url&&t.jsonData.database&&t.user&&(t.secureJsonData?.password||t.secureJsonFields?.password)&&(t.jsonData.sslmode===v.disable||t.jsonData.sslCertFile&&t.jsonData.sslKeyFile&&t.jsonData.sslRootCertFile)&&!t.jsonData.postgresVersion&&!t.readOnly}const x=[{label:"9.0",value:900},{label:"9.1",value:901},{label:"9.2",value:902},{label:"9.3",value:903},{label:"9.4",value:904},{label:"9.5",value:905},{label:"9.6",value:906},{label:"10",value:1e3},{label:"11",value:1100},{label:"12",value:1200},{label:"13",value:1300},{label:"14",value:1400},{label:"15",value:1500}],de=t=>{const[r,n]=(0,e.useState)(x);ce({props:t,setVersionOptions:n}),(0,G.Q)(t);const{options:i,onOptionsChange:s}=t,c=i.jsonData,F=()=>{(0,f.Mf)(t,"password")},C=[{value:v.disable,label:"disable"},{value:v.require,label:"require"},{value:v.verifyCA,label:"verify-ca"},{value:v.verifyFull,label:"verify-full"}],W=[{value:I.filePath,label:"File system path"},{value:I.fileContent,label:"Certificate content"}],h=T=>P=>{(0,f.tp)(t,T,P.value)},B=T=>{(0,f.tp)(t,"timescaledb",T.currentTarget.checked)},O=T=>P=>{s({...i,[T]:P.currentTarget.value})},L=25,p=20,A=20;return e.createElement(e.Fragment,null,e.createElement(S.C,{label:"PostgreSQL Connection",width:400},e.createElement(o._,{labelWidth:p,label:"Host"},e.createElement(g.I,{width:40,name:"host",type:"text",value:i.url||"",placeholder:"localhost:5432",onChange:O("url")})),e.createElement(o._,{labelWidth:p,label:"Database"},e.createElement(g.I,{width:40,name:"database",value:c.database||"",placeholder:"database name",onChange:(0,f._R)(t,"database")})),e.createElement(D.Z,null,e.createElement(o._,{labelWidth:p,label:"User"},e.createElement(g.I,{value:i.user||"",placeholder:"user",onChange:O("user")})),e.createElement(o._,{label:"Password"},e.createElement(d.m4,{placeholder:"Password",isConfigured:i.secureJsonFields?.password,onReset:F,onBlur:(0,f.fi)(t,"password")}))),e.createElement(o._,{labelWidth:p,label:"TLS/SSL Mode",htmlFor:"tlsMode",tooltip:"This option determines whether or with what priority a secure TLS/SSL TCP/IP connection will be negotiated with the server."},e.createElement(y.Ph,{options:C,inputId:"tlsMode",value:c.sslmode||v.verifyFull,onChange:h("sslmode")})),i.jsonData.sslmode!==v.disable?e.createElement(o._,{labelWidth:p,label:"TLS/SSL Method",htmlFor:"tlsMethod",tooltip:e.createElement("span",null,"This option determines how TLS/SSL certifications are configured. Selecting ",e.createElement("i",null,"File system path")," will allow you to configure certificates by specifying paths to existing certificates on the local file system where Grafana is running. Be sure that the file is readable by the user executing the Grafana process.",e.createElement("br",null),e.createElement("br",null),"Selecting ",e.createElement("i",null,"Certificate content")," will allow you to configure certificates by specifying its content. The content will be stored encrypted in Grafana's database. When connecting to the database the certificates will be written as files to Grafana's configured data path on the local file system.")},e.createElement(y.Ph,{options:W,inputId:"tlsMethod",value:c.tlsConfigurationMethod||I.filePath,onChange:h("tlsConfigurationMethod")})):null),c.sslmode!==v.disable?e.createElement(S.C,{label:"TLS/SSL Auth Details"},c.tlsConfigurationMethod===I.fileContent?e.createElement($.d,{showCACert:c.sslmode===v.verifyCA||c.sslmode===v.verifyFull,editorProps:t,labelWidth:L}):e.createElement(e.Fragment,null,e.createElement(o._,{tooltip:e.createElement("span",null,"If the selected TLS/SSL mode requires a server root certificate, provide the path to the file here."),labelWidth:L,label:"TLS/SSL Root Certificate"},e.createElement(g.I,{value:c.sslRootCertFile||"",onChange:(0,f._R)(t,"sslRootCertFile"),placeholder:"TLS/SSL root cert file"})),e.createElement(o._,{tooltip:e.createElement("span",null,"To authenticate with an TLS/SSL client certificate, provide the path to the file here. Be sure that the file is readable by the user executing the grafana process."),labelWidth:L,label:"TLS/SSL Client Certificate"},e.createElement(g.I,{value:c.sslCertFile||"",onChange:(0,f._R)(t,"sslCertFile"),placeholder:"TLS/SSL client cert file"})),e.createElement(o._,{tooltip:e.createElement("span",null,"To authenticate with a client TLS/SSL certificate, provide the path to the corresponding key file here. Be sure that the file is ",e.createElement("i",null,"only")," readable by the user executing the grafana process."),labelWidth:L,label:"TLS/SSL Client Key"},e.createElement(g.I,{value:c.sslKeyFile||"",onChange:(0,f._R)(t,"sslKeyFile"),placeholder:"TLS/SSL client key file"})))):null,e.createElement(K.K,{labelWidth:A,jsonData:c,onPropertyChanged:(T,P)=>{(0,f.tp)(t,T,P)}}),e.createElement(S.C,{label:"PostgreSQL details"},e.createElement(o._,{tooltip:"This option controls what functions are available in the PostgreSQL query builder",labelWidth:A,htmlFor:"postgresVersion",label:"Version"},e.createElement(y.Ph,{value:c.postgresVersion||903,inputId:"postgresVersion",onChange:h("postgresVersion"),options:r})),e.createElement(o._,{tooltip:e.createElement("span",null,"TimescaleDB is a time-series database built as a PostgreSQL extension. If enabled, Grafana will use",e.createElement("code",null,"time_bucket")," in the ",e.createElement("code",null,"$__timeGroup")," macro and display TimescaleDB specific aggregate functions in the query builder."),labelWidth:A,label:"TimescaleDB",htmlFor:"timescaledb"},e.createElement(M.x,{id:"timescaledb",value:c.timescaledb||!1,onChange:B})),e.createElement(o._,{tooltip:e.createElement("span",null,"A lower limit for the auto group by time interval. Recommended to be set to write frequency, for example",e.createElement("code",null,"1m")," if your data is written every minute."),labelWidth:A,label:"Min time interval"},e.createElement(g.I,{placeholder:"1m",value:c.timeInterval||"",onChange:(0,f._R)(t,"timeInterval")}))),e.createElement(w.b,{title:"User Permission",severity:"info"},"The database user should only be granted SELECT permissions on the specified database & tables you want to query. Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements like ",e.createElement("code",null,"DELETE FROM user;")," and ",e.createElement("code",null,"DROP TABLE user;")," would be executed. To protect against this we ",e.createElement("strong",null,"Highly")," recommend you create a specific PostgreSQL user with restricted permissions. Check out the"," ",e.createElement(Q.r,{rel:"noreferrer",target:"_blank",href:"http://docs.grafana.org/features/datasources/postgres/"},"PostgreSQL Data Source Docs")," ","for more information."))},fe=new l.hf(j).setQueryEditor(E).setConfigEditor(de)},88771:(R,b,a)=>{"use strict";a.d(b,{Z:()=>D});var l=a(68404),e=function(d){return d!==Object(d)},u=function(d,y,M){var w=(0,l.useRef)(void 0);(!w.current||!M(y,w.current))&&(w.current=y),(0,l.useEffect)(d,w.current)};const m=u;var E=a(48322),f=a.n(E);const S=f();var o=function(d){return d!==Object(d)},g=function(d,y){m(d,y,S)};const D=g},48322:R=>{"use strict";R.exports=function b(a,l){if(a===l)return!0;if(a&&l&&typeof a=="object"&&typeof l=="object"){if(a.constructor!==l.constructor)return!1;var e,u,m;if(Array.isArray(a)){if(e=a.length,e!=l.length)return!1;for(u=e;u--!==0;)if(!b(a[u],l[u]))return!1;return!0}if(a.constructor===RegExp)return a.source===l.source&&a.flags===l.flags;if(a.valueOf!==Object.prototype.valueOf)return a.valueOf()===l.valueOf();if(a.toString!==Object.prototype.toString)return a.toString()===l.toString();if(m=Object.keys(a),e=m.length,e!==Object.keys(l).length)return!1;for(u=e;u--!==0;)if(!Object.prototype.hasOwnProperty.call(l,m[u]))return!1;for(u=e;u--!==0;){var E=m[u];if(!(E==="_owner"&&a.$$typeof)&&!b(a[E],l[E]))return!1}return!0}return a!==a&&l!==l}},76345:()=>{},56834:()=>{}}]);

//# sourceMappingURL=postgresPlugin.25a179215f50b8b3faf5.js.map