diff --git a/pkg/registry/apis/datasource/converter_test.go b/pkg/registry/apis/datasource/converter_test.go index ebbc7cd9ca8..f3fd7fa2f5b 100644 --- a/pkg/registry/apis/datasource/converter_test.go +++ b/pkg/registry/apis/datasource/converter_test.go @@ -25,14 +25,14 @@ func TestConverter(t *testing.T) { } for _, name := range check { t.Run(name, func(t *testing.T) { - fpath := filepath.Join("testdata", name+"-input.json") + fpath := filepath.Join("testdata", name+".json") raw, err := os.ReadFile(fpath) // nolint:gosec require.NoError(t, err) err = json.Unmarshal(raw, obj) require.NoError(t, err) // The add command - fpath = filepath.Join("testdata", name+"-output-add.json") + fpath = filepath.Join("testdata", name+"-cmd-add.json") add, err := converter.toAddCommand(obj) require.NoError(t, err) out, err := json.MarshalIndent(add, "", " ") @@ -43,7 +43,7 @@ func TestConverter(t *testing.T) { } // The update command - fpath = filepath.Join("testdata", name+"-output-update.json") + fpath = filepath.Join("testdata", name+"-cmd-update.json") update, err := converter.toUpdateCommand(obj) require.NoError(t, err) out, err = json.MarshalIndent(update, "", " ") diff --git a/pkg/registry/apis/datasource/testdata/convert-testdata-A-input.json b/pkg/registry/apis/datasource/testdata/convert-testdata-A-input.json deleted file mode 100644 index 0305b386786..00000000000 --- a/pkg/registry/apis/datasource/testdata/convert-testdata-A-input.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "metadata": { - "name": "cejobd88i85j4d", - "namespace": "default", - "uid": "IGIUtEQS21DtLpBG2rSGfuDoUX8cwsGrtb5aXauYeA4X", - "resourceVersion": "1745320815000", - "generation": 2, - "creationTimestamp": "2025-04-22T11:20:11Z" - }, - "spec": { - "title": "grafana-testdata-datasource", - "access": "proxy", - "isDefault": true, - "url": "http://something/", - "database": "db", - "jsonData": { - "aaa": "bbb", - "bbb": true, - "ccc": 1.234 - } - }, - "secure": { - "password": { "input": "XXXX" } - } -} \ No newline at end of file diff --git a/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-add.json b/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-add.json deleted file mode 100644 index fdec9b140dc..00000000000 --- a/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-add.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "grafana-testdata-datasource", - "type": "test-datasource", - "access": "proxy", - "url": "http://something/", - "database": "db", - "user": "", - "basicAuth": false, - "basicAuthUser": "", - "withCredentials": false, - "isDefault": true, - "jsonData": { - "aaa": "bbb", - "bbb": true, - "ccc": 1.234 - }, - "secureJsonData": { - "password": "XXXX" - }, - "uid": "cejobd88i85j4d", - "apiVersion": "", - "IsPrunable": false -} \ No newline at end of file diff --git a/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-update.json b/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-update.json deleted file mode 100644 index 71515fe26b5..00000000000 --- a/pkg/registry/apis/datasource/testdata/convert-testdata-A-output-update.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "grafana-testdata-datasource", - "type": "test-datasource", - "access": "proxy", - "url": "http://something/", - "user": "", - "database": "db", - "basicAuth": false, - "basicAuthUser": "", - "withCredentials": false, - "isDefault": true, - "jsonData": { - "aaa": "bbb", - "bbb": true, - "ccc": 1.234 - }, - "secureJsonData": { - "password": "XXXX" - }, - "version": 2, - "uid": "cejobd88i85j4d", - "apiVersion": "", - "IsPrunable": false -} \ No newline at end of file diff --git a/pkg/services/datasources/models.go b/pkg/services/datasources/models.go index d81e99bdf11..00508f8c3ee 100644 --- a/pkg/services/datasources/models.go +++ b/pkg/services/datasources/models.go @@ -156,8 +156,8 @@ type AddDataSourceCommand struct { Type string `json:"type" binding:"Required"` Access DsAccess `json:"access" binding:"Required"` URL string `json:"url"` - Database string `json:"database"` User string `json:"user"` + Database string `json:"database"` BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser"` WithCredentials bool `json:"withCredentials"` @@ -166,9 +166,9 @@ type AddDataSourceCommand struct { SecureJsonData map[string]string `json:"secureJsonData"` UID string `json:"uid"` // swagger:ignore - APIVersion string `json:"apiVersion"` + APIVersion string `json:"apiVersion,omitempty"` // swagger:ignore - IsPrunable bool + IsPrunable bool `json:"-"` OrgID int64 `json:"-"` UserID int64 `json:"-"` @@ -191,12 +191,15 @@ type UpdateDataSourceCommand struct { IsDefault bool `json:"isDefault"` JsonData *simplejson.Json `json:"jsonData"` SecureJsonData map[string]string `json:"secureJsonData"` - Version int `json:"version"` UID string `json:"uid"` // swagger:ignore - APIVersion string `json:"apiVersion"` + APIVersion string `json:"apiVersion,omitempty"` // swagger:ignore - IsPrunable bool + IsPrunable bool `json:"-"` + // Everything above is identical in AddDataSourceCommand + + // The previous version -- used for optimistic locking + Version int `json:"version"` OrgID int64 `json:"-"` ID int64 `json:"-"`