Commit 42476811 by Sofia Papagiannaki Committed by GitHub

Cloudwatch: Fix loading custom credentials profile (#27684)

* Store credentials profile in JSON

* Update docs example

* Apply suggestions from code review

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
parent f0a586a9
...@@ -161,6 +161,7 @@ Since not all datasources have the same configuration settings we only have the ...@@ -161,6 +161,7 @@ Since not all datasources have the same configuration settings we only have the
| assumeRoleArn | string | Cloudwatch | ARN of Assume Role | | assumeRoleArn | string | Cloudwatch | ARN of Assume Role |
| defaultRegion | string | Cloudwatch | AWS region | | defaultRegion | string | Cloudwatch | AWS region |
| customMetricsNamespaces | string | Cloudwatch | Namespaces of Custom Metrics | | customMetricsNamespaces | string | Cloudwatch | Namespaces of Custom Metrics |
| profile | string | Cloudwatch | Custom credentials profile
| tsdbVersion | string | OpenTSDB | Version | | tsdbVersion | string | OpenTSDB | Version |
| tsdbResolution | string | OpenTSDB | Resolution | | tsdbResolution | string | OpenTSDB | Resolution |
| sslmode | string | PostgreSQL | SSLmode. 'disable', 'require', 'verify-ca' or 'verify-full' | | sslmode | string | PostgreSQL | SSLmode. 'disable', 'require', 'verify-ca' or 'verify-full' |
......
...@@ -372,7 +372,7 @@ It's now possible to configure data sources using config files with Grafana's pr ...@@ -372,7 +372,7 @@ It's now possible to configure data sources using config files with Grafana's pr
Here are some provisioning examples for this data source. Here are some provisioning examples for this data source.
### Using a credentials file ### Using credentials profile name (non-default)
```yaml ```yaml
apiVersion: 1 apiVersion: 1
...@@ -384,6 +384,7 @@ datasources: ...@@ -384,6 +384,7 @@ datasources:
authType: credentials authType: credentials
defaultRegion: eu-west-2 defaultRegion: eu-west-2
customMetricsNamespaces: 'CWAgent,CustomNameSpace' customMetricsNamespaces: 'CWAgent,CustomNameSpace'
profile: secondary
``` ```
### Using `accessKey` and `secretKey` ### Using `accessKey` and `secretKey`
......
...@@ -499,6 +499,7 @@ export interface MetricFindValue { ...@@ -499,6 +499,7 @@ export interface MetricFindValue {
export interface DataSourceJsonData { export interface DataSourceJsonData {
authType?: string; authType?: string;
defaultRegion?: string; defaultRegion?: string;
profile?: string;
} }
/** /**
......
...@@ -294,9 +294,14 @@ func (e *cloudWatchExecutor) getDSInfo(region string) *datasourceInfo { ...@@ -294,9 +294,14 @@ func (e *cloudWatchExecutor) getDSInfo(region string) *datasourceInfo {
accessKey := decrypted["accessKey"] accessKey := decrypted["accessKey"]
secretKey := decrypted["secretKey"] secretKey := decrypted["secretKey"]
profile := e.DataSource.JsonData.Get("profile").MustString()
if profile == "" {
profile = e.DataSource.Database // legacy support
}
return &datasourceInfo{ return &datasourceInfo{
Region: region, Region: region,
Profile: e.DataSource.Database, Profile: profile,
AuthType: authType, AuthType: authType,
AssumeRoleArn: assumeRoleArn, AssumeRoleArn: assumeRoleArn,
ExternalID: externalID, ExternalID: externalID,
......
...@@ -4,7 +4,6 @@ const { Select, Input } = LegacyForms; ...@@ -4,7 +4,6 @@ const { Select, Input } = LegacyForms;
import { import {
DataSourcePluginOptionsEditorProps, DataSourcePluginOptionsEditorProps,
onUpdateDatasourceJsonDataOptionSelect, onUpdateDatasourceJsonDataOptionSelect,
onUpdateDatasourceOption,
onUpdateDatasourceResetOption, onUpdateDatasourceResetOption,
onUpdateDatasourceJsonDataOption, onUpdateDatasourceJsonDataOption,
onUpdateDatasourceSecureJsonDataOption, onUpdateDatasourceSecureJsonDataOption,
...@@ -115,6 +114,10 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -115,6 +114,10 @@ export class ConfigEditor extends PureComponent<Props, State> {
const { regions } = this.state; const { regions } = this.state;
const { options } = this.props; const { options } = this.props;
const secureJsonData = (options.secureJsonData || {}) as CloudWatchSecureJsonData; const secureJsonData = (options.secureJsonData || {}) as CloudWatchSecureJsonData;
let profile = options.jsonData.profile;
if (!profile) {
profile = options.database;
}
return ( return (
<> <>
...@@ -151,8 +154,8 @@ export class ConfigEditor extends PureComponent<Props, State> { ...@@ -151,8 +154,8 @@ export class ConfigEditor extends PureComponent<Props, State> {
<Input <Input
className="width-30" className="width-30"
placeholder="default" placeholder="default"
value={options.jsonData.database} value={profile}
onChange={onUpdateDatasourceOption(this.props, 'database')} onChange={onUpdateDatasourceJsonDataOption(this.props, 'profile')}
/> />
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment