Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sd2k/grafana-materialize-datasource
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: sd2k/grafana-materialize-datasource
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: add-password-support
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Sep 21, 2022

  1. Add password configuration to datasource settings

    This currently bumps the minimum Grafana version to 9.1.0 through use of
    `SecretInput`, which isn't ideal - perhaps we could copy/paste
    that component in instead, or just write our own.
    
    Closes #16.
    sd2k committed Sep 21, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    sd2k Ben Sully
    Copy the full SHA
    93c25c9 View commit details
Showing with 924 additions and 591 deletions.
  1. +4 −0 CHANGELOG.md
  2. +10 −4 backend/src/lib.rs
  3. +1 −1 docker-compose.yaml
  4. +5 −5 package.json
  5. +15 −4 src/ConfigEditor.tsx
  6. +7 −0 src/types.ts
  7. +882 −577 yarn.lock
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add a 'password' field to the datasource settings and pass this when connecting to Materialize. This is required for Materialize Cloud.

## [0.1.1] - 2022-08-12

### Changed
14 changes: 10 additions & 4 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -38,12 +38,18 @@ impl MaterializePlugin {
let settings: MaterializeDatasourceSettings =
serde_json::from_value(datasource_settings.json_data.clone())
.map_err(Error::InvalidDatasourceSettings)?;
let (client, connection) = Config::new()
let mut config = Config::new();
config
.user(&settings.username)
.host(&settings.host)
.port(settings.port)
.connect(NoTls)
.await?;
.port(settings.port);
if let Some(p) = &datasource_settings
.decrypted_secure_json_data
.get("password")
{
config.password(p);
}
let (client, connection) = config.connect(NoTls).await?;
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ version: "3"

services:
grafana:
image: grafana/grafana:9.0.7
image: grafana/grafana:9.1.6
ports:
- "3000:3000"
restart: on-failure
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@
"author": "Ben Sully",
"license": "Apache-2.0",
"devDependencies": {
"@grafana/data": "^9.0.0",
"@grafana/runtime": "^9.0.0",
"@grafana/toolkit": "^9.0.0",
"@grafana/ui": "^9.0.0",
"@grafana/data": "^9.1.0",
"@grafana/runtime": "^9.1.0",
"@grafana/toolkit": "^9.1.0",
"@grafana/ui": "^9.1.0",
"@types/lodash": "^4.14.177"
},
"resolutions": {
"rxjs": "7.5.5"
"rxjs": "7.5.6"
},
"engines": {
"node": ">=14"
19 changes: 15 additions & 4 deletions src/ConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useCallback } from 'react';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { DataSourceOptions } from './types';
import { FieldSet, Form, InlineField, Input } from '@grafana/ui';
import { DataSourceOptions, DataSourceSecureOptions } from './types';
import { FieldSet, Form, InlineField, Input, SecretInput } from '@grafana/ui';

interface Props extends DataSourcePluginOptionsEditorProps<DataSourceOptions> {}
interface Props extends DataSourcePluginOptionsEditorProps<DataSourceOptions, DataSourceSecureOptions> { }

export const ConfigEditor = ({ options, onOptionsChange }: Props): JSX.Element => {
const onSettingsChange = useCallback(
(change: Partial<DataSourceSettings<DataSourceOptions>>) => {
(change: Partial<DataSourceSettings<DataSourceOptions, DataSourceSecureOptions>>) => {
onOptionsChange({
...options,
...change,
@@ -52,6 +52,17 @@ export const ConfigEditor = ({ options, onOptionsChange }: Props): JSX.Element =
}
/>
</InlineField>

<InlineField label="Password" labelWidth={20}>
<SecretInput
isConfigured={!!options.secureJsonData?.password ?? false}
onReset={() => onSettingsChange({ secureJsonData: { ...options.secureJsonData, password: undefined } })}
value={options.secureJsonData?.password}
onBlur={(event) =>
onSettingsChange({ secureJsonData: { ...options.secureJsonData, password: event.currentTarget.value } })
}
/>
</InlineField>
</FieldSet>
</>
)}
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -70,3 +70,10 @@ export interface DataSourceOptions extends DataSourceJsonData {
port?: number;
username?: string;
}

/**
* These are secure options configured for each DataSource instance.
*/
export interface DataSourceSecureOptions extends DataSourceJsonData {
password?: string;
}
Loading