CloudWatch: de-duplicate implementation of AWSDatasourceSettings.Load in LoadCloudWatchSettings (#83556)
This commit is contained in:
@@ -25,18 +25,16 @@ type CloudWatchSettings struct {
|
||||
|
||||
func LoadCloudWatchSettings(ctx context.Context, config backend.DataSourceInstanceSettings) (CloudWatchSettings, error) {
|
||||
instance := CloudWatchSettings{}
|
||||
|
||||
if config.JSONData != nil && len(config.JSONData) > 1 {
|
||||
if err := json.Unmarshal(config.JSONData, &instance); err != nil {
|
||||
return CloudWatchSettings{}, fmt.Errorf("could not unmarshal DatasourceSettings json: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if instance.Region == "default" || instance.Region == "" {
|
||||
instance.Region = instance.DefaultRegion
|
||||
}
|
||||
|
||||
if instance.Profile == "" {
|
||||
instance.Profile = config.Database
|
||||
// load the instance using the loader for the wrapped awsds.AWSDatasourceSettings
|
||||
if err := instance.Load(config); err != nil {
|
||||
return CloudWatchSettings{}, err
|
||||
}
|
||||
|
||||
// logs timeout default is 30 minutes, the same as timeout in frontend logs query
|
||||
@@ -45,8 +43,6 @@ func LoadCloudWatchSettings(ctx context.Context, config backend.DataSourceInstan
|
||||
instance.LogsTimeout = Duration{30 * time.Minute}
|
||||
}
|
||||
|
||||
instance.AccessKey = config.DecryptedSecureJSONData["accessKey"]
|
||||
instance.SecretKey = config.DecryptedSecureJSONData["secretKey"]
|
||||
instance.GrafanaSettings = *awsds.ReadAuthSettings(ctx)
|
||||
|
||||
return instance, nil
|
||||
|
||||
Reference in New Issue
Block a user