diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 24f2fb24fb9..9bd1631214e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -104,6 +104,8 @@ /pkg/server/ @grafana/grafana-backend-group /pkg/apiserver @grafana/grafana-app-platform-squad /pkg/apimachinery @grafana/grafana-app-platform-squad +/pkg/apimachinery/identity/ @grafana/identity-access-team +/pkg/apimachinery/errutil/ @grafana/grafana-backend-group /pkg/promlib @grafana/observability-metrics /pkg/services/annotations/ @grafana/grafana-search-and-storage /pkg/services/apikey/ @grafana/identity-access-team diff --git a/conf/defaults.ini b/conf/defaults.ini index 966edbf4afc..898b0261fa2 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1399,6 +1399,23 @@ max_age = # Configures max number of alert annotations that Grafana stores. Default value is 0, which keeps all alert annotations. max_annotations_to_keep = +[recording_rules] +# Target URL (including write path) for recording rules. +url = + +# Optional username for basic authentication on recording rule write requests. Can be left blank to disable basic auth +basic_auth_username = + +# Optional assword for basic authentication on recording rule write requests. Can be left blank. +basic_auth_password = + +# Request timeout for recording rule writes. +timeout = 10s + +# Optional custom headers to include in recording rule write requests. +[recording_rules.custom_headers] +# exampleHeader = exampleValue + # NOTE: this configuration options are not used yet. [remote.alertmanager] diff --git a/conf/sample.ini b/conf/sample.ini index 40a3279a378..b1d61c44187 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -1389,6 +1389,24 @@ max_age = # Configures max number of alert annotations that Grafana stores. Default value is 0, which keeps all alert annotations. max_annotations_to_keep = +#################################### Recording Rules ##################### +[recording_rules] +# Target URL (including write path) for recording rules. +url = + +# Optional username for basic authentication on recording rule write requests. Can be left blank to disable basic auth +basic_auth_username = + +# Optional assword for basic authentication on recording rule write requests. Can be left blank. +basic_auth_password = + +# Request timeout for recording rule writes. +timeout = 30s + +# Optional custom headers to include in recording rule write requests. +[recording_rules.custom_headers] +# exampleHeader = exampleValue + #################################### Annotations ######################### [annotations] # Configures the batch size for the annotation clean-up job. This setting is used for dashboard, API, and alert annotations. diff --git a/packages/grafana-e2e-selectors/src/selectors/pages.ts b/packages/grafana-e2e-selectors/src/selectors/pages.ts index 574b8c3fd29..763c8b1bbb4 100644 --- a/packages/grafana-e2e-selectors/src/selectors/pages.ts +++ b/packages/grafana-e2e-selectors/src/selectors/pages.ts @@ -65,6 +65,7 @@ export const Pages = { menu: { container: 'data-testid new share button menu', shareInternally: 'data-testid new share button share internally', + shareExternally: 'data-testid new share button share externally', }, }, playlistControls: { @@ -280,6 +281,13 @@ export const Pages = { CopyUrlInput: 'data-testid snapshot copy url input', }, }, + ShareDashboardDrawer: { + ShareExternally: { + container: 'data-testid share externally drawer container', + copyUrlButton: 'data-testid share externally copy url button', + shareTypeSelect: 'data-testid share externally share type select', + }, + }, PublicDashboard: { page: 'public-dashboard-page', NotAvailable: { diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index e9c8c38ae0f..43acfb25fdb 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -215,7 +215,7 @@ export const Table = memo((props: Props) => { if (isCountRowsSet) { const footerItemsCountRows: FooterItem[] = []; - footerItemsCountRows[0] = headerGroups[0]?.headers[0]?.filteredRows.length.toString() ?? data.length.toString(); + footerItemsCountRows[0] = rows.length.toString() ?? data.length.toString(); setFooterItems(footerItemsCountRows); return; } @@ -287,7 +287,7 @@ export const Table = memo((props: Props) => { /> {isSmall ? null : (
- {itemsRangeStart} - {itemsRangeEnd} of {data.length} rows + {itemsRangeStart} - {itemsRangeEnd < rows.length ? itemsRangeEnd : rows.length} of {rows.length} rows
)} diff --git a/pkg/api/admin.go b/pkg/api/admin.go index da2d61c4306..1ede4f5e138 100644 --- a/pkg/api/admin.go +++ b/pkg/api/admin.go @@ -6,8 +6,8 @@ import ( "time" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/stats" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 380dee3a434..631b74a5bf6 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -14,12 +14,12 @@ import ( "github.com/grafana/grafana/pkg/api/apierrors" "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" dashboardsV0 "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1" "github.com/grafana/grafana/pkg/components/dashdiffs" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" dashver "github.com/grafana/grafana/pkg/services/dashboardversion" diff --git a/pkg/api/dashboard_permission.go b/pkg/api/dashboard_permission.go index 1754ef752b7..061a343330e 100644 --- a/pkg/api/dashboard_permission.go +++ b/pkg/api/dashboard_permission.go @@ -8,9 +8,9 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" diff --git a/pkg/api/dashboard_snapshot.go b/pkg/api/dashboard_snapshot.go index de672ba51aa..4e8acb6a3f3 100644 --- a/pkg/api/dashboard_snapshot.go +++ b/pkg/api/dashboard_snapshot.go @@ -19,7 +19,7 @@ import ( "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/util/errhttp" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/api/dashboard_test.go b/pkg/api/dashboard_test.go index 730beb90181..7b724e6209c 100644 --- a/pkg/api/dashboard_test.go +++ b/pkg/api/dashboard_test.go @@ -16,6 +16,7 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" @@ -29,7 +30,6 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/actest" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index c95aea33d87..4c207742c74 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -19,10 +19,10 @@ import ( "github.com/grafana/grafana/pkg/api/datasource" "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/log" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/api/ds_query.go b/pkg/api/ds_query.go index bac9342383f..77d02dc63fa 100644 --- a/pkg/api/ds_query.go +++ b/pkg/api/ds_query.go @@ -17,7 +17,7 @@ import ( contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/featuremgmt" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/util/errhttp" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/api/ds_query_test.go b/pkg/api/ds_query_test.go index 8139a4c7302..6c0067c2460 100644 --- a/pkg/api/ds_query_test.go +++ b/pkg/api/ds_query_test.go @@ -14,6 +14,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/db/dbtest" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/plugins" @@ -33,7 +34,6 @@ import ( secretstest "github.com/grafana/grafana/pkg/services/secrets/fakes" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web/webtest" ) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 8933f8b49bb..60a0d05335e 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -6,9 +6,9 @@ import ( "regexp" "strings" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/api/folder.go b/pkg/api/folder.go index 5b129f7c013..109281b1990 100644 --- a/pkg/api/folder.go +++ b/pkg/api/folder.go @@ -9,9 +9,9 @@ import ( "github.com/grafana/grafana/pkg/api/apierrors" "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" diff --git a/pkg/api/folder_permission.go b/pkg/api/folder_permission.go index 8901eaa3073..57e6aee6a60 100644 --- a/pkg/api/folder_permission.go +++ b/pkg/api/folder_permission.go @@ -8,8 +8,8 @@ import ( "github.com/grafana/grafana/pkg/api/apierrors" "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" diff --git a/pkg/api/index.go b/pkg/api/index.go index 23ce1e540e0..95a8c984ec0 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -10,9 +10,9 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/webassets" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/middleware" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/api/login.go b/pkg/api/login.go index 3dc203069c2..7123a3ba6de 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -10,11 +10,12 @@ import ( "strings" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/network" "github.com/grafana/grafana/pkg/middleware/cookies" "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -23,7 +24,6 @@ import ( "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/api/org.go b/pkg/api/org.go index 49a52e7cc78..e6b129dd7dc 100644 --- a/pkg/api/org.go +++ b/pkg/api/org.go @@ -8,8 +8,8 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/util" diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 0c058ec822d..706ef2ca64b 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -10,10 +10,10 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/metrics" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/api/org_users_test.go b/pkg/api/org_users_test.go index f3a3834b22f..ea5f4930661 100644 --- a/pkg/api/org_users_test.go +++ b/pkg/api/org_users_test.go @@ -13,12 +13,12 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db/dbtest" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/login/social" "github.com/grafana/grafana/pkg/login/social/socialtest" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -278,7 +278,7 @@ func TestOrgUsersAPIEndpoint_updateOrgRole(t *testing.T) { }) req := server.NewRequest(http.MethodPatch, fmt.Sprintf("/api/orgs/%d/users/%d", userRequesting.OrgID, userRequesting.ID), strings.NewReader(reqBody)) req.Header.Set("Content-Type", "application/json") - userWithPermissions.OrgRole = roletype.RoleAdmin + userWithPermissions.OrgRole = identity.RoleAdmin res, err := server.Send(webtest.RequestWithSignedInUser(req, userWithPermissions)) require.NoError(t, err) assert.Equal(t, tt.expectedCode, res.StatusCode) diff --git a/pkg/api/playlist.go b/pkg/api/playlist.go index 40daad0e6f5..b395fad006e 100644 --- a/pkg/api/playlist.go +++ b/pkg/api/playlist.go @@ -20,7 +20,7 @@ import ( contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/playlist" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/util/errhttp" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/api/pluginproxy/ds_proxy_test.go b/pkg/api/pluginproxy/ds_proxy_test.go index acd8e6cd8fe..03fa9f076cc 100644 --- a/pkg/api/pluginproxy/ds_proxy_test.go +++ b/pkg/api/pluginproxy/ds_proxy_test.go @@ -20,6 +20,7 @@ import ( "golang.org/x/oauth2" "github.com/grafana/grafana/pkg/api/datasource" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db/dbtest" @@ -30,7 +31,6 @@ import ( pluginfakes "github.com/grafana/grafana/pkg/plugins/manager/fakes" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/datasources" diff --git a/pkg/api/preferences.go b/pkg/api/preferences.go index 7cbbcfd1912..7df46bb25c1 100644 --- a/pkg/api/preferences.go +++ b/pkg/api/preferences.go @@ -6,8 +6,8 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/kinds/preferences" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" pref "github.com/grafana/grafana/pkg/services/preference" diff --git a/pkg/api/render.go b/pkg/api/render.go index 52b0214ca6c..ed2bb57a93b 100644 --- a/pkg/api/render.go +++ b/pkg/api/render.go @@ -7,8 +7,8 @@ import ( "strconv" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/models" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/util" diff --git a/pkg/api/response/response.go b/pkg/api/response/response.go index a1d9d243255..3d5b23a8fc9 100644 --- a/pkg/api/response/response.go +++ b/pkg/api/response/response.go @@ -12,10 +12,10 @@ import ( jsoniter "github.com/json-iterator/go" "gopkg.in/yaml.v3" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/middleware/requestmeta" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" - "github.com/grafana/grafana/pkg/util/errutil" ) var errRequestCanceledBase = errutil.ClientClosedRequest("api.requestCanceled", diff --git a/pkg/api/response/response_test.go b/pkg/api/response/response_test.go index ec0c318194e..277a719a8d2 100644 --- a/pkg/api/response/response_test.go +++ b/pkg/api/response/response_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) func TestErrors(t *testing.T) { diff --git a/pkg/api/signup.go b/pkg/api/signup.go index 3309a028e28..74cb5379c45 100644 --- a/pkg/api/signup.go +++ b/pkg/api/signup.go @@ -7,9 +7,9 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" tempuser "github.com/grafana/grafana/pkg/services/temp_user" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/api/user.go b/pkg/api/user.go index d7df33c38e2..32b9d5f5199 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -10,7 +10,7 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/api/user_token.go b/pkg/api/user_token.go index 0662abcf5d7..50b34ebfd0f 100644 --- a/pkg/api/user_token.go +++ b/pkg/api/user_token.go @@ -10,9 +10,9 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/network" "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/util/errutil/doc.go b/pkg/apimachinery/errutil/doc.go similarity index 100% rename from pkg/util/errutil/doc.go rename to pkg/apimachinery/errutil/doc.go diff --git a/pkg/util/errutil/errors.go b/pkg/apimachinery/errutil/errors.go similarity index 100% rename from pkg/util/errutil/errors.go rename to pkg/apimachinery/errutil/errors.go diff --git a/pkg/util/errutil/errors_example_test.go b/pkg/apimachinery/errutil/errors_example_test.go similarity index 96% rename from pkg/util/errutil/errors_example_test.go rename to pkg/apimachinery/errutil/errors_example_test.go index 14f35e9b5b9..9539baa7437 100644 --- a/pkg/util/errutil/errors_example_test.go +++ b/pkg/apimachinery/errutil/errors_example_test.go @@ -7,7 +7,7 @@ import ( "path" "strings" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/util/errutil/errors_test.go b/pkg/apimachinery/errutil/errors_test.go similarity index 100% rename from pkg/util/errutil/errors_test.go rename to pkg/apimachinery/errutil/errors_test.go diff --git a/pkg/util/errutil/log.go b/pkg/apimachinery/errutil/log.go similarity index 100% rename from pkg/util/errutil/log.go rename to pkg/apimachinery/errutil/log.go diff --git a/pkg/util/errutil/source.go b/pkg/apimachinery/errutil/source.go similarity index 100% rename from pkg/util/errutil/source.go rename to pkg/apimachinery/errutil/source.go diff --git a/pkg/util/errutil/status.go b/pkg/apimachinery/errutil/status.go similarity index 100% rename from pkg/util/errutil/status.go rename to pkg/apimachinery/errutil/status.go diff --git a/pkg/util/errutil/template.go b/pkg/apimachinery/errutil/template.go similarity index 100% rename from pkg/util/errutil/template.go rename to pkg/apimachinery/errutil/template.go diff --git a/pkg/util/errutil/template_test.go b/pkg/apimachinery/errutil/template_test.go similarity index 97% rename from pkg/util/errutil/template_test.go rename to pkg/apimachinery/errutil/template_test.go index 85fceac02b1..99d6a95d7e6 100644 --- a/pkg/util/errutil/template_test.go +++ b/pkg/apimachinery/errutil/template_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) func TestTemplate(t *testing.T) { diff --git a/pkg/apimachinery/identity/context.go b/pkg/apimachinery/identity/context.go new file mode 100644 index 00000000000..94cd9ecee02 --- /dev/null +++ b/pkg/apimachinery/identity/context.go @@ -0,0 +1,23 @@ +package identity + +import ( + "context" + "fmt" +) + +type ctxUserKey struct{} + +// WithRequester attaches the requester to the context. +func WithRequester(ctx context.Context, usr Requester) context.Context { + return context.WithValue(ctx, ctxUserKey{}, usr) +} + +// Get the Requester from context +func GetRequester(ctx context.Context) (Requester, error) { + // Set by appcontext.WithUser + u, ok := ctx.Value(ctxUserKey{}).(Requester) + if ok && u != nil { + return u, nil + } + return nil, fmt.Errorf("a Requester was not found in the context") +} diff --git a/pkg/apimachinery/identity/context_test.go b/pkg/apimachinery/identity/context_test.go new file mode 100644 index 00000000000..6464a7360fb --- /dev/null +++ b/pkg/apimachinery/identity/context_test.go @@ -0,0 +1,142 @@ +package identity_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/grafana/grafana/pkg/apimachinery/identity" +) + +func TestRequesterFromContext(t *testing.T) { + t.Run("User should error when context is missing user", func(t *testing.T) { + usr, err := identity.GetRequester(context.Background()) + require.Nil(t, usr) + require.Error(t, err) + }) + + t.Run("should return user set by ContextWithUser", func(t *testing.T) { + expected := &dummyUser{UID: "AAA"} + ctx := identity.WithRequester(context.Background(), expected) + actual, err := identity.GetRequester(ctx) + require.NoError(t, err) + require.Equal(t, expected.GetUID(), actual.GetUID()) + }) +} + +type dummyUser struct { + UID string +} + +// GetAuthID implements identity.Requester. +func (d *dummyUser) GetAuthID() string { + panic("unimplemented") +} + +// GetAuthenticatedBy implements identity.Requester. +func (d *dummyUser) GetAuthenticatedBy() string { + panic("unimplemented") +} + +// GetCacheKey implements identity.Requester. +func (d *dummyUser) GetCacheKey() string { + panic("unimplemented") +} + +// GetDisplayName implements identity.Requester. +func (d *dummyUser) GetDisplayName() string { + panic("unimplemented") +} + +// GetEmail implements identity.Requester. +func (d *dummyUser) GetEmail() string { + panic("unimplemented") +} + +// GetGlobalPermissions implements identity.Requester. +func (d *dummyUser) GetGlobalPermissions() map[string][]string { + panic("unimplemented") +} + +// GetID implements identity.Requester. +func (d *dummyUser) GetID() identity.NamespaceID { + panic("unimplemented") +} + +// GetIDToken implements identity.Requester. +func (d *dummyUser) GetIDToken() string { + panic("unimplemented") +} + +// GetIsGrafanaAdmin implements identity.Requester. +func (d *dummyUser) GetIsGrafanaAdmin() bool { + panic("unimplemented") +} + +// GetLogin implements identity.Requester. +func (d *dummyUser) GetLogin() string { + panic("unimplemented") +} + +// GetNamespacedID implements identity.Requester. +func (d *dummyUser) GetNamespacedID() (namespace identity.Namespace, identifier string) { + panic("unimplemented") +} + +// GetOrgID implements identity.Requester. +func (d *dummyUser) GetOrgID() int64 { + panic("unimplemented") +} + +// GetOrgName implements identity.Requester. +func (d *dummyUser) GetOrgName() string { + panic("unimplemented") +} + +// GetOrgRole implements identity.Requester. +func (d *dummyUser) GetOrgRole() identity.RoleType { + panic("unimplemented") +} + +// GetPermissions implements identity.Requester. +func (d *dummyUser) GetPermissions() map[string][]string { + panic("unimplemented") +} + +// GetTeams implements identity.Requester. +func (d *dummyUser) GetTeams() []int64 { + panic("unimplemented") +} + +// GetUID implements identity.Requester. +func (d *dummyUser) GetUID() identity.NamespaceID { + return identity.NewNamespaceIDString(identity.NamespaceUser, d.UID) +} + +// HasRole implements identity.Requester. +func (d *dummyUser) HasRole(role identity.RoleType) bool { + panic("unimplemented") +} + +// HasUniqueId implements identity.Requester. +func (d *dummyUser) HasUniqueId() bool { + panic("unimplemented") +} + +// IsAuthenticatedBy implements identity.Requester. +func (d *dummyUser) IsAuthenticatedBy(providers ...string) bool { + panic("unimplemented") +} + +// IsEmailVerified implements identity.Requester. +func (d *dummyUser) IsEmailVerified() bool { + panic("unimplemented") +} + +// IsNil implements identity.Requester. +func (d *dummyUser) IsNil() bool { + return false +} + +var _ identity.Requester = &dummyUser{} diff --git a/pkg/services/auth/identity/error.go b/pkg/apimachinery/identity/error.go similarity index 83% rename from pkg/services/auth/identity/error.go rename to pkg/apimachinery/identity/error.go index 1637af46402..91291e7bbb8 100644 --- a/pkg/services/auth/identity/error.go +++ b/pkg/apimachinery/identity/error.go @@ -3,7 +3,7 @@ package identity import ( "errors" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/auth/identity/namespace.go b/pkg/apimachinery/identity/namespace.go similarity index 100% rename from pkg/services/auth/identity/namespace.go rename to pkg/apimachinery/identity/namespace.go diff --git a/pkg/services/auth/identity/requester.go b/pkg/apimachinery/identity/requester.go similarity index 95% rename from pkg/services/auth/identity/requester.go rename to pkg/apimachinery/identity/requester.go index 1995769f81b..9791077fe5f 100644 --- a/pkg/services/auth/identity/requester.go +++ b/pkg/apimachinery/identity/requester.go @@ -3,15 +3,13 @@ package identity import ( "fmt" "strconv" - - "github.com/grafana/grafana/pkg/models/roletype" ) type Requester interface { // GetID returns namespaced id for the entity GetID() NamespaceID // GetNamespacedID returns the namespace and ID of the active entity. - // The namespace is one of the constants defined in pkg/services/auth/identity. + // The namespace is one of the constants defined in pkg/apimachinery/identity. // Deprecated: use GetID instead GetNamespacedID() (namespace Namespace, identifier string) // GetUID returns namespaced uid for the entity @@ -32,7 +30,7 @@ type Requester interface { // GetOrgID returns the ID of the active organization GetOrgID() int64 // GetOrgRole returns the role of the active entity in the active organization. - GetOrgRole() roletype.RoleType + GetOrgRole() RoleType // GetPermissions returns the permissions of the active entity. GetPermissions() map[string][]string // GetGlobalPermissions returns the permissions of the active entity that are available across all organizations. @@ -56,7 +54,7 @@ type Requester interface { // Legacy // HasRole returns true if the active entity has the given role in the active organization. - HasRole(role roletype.RoleType) bool + HasRole(role RoleType) bool // GetCacheKey returns a unique key for the entity. // Add an extra prefix to avoid collisions with other caches GetCacheKey() string diff --git a/pkg/models/roletype/role_type.go b/pkg/apimachinery/identity/role_type.go similarity index 98% rename from pkg/models/roletype/role_type.go rename to pkg/apimachinery/identity/role_type.go index b119eb58daa..d1688952b8d 100644 --- a/pkg/models/roletype/role_type.go +++ b/pkg/apimachinery/identity/role_type.go @@ -1,4 +1,4 @@ -package roletype +package identity import ( "fmt" diff --git a/pkg/expr/errors.go b/pkg/expr/errors.go index 3f162b7026c..9835f51184c 100644 --- a/pkg/expr/errors.go +++ b/pkg/expr/errors.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ErrSeriesMustBeWide = errors.New("input data must be a wide series") diff --git a/pkg/expr/errors_test.go b/pkg/expr/errors_test.go index 718d5383fcf..6da2889ba47 100644 --- a/pkg/expr/errors_test.go +++ b/pkg/expr/errors_test.go @@ -5,9 +5,10 @@ import ( "fmt" "testing" - "github.com/grafana/grafana/pkg/expr" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/stretchr/testify/require" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/expr" ) func TestQueryErrorType(t *testing.T) { diff --git a/pkg/expr/service.go b/pkg/expr/service.go index 01c88be979b..1f78491d9e3 100644 --- a/pkg/expr/service.go +++ b/pkg/expr/service.go @@ -9,10 +9,10 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/prometheus/client_golang/prometheus" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" diff --git a/pkg/expr/service_test.go b/pkg/expr/service_test.go index 5ff1e9fd4af..35378b289e8 100644 --- a/pkg/expr/service_test.go +++ b/pkg/expr/service_test.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/services/datasources" @@ -23,7 +24,6 @@ import ( "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) func TestService(t *testing.T) { diff --git a/pkg/expr/sql_command.go b/pkg/expr/sql_command.go index ce86d3258c6..05636f79ffc 100644 --- a/pkg/expr/sql_command.go +++ b/pkg/expr/sql_command.go @@ -9,10 +9,10 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/scottlepp/go-duck/duck" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/expr/mathexp" "github.com/grafana/grafana/pkg/expr/sql" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/util/errutil" ) // SQLCommand is an expression to run SQL over results diff --git a/pkg/expr/testing.go b/pkg/expr/testing.go index 412c38a2f26..d70dd097743 100644 --- a/pkg/expr/testing.go +++ b/pkg/expr/testing.go @@ -7,8 +7,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/expr/mathexp" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/expr/transform.go b/pkg/expr/transform.go index ac97c01930c..cbe60a3c894 100644 --- a/pkg/expr/transform.go +++ b/pkg/expr/transform.go @@ -8,7 +8,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/infra/appcontext/user.go b/pkg/infra/appcontext/user.go index d68071006de..c2a92da8d6a 100644 --- a/pkg/infra/appcontext/user.go +++ b/pkg/infra/appcontext/user.go @@ -7,7 +7,7 @@ import ( k8suser "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/endpoints/request" - "github.com/grafana/grafana/pkg/models/roletype" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" @@ -19,7 +19,8 @@ type ctxUserKey struct{} // WithUser adds the supplied SignedInUser to the context. func WithUser(ctx context.Context, usr *user.SignedInUser) context.Context { - return context.WithValue(ctx, ctxUserKey{}, usr) + ctx = context.WithValue(ctx, ctxUserKey{}, usr) + return identity.WithRequester(ctx, usr) } // User extracts the SignedInUser from the supplied context. @@ -57,7 +58,7 @@ func User(ctx context.Context) (*user.SignedInUser, error) { OrgID: orgId, Name: k8sUserInfo.GetName(), Login: k8sUserInfo.GetName(), - OrgRole: roletype.RoleAdmin, + OrgRole: identity.RoleAdmin, IsGrafanaAdmin: true, Permissions: map[int64]map[string][]string{ orgId: { diff --git a/pkg/infra/appcontext/user_test.go b/pkg/infra/appcontext/user_test.go index 6db4735b647..63300b13d17 100644 --- a/pkg/infra/appcontext/user_test.go +++ b/pkg/infra/appcontext/user_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/appcontext" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" @@ -35,6 +36,11 @@ func TestUserFromContext(t *testing.T) { actual, err := appcontext.User(ctx) require.NoError(t, err) require.Equal(t, expected.UserID, actual.UserID) + + // The requester is also in context + requester, err := identity.GetRequester(ctx) + require.NoError(t, err) + require.Equal(t, expected.GetUID(), requester.GetUID()) }) t.Run("should return user set by gRPC context", func(t *testing.T) { diff --git a/pkg/infra/db/sqlbuilder.go b/pkg/infra/db/sqlbuilder.go index b6d88a37879..0d9e655fe26 100644 --- a/pkg/infra/db/sqlbuilder.go +++ b/pkg/infra/db/sqlbuilder.go @@ -3,7 +3,7 @@ package db import ( "bytes" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" diff --git a/pkg/infra/tracing/tracing.go b/pkg/infra/tracing/tracing.go index f8f1db557f7..29dbee5e9e6 100644 --- a/pkg/infra/tracing/tracing.go +++ b/pkg/infra/tracing/tracing.go @@ -28,8 +28,8 @@ import ( "github.com/go-kit/log/level" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/login/social/connectors/azuread_oauth.go b/pkg/login/social/connectors/azuread_oauth.go index e6f0997357f..cd91c95e922 100644 --- a/pkg/login/social/connectors/azuread_oauth.go +++ b/pkg/login/social/connectors/azuread_oauth.go @@ -15,9 +15,9 @@ import ( "github.com/google/uuid" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/ssosettings" diff --git a/pkg/login/social/connectors/azuread_oauth_test.go b/pkg/login/social/connectors/azuread_oauth_test.go index d78bc202ea2..8a25f9491a2 100644 --- a/pkg/login/social/connectors/azuread_oauth_test.go +++ b/pkg/login/social/connectors/azuread_oauth_test.go @@ -16,9 +16,9 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/errors.go b/pkg/login/social/connectors/errors.go index 0673d0547de..ecd8e4cd1b0 100644 --- a/pkg/login/social/connectors/errors.go +++ b/pkg/login/social/connectors/errors.go @@ -3,7 +3,7 @@ package connectors import ( "errors" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/login/social/connectors/generic_oauth.go b/pkg/login/social/connectors/generic_oauth.go index 24feb363c0a..e9d7d1513eb 100644 --- a/pkg/login/social/connectors/generic_oauth.go +++ b/pkg/login/social/connectors/generic_oauth.go @@ -12,8 +12,8 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" ssoModels "github.com/grafana/grafana/pkg/services/ssosettings/models" diff --git a/pkg/login/social/connectors/generic_oauth_test.go b/pkg/login/social/connectors/generic_oauth_test.go index 5d764ef7541..5bcd8204d92 100644 --- a/pkg/login/social/connectors/generic_oauth_test.go +++ b/pkg/login/social/connectors/generic_oauth_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/github_oauth.go b/pkg/login/social/connectors/github_oauth.go index 757c2c71d84..80e840e80e4 100644 --- a/pkg/login/social/connectors/github_oauth.go +++ b/pkg/login/social/connectors/github_oauth.go @@ -12,8 +12,9 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/ssosettings" @@ -21,7 +22,6 @@ import ( "github.com/grafana/grafana/pkg/services/ssosettings/validation" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var ExtraGithubSettingKeys = map[string]ExtraKeyInfo{ diff --git a/pkg/login/social/connectors/github_oauth_test.go b/pkg/login/social/connectors/github_oauth_test.go index 11ee97347ef..e54d617c217 100644 --- a/pkg/login/social/connectors/github_oauth_test.go +++ b/pkg/login/social/connectors/github_oauth_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/gitlab_oauth.go b/pkg/login/social/connectors/gitlab_oauth.go index f934d01a27c..357ab458611 100644 --- a/pkg/login/social/connectors/gitlab_oauth.go +++ b/pkg/login/social/connectors/gitlab_oauth.go @@ -11,8 +11,8 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" ssoModels "github.com/grafana/grafana/pkg/services/ssosettings/models" diff --git a/pkg/login/social/connectors/gitlab_oauth_test.go b/pkg/login/social/connectors/gitlab_oauth_test.go index 3f638d1005e..3963864974d 100644 --- a/pkg/login/social/connectors/gitlab_oauth_test.go +++ b/pkg/login/social/connectors/gitlab_oauth_test.go @@ -15,8 +15,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/google_oauth.go b/pkg/login/social/connectors/google_oauth.go index fba95f5c640..ac369137ecf 100644 --- a/pkg/login/social/connectors/google_oauth.go +++ b/pkg/login/social/connectors/google_oauth.go @@ -10,14 +10,14 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" ssoModels "github.com/grafana/grafana/pkg/services/ssosettings/models" "github.com/grafana/grafana/pkg/services/ssosettings/validation" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/login/social/connectors/google_oauth_test.go b/pkg/login/social/connectors/google_oauth_test.go index a599e454a5b..4865c259674 100644 --- a/pkg/login/social/connectors/google_oauth_test.go +++ b/pkg/login/social/connectors/google_oauth_test.go @@ -14,8 +14,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/grafana_com_oauth.go b/pkg/login/social/connectors/grafana_com_oauth.go index 7371b5a2118..b6d4b32d3fa 100644 --- a/pkg/login/social/connectors/grafana_com_oauth.go +++ b/pkg/login/social/connectors/grafana_com_oauth.go @@ -8,9 +8,8 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/models/roletype" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" ssoModels "github.com/grafana/grafana/pkg/services/ssosettings/models" @@ -147,7 +146,7 @@ func (s *SocialGrafanaCom) UserInfo(ctx context.Context, client *http.Client, _ } if !s.info.SkipOrgRoleSync { - userInfo.OrgRoles = s.orgRoleMapper.MapOrgRoles(&MappingConfiguration{strictRoleMapping: false}, nil, roletype.RoleType(data.Role)) + userInfo.OrgRoles = s.orgRoleMapper.MapOrgRoles(&MappingConfiguration{strictRoleMapping: false}, nil, identity.RoleType(data.Role)) } if !s.isOrganizationMember(data.Orgs) { diff --git a/pkg/login/social/connectors/grafana_com_oauth_test.go b/pkg/login/social/connectors/grafana_com_oauth_test.go index a4fdb275e8c..a9ee26bbbd2 100644 --- a/pkg/login/social/connectors/grafana_com_oauth_test.go +++ b/pkg/login/social/connectors/grafana_com_oauth_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/okta_oauth.go b/pkg/login/social/connectors/okta_oauth.go index 45f787edc74..4110ef5fec7 100644 --- a/pkg/login/social/connectors/okta_oauth.go +++ b/pkg/login/social/connectors/okta_oauth.go @@ -10,8 +10,8 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" ssoModels "github.com/grafana/grafana/pkg/services/ssosettings/models" diff --git a/pkg/login/social/connectors/okta_oauth_test.go b/pkg/login/social/connectors/okta_oauth_test.go index c37f8f2e36f..69c94bdf3bc 100644 --- a/pkg/login/social/connectors/okta_oauth_test.go +++ b/pkg/login/social/connectors/okta_oauth_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgtest" diff --git a/pkg/login/social/connectors/social_base.go b/pkg/login/social/connectors/social_base.go index 6f801a02ad4..92fe4b6d6e7 100644 --- a/pkg/login/social/connectors/social_base.go +++ b/pkg/login/social/connectors/social_base.go @@ -17,9 +17,9 @@ import ( "golang.org/x/text/cases" "golang.org/x/text/language" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/ssosettings/validation" diff --git a/pkg/middleware/loggermw/logger.go b/pkg/middleware/loggermw/logger.go index 34dcab5066e..2262845a00d 100644 --- a/pkg/middleware/loggermw/logger.go +++ b/pkg/middleware/loggermw/logger.go @@ -25,7 +25,7 @@ import ( "github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware/requestmeta" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/contexthandler" diff --git a/pkg/middleware/loggermw/logger_test.go b/pkg/middleware/loggermw/logger_test.go index bd2a5272bd8..7f6bb5570c9 100644 --- a/pkg/middleware/loggermw/logger_test.go +++ b/pkg/middleware/loggermw/logger_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/plugins/errors.go b/pkg/plugins/errors.go index b9c86bdf2b5..f65beac7d2d 100644 --- a/pkg/plugins/errors.go +++ b/pkg/plugins/errors.go @@ -1,6 +1,6 @@ package plugins -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" var ( errPluginNotRegisteredBase = errutil.NotFound("plugin.notRegistered", diff --git a/pkg/plugins/repo/errors.go b/pkg/plugins/repo/errors.go index e6a873bc8f3..15c0db83068 100644 --- a/pkg/plugins/repo/errors.go +++ b/pkg/plugins/repo/errors.go @@ -3,7 +3,7 @@ package repo import ( "fmt" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) type ErrResponse4xx struct { diff --git a/pkg/plugins/repo/errors_test.go b/pkg/plugins/repo/errors_test.go index a20298cee23..7e10ed587b8 100644 --- a/pkg/plugins/repo/errors_test.go +++ b/pkg/plugins/repo/errors_test.go @@ -5,8 +5,9 @@ import ( "net/http" "testing" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/stretchr/testify/require" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) func TestErrResponse4xx(t *testing.T) { diff --git a/pkg/registry/apis/dashboard/sub_access.go b/pkg/registry/apis/dashboard/sub_access.go index 3436a3f1fc8..21fbbbe480e 100644 --- a/pkg/registry/apis/dashboard/sub_access.go +++ b/pkg/registry/apis/dashboard/sub_access.go @@ -8,11 +8,11 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" + "github.com/grafana/grafana/pkg/apimachinery/identity" dashboard "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1" "github.com/grafana/grafana/pkg/infra/appcontext" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" - "github.com/grafana/grafana/pkg/services/auth/identity" dashboardssvc "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/guardian" ) diff --git a/pkg/registry/apis/dashboardsnapshot/register.go b/pkg/registry/apis/dashboardsnapshot/register.go index c9414687aa3..7d884889ad1 100644 --- a/pkg/registry/apis/dashboardsnapshot/register.go +++ b/pkg/registry/apis/dashboardsnapshot/register.go @@ -33,7 +33,7 @@ import ( "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/util/errhttp" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/registry/apis/featuretoggle/current.go b/pkg/registry/apis/featuretoggle/current.go index 97d59a76a1e..a05fb62f4c2 100644 --- a/pkg/registry/apis/featuretoggle/current.go +++ b/pkg/registry/apis/featuretoggle/current.go @@ -12,6 +12,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/apis/featuretoggle/v0alpha1" "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" "github.com/grafana/grafana/pkg/infra/appcontext" @@ -19,8 +20,7 @@ import ( "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/util/errhttp" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/registry/apis/query/errors.go b/pkg/registry/apis/query/errors.go index 7fc7036c324..23cbc1c6709 100644 --- a/pkg/registry/apis/query/errors.go +++ b/pkg/registry/apis/query/errors.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var QueryError = errutil.BadRequest("query.error").MustTemplate( diff --git a/pkg/registry/apis/query/errors_test.go b/pkg/registry/apis/query/errors_test.go index f44c601b41c..e96c591c2ad 100644 --- a/pkg/registry/apis/query/errors_test.go +++ b/pkg/registry/apis/query/errors_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/expr" - "github.com/grafana/grafana/pkg/util/errutil" ) func TestQueryErrorType(t *testing.T) { diff --git a/pkg/services/accesscontrol/accesscontrol.go b/pkg/services/accesscontrol/accesscontrol.go index 80a9781867b..66593e0335b 100644 --- a/pkg/services/accesscontrol/accesscontrol.go +++ b/pkg/services/accesscontrol/accesscontrol.go @@ -6,8 +6,8 @@ import ( "fmt" "strings" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/registry" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/accesscontrol/acimpl/accesscontrol.go b/pkg/services/accesscontrol/acimpl/accesscontrol.go index 374c844c4c6..fe2d8697972 100644 --- a/pkg/services/accesscontrol/acimpl/accesscontrol.go +++ b/pkg/services/accesscontrol/acimpl/accesscontrol.go @@ -6,10 +6,10 @@ import ( "github.com/prometheus/client_golang/prometheus" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" ) diff --git a/pkg/services/accesscontrol/acimpl/service.go b/pkg/services/accesscontrol/acimpl/service.go index ae8db4b6d11..eb9010513aa 100644 --- a/pkg/services/accesscontrol/acimpl/service.go +++ b/pkg/services/accesscontrol/acimpl/service.go @@ -11,6 +11,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" @@ -23,7 +24,6 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/database" "github.com/grafana/grafana/pkg/services/accesscontrol/migrator" "github.com/grafana/grafana/pkg/services/accesscontrol/pluginutils" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/accesscontrol/acimpl/service_test.go b/pkg/services/accesscontrol/acimpl/service_test.go index ffe845519d9..7c6e18a4d6c 100644 --- a/pkg/services/accesscontrol/acimpl/service_test.go +++ b/pkg/services/accesscontrol/acimpl/service_test.go @@ -9,17 +9,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" "github.com/grafana/grafana/pkg/services/accesscontrol/database" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/licensing" "github.com/grafana/grafana/pkg/services/user" @@ -396,7 +395,7 @@ func TestService_SearchUsersPermissions(t *testing.T) { siuPermissions: listAllPerms, searchOption: searchOption, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, accesscontrol.RoleGrafanaAdmin: {Permissions: []accesscontrol.Permission{ @@ -404,8 +403,8 @@ func TestService_SearchUsersPermissions(t *testing.T) { }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ 2: {{Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, @@ -422,8 +421,8 @@ func TestService_SearchUsersPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:*"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ 1: {{Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}}, @@ -436,7 +435,7 @@ func TestService_SearchUsersPermissions(t *testing.T) { siuPermissions: listAllPerms, searchOption: searchOption, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, accesscontrol.RoleGrafanaAdmin: {Permissions: []accesscontrol.Permission{ @@ -449,8 +448,8 @@ func TestService_SearchUsersPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:id:1"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ 1: {{Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}}, @@ -465,13 +464,13 @@ func TestService_SearchUsersPermissions(t *testing.T) { siuPermissions: listAllPerms, searchOption: accesscontrol.SearchOptions{Scope: "teams:id:2"}, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ 2: {{Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}}, @@ -492,7 +491,7 @@ func TestService_SearchUsersPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:id:1"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, + 1: {string(identity.RoleEditor)}, 2: {accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ @@ -544,10 +543,10 @@ func TestService_SearchUsersPermissions(t *testing.T) { siuPermissions: listAllPerms, searchOption: accesscontrol.SearchOptions{NamespacedID: fmt.Sprintf("%s:1", identity.NamespaceServiceAccount)}, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsWrite, Scope: "teams:*"}, }}, accesscontrol.RoleGrafanaAdmin: {Permissions: []accesscontrol.Permission{ @@ -560,8 +559,8 @@ func TestService_SearchUsersPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:id:1"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: map[int64][]accesscontrol.Permission{ 1: {{Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}, {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}}, @@ -617,10 +616,10 @@ func TestService_SearchUserPermissions(t *testing.T) { NamespacedID: fmt.Sprintf("%s:2", identity.NamespaceUser), }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsCreate}, }}, - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, accesscontrol.RoleGrafanaAdmin: {Permissions: []accesscontrol.Permission{ @@ -628,8 +627,8 @@ func TestService_SearchUserPermissions(t *testing.T) { }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, @@ -647,8 +646,8 @@ func TestService_SearchUserPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:*"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, @@ -662,7 +661,7 @@ func TestService_SearchUserPermissions(t *testing.T) { NamespacedID: fmt.Sprintf("%s:2", identity.NamespaceUser), }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleAdmin): {Permissions: []accesscontrol.Permission{ + string(identity.RoleAdmin): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, }}, accesscontrol.RoleGrafanaAdmin: {Permissions: []accesscontrol.Permission{ @@ -675,8 +674,8 @@ func TestService_SearchUserPermissions(t *testing.T) { {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:id:1"}}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, - 2: {string(roletype.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, + 1: {string(identity.RoleEditor)}, + 2: {string(identity.RoleAdmin), accesscontrol.RoleGrafanaAdmin}, }, want: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}, @@ -692,7 +691,7 @@ func TestService_SearchUserPermissions(t *testing.T) { NamespacedID: fmt.Sprintf("%s:1", identity.NamespaceUser), }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, {Action: accesscontrol.ActionUsersCreate}, {Action: accesscontrol.ActionTeamsPermissionsRead, Scope: "teams:*"}, @@ -700,7 +699,7 @@ func TestService_SearchUserPermissions(t *testing.T) { }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, + 1: {string(identity.RoleEditor)}, }, want: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, @@ -714,7 +713,7 @@ func TestService_SearchUserPermissions(t *testing.T) { NamespacedID: fmt.Sprintf("%s:1", identity.NamespaceUser), }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:*"}, {Action: accesscontrol.ActionUsersCreate}, {Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}, @@ -722,7 +721,7 @@ func TestService_SearchUserPermissions(t *testing.T) { }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, + 1: {string(identity.RoleEditor)}, }, want: []accesscontrol.Permission{ {Action: accesscontrol.ActionTeamsRead, Scope: "teams:id:1"}, @@ -741,12 +740,12 @@ func TestService_SearchUserPermissions(t *testing.T) { "dashboards:edit": {"dashboards:read", "dashboards:write", "dashboards:read-advanced"}, }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: "dashboards:read", Scope: "dashboards:uid:ram"}, }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, + 1: {string(identity.RoleEditor)}, }, storedPerms: map[int64][]accesscontrol.Permission{ 1: { @@ -775,12 +774,12 @@ func TestService_SearchUserPermissions(t *testing.T) { "dashboards:edit": {"dashboards:read", "dashboards:write"}, }, ramRoles: map[string]*accesscontrol.RoleDTO{ - string(roletype.RoleEditor): {Permissions: []accesscontrol.Permission{ + string(identity.RoleEditor): {Permissions: []accesscontrol.Permission{ {Action: "dashboards:read", Scope: "dashboards:uid:ram"}, }}, }, storedRoles: map[int64][]string{ - 1: {string(roletype.RoleEditor)}, + 1: {string(identity.RoleEditor)}, }, storedPerms: map[int64][]accesscontrol.Permission{ 1: { diff --git a/pkg/services/accesscontrol/actest/fake.go b/pkg/services/accesscontrol/actest/fake.go index 7b8059f23f1..d916f553f32 100644 --- a/pkg/services/accesscontrol/actest/fake.go +++ b/pkg/services/accesscontrol/actest/fake.go @@ -3,8 +3,8 @@ package actest import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" ) var _ accesscontrol.Service = new(FakeService) diff --git a/pkg/services/accesscontrol/cacheutils.go b/pkg/services/accesscontrol/cacheutils.go index 40119929090..9326d9d88c8 100644 --- a/pkg/services/accesscontrol/cacheutils.go +++ b/pkg/services/accesscontrol/cacheutils.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) func GetPermissionCacheKey(user identity.Requester) string { diff --git a/pkg/services/accesscontrol/cacheutils_test.go b/pkg/services/accesscontrol/cacheutils_test.go index e97037da3fc..91416b51223 100644 --- a/pkg/services/accesscontrol/cacheutils_test.go +++ b/pkg/services/accesscontrol/cacheutils_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" ) diff --git a/pkg/services/accesscontrol/database/database_test.go b/pkg/services/accesscontrol/database/database_test.go index a45a967a1ca..8f8b237cd35 100644 --- a/pkg/services/accesscontrol/database/database_test.go +++ b/pkg/services/accesscontrol/database/database_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/database" rs "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/accesscontrol/errors.go b/pkg/services/accesscontrol/errors.go index 1152c6f6fa0..34534bda777 100644 --- a/pkg/services/accesscontrol/errors.go +++ b/pkg/services/accesscontrol/errors.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) const ( diff --git a/pkg/services/accesscontrol/filter.go b/pkg/services/accesscontrol/filter.go index f91e91b6a94..934b3ad9636 100644 --- a/pkg/services/accesscontrol/filter.go +++ b/pkg/services/accesscontrol/filter.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) var sqlIDAcceptList = map[string]struct{}{ diff --git a/pkg/services/accesscontrol/middleware.go b/pkg/services/accesscontrol/middleware.go index 714f37b9041..59e117a0895 100644 --- a/pkg/services/accesscontrol/middleware.go +++ b/pkg/services/accesscontrol/middleware.go @@ -14,10 +14,10 @@ import ( "text/template" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/middleware/cookies" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/accesscontrol/mock/mock.go b/pkg/services/accesscontrol/mock/mock.go index 2390df1f1d7..6ceda3a6700 100644 --- a/pkg/services/accesscontrol/mock/mock.go +++ b/pkg/services/accesscontrol/mock/mock.go @@ -4,10 +4,10 @@ import ( "context" "errors" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/user" ) diff --git a/pkg/services/accesscontrol/mock/service_mock.go b/pkg/services/accesscontrol/mock/service_mock.go index 6232e7df8a5..87961115f76 100644 --- a/pkg/services/accesscontrol/mock/service_mock.go +++ b/pkg/services/accesscontrol/mock/service_mock.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/mock" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" ) var _ accesscontrol.PermissionsService = new(MockPermissionsService) diff --git a/pkg/services/accesscontrol/models.go b/pkg/services/accesscontrol/models.go index d59230e5443..8076ef98fe6 100644 --- a/pkg/services/accesscontrol/models.go +++ b/pkg/services/accesscontrol/models.go @@ -7,10 +7,10 @@ import ( "strings" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/slugify" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/org" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/accesscontrol/ossaccesscontrol/permissions_services.go b/pkg/services/accesscontrol/ossaccesscontrol/permissions_services.go index 0e28a6a5316..a9d9325a41c 100644 --- a/pkg/services/accesscontrol/ossaccesscontrol/permissions_services.go +++ b/pkg/services/accesscontrol/ossaccesscontrol/permissions_services.go @@ -7,11 +7,11 @@ import ( "strconv" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/datasources" diff --git a/pkg/services/accesscontrol/resourcepermissions/error.go b/pkg/services/accesscontrol/resourcepermissions/error.go index 985fd51cf08..258f563413d 100644 --- a/pkg/services/accesscontrol/resourcepermissions/error.go +++ b/pkg/services/accesscontrol/resourcepermissions/error.go @@ -1,7 +1,7 @@ package resourcepermissions import ( - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) const ( diff --git a/pkg/services/accesscontrol/resourcepermissions/models.go b/pkg/services/accesscontrol/resourcepermissions/models.go index 35b6f584e20..260448394d8 100644 --- a/pkg/services/accesscontrol/resourcepermissions/models.go +++ b/pkg/services/accesscontrol/resourcepermissions/models.go @@ -1,8 +1,8 @@ package resourcepermissions import ( + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" ) type SetResourcePermissionCommand struct { diff --git a/pkg/services/accesscontrol/resourcepermissions/service.go b/pkg/services/accesscontrol/resourcepermissions/service.go index fc25f9ce2c6..2d3a2de07ec 100644 --- a/pkg/services/accesscontrol/resourcepermissions/service.go +++ b/pkg/services/accesscontrol/resourcepermissions/service.go @@ -7,10 +7,10 @@ import ( "sort" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/licensing" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/annotations/accesscontrol/accesscontrol.go b/pkg/services/annotations/accesscontrol/accesscontrol.go index d0d22703414..206ef49a10b 100644 --- a/pkg/services/annotations/accesscontrol/accesscontrol.go +++ b/pkg/services/annotations/accesscontrol/accesscontrol.go @@ -3,6 +3,7 @@ package accesscontrol import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/db" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/annotations" @@ -10,7 +11,6 @@ import ( "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/sqlstore/permissions" "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/annotations/annotations.go b/pkg/services/annotations/annotations.go index 08e0b635847..ab88cfa5ce0 100644 --- a/pkg/services/annotations/annotations.go +++ b/pkg/services/annotations/annotations.go @@ -4,8 +4,8 @@ import ( "context" "errors" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/annotations/annotationsimpl/loki/historian_store.go b/pkg/services/annotations/annotationsimpl/loki/historian_store.go index 1c4cf9da98c..1fca8d4f176 100644 --- a/pkg/services/annotations/annotationsimpl/loki/historian_store.go +++ b/pkg/services/annotations/annotationsimpl/loki/historian_store.go @@ -8,11 +8,12 @@ import ( "sort" "time" + "golang.org/x/exp/constraints" + "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/services/annotations/accesscontrol" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ngalert" - "golang.org/x/exp/constraints" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" @@ -24,9 +25,9 @@ import ( "github.com/prometheus/client_golang/prometheus" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/annotations/annotationsimpl/xorm_store.go b/pkg/services/annotations/annotationsimpl/xorm_store.go index 6ae9ddc3ce1..b7e4ff911b9 100644 --- a/pkg/services/annotations/annotationsimpl/xorm_store.go +++ b/pkg/services/annotations/annotationsimpl/xorm_store.go @@ -12,10 +12,10 @@ import ( "github.com/grafana/grafana/pkg/services/annotations/accesscontrol" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/annotations" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/annotations/models.go b/pkg/services/annotations/models.go index 2b1325b4f3c..f994875c58e 100644 --- a/pkg/services/annotations/models.go +++ b/pkg/services/annotations/models.go @@ -1,8 +1,8 @@ package annotations import ( + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/services/auth/identity" ) type ItemQuery struct { diff --git a/pkg/services/anonymous/anonimpl/client.go b/pkg/services/anonymous/anonimpl/client.go index ac20182b00f..b6fd22271a1 100644 --- a/pkg/services/anonymous/anonimpl/client.go +++ b/pkg/services/anonymous/anonimpl/client.go @@ -6,14 +6,14 @@ import ( "net/http" "strings" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/anonymous" "github.com/grafana/grafana/pkg/services/anonymous/anonimpl/anonstore" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/anonymous/sortopts/sortopts.go b/pkg/services/anonymous/sortopts/sortopts.go index 4ebb16e4929..3b922de5002 100644 --- a/pkg/services/anonymous/sortopts/sortopts.go +++ b/pkg/services/anonymous/sortopts/sortopts.go @@ -5,10 +5,11 @@ import ( "sort" "strings" - "github.com/grafana/grafana/pkg/services/search/model" - "github.com/grafana/grafana/pkg/util/errutil" "golang.org/x/text/cases" "golang.org/x/text/language" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/services/search/model" ) var ( diff --git a/pkg/services/apikey/apikeyimpl/store_test.go b/pkg/services/apikey/apikeyimpl/store_test.go index 3b5089526cd..d7ae8f27069 100644 --- a/pkg/services/apikey/apikeyimpl/store_test.go +++ b/pkg/services/apikey/apikeyimpl/store_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/apikey" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/tests/testsuite" ) diff --git a/pkg/services/apikey/model.go b/pkg/services/apikey/model.go index c9457b8e845..e5af5731c81 100644 --- a/pkg/services/apikey/model.go +++ b/pkg/services/apikey/model.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/quota" ) diff --git a/pkg/services/auth/authtest/testing.go b/pkg/services/auth/authtest/testing.go index 9f834382f27..d5ffa7ae8ff 100644 --- a/pkg/services/auth/authtest/testing.go +++ b/pkg/services/auth/authtest/testing.go @@ -7,8 +7,8 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/services/auth/gcomsso/gcom_logout_hook.go b/pkg/services/auth/gcomsso/gcom_logout_hook.go index 620bfde0bcc..eb1d2e8db11 100644 --- a/pkg/services/auth/gcomsso/gcom_logout_hook.go +++ b/pkg/services/auth/gcomsso/gcom_logout_hook.go @@ -8,8 +8,8 @@ import ( "log/slog" "net/http" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/auth/id.go b/pkg/services/auth/id.go index d40f5d4db41..63fa61c05c9 100644 --- a/pkg/services/auth/id.go +++ b/pkg/services/auth/id.go @@ -5,7 +5,7 @@ import ( authnlib "github.com/grafana/authlib/authn" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) type IDService interface { diff --git a/pkg/services/auth/idimpl/service.go b/pkg/services/auth/idimpl/service.go index ea833d8f88c..95f19f8181c 100644 --- a/pkg/services/auth/idimpl/service.go +++ b/pkg/services/auth/idimpl/service.go @@ -11,11 +11,11 @@ import ( "github.com/prometheus/client_golang/prometheus" "golang.org/x/sync/singleflight" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/auth/idtest/mock.go b/pkg/services/auth/idtest/mock.go index c6a2aca8c03..2613d6a7690 100644 --- a/pkg/services/auth/idtest/mock.go +++ b/pkg/services/auth/idtest/mock.go @@ -3,8 +3,8 @@ package idtest import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/auth/identity" ) var _ auth.IDService = (*MockService)(nil) diff --git a/pkg/services/authn/authn.go b/pkg/services/authn/authn.go index 5897056b5be..15974b1b983 100644 --- a/pkg/services/authn/authn.go +++ b/pkg/services/authn/authn.go @@ -9,9 +9,9 @@ import ( "time" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/middleware/cookies" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/web" diff --git a/pkg/services/authn/authnimpl/service.go b/pkg/services/authn/authnimpl/service.go index 1ad86ef9d33..27aab40a4f0 100644 --- a/pkg/services/authn/authnimpl/service.go +++ b/pkg/services/authn/authnimpl/service.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/network" "github.com/grafana/grafana/pkg/infra/tracing" @@ -21,7 +22,6 @@ import ( "github.com/grafana/grafana/pkg/services/authn/clients" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/authn/authnimpl/service_test.go b/pkg/services/authn/authnimpl/service_test.go index 748d0d3ebc6..9dc1ebedd17 100644 --- a/pkg/services/authn/authnimpl/service_test.go +++ b/pkg/services/authn/authnimpl/service_test.go @@ -15,12 +15,12 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace/tracetest" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/models/usertoken" "github.com/grafana/grafana/pkg/services/auth" "github.com/grafana/grafana/pkg/services/auth/authtest" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/authn/authntest" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/services/authn/authnimpl/sync/org_sync_test.go b/pkg/services/authn/authnimpl/sync/org_sync_test.go index f8b774696d9..d6b6799e881 100644 --- a/pkg/services/authn/authnimpl/sync/org_sync_test.go +++ b/pkg/services/authn/authnimpl/sync/org_sync_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" "github.com/grafana/grafana/pkg/services/authn" @@ -79,7 +79,7 @@ func TestOrgSync_SyncOrgRolesHook(t *testing.T) { Login: "test", Name: "test", Email: "test", - OrgRoles: map[int64]roletype.RoleType{1: org.RoleAdmin, 2: org.RoleEditor}, + OrgRoles: map[int64]identity.RoleType{1: org.RoleAdmin, 2: org.RoleEditor}, IsGrafanaAdmin: ptrBool(false), ClientParams: authn.ClientParams{ SyncOrgRoles: true, @@ -95,7 +95,7 @@ func TestOrgSync_SyncOrgRolesHook(t *testing.T) { Login: "test", Name: "test", Email: "test", - OrgRoles: map[int64]roletype.RoleType{1: org.RoleAdmin, 2: org.RoleEditor}, + OrgRoles: map[int64]identity.RoleType{1: org.RoleAdmin, 2: org.RoleEditor}, OrgID: 1, //set using org IsGrafanaAdmin: ptrBool(false), ClientParams: authn.ClientParams{ diff --git a/pkg/services/authn/authnimpl/sync/rbac_sync.go b/pkg/services/authn/authnimpl/sync/rbac_sync.go index e410799c223..537238b838f 100644 --- a/pkg/services/authn/authnimpl/sync/rbac_sync.go +++ b/pkg/services/authn/authnimpl/sync/rbac_sync.go @@ -4,12 +4,12 @@ import ( "context" "errors" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/authn/authnimpl/sync/user_sync.go b/pkg/services/authn/authnimpl/sync/user_sync.go index fb2c0b02b29..cbc818f6592 100644 --- a/pkg/services/authn/authnimpl/sync/user_sync.go +++ b/pkg/services/authn/authnimpl/sync/user_sync.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/services/user" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/authn/authntest/fake.go b/pkg/services/authn/authntest/fake.go index b27e0199d17..73219cf245c 100644 --- a/pkg/services/authn/authntest/fake.go +++ b/pkg/services/authn/authntest/fake.go @@ -3,8 +3,8 @@ package authntest import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" ) diff --git a/pkg/services/authn/authntest/mock.go b/pkg/services/authn/authntest/mock.go index ef47e21f94a..177fc7c722a 100644 --- a/pkg/services/authn/authntest/mock.go +++ b/pkg/services/authn/authntest/mock.go @@ -3,8 +3,8 @@ package authntest import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" ) diff --git a/pkg/services/authn/clients/api_key.go b/pkg/services/authn/clients/api_key.go index 5f549151b81..b8095831c75 100644 --- a/pkg/services/authn/clients/api_key.go +++ b/pkg/services/authn/clients/api_key.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/components/apikeygen" "github.com/grafana/grafana/pkg/components/satokengen" "github.com/grafana/grafana/pkg/infra/log" @@ -14,7 +15,6 @@ import ( "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/authn/clients/basic.go b/pkg/services/authn/clients/basic.go index e714cc03765..f27d15672e8 100644 --- a/pkg/services/authn/clients/basic.go +++ b/pkg/services/authn/clients/basic.go @@ -3,8 +3,8 @@ package clients import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/authn" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/authn/clients/constants.go b/pkg/services/authn/clients/constants.go index f2fee7a82d8..8a1840baae8 100644 --- a/pkg/services/authn/clients/constants.go +++ b/pkg/services/authn/clients/constants.go @@ -1,6 +1,6 @@ package clients -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" const ( basicPrefix = "Basic " diff --git a/pkg/services/authn/clients/ext_jwt.go b/pkg/services/authn/clients/ext_jwt.go index 04d82c61957..f58fc48b892 100644 --- a/pkg/services/authn/clients/ext_jwt.go +++ b/pkg/services/authn/clients/ext_jwt.go @@ -8,12 +8,13 @@ import ( "github.com/go-jose/go-jose/v3/jwt" authlib "github.com/grafana/authlib/authn" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var _ authn.Client = new(ExtendedJWT) diff --git a/pkg/services/authn/clients/form.go b/pkg/services/authn/clients/form.go index b64e2b06ef7..af9fb33fb23 100644 --- a/pkg/services/authn/clients/form.go +++ b/pkg/services/authn/clients/form.go @@ -3,8 +3,8 @@ package clients import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/authn" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/authn/clients/jwt.go b/pkg/services/authn/clients/jwt.go index 3e49d31d379..430985d7ae1 100644 --- a/pkg/services/authn/clients/jwt.go +++ b/pkg/services/authn/clients/jwt.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/auth" authJWT "github.com/grafana/grafana/pkg/services/auth/jwt" @@ -13,7 +14,6 @@ import ( "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) const authQueryParamName = "auth_token" diff --git a/pkg/services/authn/clients/jwt_test.go b/pkg/services/authn/clients/jwt_test.go index 538ffb26e65..73cac5818f2 100644 --- a/pkg/services/authn/clients/jwt_test.go +++ b/pkg/services/authn/clients/jwt_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/models/roletype" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/auth/jwt" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" @@ -38,7 +38,7 @@ func TestAuthenticateJWT(t *testing.T) { wantID: &authn.Identity{ OrgID: 0, OrgName: "", - OrgRoles: map[int64]roletype.RoleType{1: roletype.RoleAdmin}, + OrgRoles: map[int64]identity.RoleType{1: identity.RoleAdmin}, Groups: []string{"foo", "bar"}, Login: "eai-doe", Name: "Eai Doe", @@ -90,7 +90,7 @@ func TestAuthenticateJWT(t *testing.T) { wantID: &authn.Identity{ OrgID: 0, OrgName: "", - OrgRoles: map[int64]roletype.RoleType{1: roletype.RoleAdmin}, + OrgRoles: map[int64]identity.RoleType{1: identity.RoleAdmin}, Login: "eai-doe", Groups: []string{}, Name: "Eai Doe", diff --git a/pkg/services/authn/clients/oauth.go b/pkg/services/authn/clients/oauth.go index bad7d9ddc8e..5929b0d8382 100644 --- a/pkg/services/authn/clients/oauth.go +++ b/pkg/services/authn/clients/oauth.go @@ -13,16 +13,16 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/login/social" "github.com/grafana/grafana/pkg/login/social/connectors" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/oauthtoken" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/authn/clients/oauth_test.go b/pkg/services/authn/clients/oauth_test.go index 95838da0159..cb3c9aa225c 100644 --- a/pkg/services/authn/clients/oauth_test.go +++ b/pkg/services/authn/clients/oauth_test.go @@ -14,9 +14,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" "github.com/grafana/grafana/pkg/login/social/socialtest" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/login" diff --git a/pkg/services/authn/clients/password.go b/pkg/services/authn/clients/password.go index a809686a5dd..a44f8615086 100644 --- a/pkg/services/authn/clients/password.go +++ b/pkg/services/authn/clients/password.go @@ -4,10 +4,10 @@ import ( "context" "errors" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/loginattempt" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/authn/clients/proxy.go b/pkg/services/authn/clients/proxy.go index 3878ba96f6f..dd691e4df32 100644 --- a/pkg/services/authn/clients/proxy.go +++ b/pkg/services/authn/clients/proxy.go @@ -12,13 +12,13 @@ import ( "strings" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/authn/clients/render.go b/pkg/services/authn/clients/render.go index 9e7dccb1dee..fc3040401cf 100644 --- a/pkg/services/authn/clients/render.go +++ b/pkg/services/authn/clients/render.go @@ -4,11 +4,11 @@ import ( "context" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/rendering" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/authn/error.go b/pkg/services/authn/error.go index 053ceeacfab..7f922f8cd51 100644 --- a/pkg/services/authn/error.go +++ b/pkg/services/authn/error.go @@ -1,6 +1,6 @@ package authn -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" var ( ErrTokenNeedsRotation = errutil.Unauthorized("session.token.rotate", errutil.WithLogLevel(errutil.LevelDebug)) diff --git a/pkg/services/authn/identity.go b/pkg/services/authn/identity.go index ef63f5f0de1..6133b58d1d1 100644 --- a/pkg/services/authn/identity.go +++ b/pkg/services/authn/identity.go @@ -6,8 +6,8 @@ import ( "golang.org/x/oauth2" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/models/usertoken" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/services/authn/namespace.go b/pkg/services/authn/namespace.go index 48e8717933e..336fec15c46 100644 --- a/pkg/services/authn/namespace.go +++ b/pkg/services/authn/namespace.go @@ -1,7 +1,7 @@ package authn import ( - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) const ( diff --git a/pkg/services/cloudmigration/cmsclient/client.go b/pkg/services/cloudmigration/cmsclient/client.go index 1694a3112f7..8b6bd7a0599 100644 --- a/pkg/services/cloudmigration/cmsclient/client.go +++ b/pkg/services/cloudmigration/cmsclient/client.go @@ -3,8 +3,8 @@ package cmsclient import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/cloudmigration" - "github.com/grafana/grafana/pkg/util/errutil" ) type Client interface { diff --git a/pkg/services/cloudmigration/model.go b/pkg/services/cloudmigration/model.go index 0b58b1e1c71..bbeb59bc133 100644 --- a/pkg/services/cloudmigration/model.go +++ b/pkg/services/cloudmigration/model.go @@ -5,7 +5,7 @@ import ( "errors" "time" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/contexthandler/contexthandler.go b/pkg/services/contexthandler/contexthandler.go index b0b10d213d8..c6bf3137864 100644 --- a/pkg/services/contexthandler/contexthandler.go +++ b/pkg/services/contexthandler/contexthandler.go @@ -10,9 +10,9 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" diff --git a/pkg/services/contexthandler/model/model.go b/pkg/services/contexthandler/model/model.go index e7b9ebc8c78..e24375ef80e 100644 --- a/pkg/services/contexthandler/model/model.go +++ b/pkg/services/contexthandler/model/model.go @@ -7,13 +7,13 @@ import ( "github.com/prometheus/client_golang/prometheus" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/models/usertoken" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/dashboardimport/dashboardimport.go b/pkg/services/dashboardimport/dashboardimport.go index 32ccfd9f3ff..d16e0230bf5 100644 --- a/pkg/services/dashboardimport/dashboardimport.go +++ b/pkg/services/dashboardimport/dashboardimport.go @@ -3,8 +3,8 @@ package dashboardimport import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/services/auth/identity" ) // ImportDashboardInput definition of input parameters when importing a dashboard. diff --git a/pkg/services/dashboardimport/service/service.go b/pkg/services/dashboardimport/service/service.go index ebd98259f79..7eeefed6585 100644 --- a/pkg/services/dashboardimport/service/service.go +++ b/pkg/services/dashboardimport/service/service.go @@ -4,10 +4,10 @@ import ( "context" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboardimport" "github.com/grafana/grafana/pkg/services/dashboardimport/api" "github.com/grafana/grafana/pkg/services/dashboardimport/utils" diff --git a/pkg/services/dashboardimport/service/service_test.go b/pkg/services/dashboardimport/service/service_test.go index e8958f22c9c..1aa249ddeac 100644 --- a/pkg/services/dashboardimport/service/service_test.go +++ b/pkg/services/dashboardimport/service/service_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboardimport" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" diff --git a/pkg/services/dashboards/dashboard.go b/pkg/services/dashboards/dashboard.go index 99517ea951f..1104dc7f059 100644 --- a/pkg/services/dashboards/dashboard.go +++ b/pkg/services/dashboards/dashboard.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/services/search/model" diff --git a/pkg/services/dashboards/dashboard_service_mock.go b/pkg/services/dashboards/dashboard_service_mock.go index 0c79642d270..6645b4cdd24 100644 --- a/pkg/services/dashboards/dashboard_service_mock.go +++ b/pkg/services/dashboards/dashboard_service_mock.go @@ -5,7 +5,7 @@ package dashboards import ( context "context" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" mock "github.com/stretchr/testify/mock" model "github.com/grafana/grafana/pkg/services/search/model" diff --git a/pkg/services/dashboards/models.go b/pkg/services/dashboards/models.go index 30fae0deafc..9428fd961e5 100644 --- a/pkg/services/dashboards/models.go +++ b/pkg/services/dashboards/models.go @@ -4,11 +4,11 @@ import ( "fmt" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/slugify" "github.com/grafana/grafana/pkg/models" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 57507af88db..7871776d224 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -13,10 +13,10 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend/gtime" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/datasources" diff --git a/pkg/services/dashboards/service/dashboard_service_integration_test.go b/pkg/services/dashboards/service/dashboard_service_integration_test.go index 448dad895b6..f20bc83d245 100644 --- a/pkg/services/dashboards/service/dashboard_service_integration_test.go +++ b/pkg/services/dashboards/service/dashboard_service_integration_test.go @@ -8,12 +8,12 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/dashboardsnapshots/database/database.go b/pkg/services/dashboardsnapshots/database/database.go index f3e32c23934..94a38fb9444 100644 --- a/pkg/services/dashboardsnapshots/database/database.go +++ b/pkg/services/dashboardsnapshots/database/database.go @@ -4,10 +4,10 @@ import ( "context" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboardsnapshots" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/dashboardsnapshots/errors.go b/pkg/services/dashboardsnapshots/errors.go index e2750d610a6..794dc8fd652 100644 --- a/pkg/services/dashboardsnapshots/errors.go +++ b/pkg/services/dashboardsnapshots/errors.go @@ -1,7 +1,7 @@ package dashboardsnapshots import ( - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ErrBaseNotFound = errutil.NotFound("dashboardsnapshots.not-found", errutil.WithPublicMessage("Snapshot not found")) diff --git a/pkg/services/dashboardsnapshots/models.go b/pkg/services/dashboardsnapshots/models.go index 7e4becec46b..1972552f398 100644 --- a/pkg/services/dashboardsnapshots/models.go +++ b/pkg/services/dashboardsnapshots/models.go @@ -3,9 +3,9 @@ package dashboardsnapshots import ( "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" dashboardsnapshot "github.com/grafana/grafana/pkg/apis/dashboardsnapshot/v0alpha1" "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/services/auth/identity" ) // DashboardSnapshot model diff --git a/pkg/services/dashboardsnapshots/service.go b/pkg/services/dashboardsnapshots/service.go index 8299fa19ce9..80f8e58197c 100644 --- a/pkg/services/dashboardsnapshots/service.go +++ b/pkg/services/dashboardsnapshots/service.go @@ -10,11 +10,11 @@ import ( "time" common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/identity" dashboardsnapshot "github.com/grafana/grafana/pkg/apis/dashboardsnapshot/v0alpha1" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/datasources/datasources.go b/pkg/services/datasources/datasources.go index 67bdf3a595d..5b45fd4d96a 100644 --- a/pkg/services/datasources/datasources.go +++ b/pkg/services/datasources/datasources.go @@ -6,8 +6,8 @@ import ( sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/httpclient" - "github.com/grafana/grafana/pkg/services/auth/identity" ) // DataSourceService interface for interacting with datasources. diff --git a/pkg/services/datasources/errors.go b/pkg/services/datasources/errors.go index c7f7e9c9aa7..e4db5a71d0f 100644 --- a/pkg/services/datasources/errors.go +++ b/pkg/services/datasources/errors.go @@ -3,7 +3,7 @@ package datasources import ( "errors" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/datasources/fakes/fake_cache_service.go b/pkg/services/datasources/fakes/fake_cache_service.go index ec0521aced7..1f647e0b12f 100644 --- a/pkg/services/datasources/fakes/fake_cache_service.go +++ b/pkg/services/datasources/fakes/fake_cache_service.go @@ -3,7 +3,7 @@ package datasources import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/services/datasources/guardian/provider.go b/pkg/services/datasources/guardian/provider.go index d2cd4d529ac..261d7d02755 100644 --- a/pkg/services/datasources/guardian/provider.go +++ b/pkg/services/datasources/guardian/provider.go @@ -1,7 +1,7 @@ package guardian import ( - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/services/datasources/service/cache.go b/pkg/services/datasources/service/cache.go index bb56d0fd8e3..618e2953dcc 100644 --- a/pkg/services/datasources/service/cache.go +++ b/pkg/services/datasources/service/cache.go @@ -5,10 +5,10 @@ import ( "fmt" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources/guardian" ) diff --git a/pkg/services/datasources/service/datasource.go b/pkg/services/datasources/service/datasource.go index b6eef68eeb3..3e4fd62fea7 100644 --- a/pkg/services/datasources/service/datasource.go +++ b/pkg/services/datasources/service/datasource.go @@ -15,6 +15,7 @@ import ( sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" sdkproxy "github.com/grafana/grafana-plugin-sdk-go/backend/proxy" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/httpclient" @@ -30,7 +31,6 @@ import ( "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/services/secrets/kvstore" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/extsvcauth/errors.go b/pkg/services/extsvcauth/errors.go index f1af61f4f0c..b8abae42b57 100644 --- a/pkg/services/extsvcauth/errors.go +++ b/pkg/services/extsvcauth/errors.go @@ -1,6 +1,6 @@ package extsvcauth -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" var ( ErrUnknownProvider = errutil.BadRequest("extsvcauth.unknown-provider") diff --git a/pkg/services/folder/folderimpl/folder.go b/pkg/services/folder/folderimpl/folder.go index 138de76c327..8dd76b6505f 100644 --- a/pkg/services/folder/folderimpl/folder.go +++ b/pkg/services/folder/folderimpl/folder.go @@ -15,12 +15,12 @@ import ( "github.com/prometheus/client_golang/prometheus" "golang.org/x/exp/slices" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/folder/model.go b/pkg/services/folder/model.go index 892c0e6ebed..55cb98dac3e 100644 --- a/pkg/services/folder/model.go +++ b/pkg/services/folder/model.go @@ -4,12 +4,12 @@ import ( "fmt" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/slugify" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var ErrMaximumDepthReached = errutil.BadRequest("folder.maximum-depth-reached", errutil.WithPublicMessage("Maximum nested folder depth reached")) diff --git a/pkg/services/folder/registry.go b/pkg/services/folder/registry.go index d87b4945761..0dbc1a4f4d9 100644 --- a/pkg/services/folder/registry.go +++ b/pkg/services/folder/registry.go @@ -3,7 +3,7 @@ package folder import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) type RegistryService interface { diff --git a/pkg/services/guardian/accesscontrol_guardian.go b/pkg/services/guardian/accesscontrol_guardian.go index 0378d0d12b6..d9d80b660c6 100644 --- a/pkg/services/guardian/accesscontrol_guardian.go +++ b/pkg/services/guardian/accesscontrol_guardian.go @@ -4,9 +4,9 @@ import ( "context" "errors" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/guardian/guardian.go b/pkg/services/guardian/guardian.go index 0d393820eeb..e094674d07e 100644 --- a/pkg/services/guardian/guardian.go +++ b/pkg/services/guardian/guardian.go @@ -4,11 +4,11 @@ import ( "context" "slices" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/guardian/provider.go b/pkg/services/guardian/provider.go index 060f4b360a7..ad07caf0695 100644 --- a/pkg/services/guardian/provider.go +++ b/pkg/services/guardian/provider.go @@ -3,8 +3,8 @@ package guardian import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/team" diff --git a/pkg/services/ldap/ldap_test.go b/pkg/services/ldap/ldap_test.go index 516f7869c40..11a38172608 100644 --- a/pkg/services/ldap/ldap_test.go +++ b/pkg/services/ldap/ldap_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/setting" ) @@ -526,7 +526,7 @@ func TestServer_Users(t *testing.T) { require.Len(t, res[0].OrgRoles, 1) role, mappingExist := res[0].OrgRoles[2] require.True(t, mappingExist) - require.Equal(t, roletype.RoleAdmin, role) + require.Equal(t, identity.RoleAdmin, role) require.False(t, res[0].IsDisabled) require.NotNil(t, res[0].IsGrafanaAdmin) assert.True(t, *res[0].IsGrafanaAdmin) @@ -540,7 +540,7 @@ func TestServer_Users(t *testing.T) { require.Len(t, res[0].OrgRoles, 1) role, mappingExist := res[0].OrgRoles[2] require.True(t, mappingExist) - require.Equal(t, roletype.RoleEditor, role) + require.Equal(t, identity.RoleEditor, role) require.False(t, res[0].IsDisabled) require.NotNil(t, res[0].IsGrafanaAdmin) assert.False(t, *res[0].IsGrafanaAdmin) diff --git a/pkg/services/libraryelements/database.go b/pkg/services/libraryelements/database.go index 7056348ff58..16150219e17 100644 --- a/pkg/services/libraryelements/database.go +++ b/pkg/services/libraryelements/database.go @@ -9,11 +9,11 @@ import ( "time" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/kinds/librarypanel" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/libraryelements/guard.go b/pkg/services/libraryelements/guard.go index 9e0b6e7af29..41df9c47049 100644 --- a/pkg/services/libraryelements/guard.go +++ b/pkg/services/libraryelements/guard.go @@ -3,8 +3,8 @@ package libraryelements import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/libraryelements/model" diff --git a/pkg/services/libraryelements/libraryelements.go b/pkg/services/libraryelements/libraryelements.go index 864f951ac75..6108e585ef0 100644 --- a/pkg/services/libraryelements/libraryelements.go +++ b/pkg/services/libraryelements/libraryelements.go @@ -5,10 +5,10 @@ import ( "encoding/json" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/libraryelements/model" diff --git a/pkg/services/librarypanels/librarypanels.go b/pkg/services/librarypanels/librarypanels.go index 91fd6107a5d..c7b2802edf9 100644 --- a/pkg/services/librarypanels/librarypanels.go +++ b/pkg/services/librarypanels/librarypanels.go @@ -8,11 +8,11 @@ import ( "strings" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/libraryelements" diff --git a/pkg/services/live/features/broadcast.go b/pkg/services/live/features/broadcast.go index 51cdd46e2a4..fc9bbc56f2b 100644 --- a/pkg/services/live/features/broadcast.go +++ b/pkg/services/live/features/broadcast.go @@ -5,8 +5,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/live/model" ) diff --git a/pkg/services/live/features/dashboard.go b/pkg/services/live/features/dashboard.go index f6e3b8df26e..c91a54c84f0 100644 --- a/pkg/services/live/features/dashboard.go +++ b/pkg/services/live/features/dashboard.go @@ -8,8 +8,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/live/model" diff --git a/pkg/services/live/features/plugin.go b/pkg/services/live/features/plugin.go index ee0afd60a16..de7a55ea2ab 100644 --- a/pkg/services/live/features/plugin.go +++ b/pkg/services/live/features/plugin.go @@ -7,8 +7,8 @@ import ( "github.com/centrifugal/centrifuge" "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/live/model" "github.com/grafana/grafana/pkg/services/live/orgchannel" "github.com/grafana/grafana/pkg/services/live/runstream" diff --git a/pkg/services/live/features/plugin_mock.go b/pkg/services/live/features/plugin_mock.go index e436c04f742..2be70496d5c 100644 --- a/pkg/services/live/features/plugin_mock.go +++ b/pkg/services/live/features/plugin_mock.go @@ -10,7 +10,7 @@ import ( gomock "github.com/golang/mock/gomock" backend "github.com/grafana/grafana-plugin-sdk-go/backend" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" ) // MockPluginContextGetter is a mock of PluginContextGetter interface. diff --git a/pkg/services/live/live.go b/pkg/services/live/live.go index 975613835ad..cb0b656a142 100644 --- a/pkg/services/live/live.go +++ b/pkg/services/live/live.go @@ -24,6 +24,8 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" @@ -33,7 +35,6 @@ import ( "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/annotations" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" @@ -56,7 +57,6 @@ import ( "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/live/livecontext/context.go b/pkg/services/live/livecontext/context.go index 0b4df1ef451..b7c18394cab 100644 --- a/pkg/services/live/livecontext/context.go +++ b/pkg/services/live/livecontext/context.go @@ -3,7 +3,7 @@ package livecontext import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) type signedUserContextKeyType int diff --git a/pkg/services/live/liveplugin/plugin.go b/pkg/services/live/liveplugin/plugin.go index 17dc25ecaa7..48179e9c3d9 100644 --- a/pkg/services/live/liveplugin/plugin.go +++ b/pkg/services/live/liveplugin/plugin.go @@ -7,7 +7,7 @@ import ( "github.com/centrifugal/centrifuge" "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/live/orgchannel" "github.com/grafana/grafana/pkg/services/live/pipeline" diff --git a/pkg/services/live/managedstream/runner.go b/pkg/services/live/managedstream/runner.go index 393a261dd5e..ae61d11bdeb 100644 --- a/pkg/services/live/managedstream/runner.go +++ b/pkg/services/live/managedstream/runner.go @@ -12,8 +12,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/grafana/grafana-plugin-sdk-go/live" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/live/model" "github.com/grafana/grafana/pkg/services/live/orgchannel" ) diff --git a/pkg/services/live/model/model.go b/pkg/services/live/model/model.go index b6b58733204..03e7ddcf4eb 100644 --- a/pkg/services/live/model/model.go +++ b/pkg/services/live/model/model.go @@ -7,7 +7,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) // ChannelPublisher writes data into a channel. Note that permissions are not checked. diff --git a/pkg/services/live/pipeline/auth.go b/pkg/services/live/pipeline/auth.go index 8d6e3efec6a..4c2e1d822b7 100644 --- a/pkg/services/live/pipeline/auth.go +++ b/pkg/services/live/pipeline/auth.go @@ -3,7 +3,7 @@ package pipeline import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/org" ) diff --git a/pkg/services/live/pipeline/pipeline.go b/pkg/services/live/pipeline/pipeline.go index 9eae295ee02..64b4c7050a2 100644 --- a/pkg/services/live/pipeline/pipeline.go +++ b/pkg/services/live/pipeline/pipeline.go @@ -17,7 +17,7 @@ import ( semconv "go.opentelemetry.io/otel/semconv/v1.17.0" "go.opentelemetry.io/otel/trace" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/live/model" ) diff --git a/pkg/services/live/pipeline/subscribe_builtin.go b/pkg/services/live/pipeline/subscribe_builtin.go index f594f8d393d..e9888c59305 100644 --- a/pkg/services/live/pipeline/subscribe_builtin.go +++ b/pkg/services/live/pipeline/subscribe_builtin.go @@ -6,7 +6,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/live" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/live/livecontext" "github.com/grafana/grafana/pkg/services/live/model" ) diff --git a/pkg/services/live/runstream/manager.go b/pkg/services/live/runstream/manager.go index b5f21b4814c..0d404ca1ead 100644 --- a/pkg/services/live/runstream/manager.go +++ b/pkg/services/live/runstream/manager.go @@ -10,9 +10,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" ) var ( diff --git a/pkg/services/live/runstream/manager_test.go b/pkg/services/live/runstream/manager_test.go index e2459724ac1..084794bbe6d 100644 --- a/pkg/services/live/runstream/manager_test.go +++ b/pkg/services/live/runstream/manager_test.go @@ -10,7 +10,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/user" ) diff --git a/pkg/services/live/runstream/mock.go b/pkg/services/live/runstream/mock.go index 32de8b10d7a..683e5f90ed1 100644 --- a/pkg/services/live/runstream/mock.go +++ b/pkg/services/live/runstream/mock.go @@ -10,7 +10,7 @@ import ( gomock "github.com/golang/mock/gomock" backend "github.com/grafana/grafana-plugin-sdk-go/backend" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" ) // MockChannelLocalPublisher is a mock of ChannelLocalPublisher interface. diff --git a/pkg/services/login/authinfoimpl/service.go b/pkg/services/login/authinfoimpl/service.go index 4bd5814302b..b153b3fb58a 100644 --- a/pkg/services/login/authinfoimpl/service.go +++ b/pkg/services/login/authinfoimpl/service.go @@ -7,12 +7,12 @@ import ( "strconv" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/services/user" - "github.com/grafana/grafana/pkg/util/errutil" ) type Service struct { diff --git a/pkg/services/navtree/navtreeimpl/applinks_test.go b/pkg/services/navtree/navtreeimpl/applinks_test.go index 9712e5555a1..0b87ea27064 100644 --- a/pkg/services/navtree/navtreeimpl/applinks_test.go +++ b/pkg/services/navtree/navtreeimpl/applinks_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/plugins" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" @@ -411,7 +411,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { Type: "page", AddToNav: true, DefaultNav: true, - Role: roletype.RoleEditor, + Role: identity.RoleEditor, Action: catalogReadAction, }, { @@ -419,7 +419,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { Path: "/a/test-app1/page2", Type: "page", AddToNav: true, - Role: roletype.RoleViewer, + Role: identity.RoleViewer, }, }, }, @@ -445,7 +445,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { t.Run("Should not add app links when the user cannot access app plugins", func(t *testing.T) { treeRoot := navtree.NavTreeRoot{} user.Permissions = map[int64]map[string][]string{} - user.OrgRole = roletype.RoleAdmin + user.OrgRole = identity.RoleAdmin err := service.addAppLinks(&treeRoot, reqCtx) require.NoError(t, err) @@ -456,7 +456,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { user.Permissions = map[int64]map[string][]string{ 1: {pluginaccesscontrol.ActionAppAccess: []string{"*"}}, } - user.OrgRole = roletype.RoleEditor + user.OrgRole = identity.RoleEditor err := service.addAppLinks(&treeRoot, reqCtx) require.NoError(t, err) @@ -472,7 +472,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { user.Permissions = map[int64]map[string][]string{ 1: {pluginaccesscontrol.ActionAppAccess: []string{"*"}}, } - user.OrgRole = roletype.RoleViewer + user.OrgRole = identity.RoleViewer err := service.addAppLinks(&treeRoot, reqCtx) require.NoError(t, err) @@ -487,7 +487,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { user.Permissions = map[int64]map[string][]string{ 1: {pluginaccesscontrol.ActionAppAccess: []string{"*"}, catalogReadAction: []string{}}, } - user.OrgRole = roletype.RoleViewer + user.OrgRole = identity.RoleViewer service.features = featuremgmt.WithFeatures(featuremgmt.FlagAccessControlOnCall) err := service.addAppLinks(&treeRoot, reqCtx) @@ -504,7 +504,7 @@ func TestAddAppLinksAccessControl(t *testing.T) { user.Permissions = map[int64]map[string][]string{ 1: {pluginaccesscontrol.ActionAppAccess: []string{"*"}}, } - user.OrgRole = roletype.RoleEditor + user.OrgRole = identity.RoleEditor service.features = featuremgmt.WithFeatures(featuremgmt.FlagAccessControlOnCall) err := service.addAppLinks(&treeRoot, reqCtx) diff --git a/pkg/services/navtree/navtreeimpl/navtree.go b/pkg/services/navtree/navtreeimpl/navtree.go index 4526465de90..102e4fe953e 100644 --- a/pkg/services/navtree/navtreeimpl/navtree.go +++ b/pkg/services/navtree/navtreeimpl/navtree.go @@ -4,11 +4,11 @@ import ( "sort" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/kvstore" "github.com/grafana/grafana/pkg/infra/log" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/apikey" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" diff --git a/pkg/services/ngalert/accesscontrol/accesscontrol.go b/pkg/services/ngalert/accesscontrol/accesscontrol.go index d779acdccd1..72f3663a18d 100644 --- a/pkg/services/ngalert/accesscontrol/accesscontrol.go +++ b/pkg/services/ngalert/accesscontrol/accesscontrol.go @@ -1,9 +1,10 @@ package accesscontrol import ( - "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "golang.org/x/net/context" + + "github.com/grafana/grafana/pkg/apimachinery/identity" + "github.com/grafana/grafana/pkg/services/accesscontrol" ) type genericService struct { diff --git a/pkg/services/ngalert/accesscontrol/fakes/rules.go b/pkg/services/ngalert/accesscontrol/fakes/rules.go index 75eab9cbc6a..f666419beca 100644 --- a/pkg/services/ngalert/accesscontrol/fakes/rules.go +++ b/pkg/services/ngalert/accesscontrol/fakes/rules.go @@ -3,8 +3,8 @@ package fakes import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/store" diff --git a/pkg/services/ngalert/accesscontrol/fakes/silences.go b/pkg/services/ngalert/accesscontrol/fakes/silences.go index 0a14248e470..4920f59ab06 100644 --- a/pkg/services/ngalert/accesscontrol/fakes/silences.go +++ b/pkg/services/ngalert/accesscontrol/fakes/silences.go @@ -3,7 +3,7 @@ package fakes import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/ngalert/models" ) diff --git a/pkg/services/ngalert/accesscontrol/models.go b/pkg/services/ngalert/accesscontrol/models.go index 49188277da4..9768378364e 100644 --- a/pkg/services/ngalert/accesscontrol/models.go +++ b/pkg/services/ngalert/accesscontrol/models.go @@ -3,8 +3,8 @@ package accesscontrol import ( "fmt" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/ngalert/accesscontrol/rules.go b/pkg/services/ngalert/accesscontrol/rules.go index 35b2246e091..998b30f56a0 100644 --- a/pkg/services/ngalert/accesscontrol/rules.go +++ b/pkg/services/ngalert/accesscontrol/rules.go @@ -5,9 +5,9 @@ import ( "golang.org/x/net/context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/accesscontrol/rules_test.go b/pkg/services/ngalert/accesscontrol/rules_test.go index 43c94073089..5a5a4e17bde 100644 --- a/pkg/services/ngalert/accesscontrol/rules_test.go +++ b/pkg/services/ngalert/accesscontrol/rules_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/folder" diff --git a/pkg/services/ngalert/accesscontrol/silences.go b/pkg/services/ngalert/accesscontrol/silences.go index 9d6eb83373f..39326649062 100644 --- a/pkg/services/ngalert/accesscontrol/silences.go +++ b/pkg/services/ngalert/accesscontrol/silences.go @@ -6,8 +6,8 @@ import ( "golang.org/x/exp/maps" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/ngalert/models" ) diff --git a/pkg/services/ngalert/accesscontrol/silences_test.go b/pkg/services/ngalert/accesscontrol/silences_test.go index 3d87bc75688..126d9a4ab78 100644 --- a/pkg/services/ngalert/accesscontrol/silences_test.go +++ b/pkg/services/ngalert/accesscontrol/silences_test.go @@ -10,8 +10,9 @@ import ( "github.com/stretchr/testify/require" alertingModels "github.com/grafana/alerting/models" + + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/ngalert/accesscontrol/testing.go b/pkg/services/ngalert/accesscontrol/testing.go index 6e99264f7e1..38909578d30 100644 --- a/pkg/services/ngalert/accesscontrol/testing.go +++ b/pkg/services/ngalert/accesscontrol/testing.go @@ -3,8 +3,8 @@ package accesscontrol import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" ) type recordingAccessControlFake struct { diff --git a/pkg/services/ngalert/api/api.go b/pkg/services/ngalert/api/api.go index 01e37e2acb9..df99909b9b4 100644 --- a/pkg/services/ngalert/api/api.go +++ b/pkg/services/ngalert/api/api.go @@ -6,10 +6,10 @@ import ( "time" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasourceproxy" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/ngalert/api/api_alertmanager_silences.go b/pkg/services/ngalert/api/api_alertmanager_silences.go index b59f3896119..0f731abcfae 100644 --- a/pkg/services/ngalert/api/api_alertmanager_silences.go +++ b/pkg/services/ngalert/api/api_alertmanager_silences.go @@ -7,7 +7,7 @@ import ( "github.com/go-openapi/strfmt" "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/api/api_notifications.go b/pkg/services/ngalert/api/api_notifications.go index 1fd4bafec30..73b59e5e250 100644 --- a/pkg/services/ngalert/api/api_notifications.go +++ b/pkg/services/ngalert/api/api_notifications.go @@ -6,8 +6,8 @@ import ( "net/http" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/api/api_notifications_test.go b/pkg/services/ngalert/api/api_notifications_test.go index 1af5cbac066..779521dd4f1 100644 --- a/pkg/services/ngalert/api/api_notifications_test.go +++ b/pkg/services/ngalert/api/api_notifications_test.go @@ -8,9 +8,9 @@ import ( "net/url" "testing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log/logtest" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/api/api_provisioning.go b/pkg/services/ngalert/api/api_provisioning.go index 7e44a1893a9..bcaa879e790 100644 --- a/pkg/services/ngalert/api/api_provisioning.go +++ b/pkg/services/ngalert/api/api_provisioning.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" diff --git a/pkg/services/ngalert/api/api_ruler.go b/pkg/services/ngalert/api/api_ruler.go index 2470ba872b4..b9d9da1fc9e 100644 --- a/pkg/services/ngalert/api/api_ruler.go +++ b/pkg/services/ngalert/api/api_ruler.go @@ -13,8 +13,9 @@ import ( "github.com/grafana/grafana/pkg/api/apierrors" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -28,7 +29,6 @@ import ( "github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) type ConditionValidator interface { diff --git a/pkg/services/ngalert/api/api_testing.go b/pkg/services/ngalert/api/api_testing.go index ad31e426fa1..11938f928c2 100644 --- a/pkg/services/ngalert/api/api_testing.go +++ b/pkg/services/ngalert/api/api_testing.go @@ -17,9 +17,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/datasources" diff --git a/pkg/services/ngalert/api/errors.go b/pkg/services/ngalert/api/errors.go index 1e9dd272b24..0207d06cc43 100644 --- a/pkg/services/ngalert/api/errors.go +++ b/pkg/services/ngalert/api/errors.go @@ -5,9 +5,9 @@ import ( "fmt" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/datasources" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/ngalert/api/lotex_ruler_test.go b/pkg/services/ngalert/api/lotex_ruler_test.go index c54272e9953..bfbc8dd7fe4 100644 --- a/pkg/services/ngalert/api/lotex_ruler_test.go +++ b/pkg/services/ngalert/api/lotex_ruler_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/datasourceproxy" "github.com/grafana/grafana/pkg/services/datasources" diff --git a/pkg/services/ngalert/api/persist.go b/pkg/services/ngalert/api/persist.go index 8b0894fd6a3..28c984dd22b 100644 --- a/pkg/services/ngalert/api/persist.go +++ b/pkg/services/ngalert/api/persist.go @@ -3,7 +3,7 @@ package api import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/api/testing.go b/pkg/services/ngalert/api/testing.go index d1098754257..6cb35aa101e 100644 --- a/pkg/services/ngalert/api/testing.go +++ b/pkg/services/ngalert/api/testing.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/api/tooling/definitions/shared.go b/pkg/services/ngalert/api/tooling/definitions/shared.go index 9f8e8447aeb..2f0e3ddf803 100644 --- a/pkg/services/ngalert/api/tooling/definitions/shared.go +++ b/pkg/services/ngalert/api/tooling/definitions/shared.go @@ -1,6 +1,6 @@ package definitions -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" // swagger:model type NotFound struct{} diff --git a/pkg/services/ngalert/backtesting/engine.go b/pkg/services/ngalert/backtesting/engine.go index 2a53ad61582..88685f00134 100644 --- a/pkg/services/ngalert/backtesting/engine.go +++ b/pkg/services/ngalert/backtesting/engine.go @@ -12,9 +12,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/schedule" diff --git a/pkg/services/ngalert/backtesting/engine_test.go b/pkg/services/ngalert/backtesting/engine_test.go index 9b0bf8304f5..d38dd34bc3c 100644 --- a/pkg/services/ngalert/backtesting/engine_test.go +++ b/pkg/services/ngalert/backtesting/engine_test.go @@ -13,7 +13,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/services/ngalert/eval/eval_mocks" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/eval/context.go b/pkg/services/ngalert/eval/context.go index ffff56c4a54..1c442324dfd 100644 --- a/pkg/services/ngalert/eval/context.go +++ b/pkg/services/ngalert/eval/context.go @@ -5,7 +5,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) // AlertingResultsReader provides fingerprints of results that are in alerting state. diff --git a/pkg/services/ngalert/eval/eval.go b/pkg/services/ngalert/eval/eval.go index b22b4e3fa16..c3ff8393c6a 100644 --- a/pkg/services/ngalert/eval/eval.go +++ b/pkg/services/ngalert/eval/eval.go @@ -15,6 +15,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/expr/classic" "github.com/grafana/grafana/pkg/infra/log" @@ -23,7 +24,6 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var logger = log.New("ngalert.eval") diff --git a/pkg/services/ngalert/models/errors.go b/pkg/services/ngalert/models/errors.go index 14cecfb16ec..1793dc0eb07 100644 --- a/pkg/services/ngalert/models/errors.go +++ b/pkg/services/ngalert/models/errors.go @@ -1,7 +1,7 @@ package models import ( - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/ngalert/models/history.go b/pkg/services/ngalert/models/history.go index 509b1a74398..1a3dd1b5b29 100644 --- a/pkg/services/ngalert/models/history.go +++ b/pkg/services/ngalert/models/history.go @@ -3,7 +3,7 @@ package models import ( "time" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) // HistoryQuery represents a query for alert state history. diff --git a/pkg/services/ngalert/ngalert.go b/pkg/services/ngalert/ngalert.go index 21c38405734..5f87cafc251 100644 --- a/pkg/services/ngalert/ngalert.go +++ b/pkg/services/ngalert/ngalert.go @@ -332,6 +332,12 @@ func (ng *AlertNG) init() error { ng.AlertsRouter = alertsRouter evalFactory := eval.NewEvaluatorFactory(ng.Cfg.UnifiedAlerting, ng.DataSourceCache, ng.ExpressionService, ng.pluginsStore) + + recordingWriter, err := createRecordingWriter(ng.FeatureToggles, ng.Cfg.UnifiedAlerting.RecordingRules) + if err != nil { + return err + } + schedCfg := schedule.SchedulerCfg{ MaxAttempts: ng.Cfg.UnifiedAlerting.MaxAttempts, C: clk, @@ -347,7 +353,7 @@ func (ng *AlertNG) init() error { AlertSender: alertsRouter, Tracer: ng.tracer, Log: log.New("ngalert.scheduler"), - RecordingWriter: writer.NewPrometheusWriter(log.New("ngalert.recording.writer")), + RecordingWriter: recordingWriter, } // There are a set of feature toggles available that act as short-circuits for common configurations. @@ -624,3 +630,13 @@ func ApplyStateHistoryFeatureToggles(cfg *setting.UnifiedAlertingStateHistorySet func createRemoteAlertmanager(cfg remote.AlertmanagerConfig, kvstore kvstore.KVStore, decryptFn remote.DecryptFn, autogenFn remote.AutogenFn, m *metrics.RemoteAlertmanager) (*remote.Alertmanager, error) { return remote.NewAlertmanager(cfg, notifier.NewFileStore(cfg.OrgID, kvstore), decryptFn, autogenFn, m) } + +func createRecordingWriter(featureToggles featuremgmt.FeatureToggles, settings setting.RecordingRuleSettings) (schedule.RecordingWriter, error) { + logger := log.New("ngalert.writer") + + if featureToggles.IsEnabledGlobally(featuremgmt.FlagGrafanaManagedRecordingRules) { + return writer.NewPrometheusWriter(settings, logger) + } + + return writer.NoopWriter{}, nil +} diff --git a/pkg/services/ngalert/notifier/alertmanager_config.go b/pkg/services/ngalert/notifier/alertmanager_config.go index 232f17a3899..ec6472723e2 100644 --- a/pkg/services/ngalert/notifier/alertmanager_config.go +++ b/pkg/services/ngalert/notifier/alertmanager_config.go @@ -8,12 +8,12 @@ import ( "github.com/go-openapi/strfmt" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/store" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/ngalert/notifier/errors.go b/pkg/services/ngalert/notifier/errors.go index 32618daab1c..337dfa7cb3b 100644 --- a/pkg/services/ngalert/notifier/errors.go +++ b/pkg/services/ngalert/notifier/errors.go @@ -1,6 +1,6 @@ package notifier -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" // WithPublicError sets the public message of an errutil error to the error message. func WithPublicError(err errutil.Error) error { diff --git a/pkg/services/ngalert/notifier/multiorg_alertmanager.go b/pkg/services/ngalert/notifier/multiorg_alertmanager.go index 4dbc1ad8602..7a1150fa843 100644 --- a/pkg/services/ngalert/notifier/multiorg_alertmanager.go +++ b/pkg/services/ngalert/notifier/multiorg_alertmanager.go @@ -10,7 +10,8 @@ import ( "github.com/prometheus/client_golang/prometheus" alertingCluster "github.com/grafana/alerting/cluster" - "github.com/grafana/grafana/pkg/util/errutil" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" alertingNotify "github.com/grafana/alerting/notify" diff --git a/pkg/services/ngalert/notifier/receiver_svc.go b/pkg/services/ngalert/notifier/receiver_svc.go index e897490525d..bef0e0cdd24 100644 --- a/pkg/services/ngalert/notifier/receiver_svc.go +++ b/pkg/services/ngalert/notifier/receiver_svc.go @@ -7,9 +7,9 @@ import ( "errors" "slices" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/secrets" diff --git a/pkg/services/ngalert/notifier/silence_svc.go b/pkg/services/ngalert/notifier/silence_svc.go index fb04dfcb5e2..dd40f11015e 100644 --- a/pkg/services/ngalert/notifier/silence_svc.go +++ b/pkg/services/ngalert/notifier/silence_svc.go @@ -6,8 +6,9 @@ import ( "golang.org/x/exp/maps" alertingModels "github.com/grafana/alerting/models" + + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/models" ) diff --git a/pkg/services/ngalert/notifier/silence_svc_test.go b/pkg/services/ngalert/notifier/silence_svc_test.go index f5042bf5859..5bfcf7d05cd 100644 --- a/pkg/services/ngalert/notifier/silence_svc_test.go +++ b/pkg/services/ngalert/notifier/silence_svc_test.go @@ -10,10 +10,11 @@ import ( "github.com/stretchr/testify/require" alertingmodels "github.com/grafana/alerting/models" + ngfakes "github.com/grafana/grafana/pkg/services/ngalert/tests/fakes" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol/fakes" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/provisioning/accesscontrol.go b/pkg/services/ngalert/provisioning/accesscontrol.go index fa0eb499e61..8e503efadc1 100644 --- a/pkg/services/ngalert/provisioning/accesscontrol.go +++ b/pkg/services/ngalert/provisioning/accesscontrol.go @@ -3,8 +3,8 @@ package provisioning import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/store" diff --git a/pkg/services/ngalert/provisioning/accesscontrol_test.go b/pkg/services/ngalert/provisioning/accesscontrol_test.go index fc712290c6c..3f771ddfa3f 100644 --- a/pkg/services/ngalert/provisioning/accesscontrol_test.go +++ b/pkg/services/ngalert/provisioning/accesscontrol_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/exp/rand" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" accesscontrol2 "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol/fakes" "github.com/grafana/grafana/pkg/services/ngalert/models" diff --git a/pkg/services/ngalert/provisioning/alert_rules.go b/pkg/services/ngalert/provisioning/alert_rules.go index 4b0b3368d85..29953f863ae 100644 --- a/pkg/services/ngalert/provisioning/alert_rules.go +++ b/pkg/services/ngalert/provisioning/alert_rules.go @@ -6,8 +6,8 @@ import ( "fmt" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" diff --git a/pkg/services/ngalert/provisioning/alert_rules_test.go b/pkg/services/ngalert/provisioning/alert_rules_test.go index 958b3ee82d6..1fca30486fd 100644 --- a/pkg/services/ngalert/provisioning/alert_rules_test.go +++ b/pkg/services/ngalert/provisioning/alert_rules_test.go @@ -13,9 +13,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/expr" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/tests/fakes" "github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest" diff --git a/pkg/services/ngalert/provisioning/contactpoints.go b/pkg/services/ngalert/provisioning/contactpoints.go index 02eeb66978d..caf5cefc297 100644 --- a/pkg/services/ngalert/provisioning/contactpoints.go +++ b/pkg/services/ngalert/provisioning/contactpoints.go @@ -11,8 +11,8 @@ import ( alertingNotify "github.com/grafana/alerting/notify" "github.com/prometheus/alertmanager/config" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/notifier" diff --git a/pkg/services/ngalert/provisioning/errors.go b/pkg/services/ngalert/provisioning/errors.go index 05663ab4e5c..45d8e3eb533 100644 --- a/pkg/services/ngalert/provisioning/errors.go +++ b/pkg/services/ngalert/provisioning/errors.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/ngalert/models" - "github.com/grafana/grafana/pkg/util/errutil" ) var ErrValidation = fmt.Errorf("invalid object specification") diff --git a/pkg/services/ngalert/provisioning/testing.go b/pkg/services/ngalert/provisioning/testing.go index 3b669c0256b..a61bdcc00c0 100644 --- a/pkg/services/ngalert/provisioning/testing.go +++ b/pkg/services/ngalert/provisioning/testing.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" mock "github.com/stretchr/testify/mock" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/notifier" diff --git a/pkg/services/ngalert/schedule/alert_rule.go b/pkg/services/ngalert/schedule/alert_rule.go index 99757cc222e..6c3d58ec3e8 100644 --- a/pkg/services/ngalert/schedule/alert_rule.go +++ b/pkg/services/ngalert/schedule/alert_rule.go @@ -16,7 +16,6 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/metrics" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/state" - "github.com/grafana/grafana/pkg/services/ngalert/writer" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/util" @@ -57,7 +56,7 @@ func newRuleFactory( met *metrics.Scheduler, logger log.Logger, tracer tracing.Tracer, - recordingWriter writer.Writer, + recordingWriter RecordingWriter, evalAppliedHook evalAppliedFunc, stopAppliedHook stopAppliedFunc, ) ruleFactoryFunc { diff --git a/pkg/services/ngalert/schedule/recording_rule.go b/pkg/services/ngalert/schedule/recording_rule.go index b84a98b6314..a30bef263d8 100644 --- a/pkg/services/ngalert/schedule/recording_rule.go +++ b/pkg/services/ngalert/schedule/recording_rule.go @@ -14,7 +14,6 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/services/ngalert/metrics" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" - "github.com/grafana/grafana/pkg/services/ngalert/writer" "github.com/grafana/grafana/pkg/util" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" @@ -39,10 +38,10 @@ type recordingRule struct { metrics *metrics.Scheduler tracer tracing.Tracer - writer writer.Writer + writer RecordingWriter } -func newRecordingRule(parent context.Context, maxAttempts int64, clock clock.Clock, evalFactory eval.EvaluatorFactory, ft featuremgmt.FeatureToggles, logger log.Logger, metrics *metrics.Scheduler, tracer tracing.Tracer, writer writer.Writer) *recordingRule { +func newRecordingRule(parent context.Context, maxAttempts int64, clock clock.Clock, evalFactory eval.EvaluatorFactory, ft featuremgmt.FeatureToggles, logger log.Logger, metrics *metrics.Scheduler, tracer tracing.Tracer, writer RecordingWriter) *recordingRule { ctx, stop := util.WithCancelCause(parent) return &recordingRule{ ctx: ctx, diff --git a/pkg/services/ngalert/schedule/schedule.go b/pkg/services/ngalert/schedule/schedule.go index 5574e52d715..c62c26ecea3 100644 --- a/pkg/services/ngalert/schedule/schedule.go +++ b/pkg/services/ngalert/schedule/schedule.go @@ -11,6 +11,7 @@ import ( "github.com/benbjohnson/clock" "golang.org/x/sync/errgroup" + "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -19,7 +20,6 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/metrics" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/state" - "github.com/grafana/grafana/pkg/services/ngalert/writer" "github.com/grafana/grafana/pkg/util/ticker" ) @@ -47,6 +47,10 @@ type RulesStore interface { GetAlertRulesForScheduling(ctx context.Context, query *ngmodels.GetAlertRulesForSchedulingQuery) error } +type RecordingWriter interface { + Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error +} + type schedule struct { // base tick rate (fastest possible configured check) baseInterval time.Duration @@ -94,7 +98,7 @@ type schedule struct { tracer tracing.Tracer - recordingWriter writer.Writer + recordingWriter RecordingWriter } // SchedulerCfg is the scheduler configuration. @@ -113,7 +117,7 @@ type SchedulerCfg struct { AlertSender AlertsSender Tracer tracing.Tracer Log log.Logger - RecordingWriter writer.Writer + RecordingWriter RecordingWriter } // NewScheduler returns a new scheduler. diff --git a/pkg/services/ngalert/state/state.go b/pkg/services/ngalert/state/state.go index cc349d7ff43..206747c652e 100644 --- a/pkg/services/ngalert/state/state.go +++ b/pkg/services/ngalert/state/state.go @@ -13,12 +13,12 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" prometheusModel "github.com/prometheus/common/model" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/screenshot" - "github.com/grafana/grafana/pkg/util/errutil" ) type State struct { diff --git a/pkg/services/ngalert/store/alert_rule.go b/pkg/services/ngalert/store/alert_rule.go index f7b81e178ea..266efc6eb48 100644 --- a/pkg/services/ngalert/store/alert_rule.go +++ b/pkg/services/ngalert/store/alert_rule.go @@ -13,9 +13,9 @@ import ( "xorm.io/xorm" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" diff --git a/pkg/services/ngalert/tests/fakes/receivers.go b/pkg/services/ngalert/tests/fakes/receivers.go index 0840e100f90..8783adc0aa6 100644 --- a/pkg/services/ngalert/tests/fakes/receivers.go +++ b/pkg/services/ngalert/tests/fakes/receivers.go @@ -3,7 +3,7 @@ package fakes import ( "context" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" ) diff --git a/pkg/services/ngalert/tests/fakes/rules.go b/pkg/services/ngalert/tests/fakes/rules.go index 3a54bf5e03f..61eb036a1d4 100644 --- a/pkg/services/ngalert/tests/fakes/rules.go +++ b/pkg/services/ngalert/tests/fakes/rules.go @@ -9,8 +9,8 @@ import ( "testing" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/util" diff --git a/pkg/services/ngalert/writer/noop.go b/pkg/services/ngalert/writer/noop.go new file mode 100644 index 00000000000..3e434fdf76e --- /dev/null +++ b/pkg/services/ngalert/writer/noop.go @@ -0,0 +1,14 @@ +package writer + +import ( + "context" + "time" + + "github.com/grafana/grafana-plugin-sdk-go/data" +) + +type NoopWriter struct{} + +func (w NoopWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error { + return nil +} diff --git a/pkg/services/ngalert/writer/prom.go b/pkg/services/ngalert/writer/prom.go index 752d93cd94a..c41d8b4e40b 100644 --- a/pkg/services/ngalert/writer/prom.go +++ b/pkg/services/ngalert/writer/prom.go @@ -7,14 +7,11 @@ import ( "github.com/grafana/dataplane/sdata/numeric" "github.com/grafana/grafana/pkg/infra/log" + "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana-plugin-sdk-go/data" ) -type PrometheusWriter struct { - logger log.Logger -} - // Metric represents a Prometheus time series metric. type Metric struct { T int64 @@ -28,27 +25,6 @@ type Point struct { Metric Metric } -func NewPrometheusWriter(l log.Logger) *PrometheusWriter { - return &PrometheusWriter{ - logger: l, - } -} - -// Write writes the given frames to the Prometheus remote write endpoint. -// TODO: stub implementation, does not make any remote write calls. -func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error { - l := w.logger.FromContext(ctx) - - points, err := PointsFromFrames(name, t, frames, extraLabels) - if err != nil { - return err - } - - // TODO: placeholder for actual remote write call - l.Debug("writing points", "points", points) - return nil -} - func PointsFromFrames(name string, t time.Time, frames data.Frames, extraLabels map[string]string) ([]Point, error) { cr, err := numeric.CollectionReaderFromFrames(frames) if err != nil { @@ -94,3 +70,31 @@ func PointsFromFrames(name string, t time.Time, frames data.Frames, extraLabels return points, nil } + +type PrometheusWriter struct { + logger log.Logger +} + +func NewPrometheusWriter( + settings setting.RecordingRuleSettings, + l log.Logger, +) (*PrometheusWriter, error) { + return &PrometheusWriter{ + logger: l, + }, nil +} + +// Write writes the given frames to the Prometheus remote write endpoint. +// TODO: stub implementation, does not make any remote write calls. +func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error { + l := w.logger.FromContext(ctx) + + points, err := PointsFromFrames(name, t, frames, extraLabels) + if err != nil { + return err + } + + // TODO: placeholder for actual remote write call + l.Debug("writing points", "points", points) + return nil +} diff --git a/pkg/services/ngalert/writer/writer.go b/pkg/services/ngalert/writer/writer.go deleted file mode 100644 index 8c52603dd12..00000000000 --- a/pkg/services/ngalert/writer/writer.go +++ /dev/null @@ -1,12 +0,0 @@ -package writer - -import ( - "context" - "time" - - "github.com/grafana/grafana-plugin-sdk-go/data" -) - -type Writer interface { - Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error -} diff --git a/pkg/services/oauthtoken/oauth_token.go b/pkg/services/oauthtoken/oauth_token.go index 632b252b353..fffc81e9547 100644 --- a/pkg/services/oauthtoken/oauth_token.go +++ b/pkg/services/oauthtoken/oauth_token.go @@ -12,10 +12,10 @@ import ( "golang.org/x/oauth2" "golang.org/x/sync/singleflight" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/user" diff --git a/pkg/services/oauthtoken/oauth_token_test.go b/pkg/services/oauthtoken/oauth_token_test.go index 873a25cc9ce..4cc0694598e 100644 --- a/pkg/services/oauthtoken/oauth_token_test.go +++ b/pkg/services/oauthtoken/oauth_token_test.go @@ -13,11 +13,11 @@ import ( "golang.org/x/oauth2" "golang.org/x/sync/singleflight" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/login/social" "github.com/grafana/grafana/pkg/login/social/socialtest" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/login/authinfoimpl" diff --git a/pkg/services/oauthtoken/oauthtokentest/mock.go b/pkg/services/oauthtoken/oauthtokentest/mock.go index c273b86b0d8..f0e8dbef2c1 100644 --- a/pkg/services/oauthtoken/oauthtokentest/mock.go +++ b/pkg/services/oauthtoken/oauthtokentest/mock.go @@ -5,7 +5,7 @@ import ( "golang.org/x/oauth2" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/login" ) diff --git a/pkg/services/oauthtoken/oauthtokentest/oauthtokentest.go b/pkg/services/oauthtoken/oauthtokentest/oauthtokentest.go index c2ecb12d105..80c8ba63723 100644 --- a/pkg/services/oauthtoken/oauthtokentest/oauthtokentest.go +++ b/pkg/services/oauthtoken/oauthtokentest/oauthtokentest.go @@ -5,7 +5,7 @@ import ( "golang.org/x/oauth2" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/login" "github.com/grafana/grafana/pkg/services/oauthtoken" diff --git a/pkg/services/oauthtoken/oauthtokentest/service_mock.go b/pkg/services/oauthtoken/oauthtokentest/service_mock.go index 7b4d8943baf..f5baa7427cf 100644 --- a/pkg/services/oauthtoken/oauthtokentest/service_mock.go +++ b/pkg/services/oauthtoken/oauthtokentest/service_mock.go @@ -5,7 +5,7 @@ package oauthtokentest import ( context "context" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" datasources "github.com/grafana/grafana/pkg/services/datasources" login "github.com/grafana/grafana/pkg/services/login" diff --git a/pkg/services/org/model.go b/pkg/services/org/model.go index 87bf3e03ee8..34f2f910a3e 100644 --- a/pkg/services/org/model.go +++ b/pkg/services/org/model.go @@ -5,10 +5,9 @@ import ( "strings" "time" - "github.com/grafana/grafana/pkg/models/roletype" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/search/model" - "github.com/grafana/grafana/pkg/util/errutil" ) // Typed errors @@ -45,13 +44,13 @@ type OrgUser struct { Updated time.Time } -type RoleType = roletype.RoleType +type RoleType = identity.RoleType const ( - RoleNone RoleType = roletype.RoleNone - RoleViewer RoleType = roletype.RoleViewer - RoleEditor RoleType = roletype.RoleEditor - RoleAdmin RoleType = roletype.RoleAdmin + RoleNone RoleType = identity.RoleNone + RoleViewer RoleType = identity.RoleViewer + RoleEditor RoleType = identity.RoleEditor + RoleAdmin RoleType = identity.RoleAdmin ) type CreateOrgCommand struct { diff --git a/pkg/services/org/orgimpl/store_test.go b/pkg/services/org/orgimpl/store_test.go index e946e97ca3d..a4f839d6842 100644 --- a/pkg/services/org/orgimpl/store_test.go +++ b/pkg/services/org/orgimpl/store_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/quota/quotaimpl" "github.com/grafana/grafana/pkg/services/searchusers/sortopts" diff --git a/pkg/services/pluginsintegration/adapters/adapters.go b/pkg/services/pluginsintegration/adapters/adapters.go index dd3fda4dca1..d52c85a349a 100644 --- a/pkg/services/pluginsintegration/adapters/adapters.go +++ b/pkg/services/pluginsintegration/adapters/adapters.go @@ -7,7 +7,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/services/pluginsintegration/clientmiddleware/user_header_middleware.go b/pkg/services/pluginsintegration/clientmiddleware/user_header_middleware.go index a216f078bcd..466ee2f2d90 100644 --- a/pkg/services/pluginsintegration/clientmiddleware/user_header_middleware.go +++ b/pkg/services/pluginsintegration/clientmiddleware/user_header_middleware.go @@ -5,8 +5,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/contexthandler" "github.com/grafana/grafana/pkg/util/proxyutil" ) diff --git a/pkg/services/pluginsintegration/plugincontext/base_plugincontext.go b/pkg/services/pluginsintegration/plugincontext/base_plugincontext.go index bf4c1f4985c..48c179bb29d 100644 --- a/pkg/services/pluginsintegration/plugincontext/base_plugincontext.go +++ b/pkg/services/pluginsintegration/plugincontext/base_plugincontext.go @@ -6,8 +6,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/useragent" + + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/pluginsintegration/adapters" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginconfig" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" diff --git a/pkg/services/pluginsintegration/plugincontext/plugincontext.go b/pkg/services/pluginsintegration/plugincontext/plugincontext.go index 21cdbf12b8e..4d170d8867f 100644 --- a/pkg/services/pluginsintegration/plugincontext/plugincontext.go +++ b/pkg/services/pluginsintegration/plugincontext/plugincontext.go @@ -9,11 +9,11 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/appcontext" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/pluginsintegration/adapters" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginconfig" diff --git a/pkg/services/preference/model.go b/pkg/services/preference/model.go index b080daf3161..576ead990d5 100644 --- a/pkg/services/preference/model.go +++ b/pkg/services/preference/model.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ErrPrefNotFound = errors.New("preference not found") diff --git a/pkg/services/provisioning/alerting/rules_provisioner.go b/pkg/services/provisioning/alerting/rules_provisioner.go index 8c6f4e21549..4baefedfebf 100644 --- a/pkg/services/provisioning/alerting/rules_provisioner.go +++ b/pkg/services/provisioning/alerting/rules_provisioner.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/folder/folderimpl" diff --git a/pkg/services/publicdashboards/api/api_test.go b/pkg/services/publicdashboards/api/api_test.go index 1984e7de1da..d76d0239a41 100644 --- a/pkg/services/publicdashboards/api/api_test.go +++ b/pkg/services/publicdashboards/api/api_test.go @@ -12,13 +12,13 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/publicdashboards" . "github.com/grafana/grafana/pkg/services/publicdashboards/models" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" - "github.com/grafana/grafana/pkg/util/errutil" ) var userNoRBACPerms = &user.SignedInUser{UserID: 1, OrgID: 1, OrgRole: org.RoleAdmin, Login: "testAdminUserNoRBACPerms"} diff --git a/pkg/services/publicdashboards/api/query_test.go b/pkg/services/publicdashboards/api/query_test.go index 8c94b90b999..9ac3bdd1fa3 100644 --- a/pkg/services/publicdashboards/api/query_test.go +++ b/pkg/services/publicdashboards/api/query_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" @@ -40,7 +41,6 @@ import ( "github.com/grafana/grafana/pkg/services/quota/quotatest" "github.com/grafana/grafana/pkg/services/tag/tagimpl" "github.com/grafana/grafana/pkg/services/user" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/web" ) diff --git a/pkg/services/publicdashboards/models/errors.go b/pkg/services/publicdashboards/models/errors.go index a7db77973ed..0c5e9bd2113 100644 --- a/pkg/services/publicdashboards/models/errors.go +++ b/pkg/services/publicdashboards/models/errors.go @@ -1,6 +1,6 @@ package models -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" var ( ErrInternalServerError = errutil.Internal("publicdashboards.internalServerError", errutil.WithPublicMessage("Internal server error")) diff --git a/pkg/services/publicdashboards/service/service_test.go b/pkg/services/publicdashboards/service/service_test.go index 23948b18695..30c662ed04a 100644 --- a/pkg/services/publicdashboards/service/service_test.go +++ b/pkg/services/publicdashboards/service/service_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/dashboards" @@ -29,7 +30,6 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/tests/testsuite" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var timeSettings = &TimeSettings{From: "now-12h", To: "now"} diff --git a/pkg/services/query/errors.go b/pkg/services/query/errors.go index 1aa41403b6d..649d888cbbc 100644 --- a/pkg/services/query/errors.go +++ b/pkg/services/query/errors.go @@ -1,7 +1,7 @@ package query import ( - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/query/query.go b/pkg/services/query/query.go index a5890dedb7a..a911529c9a6 100644 --- a/pkg/services/query/query.go +++ b/pkg/services/query/query.go @@ -13,18 +13,18 @@ import ( "golang.org/x/sync/errgroup" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/contexthandler" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/grafanads" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( diff --git a/pkg/services/query/query_service_mock.go b/pkg/services/query/query_service_mock.go index f3fc8684661..5c5b4b69d37 100644 --- a/pkg/services/query/query_service_mock.go +++ b/pkg/services/query/query_service_mock.go @@ -11,7 +11,7 @@ import ( mock "github.com/stretchr/testify/mock" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" ) // FakeQueryService is an autogenerated mock type for the Service type diff --git a/pkg/services/query/query_test.go b/pkg/services/query/query_test.go index 2df66a19e8b..61c13e440b1 100644 --- a/pkg/services/query/query_test.go +++ b/pkg/services/query/query_test.go @@ -16,15 +16,14 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/contexthandler" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" @@ -491,7 +490,7 @@ func setup(t *testing.T) *testContext { secretStore: ss, pluginRequestValidator: rv, queryService: queryService, - signedInUser: &user.SignedInUser{OrgID: 1, Login: "login", Name: "name", Email: "email", OrgRole: roletype.RoleAdmin}, + signedInUser: &user.SignedInUser{OrgID: 1, Login: "login", Name: "name", Email: "email", OrgRole: identity.RoleAdmin}, } } diff --git a/pkg/services/quota/model.go b/pkg/services/quota/model.go index aa9022d3d2d..c5dcc33f0db 100644 --- a/pkg/services/quota/model.go +++ b/pkg/services/quota/model.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ErrBadRequest = errutil.BadRequest("quota.bad-request") diff --git a/pkg/services/rendering/interface.go b/pkg/services/rendering/interface.go index 25ffddbec9c..9b5b2f17cdc 100644 --- a/pkg/services/rendering/interface.go +++ b/pkg/services/rendering/interface.go @@ -5,9 +5,9 @@ import ( "errors" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/org" - "github.com/grafana/grafana/pkg/util/errutil" ) var ErrTimeout = errors.New("timeout error - you can set timeout in seconds with &timeout url parameter") diff --git a/pkg/services/searchusers/sortopts/sortopts.go b/pkg/services/searchusers/sortopts/sortopts.go index c6a19e167b6..89ffd5638aa 100644 --- a/pkg/services/searchusers/sortopts/sortopts.go +++ b/pkg/services/searchusers/sortopts/sortopts.go @@ -5,10 +5,11 @@ import ( "sort" "strings" - "github.com/grafana/grafana/pkg/services/search/model" - "github.com/grafana/grafana/pkg/util/errutil" "golang.org/x/text/cases" "golang.org/x/text/language" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/services/search/model" ) var ( diff --git a/pkg/services/serviceaccounts/api/api.go b/pkg/services/serviceaccounts/api/api.go index 8759e8af99a..1841f0c1b37 100644 --- a/pkg/services/serviceaccounts/api/api.go +++ b/pkg/services/serviceaccounts/api/api.go @@ -7,10 +7,10 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/middleware/requestmeta" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/serviceaccounts/extsvcaccounts/models.go b/pkg/services/serviceaccounts/extsvcaccounts/models.go index fd74e821e7f..be3845f1d2e 100644 --- a/pkg/services/serviceaccounts/extsvcaccounts/models.go +++ b/pkg/services/serviceaccounts/extsvcaccounts/models.go @@ -1,12 +1,12 @@ package extsvcaccounts import ( - "github.com/grafana/grafana/pkg/models/roletype" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/extsvcauth" "github.com/grafana/grafana/pkg/services/serviceaccounts" "github.com/grafana/grafana/pkg/services/user" - "github.com/grafana/grafana/pkg/util/errutil" ) const ( @@ -56,7 +56,7 @@ type saveCmd struct { SaID int64 } -func newRole(r roletype.RoleType) *roletype.RoleType { +func newRole(r identity.RoleType) *identity.RoleType { return &r } diff --git a/pkg/services/serviceaccounts/extsvcaccounts/service.go b/pkg/services/serviceaccounts/extsvcaccounts/service.go index c556ee7c5f5..341328945d8 100644 --- a/pkg/services/serviceaccounts/extsvcaccounts/service.go +++ b/pkg/services/serviceaccounts/extsvcaccounts/service.go @@ -7,13 +7,13 @@ import ( "github.com/prometheus/client_golang/prometheus" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/satokengen" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/slugify" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models/roletype" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/extsvcauth" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -101,7 +101,7 @@ func (esa *ExtSvcAccountsService) RetrieveExtSvcAccount(ctx context.Context, org Name: svcAcc.Name, OrgID: svcAcc.OrgId, IsDisabled: svcAcc.IsDisabled, - Role: roletype.RoleType(svcAcc.Role), + Role: identity.RoleType(svcAcc.Role), }, nil } @@ -285,7 +285,7 @@ func (esa *ExtSvcAccountsService) saveExtSvcAccount(ctx context.Context, cmd *sa ctxLogger.Info("Create service account", "service", cmd.ExtSvcSlug, "orgID", cmd.OrgID) sa, err := esa.saSvc.CreateServiceAccount(ctx, cmd.OrgID, &sa.CreateServiceAccountForm{ Name: sa.ExtSvcPrefix + cmd.ExtSvcSlug, - Role: newRole(roletype.RoleNone), + Role: newRole(identity.RoleNone), IsDisabled: newBool(false), }) if err != nil { diff --git a/pkg/services/serviceaccounts/extsvcaccounts/service_test.go b/pkg/services/serviceaccounts/extsvcaccounts/service_test.go index 8eb9edca532..8b4365c5c9c 100644 --- a/pkg/services/serviceaccounts/extsvcaccounts/service_test.go +++ b/pkg/services/serviceaccounts/extsvcaccounts/service_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/components/satokengen" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models/roletype" ac "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" @@ -67,7 +67,7 @@ func TestExtSvcAccountsService_ManageExtSvcAccount(t *testing.T) { Login: extSvcSlug, OrgId: extSvcOrgID, IsDisabled: false, - Role: string(roletype.RoleNone), + Role: string(identity.RoleNone), } tests := []struct { @@ -128,7 +128,7 @@ func TestExtSvcAccountsService_ManageExtSvcAccount(t *testing.T) { mock.Anything, extSvcOrgID, mock.MatchedBy(func(cmd *sa.CreateServiceAccountForm) bool { - return cmd.Name == sa.ExtSvcPrefix+extSvcSlug && *cmd.Role == roletype.RoleNone + return cmd.Name == sa.ExtSvcPrefix+extSvcSlug && *cmd.Role == identity.RoleNone })). Return(extSvcAccount, nil) env.SaSvc.On("EnableServiceAccount", mock.Anything, extSvcOrgID, extSvcAccount.Id, true).Return(nil) @@ -211,7 +211,7 @@ func TestExtSvcAccountsService_SaveExternalService(t *testing.T) { Login: extSvcSlug, OrgId: tmpOrgID, IsDisabled: false, - Role: string(roletype.RoleNone), + Role: string(identity.RoleNone), } tests := []struct { @@ -293,7 +293,7 @@ func TestExtSvcAccountsService_SaveExternalService(t *testing.T) { mock.Anything, tmpOrgID, mock.MatchedBy(func(cmd *sa.CreateServiceAccountForm) bool { - return cmd.Name == sa.ExtSvcPrefix+extSvcSlug && *cmd.Role == roletype.RoleNone + return cmd.Name == sa.ExtSvcPrefix+extSvcSlug && *cmd.Role == identity.RoleNone })). Return(extSvcAccount, nil) env.SaSvc.On("EnableServiceAccount", mock.Anything, tmpOrgID, extSvcAccID, true).Return(nil) diff --git a/pkg/services/serviceaccounts/models.go b/pkg/services/serviceaccounts/models.go index d83d298ea88..777d9de6170 100644 --- a/pkg/services/serviceaccounts/models.go +++ b/pkg/services/serviceaccounts/models.go @@ -3,12 +3,11 @@ package serviceaccounts import ( "time" - "github.com/grafana/grafana/pkg/models/roletype" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/extsvcauth" "github.com/grafana/grafana/pkg/services/org" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( @@ -190,7 +189,7 @@ type ExtSvcAccount struct { Name string OrgID int64 IsDisabled bool - Role roletype.RoleType + Role identity.RoleType } type ManageExtSvcAccountCmd struct { diff --git a/pkg/services/shorturls/models.go b/pkg/services/shorturls/models.go index 37355552fa3..ffa38d91390 100644 --- a/pkg/services/shorturls/models.go +++ b/pkg/services/shorturls/models.go @@ -3,7 +3,7 @@ package shorturls import ( "time" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/signingkeys/error.go b/pkg/services/signingkeys/error.go index 8dfe65dd972..772c8353e40 100644 --- a/pkg/services/signingkeys/error.go +++ b/pkg/services/signingkeys/error.go @@ -1,6 +1,6 @@ package signingkeys -import "github.com/grafana/grafana/pkg/util/errutil" +import "github.com/grafana/grafana/pkg/apimachinery/errutil" var ( ErrSigningKeyNotFound = errutil.NotFound("signingkeys.keyNotFound") diff --git a/pkg/services/sqlstore/permissions/dashboard.go b/pkg/services/sqlstore/permissions/dashboard.go index 0b05dfeadfd..c89eb2a612f 100644 --- a/pkg/services/sqlstore/permissions/dashboard.go +++ b/pkg/services/sqlstore/permissions/dashboard.go @@ -6,8 +6,8 @@ import ( "slices" "strings" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/sqlstore/permissions/dashboard_filter_no_subquery.go b/pkg/services/sqlstore/permissions/dashboard_filter_no_subquery.go index 911311a1f1d..524bb5b4760 100644 --- a/pkg/services/sqlstore/permissions/dashboard_filter_no_subquery.go +++ b/pkg/services/sqlstore/permissions/dashboard_filter_no_subquery.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" diff --git a/pkg/services/sqlstore/session.go b/pkg/services/sqlstore/session.go index 8b2a5bebca8..7bf71e9e230 100644 --- a/pkg/services/sqlstore/session.go +++ b/pkg/services/sqlstore/session.go @@ -12,10 +12,10 @@ import ( "go.opentelemetry.io/otel/trace" "xorm.io/xorm" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" - "github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/util/retryer" ) diff --git a/pkg/services/ssosettings/api/api.go b/pkg/services/ssosettings/api/api.go index 8e2a8f0da21..c5d2540ebb1 100644 --- a/pkg/services/ssosettings/api/api.go +++ b/pkg/services/ssosettings/api/api.go @@ -9,9 +9,9 @@ import ( "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ssosettings" diff --git a/pkg/services/ssosettings/errors.go b/pkg/services/ssosettings/errors.go index 9e1169d1a17..6edaf8668fb 100644 --- a/pkg/services/ssosettings/errors.go +++ b/pkg/services/ssosettings/errors.go @@ -1,7 +1,7 @@ package ssosettings import ( - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/ssosettings/ssosettings.go b/pkg/services/ssosettings/ssosettings.go index 764c7b88efb..96aec5daad5 100644 --- a/pkg/services/ssosettings/ssosettings.go +++ b/pkg/services/ssosettings/ssosettings.go @@ -3,8 +3,8 @@ package ssosettings import ( "context" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ssosettings/models" ) diff --git a/pkg/services/ssosettings/ssosettingsimpl/service.go b/pkg/services/ssosettings/ssosettingsimpl/service.go index 7d8dd5341a7..0de3874e1fb 100644 --- a/pkg/services/ssosettings/ssosettingsimpl/service.go +++ b/pkg/services/ssosettings/ssosettingsimpl/service.go @@ -11,12 +11,12 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/usagestats" "github.com/grafana/grafana/pkg/login/social" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/ldap/service" "github.com/grafana/grafana/pkg/services/licensing" diff --git a/pkg/services/ssosettings/ssosettingstests/reloadable_mock.go b/pkg/services/ssosettings/ssosettingstests/reloadable_mock.go index f6bc845d7aa..b02bc013056 100644 --- a/pkg/services/ssosettings/ssosettingstests/reloadable_mock.go +++ b/pkg/services/ssosettings/ssosettingstests/reloadable_mock.go @@ -5,7 +5,7 @@ package ssosettingstests import ( context "context" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" mock "github.com/stretchr/testify/mock" models "github.com/grafana/grafana/pkg/services/ssosettings/models" diff --git a/pkg/services/ssosettings/ssosettingstests/service_mock.go b/pkg/services/ssosettings/ssosettingstests/service_mock.go index 02837917856..45bd2ab9dc9 100644 --- a/pkg/services/ssosettings/ssosettingstests/service_mock.go +++ b/pkg/services/ssosettings/ssosettingstests/service_mock.go @@ -5,7 +5,7 @@ package ssosettingstests import ( context "context" - identity "github.com/grafana/grafana/pkg/services/auth/identity" + identity "github.com/grafana/grafana/pkg/apimachinery/identity" mock "github.com/stretchr/testify/mock" models "github.com/grafana/grafana/pkg/services/ssosettings/models" diff --git a/pkg/services/ssosettings/validation/oauth_validators.go b/pkg/services/ssosettings/validation/oauth_validators.go index 23c8b256601..56fdf53f459 100644 --- a/pkg/services/ssosettings/validation/oauth_validators.go +++ b/pkg/services/ssosettings/validation/oauth_validators.go @@ -5,8 +5,8 @@ import ( "net/url" "strings" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ssosettings" ) diff --git a/pkg/services/ssosettings/validation/oauth_validators_test.go b/pkg/services/ssosettings/validation/oauth_validators_test.go index 1435fa110b9..6cdea2a067d 100644 --- a/pkg/services/ssosettings/validation/oauth_validators_test.go +++ b/pkg/services/ssosettings/validation/oauth_validators_test.go @@ -3,11 +3,12 @@ package validation import ( "testing" + "github.com/stretchr/testify/require" + + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ssosettings" "github.com/grafana/grafana/pkg/services/user" - "github.com/stretchr/testify/require" ) type testCase struct { diff --git a/pkg/services/ssosettings/validation/validator.go b/pkg/services/ssosettings/validation/validator.go index b235f7f41cb..8a002de607c 100644 --- a/pkg/services/ssosettings/validation/validator.go +++ b/pkg/services/ssosettings/validation/validator.go @@ -1,8 +1,8 @@ package validation import ( + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/login/social" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/ssosettings" ) diff --git a/pkg/services/star/api/api.go b/pkg/services/star/api/api.go index b0f931c40f3..516b8d08a74 100644 --- a/pkg/services/star/api/api.go +++ b/pkg/services/star/api/api.go @@ -6,7 +6,7 @@ import ( "strconv" "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/star" diff --git a/pkg/services/supportbundles/supportbundlesimpl/service.go b/pkg/services/supportbundles/supportbundlesimpl/service.go index dd9ade72d20..a923de9deea 100644 --- a/pkg/services/supportbundles/supportbundlesimpl/service.go +++ b/pkg/services/supportbundles/supportbundlesimpl/service.go @@ -7,13 +7,13 @@ import ( grafanaApi "github.com/grafana/grafana/pkg/api" "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/kvstore" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/infra/usagestats" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" diff --git a/pkg/services/supportbundles/supportbundlesimpl/store.go b/pkg/services/supportbundles/supportbundlesimpl/store.go index d437b0d4e1a..7f99457975b 100644 --- a/pkg/services/supportbundles/supportbundlesimpl/store.go +++ b/pkg/services/supportbundles/supportbundlesimpl/store.go @@ -13,9 +13,9 @@ import ( "github.com/google/uuid" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/kvstore" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/supportbundles" ) diff --git a/pkg/services/team/model.go b/pkg/services/team/model.go index b05c4d84359..8bd371de36a 100644 --- a/pkg/services/team/model.go +++ b/pkg/services/team/model.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/search/model" ) diff --git a/pkg/services/team/sortopts/sortopts.go b/pkg/services/team/sortopts/sortopts.go index fda1f2ca560..307475b2463 100644 --- a/pkg/services/team/sortopts/sortopts.go +++ b/pkg/services/team/sortopts/sortopts.go @@ -5,10 +5,11 @@ import ( "sort" "strings" - "github.com/grafana/grafana/pkg/services/search/model" - "github.com/grafana/grafana/pkg/util/errutil" "golang.org/x/text/cases" "golang.org/x/text/language" + + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/services/search/model" ) var ( diff --git a/pkg/services/team/teamapi/team.go b/pkg/services/team/teamapi/team.go index 0f5911a9198..79b697cd99c 100644 --- a/pkg/services/team/teamapi/team.go +++ b/pkg/services/team/teamapi/team.go @@ -7,8 +7,8 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/preference/prefapi" diff --git a/pkg/services/team/teamapi/team_members.go b/pkg/services/team/teamapi/team_members.go index 3b67a9629e2..6d4dc62457b 100644 --- a/pkg/services/team/teamapi/team_members.go +++ b/pkg/services/team/teamapi/team_members.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/login" diff --git a/pkg/services/team/teamimpl/store.go b/pkg/services/team/teamimpl/store.go index 2076c5cf95d..76658966c0b 100644 --- a/pkg/services/team/teamimpl/store.go +++ b/pkg/services/team/teamimpl/store.go @@ -7,9 +7,9 @@ import ( "strings" "time" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" "github.com/grafana/grafana/pkg/services/team" diff --git a/pkg/services/team/teamimpl/store_test.go b/pkg/services/team/teamimpl/store_test.go index 4fdeaab2ba4..f63fd758e9b 100644 --- a/pkg/services/team/teamimpl/store_test.go +++ b/pkg/services/team/teamimpl/store_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" ac "github.com/grafana/grafana/pkg/services/accesscontrol" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/org/orgimpl" "github.com/grafana/grafana/pkg/services/quota/quotaimpl" diff --git a/pkg/services/user/error.go b/pkg/services/user/error.go index 9460ed6f7f9..040382ced5a 100644 --- a/pkg/services/user/error.go +++ b/pkg/services/user/error.go @@ -3,7 +3,7 @@ package user import ( "errors" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) var ( diff --git a/pkg/services/user/identity.go b/pkg/services/user/identity.go index 5ceee009a78..bc3d8e273ef 100644 --- a/pkg/services/user/identity.go +++ b/pkg/services/user/identity.go @@ -5,20 +5,21 @@ import ( "strconv" "time" - "github.com/grafana/grafana/pkg/models/roletype" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) const ( GlobalOrgID = int64(0) ) +var _ identity.Requester = &SignedInUser{} + type SignedInUser struct { UserID int64 `xorm:"user_id"` UserUID string `xorm:"user_uid"` OrgID int64 `xorm:"org_id"` OrgName string - OrgRole roletype.RoleType + OrgRole identity.RoleType Login string Name string Email string @@ -57,7 +58,7 @@ func (u *SignedInUser) NameOrFallback() string { return u.Email } -func (u *SignedInUser) HasRole(role roletype.RoleType) bool { +func (u *SignedInUser) HasRole(role identity.RoleType) bool { if u.IsGrafanaAdmin { return true } @@ -97,7 +98,7 @@ func (u *SignedInUser) GetCacheKey() string { // e.g. anonymous and render key. orgRole := u.GetOrgRole() if orgRole == "" { - orgRole = roletype.RoleNone + orgRole = identity.RoleNone } id = string(orgRole) @@ -161,7 +162,7 @@ func (u *SignedInUser) GetTeams() []int64 { } // GetOrgRole returns the role of the active entity in the active organization -func (u *SignedInUser) GetOrgRole() roletype.RoleType { +func (u *SignedInUser) GetOrgRole() identity.RoleType { return u.OrgRole } @@ -172,7 +173,7 @@ func (u *SignedInUser) GetID() identity.NamespaceID { } // GetNamespacedID returns the namespace and ID of the active entity -// The namespace is one of the constants defined in pkg/services/auth/identity +// The namespace is one of the constants defined in pkg/apimachinery/identity func (u *SignedInUser) GetNamespacedID() (identity.Namespace, string) { switch { case u.ApiKeyID != 0: diff --git a/pkg/services/user/model.go b/pkg/services/user/model.go index abff317f983..12e992e5081 100644 --- a/pkg/services/user/model.go +++ b/pkg/services/user/model.go @@ -3,7 +3,7 @@ package user import ( "time" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/search/model" ) diff --git a/pkg/services/user/password.go b/pkg/services/user/password.go index 78c4f8585ab..d084ae160ff 100644 --- a/pkg/services/user/password.go +++ b/pkg/services/user/password.go @@ -3,9 +3,9 @@ package user import ( "unicode" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/user/userimpl/verifier.go b/pkg/services/user/userimpl/verifier.go index b9d3eb5775f..500216208d0 100644 --- a/pkg/services/user/userimpl/verifier.go +++ b/pkg/services/user/userimpl/verifier.go @@ -7,6 +7,7 @@ import ( "net/mail" "time" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/auth" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/notifications" @@ -14,7 +15,6 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) var ( diff --git a/pkg/services/user/userimpl/verifier_test.go b/pkg/services/user/userimpl/verifier_test.go index 0c3e0f960e1..8f7f17218d6 100644 --- a/pkg/services/user/userimpl/verifier_test.go +++ b/pkg/services/user/userimpl/verifier_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/auth/idtest" "github.com/grafana/grafana/pkg/services/notifications" tempuser "github.com/grafana/grafana/pkg/services/temp_user" diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 96ded83193b..df89c95455e 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -29,8 +29,8 @@ import ( "github.com/grafana/grafana-azure-sdk-go/v2/azsettings" "github.com/grafana/grafana-plugin-sdk-go/backend/gtime" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util/osutil" ) @@ -1657,11 +1657,11 @@ func readUserSettings(iniFile *ini.File, cfg *Cfg) error { cfg.AutoAssignOrgId = users.Key("auto_assign_org_id").MustInt(1) cfg.LoginDefaultOrgId = users.Key("login_default_org_id").MustInt64(-1) cfg.AutoAssignOrgRole = users.Key("auto_assign_org_role").In( - string(roletype.RoleViewer), []string{ - string(roletype.RoleNone), - string(roletype.RoleViewer), - string(roletype.RoleEditor), - string(roletype.RoleAdmin)}) + string(identity.RoleViewer), []string{ + string(identity.RoleNone), + string(identity.RoleViewer), + string(identity.RoleEditor), + string(identity.RoleAdmin)}) cfg.VerifyEmailEnabled = users.Key("verify_email_enabled").MustBool(false) // Deprecated diff --git a/pkg/setting/setting_unified_alerting.go b/pkg/setting/setting_unified_alerting.go index 6536bd442f8..4cd4e9dde85 100644 --- a/pkg/setting/setting_unified_alerting.go +++ b/pkg/setting/setting_unified_alerting.go @@ -59,9 +59,10 @@ const ( // with intervals that are not exactly divided by this number not to be evaluated SchedulerBaseInterval = 10 * time.Second // DefaultRuleEvaluationInterval indicates a default interval of for how long a rule should be evaluated to change state from Pending to Alerting - DefaultRuleEvaluationInterval = SchedulerBaseInterval * 6 // == 60 seconds - stateHistoryDefaultEnabled = true - lokiDefaultMaxQueryLength = 721 * time.Hour // 30d1h, matches the default value in Loki + DefaultRuleEvaluationInterval = SchedulerBaseInterval * 6 // == 60 seconds + stateHistoryDefaultEnabled = true + lokiDefaultMaxQueryLength = 721 * time.Hour // 30d1h, matches the default value in Loki + defaultRecordingRequestTimeout = 10 * time.Second ) type UnifiedAlertingSettings struct { @@ -103,6 +104,8 @@ type UnifiedAlertingSettings struct { SkipClustering bool StateHistory UnifiedAlertingStateHistorySettings RemoteAlertmanager RemoteAlertmanagerSettings + RecordingRules RecordingRuleSettings + // MaxStateSaveConcurrency controls the number of goroutines (per rule) that can save alert state in parallel. MaxStateSaveConcurrency int StatePeriodicSaveInterval time.Duration @@ -112,6 +115,14 @@ type UnifiedAlertingSettings struct { NotificationLogRetention time.Duration } +type RecordingRuleSettings struct { + URL string + BasicAuthUsername string + BasicAuthPassword string + CustomHeaders map[string]string + Timeout time.Duration +} + // RemoteAlertmanagerSettings contains the configuration needed // to disable the internal Alertmanager and use an external one instead. type RemoteAlertmanagerSettings struct { @@ -395,6 +406,23 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error { } uaCfg.StateHistory = uaCfgStateHistory + rr := iniFile.Section("recording_rules") + uaCfgRecordingRules := RecordingRuleSettings{ + URL: rr.Key("url").MustString(""), + BasicAuthUsername: rr.Key("basic_auth_username").MustString(""), + BasicAuthPassword: rr.Key("basic_auth_password").MustString(""), + Timeout: rr.Key("timeout").MustDuration(defaultRecordingRequestTimeout), + } + + rrHeaders := iniFile.Section("recording_rules.custom_headers") + rrHeadersKeys := rrHeaders.Keys() + uaCfgRecordingRules.CustomHeaders = make(map[string]string, len(rrHeadersKeys)) + for _, key := range rrHeadersKeys { + uaCfgRecordingRules.CustomHeaders[key.Name()] = key.Value() + } + + uaCfg.RecordingRules = uaCfgRecordingRules + uaCfg.MaxStateSaveConcurrency = ua.Key("max_state_save_concurrency").MustInt(1) uaCfg.StatePeriodicSaveInterval, err = gtime.ParseDuration(valueAsString(ua, "state_periodic_save_interval", (time.Minute * 5).String())) diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index 07da4e987b4..c24a18f2411 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" @@ -33,7 +34,6 @@ import ( "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tests/testinfra" "github.com/grafana/grafana/pkg/util" - "github.com/grafana/grafana/pkg/util/errutil" ) type Response struct { diff --git a/pkg/tests/api/alerting/api_backtesting_test.go b/pkg/tests/api/alerting/api_backtesting_test.go index 8c37cec5173..f292ca734de 100644 --- a/pkg/tests/api/alerting/api_backtesting_test.go +++ b/pkg/tests/api/alerting/api_backtesting_test.go @@ -11,7 +11,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/models/roletype" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" "github.com/grafana/grafana/pkg/services/datasources" @@ -93,7 +93,7 @@ func TestBacktesting(t *testing.T) { t.Run("if user does not have permissions", func(t *testing.T) { testUserId := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{ - DefaultOrgRole: string(roletype.RoleNone), + DefaultOrgRole: string(identity.RoleNone), Password: "test", Login: "test", OrgID: 1, diff --git a/pkg/tests/api/alerting/api_provisioning_test.go b/pkg/tests/api/alerting/api_provisioning_test.go index b37a206437e..f56b1df0cb6 100644 --- a/pkg/tests/api/alerting/api_provisioning_test.go +++ b/pkg/tests/api/alerting/api_provisioning_test.go @@ -16,12 +16,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/tests/testinfra" - "github.com/grafana/grafana/pkg/util/errutil" ) func TestIntegrationProvisioning(t *testing.T) { diff --git a/pkg/tests/apis/helper.go b/pkg/tests/apis/helper.go index c491dea3847..ad0bef49eb6 100644 --- a/pkg/tests/apis/helper.go +++ b/pkg/tests/apis/helper.go @@ -24,11 +24,11 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/server" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" - "github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org/orgimpl" diff --git a/pkg/util/errutil/errhttp/writer.go b/pkg/util/errhttp/writer.go similarity index 98% rename from pkg/util/errutil/errhttp/writer.go rename to pkg/util/errhttp/writer.go index bbfcbb70df1..b94deb18861 100644 --- a/pkg/util/errutil/errhttp/writer.go +++ b/pkg/util/errhttp/writer.go @@ -9,8 +9,8 @@ import ( "k8s.io/apiserver/pkg/endpoints/request" + "github.com/grafana/grafana/pkg/apimachinery/errutil" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/util/errutil" ) var ErrNonGrafanaError = errutil.Internal("core.MalformedError") diff --git a/pkg/util/errutil/errhttp/writer_test.go b/pkg/util/errhttp/writer_test.go similarity index 96% rename from pkg/util/errutil/errhttp/writer_test.go rename to pkg/util/errhttp/writer_test.go index 405055c5ce2..65a071cc7e3 100644 --- a/pkg/util/errutil/errhttp/writer_test.go +++ b/pkg/util/errhttp/writer_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apiserver/pkg/endpoints/request" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) func TestWrite(t *testing.T) { diff --git a/pkg/util/json.go b/pkg/util/json.go index b1e7503bf51..cb1b0fef76d 100644 --- a/pkg/util/json.go +++ b/pkg/util/json.go @@ -5,7 +5,7 @@ import ( "github.com/jmespath/go-jmespath" - "github.com/grafana/grafana/pkg/util/errutil" + "github.com/grafana/grafana/pkg/apimachinery/errutil" ) // DynMap defines a dynamic map interface. diff --git a/pkg/util/proxyutil/proxyutil.go b/pkg/util/proxyutil/proxyutil.go index 3d4cbcdf245..59b69a3f1ab 100644 --- a/pkg/util/proxyutil/proxyutil.go +++ b/pkg/util/proxyutil/proxyutil.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" ) const ( diff --git a/pkg/util/proxyutil/proxyutil_test.go b/pkg/util/proxyutil/proxyutil_test.go index d84578f638a..14111cd49ac 100644 --- a/pkg/util/proxyutil/proxyutil_test.go +++ b/pkg/util/proxyutil/proxyutil_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/services/auth/identity" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/services/user" ) diff --git a/pkg/web/context.go b/pkg/web/context.go index 706da507ece..401b53dd6a0 100644 --- a/pkg/web/context.go +++ b/pkg/web/context.go @@ -26,8 +26,8 @@ import ( "strings" "syscall" - "github.com/grafana/grafana/pkg/util/errutil" - "github.com/grafana/grafana/pkg/util/errutil/errhttp" + "github.com/grafana/grafana/pkg/apimachinery/errutil" + "github.com/grafana/grafana/pkg/util/errhttp" ) // Context represents the runtime context of current request of Macaron instance. diff --git a/public/app/features/admin/UserListPage.tsx b/public/app/features/admin/UserListPage.tsx index 378740f95a6..d5bb089c62f 100644 --- a/public/app/features/admin/UserListPage.tsx +++ b/public/app/features/admin/UserListPage.tsx @@ -3,11 +3,11 @@ import React, { useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; -import { config, featureEnabled } from '@grafana/runtime'; +import { config } from '@grafana/runtime'; import { useStyles2, TabsBar, Tab } from '@grafana/ui'; import { t } from 'app/core/internationalization'; import { contextSrv } from 'app/core/services/context_srv'; -import { isPublicDashboardsEnabled } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { isEmailSharingEnabled } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; import { Page } from '../../core/components/Page/Page'; import { AccessControlAction } from '../../types'; @@ -47,10 +47,6 @@ export default function UserListPage() { const hasAccessToAdminUsers = contextSrv.hasPermission(AccessControlAction.UsersRead); const hasAccessToOrgUsers = contextSrv.hasPermission(AccessControlAction.OrgUsersRead); - const hasEmailSharingEnabled = - isPublicDashboardsEnabled() && - Boolean(config.featureToggles.publicDashboardsEmailSharing) && - featureEnabled('publicDashboardsEmailSharing'); const [view, setView] = useState(() => { if (hasAccessToAdminUsers) { @@ -87,10 +83,10 @@ export default function UserListPage() { data-testid={selectors.tabs.anonUserDevices} /> )} - {hasEmailSharingEnabled && } + {isEmailSharingEnabled() && } ) : ( - hasEmailSharingEnabled && ( + isEmailSharingEnabled() && ( ({ name: 'settingsViewable', @@ -99,7 +100,7 @@ export const constraintViewable = (scene: Scene) => ({ events: [], render(moveable: MoveableManagerInterface, React: Renderer) { const rect = moveable.getRect(); - const targetElement = scene.findElementByTarget(moveable.state.target!); + const targetElement = findElementByTarget(moveable.state.target!, scene.root.elements); // If selection is more than 1 element don't display constraint visualizations if (scene.selecto?.getSelectedTargets() && scene.selecto?.getSelectedTargets().length > 1) { diff --git a/public/app/features/canvas/runtime/frame.tsx b/public/app/features/canvas/runtime/frame.tsx index 99cdb1abe80..7307fdb5513 100644 --- a/public/app/features/canvas/runtime/frame.tsx +++ b/public/app/features/canvas/runtime/frame.tsx @@ -14,6 +14,7 @@ import { canvasElementRegistry } from '../registry'; import { ElementState } from './element'; import { RootElement } from './root'; import { Scene } from './scene'; +import { initMoveable } from './sceneAbleManagement'; const DEFAULT_OFFSET = 10; const HORIZONTAL_OFFSET = 50; @@ -111,7 +112,7 @@ export class FrameState extends ElementState { reinitializeMoveable() { // Need to first clear current selection and then re-init moveable with slight delay this.scene.clearCurrentSelection(); - setTimeout(() => this.scene.initMoveable(true, this.scene.isEditingEnabled)); + setTimeout(() => initMoveable(true, this.scene.isEditingEnabled, this.scene)); } // ??? or should this be on the element directly? diff --git a/public/app/features/canvas/runtime/scene.tsx b/public/app/features/canvas/runtime/scene.tsx index 77ab717f611..5df905d1dd8 100644 --- a/public/app/features/canvas/runtime/scene.tsx +++ b/public/app/features/canvas/runtime/scene.tsx @@ -3,7 +3,6 @@ import Moveable from 'moveable'; import React, { createRef, CSSProperties, RefObject } from 'react'; import { ReactZoomPanPinchContentRef } from 'react-zoom-pan-pinch'; import { BehaviorSubject, ReplaySubject, Subject, Subscription } from 'rxjs'; -import { first } from 'rxjs/operators'; import Selecto from 'selecto'; import { AppEvents, PanelData } from '@grafana/data'; @@ -27,15 +26,9 @@ import { } from 'app/features/dimensions/utils'; import { CanvasContextMenu } from 'app/plugins/panel/canvas/components/CanvasContextMenu'; import { CanvasTooltip } from 'app/plugins/panel/canvas/components/CanvasTooltip'; -import { CONNECTION_ANCHOR_DIV_ID } from 'app/plugins/panel/canvas/components/connections/ConnectionAnchors'; -import { - Connections, - CONNECTION_VERTEX_ADD_ID, - CONNECTION_VERTEX_ID, -} from 'app/plugins/panel/canvas/components/connections/Connections'; -import { HorizontalConstraint, Placement, VerticalConstraint } from 'app/plugins/panel/canvas/panelcfg.gen'; -import { AnchorPoint, CanvasTooltipPayload, LayerActionID } from 'app/plugins/panel/canvas/types'; -import { getParent, getTransformInstance } from 'app/plugins/panel/canvas/utils'; +import { Connections } from 'app/plugins/panel/canvas/components/connections/Connections'; +import { AnchorPoint, CanvasTooltipPayload } from 'app/plugins/panel/canvas/types'; +import { getTransformInstance } from 'app/plugins/panel/canvas/utils'; import appEvents from '../../../core/app_events'; import { CanvasPanel } from '../../../plugins/panel/canvas/CanvasPanel'; @@ -43,10 +36,11 @@ import { CanvasFrameOptions } from '../frame'; import { DEFAULT_CANVAS_ELEMENT_CONFIG } from '../registry'; import { SceneTransformWrapper } from './SceneTransformWrapper'; -import { constraintViewable, dimensionViewable, settingsViewable } from './ables'; import { ElementState } from './element'; import { FrameState } from './frame'; import { RootElement } from './root'; +import { initMoveable } from './sceneAbleManagement'; +import { findElementByTarget } from './sceneElementManagement'; export interface SelectionParams { targets: Array; @@ -176,7 +170,7 @@ export class Scene { if (this.div) { // If editing is enabled, clear selecto instance const destroySelecto = enableEditing; - this.initMoveable(destroySelecto, enableEditing); + initMoveable(destroySelecto, enableEditing, this); this.currentLayer = this.root; this.selection.next([]); this.connections.select(undefined); @@ -210,126 +204,24 @@ export class Scene { } } - frameSelection() { - this.selection.pipe(first()).subscribe((currentSelectedElements) => { - const currentLayer = currentSelectedElements[0].parent!; - - const newLayer = new FrameState( - { - type: 'frame', - name: this.getNextElementName(true), - elements: [], - }, - this, - currentSelectedElements[0].parent - ); - - const framePlacement = this.generateFrameContainer(currentSelectedElements); - - newLayer.options.placement = framePlacement; - - currentSelectedElements.forEach((element: ElementState) => { - const elementContainer = element.div?.getBoundingClientRect(); - - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - element.setPlacementFromConstraint(elementContainer, framePlacement as DOMRect); - currentLayer.doAction(LayerActionID.Delete, element); - newLayer.doAction(LayerActionID.Duplicate, element, false, false); - }); - - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - newLayer.setPlacementFromConstraint(framePlacement as DOMRect, currentLayer.div?.getBoundingClientRect()); - - currentLayer.elements.push(newLayer); - - this.byName.set(newLayer.getName(), newLayer); - - this.save(); - }); - } - - private generateFrameContainer = (elements: ElementState[]): Placement => { - let minTop = Infinity; - let minLeft = Infinity; - let maxRight = 0; - let maxBottom = 0; - - elements.forEach((element: ElementState) => { - const elementContainer = element.div?.getBoundingClientRect(); - - if (!elementContainer) { - return; - } - - if (minTop > elementContainer.top) { - minTop = elementContainer.top; - } - - if (minLeft > elementContainer.left) { - minLeft = elementContainer.left; - } - - if (maxRight < elementContainer.right) { - maxRight = elementContainer.right; - } - - if (maxBottom < elementContainer.bottom) { - maxBottom = elementContainer.bottom; - } - }); - - return { - top: minTop, - left: minLeft, - width: maxRight - minLeft, - height: maxBottom - minTop, - }; - }; - clearCurrentSelection(skipNextSelectionBroadcast = false) { this.skipNextSelectionBroadcast = skipNextSelectionBroadcast; let event: MouseEvent = new MouseEvent('click'); this.selecto?.clickTarget(event, this.div); } - updateCurrentLayer(newLayer: FrameState) { - this.currentLayer = newLayer; - this.clearCurrentSelection(); - this.save(); - } - save = (updateMoveable = false) => { this.onSave(this.root.getSaveModel()); if (updateMoveable) { setTimeout(() => { if (this.div) { - this.initMoveable(true, this.isEditingEnabled); + initMoveable(true, this.isEditingEnabled, this); } }); } }; - findElementByTarget = (target: Element): ElementState | undefined => { - // We will probably want to add memoization to this as we are calling on drag / resize - - const stack = [...this.root.elements]; - while (stack.length > 0) { - const currentElement = stack.shift(); - - if (currentElement && currentElement.div && currentElement.div === target) { - return currentElement; - } - - const nestedElements = currentElement instanceof FrameState ? currentElement.elements : []; - for (const nestedElement of nestedElements) { - stack.unshift(nestedElement); - } - } - - return undefined; - }; - setNonTargetPointerEvents = (target: Element, disablePointerEvents: boolean) => { const stack = [...this.root.elements]; while (stack.length > 0) { @@ -363,7 +255,7 @@ export class Scene { } }; - private updateSelection = (selection: SelectionParams) => { + updateSelection = (selection: SelectionParams) => { this.moveable!.target = selection.targets; if (this.skipNextSelectionBroadcast) { this.skipNextSelectionBroadcast = false; @@ -373,431 +265,11 @@ export class Scene { if (selection.frame) { this.selection.next([selection.frame]); } else { - const s = selection.targets.map((t) => this.findElementByTarget(t)!); + const s = selection.targets.map((t) => findElementByTarget(t, this.root.elements)!); this.selection.next(s); } }; - private generateTargetElements = (rootElements: ElementState[]): HTMLDivElement[] => { - let targetElements: HTMLDivElement[] = []; - - const stack = [...rootElements]; - while (stack.length > 0) { - const currentElement = stack.shift(); - - if (currentElement && currentElement.div) { - targetElements.push(currentElement.div); - } - - const nestedElements = currentElement instanceof FrameState ? currentElement.elements : []; - for (const nestedElement of nestedElements) { - stack.unshift(nestedElement); - } - } - - return targetElements; - }; - - disableCustomables = () => { - this.moveable!.props = { - dimensionViewable: false, - constraintViewable: false, - settingsViewable: false, - }; - }; - - enableCustomables = () => { - this.moveable!.props = { - dimensionViewable: true, - constraintViewable: true, - settingsViewable: true, - }; - }; - - initMoveable = (destroySelecto = false, allowChanges = true) => { - const targetElements = this.generateTargetElements(this.root.elements); - - if (destroySelecto && this.selecto) { - this.selecto.destroy(); - } - - this.selecto = new Selecto({ - container: this.div, - rootContainer: getParent(this), - selectableTargets: targetElements, - toggleContinueSelect: 'shift', - selectFromInside: false, - hitRate: 0, - }); - - const snapDirections = { top: true, left: true, bottom: true, right: true, center: true, middle: true }; - const elementSnapDirections = { top: true, left: true, bottom: true, right: true, center: true, middle: true }; - - this.moveable = new Moveable(this.div!, { - draggable: allowChanges && !this.editModeEnabled.getValue(), - resizable: allowChanges, - - // Setup rotatable - rotatable: allowChanges, - throttleRotate: 5, - rotationPosition: ['top', 'right'], - - // Setup snappable - snappable: allowChanges, - snapDirections: snapDirections, - elementSnapDirections: elementSnapDirections, - elementGuidelines: targetElements, - - ables: [dimensionViewable, constraintViewable(this), settingsViewable(this)], - props: { - dimensionViewable: allowChanges, - constraintViewable: allowChanges, - settingsViewable: allowChanges, - }, - origin: false, - }) - .on('rotateStart', () => { - this.disableCustomables(); - }) - .on('rotate', (event) => { - const targetedElement = this.findElementByTarget(event.target); - - if (targetedElement) { - targetedElement.applyRotate(event); - } - }) - .on('rotateGroup', (e) => { - for (let event of e.events) { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.applyRotate(event); - } - } - }) - .on('rotateEnd', () => { - this.enableCustomables(); - // Update the editor with the new rotation - this.moved.next(Date.now()); - }) - .on('click', (event) => { - const targetedElement = this.findElementByTarget(event.target); - let elementSupportsEditing = false; - if (targetedElement) { - elementSupportsEditing = targetedElement.item.hasEditMode ?? false; - } - - if (event.isDouble && allowChanges && !this.editModeEnabled.getValue() && elementSupportsEditing) { - this.editModeEnabled.next(true); - } - }) - .on('clickGroup', (event) => { - this.selecto!.clickTarget(event.inputEvent, event.inputTarget); - }) - .on('dragStart', (event) => { - this.ignoreDataUpdate = true; - this.setNonTargetPointerEvents(event.target, true); - - // Remove the selected element from the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - const targetIndex = this.moveable.elementGuidelines.indexOf(event.target); - if (targetIndex > -1) { - this.moveable.elementGuidelines.splice(targetIndex, 1); - } - } - }) - .on('dragGroupStart', (e) => { - this.ignoreDataUpdate = true; - - // Remove the selected elements from the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - for (let event of e.events) { - const targetIndex = this.moveable.elementGuidelines.indexOf(event.target); - if (targetIndex > -1) { - this.moveable.elementGuidelines.splice(targetIndex, 1); - } - } - } - }) - .on('drag', (event) => { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.applyDrag(event); - - if (this.connections.connectionsNeedUpdate(targetedElement) && this.moveableActionCallback) { - this.moveableActionCallback(true); - } - } - }) - .on('dragGroup', (e) => { - let needsUpdate = false; - for (let event of e.events) { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.applyDrag(event); - if (!needsUpdate) { - needsUpdate = this.connections.connectionsNeedUpdate(targetedElement); - } - } - } - - if (needsUpdate && this.moveableActionCallback) { - this.moveableActionCallback(true); - } - }) - .on('dragGroupEnd', (e) => { - e.events.forEach((event) => { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - if (targetedElement) { - targetedElement.setPlacementFromConstraint(undefined, undefined, this.scale); - } - - // re-add the selected elements to the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - this.moveable.elementGuidelines.push(event.target); - } - } - }); - - this.moved.next(Date.now()); - this.ignoreDataUpdate = false; - }) - .on('dragEnd', (event) => { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.setPlacementFromConstraint(undefined, undefined, this.scale); - } - - this.moved.next(Date.now()); - this.ignoreDataUpdate = false; - this.setNonTargetPointerEvents(event.target, false); - - // re-add the selected element to the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - this.moveable.elementGuidelines.push(event.target); - } - }) - .on('resizeStart', (event) => { - const targetedElement = this.findElementByTarget(event.target); - - if (targetedElement) { - // Remove the selected element from the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - const targetIndex = this.moveable.elementGuidelines.indexOf(event.target); - if (targetIndex > -1) { - this.moveable.elementGuidelines.splice(targetIndex, 1); - } - } - - targetedElement.tempConstraint = { ...targetedElement.options.constraint }; - targetedElement.options.constraint = { - vertical: VerticalConstraint.Top, - horizontal: HorizontalConstraint.Left, - }; - targetedElement.setPlacementFromConstraint(undefined, undefined, this.scale); - } - }) - .on('resizeGroupStart', (e) => { - // Remove the selected elements from the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - for (let event of e.events) { - const targetIndex = this.moveable.elementGuidelines.indexOf(event.target); - if (targetIndex > -1) { - this.moveable.elementGuidelines.splice(targetIndex, 1); - } - } - } - }) - .on('resize', (event) => { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.applyResize(event, this.scale); - - if (this.connections.connectionsNeedUpdate(targetedElement) && this.moveableActionCallback) { - this.moveableActionCallback(true); - } - } - this.moved.next(Date.now()); // TODO only on end - }) - .on('resizeGroup', (e) => { - let needsUpdate = false; - for (let event of e.events) { - const targetedElement = this.findElementByTarget(event.target); - if (targetedElement) { - targetedElement.applyResize(event); - - if (!needsUpdate) { - needsUpdate = this.connections.connectionsNeedUpdate(targetedElement); - } - } - } - - if (needsUpdate && this.moveableActionCallback) { - this.moveableActionCallback(true); - } - - this.moved.next(Date.now()); // TODO only on end - }) - .on('resizeEnd', (event) => { - const targetedElement = this.findElementByTarget(event.target); - - if (targetedElement) { - if (targetedElement.tempConstraint) { - targetedElement.options.constraint = targetedElement.tempConstraint; - targetedElement.tempConstraint = undefined; - } - - targetedElement.setPlacementFromConstraint(undefined, undefined, this.scale); - - // re-add the selected element to the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - this.moveable.elementGuidelines.push(event.target); - } - } - }) - .on('resizeGroupEnd', (e) => { - // re-add the selected elements to the snappable guidelines - if (this.moveable && this.moveable.elementGuidelines) { - for (let event of e.events) { - this.moveable.elementGuidelines.push(event.target); - } - } - }); - - let targets: Array = []; - this.selecto!.on('dragStart', (event) => { - const selectedTarget = event.inputEvent.target; - - // If selected target is a connection control, eject to handle connection event - if (selectedTarget.id === CONNECTION_ANCHOR_DIV_ID) { - this.connections.handleConnectionDragStart(selectedTarget, event.inputEvent.clientX, event.inputEvent.clientY); - event.stop(); - return; - } - - // If selected target is a vertex, eject to handle vertex event - if (selectedTarget.id === CONNECTION_VERTEX_ID) { - this.connections.handleVertexDragStart(selectedTarget); - event.stop(); - return; - } - - // If selected target is an add vertex point, eject to handle add vertex event - if (selectedTarget.id === CONNECTION_VERTEX_ADD_ID) { - this.connections.handleVertexAddDragStart(selectedTarget); - event.stop(); - return; - } - - const isTargetMoveableElement = - this.moveable!.isMoveableElement(selectedTarget) || - targets.some((target) => target === selectedTarget || target.contains(selectedTarget)); - - const isTargetAlreadySelected = this.selecto - ?.getSelectedTargets() - .includes(selectedTarget.parentElement.parentElement); - - // Apply grabbing cursor while dragging, applyLayoutStylesToDiv() resets it to grab when done - if ( - this.isEditingEnabled && - !this.editModeEnabled.getValue() && - isTargetMoveableElement && - this.selecto?.getSelectedTargets().length - ) { - this.selecto.getSelectedTargets()[0].style.cursor = 'grabbing'; - } - - if (isTargetMoveableElement || isTargetAlreadySelected || !this.isEditingEnabled) { - // Prevent drawing selection box when selected target is a moveable element or already selected - event.stop(); - } - }) - .on('select', () => { - this.editModeEnabled.next(false); - - // Hide connection anchors on select - if (this.connections.connectionAnchorDiv) { - this.connections.connectionAnchorDiv.style.display = 'none'; - } - }) - .on('selectEnd', (event) => { - targets = event.selected; - this.updateSelection({ targets }); - - if (event.isDragStart) { - if (this.isEditingEnabled && !this.editModeEnabled.getValue() && this.selecto?.getSelectedTargets().length) { - this.selecto.getSelectedTargets()[0].style.cursor = 'grabbing'; - } - event.inputEvent.preventDefault(); - event.data.timer = setTimeout(() => { - this.moveable!.dragStart(event.inputEvent); - }); - } - }) - .on('dragEnd', (event) => { - clearTimeout(event.data.timer); - }); - }; - - reorderElements = (src: ElementState, dest: ElementState, dragToGap: boolean, destPosition: number) => { - switch (dragToGap) { - case true: - switch (destPosition) { - case -1: - // top of the tree - if (src.parent instanceof FrameState) { - // move outside the frame - if (dest.parent) { - this.updateElements(src, dest.parent, dest.parent.elements.length); - src.updateData(dest.parent.scene.context); - } - } else { - dest.parent?.reorderTree(src, dest, true); - } - break; - default: - if (dest.parent) { - this.updateElements(src, dest.parent, dest.parent.elements.indexOf(dest)); - src.updateData(dest.parent.scene.context); - } - break; - } - break; - case false: - if (dest instanceof FrameState) { - if (src.parent === dest) { - // same frame parent - src.parent?.reorderTree(src, dest, true); - } else { - this.updateElements(src, dest); - src.updateData(dest.scene.context); - } - } else if (src.parent === dest.parent) { - src.parent?.reorderTree(src, dest); - } else { - if (dest.parent) { - this.updateElements(src, dest.parent); - src.updateData(dest.parent.scene.context); - } - } - break; - } - }; - - private updateElements = (src: ElementState, dest: FrameState | RootElement, idx: number | null = null) => { - src.parent?.doAction(LayerActionID.Delete, src); - src.parent = dest; - - const elementContainer = src.div?.getBoundingClientRect(); - src.setPlacementFromConstraint(elementContainer, dest.div?.getBoundingClientRect()); - - const destIndex = idx ?? dest.elements.length - 1; - dest.elements.splice(destIndex, 0, src); - dest.scene.save(); - - dest.reinitializeMoveable(); - }; - addToSelection = () => { try { let selection: SelectionParams = { targets: [] }; diff --git a/public/app/features/canvas/runtime/sceneAbleManagement.ts b/public/app/features/canvas/runtime/sceneAbleManagement.ts new file mode 100644 index 00000000000..b5b0aa06cc4 --- /dev/null +++ b/public/app/features/canvas/runtime/sceneAbleManagement.ts @@ -0,0 +1,382 @@ +import Moveable from 'moveable'; +import Selecto from 'selecto'; + +import { CONNECTION_ANCHOR_DIV_ID } from 'app/plugins/panel/canvas/components/connections/ConnectionAnchors'; +import { + CONNECTION_VERTEX_ID, + CONNECTION_VERTEX_ADD_ID, +} from 'app/plugins/panel/canvas/components/connections/Connections'; +import { VerticalConstraint, HorizontalConstraint } from 'app/plugins/panel/canvas/panelcfg.gen'; +import { getParent } from 'app/plugins/panel/canvas/utils'; + +import { dimensionViewable, constraintViewable, settingsViewable } from './ables'; +import { ElementState } from './element'; +import { FrameState } from './frame'; +import { Scene } from './scene'; +import { findElementByTarget } from './sceneElementManagement'; + +// Helper function that disables custom able functionality +const disableCustomables = (moveable: Moveable) => { + moveable!.props = { + dimensionViewable: false, + constraintViewable: false, + settingsViewable: false, + }; +}; + +// Helper function that enables custom able functionality +const enableCustomables = (moveable: Moveable) => { + moveable!.props = { + dimensionViewable: true, + constraintViewable: true, + settingsViewable: true, + }; +}; + +// Generate HTML element divs for every canvas element to configure selecto / moveable +const generateTargetElements = (rootElements: ElementState[]): HTMLDivElement[] => { + let targetElements: HTMLDivElement[] = []; + + const stack = [...rootElements]; + while (stack.length > 0) { + const currentElement = stack.shift(); + + if (currentElement && currentElement.div) { + targetElements.push(currentElement.div); + } + + const nestedElements = currentElement instanceof FrameState ? currentElement.elements : []; + for (const nestedElement of nestedElements) { + stack.unshift(nestedElement); + } + } + + return targetElements; +}; + +// Main entry point for initializing / updating moveable and selecto configuration +export const initMoveable = (destroySelecto = false, allowChanges = true, scene: Scene) => { + const targetElements = generateTargetElements(scene.root.elements); + + if (destroySelecto && scene.selecto) { + scene.selecto.destroy(); + } + + scene.selecto = new Selecto({ + container: scene.div, + rootContainer: getParent(scene), + selectableTargets: targetElements, + toggleContinueSelect: 'shift', + selectFromInside: false, + hitRate: 0, + }); + + const snapDirections = { top: true, left: true, bottom: true, right: true, center: true, middle: true }; + const elementSnapDirections = { top: true, left: true, bottom: true, right: true, center: true, middle: true }; + + scene.moveable = new Moveable(scene.div!, { + draggable: allowChanges && !scene.editModeEnabled.getValue(), + resizable: allowChanges, + + // Setup rotatable + rotatable: allowChanges, + throttleRotate: 5, + rotationPosition: ['top', 'right'], + + // Setup snappable + snappable: allowChanges, + snapDirections: snapDirections, + elementSnapDirections: elementSnapDirections, + elementGuidelines: targetElements, + + ables: [dimensionViewable, constraintViewable(scene), settingsViewable(scene)], + props: { + dimensionViewable: allowChanges, + constraintViewable: allowChanges, + settingsViewable: allowChanges, + }, + origin: false, + }) + .on('rotateStart', () => { + disableCustomables(scene.moveable!); + }) + .on('rotate', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + + if (targetedElement) { + targetedElement.applyRotate(event); + } + }) + .on('rotateGroup', (e) => { + for (let event of e.events) { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.applyRotate(event); + } + } + }) + .on('rotateEnd', () => { + enableCustomables(scene.moveable!); + // Update the editor with the new rotation + scene.moved.next(Date.now()); + }) + .on('click', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + let elementSupportsEditing = false; + if (targetedElement) { + elementSupportsEditing = targetedElement.item.hasEditMode ?? false; + } + + if (event.isDouble && allowChanges && !scene.editModeEnabled.getValue() && elementSupportsEditing) { + scene.editModeEnabled.next(true); + } + }) + .on('clickGroup', (event) => { + scene.selecto!.clickTarget(event.inputEvent, event.inputTarget); + }) + .on('dragStart', (event) => { + scene.ignoreDataUpdate = true; + scene.setNonTargetPointerEvents(event.target, true); + + // Remove the selected element from the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + const targetIndex = scene.moveable.elementGuidelines.indexOf(event.target); + if (targetIndex > -1) { + scene.moveable.elementGuidelines.splice(targetIndex, 1); + } + } + }) + .on('dragGroupStart', (e) => { + scene.ignoreDataUpdate = true; + + // Remove the selected elements from the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + for (let event of e.events) { + const targetIndex = scene.moveable.elementGuidelines.indexOf(event.target); + if (targetIndex > -1) { + scene.moveable.elementGuidelines.splice(targetIndex, 1); + } + } + } + }) + .on('drag', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.applyDrag(event); + + if (scene.connections.connectionsNeedUpdate(targetedElement) && scene.moveableActionCallback) { + scene.moveableActionCallback(true); + } + } + }) + .on('dragGroup', (e) => { + let needsUpdate = false; + for (let event of e.events) { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.applyDrag(event); + if (!needsUpdate) { + needsUpdate = scene.connections.connectionsNeedUpdate(targetedElement); + } + } + } + + if (needsUpdate && scene.moveableActionCallback) { + scene.moveableActionCallback(true); + } + }) + .on('dragGroupEnd', (e) => { + e.events.forEach((event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + if (targetedElement) { + targetedElement.setPlacementFromConstraint(undefined, undefined, scene.scale); + } + + // re-add the selected elements to the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + scene.moveable.elementGuidelines.push(event.target); + } + } + }); + + scene.moved.next(Date.now()); + scene.ignoreDataUpdate = false; + }) + .on('dragEnd', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.setPlacementFromConstraint(undefined, undefined, scene.scale); + } + + scene.moved.next(Date.now()); + scene.ignoreDataUpdate = false; + scene.setNonTargetPointerEvents(event.target, false); + + // re-add the selected element to the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + scene.moveable.elementGuidelines.push(event.target); + } + }) + .on('resizeStart', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + + if (targetedElement) { + // Remove the selected element from the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + const targetIndex = scene.moveable.elementGuidelines.indexOf(event.target); + if (targetIndex > -1) { + scene.moveable.elementGuidelines.splice(targetIndex, 1); + } + } + + targetedElement.tempConstraint = { ...targetedElement.options.constraint }; + targetedElement.options.constraint = { + vertical: VerticalConstraint.Top, + horizontal: HorizontalConstraint.Left, + }; + targetedElement.setPlacementFromConstraint(undefined, undefined, scene.scale); + } + }) + .on('resizeGroupStart', (e) => { + // Remove the selected elements from the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + for (let event of e.events) { + const targetIndex = scene.moveable.elementGuidelines.indexOf(event.target); + if (targetIndex > -1) { + scene.moveable.elementGuidelines.splice(targetIndex, 1); + } + } + } + }) + .on('resize', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.applyResize(event, scene.scale); + + if (scene.connections.connectionsNeedUpdate(targetedElement) && scene.moveableActionCallback) { + scene.moveableActionCallback(true); + } + } + scene.moved.next(Date.now()); // TODO only on end + }) + .on('resizeGroup', (e) => { + let needsUpdate = false; + for (let event of e.events) { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + if (targetedElement) { + targetedElement.applyResize(event); + + if (!needsUpdate) { + needsUpdate = scene.connections.connectionsNeedUpdate(targetedElement); + } + } + } + + if (needsUpdate && scene.moveableActionCallback) { + scene.moveableActionCallback(true); + } + + scene.moved.next(Date.now()); // TODO only on end + }) + .on('resizeEnd', (event) => { + const targetedElement = findElementByTarget(event.target, scene.root.elements); + + if (targetedElement) { + if (targetedElement.tempConstraint) { + targetedElement.options.constraint = targetedElement.tempConstraint; + targetedElement.tempConstraint = undefined; + } + + targetedElement.setPlacementFromConstraint(undefined, undefined, scene.scale); + + // re-add the selected element to the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + scene.moveable.elementGuidelines.push(event.target); + } + } + }) + .on('resizeGroupEnd', (e) => { + // re-add the selected elements to the snappable guidelines + if (scene.moveable && scene.moveable.elementGuidelines) { + for (let event of e.events) { + scene.moveable.elementGuidelines.push(event.target); + } + } + }); + + let targets: Array = []; + scene + .selecto!.on('dragStart', (event) => { + const selectedTarget = event.inputEvent.target; + + // If selected target is a connection control, eject to handle connection event + if (selectedTarget.id === CONNECTION_ANCHOR_DIV_ID) { + scene.connections.handleConnectionDragStart(selectedTarget, event.inputEvent.clientX, event.inputEvent.clientY); + event.stop(); + return; + } + + // If selected target is a vertex, eject to handle vertex event + if (selectedTarget.id === CONNECTION_VERTEX_ID) { + scene.connections.handleVertexDragStart(selectedTarget); + event.stop(); + return; + } + + // If selected target is an add vertex point, eject to handle add vertex event + if (selectedTarget.id === CONNECTION_VERTEX_ADD_ID) { + scene.connections.handleVertexAddDragStart(selectedTarget); + event.stop(); + return; + } + + const isTargetMoveableElement = + scene.moveable!.isMoveableElement(selectedTarget) || + targets.some((target) => target === selectedTarget || target.contains(selectedTarget)); + + const isTargetAlreadySelected = scene.selecto + ?.getSelectedTargets() + .includes(selectedTarget.parentElement.parentElement); + + // Apply grabbing cursor while dragging, applyLayoutStylesToDiv() resets it to grab when done + if ( + scene.isEditingEnabled && + !scene.editModeEnabled.getValue() && + isTargetMoveableElement && + scene.selecto?.getSelectedTargets().length + ) { + scene.selecto.getSelectedTargets()[0].style.cursor = 'grabbing'; + } + + if (isTargetMoveableElement || isTargetAlreadySelected || !scene.isEditingEnabled) { + // Prevent drawing selection box when selected target is a moveable element or already selected + event.stop(); + } + }) + .on('select', () => { + scene.editModeEnabled.next(false); + + // Hide connection anchors on select + if (scene.connections.connectionAnchorDiv) { + scene.connections.connectionAnchorDiv.style.display = 'none'; + } + }) + .on('selectEnd', (event) => { + targets = event.selected; + scene.updateSelection({ targets }); + + if (event.isDragStart) { + if (scene.isEditingEnabled && !scene.editModeEnabled.getValue() && scene.selecto?.getSelectedTargets().length) { + scene.selecto.getSelectedTargets()[0].style.cursor = 'grabbing'; + } + event.inputEvent.preventDefault(); + event.data.timer = setTimeout(() => { + scene.moveable!.dragStart(event.inputEvent); + }); + } + }) + .on('dragEnd', (event) => { + clearTimeout(event.data.timer); + }); +}; diff --git a/public/app/features/canvas/runtime/sceneElementManagement.ts b/public/app/features/canvas/runtime/sceneElementManagement.ts new file mode 100644 index 00000000000..9a2e94db2d0 --- /dev/null +++ b/public/app/features/canvas/runtime/sceneElementManagement.ts @@ -0,0 +1,170 @@ +import { first } from 'rxjs/operators'; + +import { Placement } from 'app/plugins/panel/canvas/panelcfg.gen'; +import { LayerActionID } from 'app/plugins/panel/canvas/types'; + +import { ElementState } from './element'; +import { FrameState } from './frame'; +import { RootElement } from './root'; +import { Scene } from './scene'; + +// TODO: Consider whether or not reorderElements + updateElements should be moved to TreeNavigationEditor +// Reorder elements in the DOM when rearranging them in the tree navigation editor +export const reorderElements = (src: ElementState, dest: ElementState, dragToGap: boolean, destPosition: number) => { + switch (dragToGap) { + case true: + switch (destPosition) { + case -1: + // top of the tree + if (src.parent instanceof FrameState) { + // move outside the frame + if (dest.parent) { + updateElements(src, dest.parent, dest.parent.elements.length); + src.updateData(dest.parent.scene.context); + } + } else { + dest.parent?.reorderTree(src, dest, true); + } + break; + default: + if (dest.parent) { + updateElements(src, dest.parent, dest.parent.elements.indexOf(dest)); + src.updateData(dest.parent.scene.context); + } + break; + } + break; + case false: + if (dest instanceof FrameState) { + if (src.parent === dest) { + // same frame parent + src.parent?.reorderTree(src, dest, true); + } else { + updateElements(src, dest); + src.updateData(dest.scene.context); + } + } else if (src.parent === dest.parent) { + src.parent?.reorderTree(src, dest); + } else { + if (dest.parent) { + updateElements(src, dest.parent); + src.updateData(dest.parent.scene.context); + } + } + break; + } +}; + +// Reorders canvas elements +const updateElements = (src: ElementState, dest: FrameState | RootElement, idx: number | null = null) => { + src.parent?.doAction(LayerActionID.Delete, src); + src.parent = dest; + + const elementContainer = src.div?.getBoundingClientRect(); + src.setPlacementFromConstraint(elementContainer, dest.div?.getBoundingClientRect()); + + const destIndex = idx ?? dest.elements.length - 1; + dest.elements.splice(destIndex, 0, src); + dest.scene.save(); + + dest.reinitializeMoveable(); +}; + +// Finds the element state if it exists for a given DOM element +export const findElementByTarget = (target: Element, sceneElements: ElementState[]): ElementState | undefined => { + // We will probably want to add memoization to this as we are calling on drag / resize + + const stack = [...sceneElements]; + while (stack.length > 0) { + const currentElement = stack.shift(); + + if (currentElement && currentElement.div && currentElement.div === target) { + return currentElement; + } + + const nestedElements = currentElement instanceof FrameState ? currentElement.elements : []; + for (const nestedElement of nestedElements) { + stack.unshift(nestedElement); + } + } + + return undefined; +}; + +// Nest selected elements into a frame object +export const frameSelection = (scene: Scene) => { + scene.selection.pipe(first()).subscribe((currentSelectedElements) => { + const currentLayer = currentSelectedElements[0].parent!; + + const newLayer = new FrameState( + { + type: 'frame', + name: scene.getNextElementName(true), + elements: [], + }, + scene, + currentSelectedElements[0].parent + ); + + const framePlacement = generateFrameContainer(currentSelectedElements); + + newLayer.options.placement = framePlacement; + + currentSelectedElements.forEach((element: ElementState) => { + const elementContainer = element.div?.getBoundingClientRect(); + + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + element.setPlacementFromConstraint(elementContainer, framePlacement as DOMRect); + currentLayer.doAction(LayerActionID.Delete, element); + newLayer.doAction(LayerActionID.Duplicate, element, false, false); + }); + + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + newLayer.setPlacementFromConstraint(framePlacement as DOMRect, currentLayer.div?.getBoundingClientRect()); + + currentLayer.elements.push(newLayer); + + scene.byName.set(newLayer.getName(), newLayer); + + scene.save(); + }); +}; + +// Helper function to generate the a frame object based on the selected elements' dimensions +const generateFrameContainer = (elements: ElementState[]): Placement => { + let minTop = Infinity; + let minLeft = Infinity; + let maxRight = 0; + let maxBottom = 0; + + elements.forEach((element: ElementState) => { + const elementContainer = element.div?.getBoundingClientRect(); + + if (!elementContainer) { + return; + } + + if (minTop > elementContainer.top) { + minTop = elementContainer.top; + } + + if (minLeft > elementContainer.left) { + minLeft = elementContainer.left; + } + + if (maxRight < elementContainer.right) { + maxRight = elementContainer.right; + } + + if (maxBottom < elementContainer.bottom) { + maxBottom = elementContainer.bottom; + } + }); + + return { + top: minTop, + left: minLeft, + width: maxRight - minLeft, + height: maxBottom - minTop, + }; +}; diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx index f5fb5a5b40c..01fcf60706b 100644 --- a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx @@ -2,21 +2,22 @@ import React, { useCallback, useState } from 'react'; import { useAsyncFn } from 'react-use'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { VizPanel } from '@grafana/scenes'; import { Button, ButtonGroup, Dropdown } from '@grafana/ui'; -import { createAndCopyDashboardShortLink } from 'app/core/utils/shortLinks'; import { DashboardScene } from '../../scene/DashboardScene'; import { DashboardInteractions } from '../../utils/interactions'; import ShareMenu from './ShareMenu'; +import { buildShareUrl } from './utils'; const newShareButtonSelector = e2eSelectors.pages.Dashboard.DashNav.newShareButton; -export default function ShareButton({ dashboard }: { dashboard: DashboardScene }) { +export default function ShareButton({ dashboard, panel }: { dashboard: DashboardScene; panel?: VizPanel }) { const [isOpen, setIsOpen] = useState(false); const [_, buildUrl] = useAsyncFn(async () => { - return await createAndCopyDashboardShortLink(dashboard, { useAbsoluteTimeRange: true, theme: 'current' }); + return await buildShareUrl(dashboard, panel); }, [dashboard]); const onMenuClick = useCallback((isOpen: boolean) => { diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.test.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.test.tsx index 687c391d7bd..e6dcc4a9eda 100644 --- a/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.test.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.test.tsx @@ -5,6 +5,7 @@ import React from 'react'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { SceneGridLayout, SceneTimeRange, VizPanel } from '@grafana/scenes'; +import { config } from '../../../../core/config'; import { DashboardGridItem } from '../../scene/DashboardGridItem'; import { DashboardScene } from '../../scene/DashboardScene'; @@ -18,6 +19,21 @@ jest.mock('app/core/utils/shortLinks', () => ({ const selector = e2eSelectors.pages.Dashboard.DashNav.newShareButton.menu; describe('ShareMenu', () => { + it('should render menu items', async () => { + config.featureToggles.publicDashboards = true; + config.publicDashboardsEnabled = true; + setup(); + + expect(await screen.findByTestId(selector.shareInternally)).toBeInTheDocument(); + expect(await screen.findByTestId(selector.shareExternally)).toBeInTheDocument(); + }); + it('should no share externally when public dashboard is disabled', async () => { + config.featureToggles.publicDashboards = false; + config.publicDashboardsEnabled = false; + setup(); + + expect(await screen.queryByTestId(selector.shareExternally)).not.toBeInTheDocument(); + }); it('should call createAndCopyDashboardShortLink when share internally clicked', async () => { setup(); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.tsx index 3e40282c551..19fdf21f199 100644 --- a/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareButton/ShareMenu.tsx @@ -2,18 +2,32 @@ import React from 'react'; import { useAsyncFn } from 'react-use'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { VizPanel } from '@grafana/scenes'; import { Menu } from '@grafana/ui'; -import { createAndCopyDashboardShortLink } from '../../../../core/utils/shortLinks'; +import { isPublicDashboardsEnabled } from '../../../dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; import { DashboardScene } from '../../scene/DashboardScene'; +import { ShareDrawer } from '../ShareDrawer/ShareDrawer'; + +import { ShareExternally } from './share-externally/ShareExternally'; +import { buildShareUrl } from './utils'; const newShareButtonSelector = e2eSelectors.pages.Dashboard.DashNav.newShareButton.menu; -export default function ShareMenu({ dashboard }: { dashboard: DashboardScene }) { +export default function ShareMenu({ dashboard, panel }: { dashboard: DashboardScene; panel?: VizPanel }) { const [_, buildUrl] = useAsyncFn(async () => { - return await createAndCopyDashboardShortLink(dashboard, { useAbsoluteTimeRange: true, theme: 'current' }); + return await buildShareUrl(dashboard, panel); }, [dashboard]); + const onShareExternallyClick = () => { + const drawer = new ShareDrawer({ + title: 'Share externally', + body: new ShareExternally({}), + }); + + dashboard.showModal(drawer); + }; + return ( + {isPublicDashboardsEnabled() && ( + + )} ); } diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/ConfigEmailSharing.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/ConfigEmailSharing.tsx new file mode 100644 index 00000000000..9f317ad0879 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/ConfigEmailSharing.tsx @@ -0,0 +1,111 @@ +import React from 'react'; +import { useForm } from 'react-hook-form'; + +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { Button, Divider, Field, FieldSet, Icon, Stack, Tooltip } from '@grafana/ui'; +import { Input } from '@grafana/ui/src/components/Input/Input'; +import { contextSrv } from 'app/core/core'; +import { t, Trans } from 'app/core/internationalization'; +import { publicDashboardApi, useAddRecipientMutation } from 'app/features/dashboard/api/publicDashboardApi'; +import { validEmailRegex } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { useShareDrawerContext } from '../../../../ShareDrawer/ShareDrawerContext'; +import ShareConfiguration from '../../ShareConfiguration'; + +import { EmailListConfiguration } from './EmailListConfiguration'; + +const selectors = e2eSelectors.pages.ShareDashboardModal.PublicDashboard.EmailSharingConfiguration; + +type EmailSharingForm = { email: string }; + +export const ConfigEmailSharing = () => { + const { dashboard } = useShareDrawerContext(); + + const { data: publicDashboard, isError } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + const [addEmail, { isLoading: isAddEmailLoading }] = useAddRecipientMutation(); + + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + + const { + register, + handleSubmit, + formState: { errors, isValid }, + reset, + } = useForm({ + defaultValues: { + email: '', + }, + mode: 'onSubmit', + }); + + const onSubmit = async (data: EmailSharingForm) => { + DashboardInteractions.publicDashboardEmailInviteClicked(); + await addEmail({ recipient: data.email, uid: publicDashboard!.uid, dashboardUid: dashboard.state.uid! }).unwrap(); + reset({ email: '' }); + }; + + return ( +
+
+
+ + Invite + + + + + } + description={t( + 'public-dashboard.email-sharing.recipient-invitation-description', + 'Invite someone by email' + )} + error={errors.email?.message} + invalid={!!errors.email?.message} + > + + + + + +
+
+ + + +
+ ); +}; diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/EmailListConfiguration.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/EmailListConfiguration.tsx new file mode 100644 index 00000000000..157f24ec448 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/ConfigEmailSharing/EmailListConfiguration.tsx @@ -0,0 +1,148 @@ +import { css } from '@emotion/css'; +import React from 'react'; + +import { GrafanaTheme2 } from '@grafana/data'; +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { Dropdown, Field, Icon, Menu, Spinner, Stack, Text, useStyles2 } from '@grafana/ui'; +import { IconButton } from '@grafana/ui/'; +import { t } from 'app/core/internationalization'; +import { + useReshareAccessToRecipientMutation, + useDeleteRecipientMutation, + publicDashboardApi, +} from 'app/features/dashboard/api/publicDashboardApi'; +import { PublicDashboard } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; + +const selectors = e2eSelectors.pages.ShareDashboardModal.PublicDashboard.EmailSharingConfiguration; + +const RecipientMenu = ({ onDelete, onReshare }: { onDelete: () => void; onReshare: () => void }) => { + return ( + + + + + ); +}; + +const EmailList = ({ + recipients, + dashboardUid, + publicDashboard, +}: { + recipients: PublicDashboard['recipients']; + dashboardUid: string; + publicDashboard: PublicDashboard; +}) => { + const styles = useStyles2(getStyles); + + const [deleteEmail, { isLoading: isDeleteLoading }] = useDeleteRecipientMutation(); + const [reshareAccess, { isLoading: isReshareLoading }] = useReshareAccessToRecipientMutation(); + + const isLoading = isDeleteLoading || isReshareLoading; + + const onDeleteEmail = (recipientUid: string, recipientEmail: string) => { + DashboardInteractions.revokePublicDashboardEmailClicked(); + deleteEmail({ recipientUid, recipientEmail, dashboardUid: dashboardUid, uid: publicDashboard.uid }); + }; + + const onReshare = (recipientUid: string) => { + DashboardInteractions.resendPublicDashboardEmailClicked(); + reshareAccess({ recipientUid, uid: publicDashboard.uid }); + }; + + return ( + + + {recipients!.map((recipient, idx) => ( + + + + + + ))} + +
+ +
+ +
+ {recipient.recipient} +
+
{isLoading && } + onDeleteEmail(recipient.uid, recipient.recipient)} + onReshare={() => onReshare(recipient.uid)} + /> + } + > + + +
+ ); +}; + +export const EmailListConfiguration = ({ dashboard }: { dashboard: DashboardScene }) => { + const styles = useStyles2(getStyles); + const { data: publicDashboard } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + return ( + + {!!publicDashboard?.recipients?.length ? ( +
+ +
+ ) : ( + <> + )} +
+ ); +}; + +const getStyles = (theme: GrafanaTheme2) => ({ + listField: css({ + marginBottom: 0, + }), + listContainer: css({ + maxHeight: '140px', + overflowY: 'auto', + }), + table: css({ + width: '100%', + }), + listItem: css({ + display: 'flex', + alignItems: 'center', + gap: theme.spacing(0.5), + padding: theme.spacing(0.75, 1), + color: theme.colors.text.secondary, + }), + user: css({ + flex: 1, + }), + icon: css({ + border: `${theme.spacing(0.25)} solid ${theme.colors.text.secondary}`, + padding: theme.spacing(0.125, 0.5), + borderRadius: theme.shape.radius.circle, + color: theme.colors.text.secondary, + }), +}); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/CreateEmailSharing.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/CreateEmailSharing.tsx new file mode 100644 index 00000000000..8ade50db3eb --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/CreateEmailSharing.tsx @@ -0,0 +1,68 @@ +import { css } from '@emotion/css'; +import React from 'react'; +import { useForm } from 'react-hook-form'; + +import { GrafanaTheme2 } from '@grafana/data'; +import { Button, Checkbox, FieldSet, Spinner, Stack } from '@grafana/ui'; +import { useStyles2 } from '@grafana/ui/'; +import { contextSrv } from 'app/core/core'; +import { t, Trans } from 'app/core/internationalization'; +import { useCreatePublicDashboardMutation } from 'app/features/dashboard/api/publicDashboardApi'; +import { PublicDashboardShareType } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { EmailSharingPricingAlert } from '../../../../../dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/EmailSharingPricingAlert'; +import { useShareDrawerContext } from '../../../ShareDrawer/ShareDrawerContext'; + +export const CreateEmailSharing = ({ hasError }: { hasError: boolean }) => { + const { dashboard } = useShareDrawerContext(); + const styles = useStyles2(getStyles); + + const [createPublicDashboard, { isLoading, isError }] = useCreatePublicDashboardMutation(); + + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + const disableInputs = !hasWritePermissions || isLoading || isError || hasError; + + const { + handleSubmit, + register, + formState: { isValid }, + } = useForm<{ billAcknowledgment: boolean }>({ mode: 'onChange' }); + + const onCreate = () => { + DashboardInteractions.generatePublicDashboardUrlClicked({ share: PublicDashboardShareType.EMAIL }); + createPublicDashboard({ dashboard, payload: { share: PublicDashboardShareType.EMAIL, isEnabled: true } }); + }; + + return ( + <> + {hasWritePermissions && } +
+
+
+ +
+ + + + {isLoading && } + +
+
+ + ); +}; + +const getStyles = (theme: GrafanaTheme2) => ({ + checkbox: css({ + marginBottom: theme.spacing(2), + }), +}); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/EmailSharing.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/EmailSharing.tsx new file mode 100644 index 00000000000..41ca1fcd401 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/EmailShare/EmailSharing.tsx @@ -0,0 +1,17 @@ +import React from 'react'; + +import { publicDashboardApi } from 'app/features/dashboard/api/publicDashboardApi'; + +import { useShareDrawerContext } from '../../../ShareDrawer/ShareDrawerContext'; + +import { ConfigEmailSharing } from './ConfigEmailSharing/ConfigEmailSharing'; +import { CreateEmailSharing } from './CreateEmailSharing'; + +export const EmailSharing = () => { + const { dashboard } = useShareDrawerContext(); + const { data: publicDashboard, isError } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + + return <>{!publicDashboard ? : }; +}; diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/CreatePublicSharing.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/CreatePublicSharing.tsx new file mode 100644 index 00000000000..ef6aa224680 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/CreatePublicSharing.tsx @@ -0,0 +1,70 @@ +import { css } from '@emotion/css'; +import React from 'react'; +import { useForm } from 'react-hook-form'; + +import { GrafanaTheme2 } from '@grafana/data'; +import { Button, Checkbox, FieldSet, Spinner, Stack, useStyles2 } from '@grafana/ui'; +import { contextSrv } from 'app/core/core'; +import { t, Trans } from 'app/core/internationalization'; +import { useCreatePublicDashboardMutation } from 'app/features/dashboard/api/publicDashboardApi'; +import { PublicDashboardShareType } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { PublicDashboardAlert } from '../../../../../dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/PublicDashboardAlert'; +import { useShareDrawerContext } from '../../../ShareDrawer/ShareDrawerContext'; + +export default function CreatePublicSharing({ hasError }: { hasError: boolean }) { + const { dashboard } = useShareDrawerContext(); + const styles = useStyles2(getStyles); + + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + + const { + handleSubmit, + register, + formState: { isValid }, + } = useForm<{ publicAcknowledgment: boolean }>({ mode: 'onChange' }); + + const [createPublicDashboard, { isLoading, isError }] = useCreatePublicDashboardMutation(); + const onCreate = () => { + DashboardInteractions.generatePublicDashboardUrlClicked({ share: PublicDashboardShareType.PUBLIC }); + createPublicDashboard({ dashboard, payload: { share: PublicDashboardShareType.PUBLIC, isEnabled: true } }); + }; + + const disableInputs = !hasWritePermissions || isLoading || isError || hasError; + + return ( + <> + {hasWritePermissions && } +
+
+
+ +
+ + + + {isLoading && } + +
+
+ + ); +} + +const getStyles = (theme: GrafanaTheme2) => ({ + checkbox: css({ + marginBottom: theme.spacing(2), + }), +}); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/PublicSharing.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/PublicSharing.tsx new file mode 100644 index 00000000000..ae2050e0d80 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/PublicShare/PublicSharing.tsx @@ -0,0 +1,17 @@ +import React from 'react'; + +import { publicDashboardApi } from 'app/features/dashboard/api/publicDashboardApi'; + +import { useShareDrawerContext } from '../../../ShareDrawer/ShareDrawerContext'; +import ShareConfiguration from '../ShareConfiguration'; + +import CreatePublicSharing from './CreatePublicSharing'; + +export function PublicSharing() { + const { dashboard } = useShareDrawerContext(); + const { data: publicDashboard, isError } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + + return <>{!publicDashboard ? : }; +} diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.test.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.test.tsx new file mode 100644 index 00000000000..e51f9a44eb2 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.test.tsx @@ -0,0 +1,118 @@ +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; + +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { + CustomVariable, + SceneDataTransformer, + SceneGridLayout, + SceneQueryRunner, + SceneTimeRange, + SceneVariableSet, + VizPanel, + VizPanelState, +} from '@grafana/scenes'; +import { contextSrv } from 'app/core/core'; +import { DashboardGridItem } from 'app/features/dashboard-scene/scene/DashboardGridItem'; +import { DashboardScene, DashboardSceneState } from 'app/features/dashboard-scene/scene/DashboardScene'; + +import { ShareDrawerContext } from '../../ShareDrawer/ShareDrawerContext'; + +import ShareAlerts from './ShareAlerts'; + +const selectors = e2eSelectors.pages.ShareDashboardModal.PublicDashboard; + +beforeEach(() => { + jest.spyOn(contextSrv, 'hasPermission').mockReturnValue(true); +}); + +describe('ShareAlerts', () => { + describe('UnsupportedTemplateVariablesAlert', () => { + it('should render alert when hasPermission and the dashboard has template vars', async () => { + await setup(undefined, { + $variables: new SceneVariableSet({ + variables: [ + new CustomVariable({ + name: 'customVar', + query: 'test, test2', + value: 'test', + text: 'test', + }), + ], + }), + }); + + expect(await screen.findByTestId(selectors.TemplateVariablesWarningAlert)).toBeInTheDocument(); + }); + it('should not render alert when hasPermission but the dashboard has no template vars', async () => { + await setup(); + + expect(screen.queryByTestId(selectors.TemplateVariablesWarningAlert)).not.toBeInTheDocument(); + }); + }); + describe('UnsupportedDataSourcesAlert', () => { + it('should render alert when hasPermission and the dashboard has unsupported ds', async () => { + await setup({ + $data: new SceneDataTransformer({ + transformations: [], + $data: new SceneQueryRunner({ + datasource: { uid: 'abcdef' }, + queries: [{ refId: 'A', datasource: { type: 'abcdef' } }], + }), + }), + }); + + expect(await screen.findByTestId(selectors.UnsupportedDataSourcesWarningAlert)).toBeInTheDocument(); + }); + it('should not render alert when hasPermission but the dashboard has no unsupported ds', async () => { + await setup({ + $data: new SceneDataTransformer({ + transformations: [], + $data: new SceneQueryRunner({ + datasource: { uid: 'prometheus' }, + queries: [{ refId: 'A', datasource: { type: 'prometheus' } }], + }), + }), + }); + + expect(screen.queryByTestId(selectors.UnsupportedDataSourcesWarningAlert)).not.toBeInTheDocument(); + }); + }); +}); + +async function setup(panelState?: Partial, dashboardState?: Partial) { + const panel = new VizPanel({ + title: 'Panel A', + pluginId: 'table', + key: 'panel-12', + ...panelState, + }); + + const dashboard = new DashboardScene({ + title: 'hello', + uid: 'dash-1', + $timeRange: new SceneTimeRange({}), + body: new SceneGridLayout({ + children: [ + new DashboardGridItem({ + key: 'griditem-1', + x: 0, + y: 0, + width: 10, + height: 12, + body: panel, + }), + ], + }), + ...dashboardState, + }); + + await act(async () => + render( + + + + ) + ); +} diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.tsx new file mode 100644 index 00000000000..e1753bf046c --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareAlerts.tsx @@ -0,0 +1,36 @@ +import React from 'react'; + +import { contextSrv } from 'app/core/core'; +import { EmailSharingPricingAlert } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/EmailSharingPricingAlert'; +import { UnsupportedDataSourcesAlert } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/UnsupportedDataSourcesAlert'; +import { UnsupportedTemplateVariablesAlert } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/UnsupportedTemplateVariablesAlert'; +import { + isEmailSharingEnabled, + PublicDashboard, + PublicDashboardShareType, +} from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { AccessControlAction } from 'app/types'; + +import { NoUpsertPermissionsAlert } from '../../../../dashboard/components/ShareModal/SharePublicDashboard/ModalAlerts/NoUpsertPermissionsAlert'; +import { useShareDrawerContext } from '../../ShareDrawer/ShareDrawerContext'; +import { useUnsupportedDatasources } from '../../public-dashboards/hooks'; + +export default function ShareAlerts({ publicDashboard }: { publicDashboard?: PublicDashboard }) { + const { dashboard } = useShareDrawerContext(); + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + const unsupportedDataSources = useUnsupportedDatasources(dashboard); + const hasTemplateVariables = (dashboard.state.$variables?.state.variables.length ?? 0) > 0; + + return ( + <> + {hasWritePermissions && hasTemplateVariables && } + {!hasWritePermissions && } + {hasWritePermissions && !!unsupportedDataSources?.length && ( + + )} + {publicDashboard?.share === PublicDashboardShareType.EMAIL && isEmailSharingEnabled() && ( + + )} + + ); +} diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareConfiguration.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareConfiguration.tsx new file mode 100644 index 00000000000..91a2345ed8e --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareConfiguration.tsx @@ -0,0 +1,131 @@ +import React from 'react'; +import { Controller, useForm } from 'react-hook-form'; + +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { sceneGraph } from '@grafana/scenes'; +import { FieldSet, Icon, Label, Spinner, Stack, Text, TimeRangeInput, Tooltip } from '@grafana/ui'; +import { Switch } from '@grafana/ui/src/components/Switch/Switch'; +import { contextSrv } from 'app/core/core'; +import { Trans, t } from 'app/core/internationalization'; +import { publicDashboardApi, useUpdatePublicDashboardMutation } from 'app/features/dashboard/api/publicDashboardApi'; +import { ConfigPublicDashboardForm } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/ConfigPublicDashboard/ConfigPublicDashboard'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { useShareDrawerContext } from '../../ShareDrawer/ShareDrawerContext'; + +const selectors = e2eSelectors.pages.ShareDashboardModal.PublicDashboard; + +type FormInput = Omit; + +export default function ShareConfiguration() { + const { dashboard } = useShareDrawerContext(); + const [update, { isLoading }] = useUpdatePublicDashboardMutation(); + + const { data: publicDashboard } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + const disableForm = isLoading || !hasWritePermissions; + const timeRangeState = sceneGraph.getTimeRange(dashboard); + const timeRange = timeRangeState.useState(); + + const { handleSubmit, setValue, control } = useForm({ + defaultValues: { + isAnnotationsEnabled: publicDashboard?.annotationsEnabled, + isTimeSelectionEnabled: publicDashboard?.timeSelectionEnabled, + }, + }); + + const onChange = async (name: keyof FormInput, value: boolean) => { + setValue(name, value); + await handleSubmit((data) => onUpdate({ ...data, [name]: value }))(); + }; + + const onUpdate = (data: FormInput) => { + const { isAnnotationsEnabled, isTimeSelectionEnabled } = data; + + update({ + dashboard: dashboard, + payload: { + ...publicDashboard!, + annotationsEnabled: isAnnotationsEnabled, + timeSelectionEnabled: isTimeSelectionEnabled, + }, + }); + }; + + return ( + + + Settings + + +
+
+ + + ( + { + DashboardInteractions.publicDashboardTimeSelectionChanged({ + enabled: e.currentTarget.checked, + }); + onChange('isTimeSelectionEnabled', e.currentTarget.checked); + }} + label={t('public-dashboard.configuration.enable-time-range-label', 'Enable time range')} + /> + )} + control={control} + name="isTimeSelectionEnabled" + /> + + + + ( + { + DashboardInteractions.publicDashboardAnnotationsSelectionChanged({ + enabled: e.currentTarget.checked, + }); + onChange('isAnnotationsEnabled', e.currentTarget.checked); + }} + label={t('public-dashboard.configuration.display-annotations-label', 'Display annotations')} + /> + )} + control={control} + name="isAnnotationsEnabled" + /> + + + + {}} /> + + + + + +
+
+ {isLoading && } +
+
+ ); +} diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareExternally.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareExternally.tsx new file mode 100644 index 00000000000..3321d5074d2 --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareExternally.tsx @@ -0,0 +1,212 @@ +import { css } from '@emotion/css'; +import React, { useMemo, useState } from 'react'; + +import { GrafanaTheme2, SelectableValue } from '@grafana/data'; +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { SceneComponentProps, SceneObjectBase } from '@grafana/scenes'; +import { Button, ClipboardButton, Divider, Spinner, Stack, useStyles2 } from '@grafana/ui'; +import { contextSrv } from 'app/core/core'; +import { t, Trans } from 'app/core/internationalization'; +import { + useDeletePublicDashboardMutation, + useGetPublicDashboardQuery, + usePauseOrResumePublicDashboardMutation, +} from 'app/features/dashboard/api/publicDashboardApi'; +import { Loader } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard'; +import { + generatePublicDashboardUrl, + isEmailSharingEnabled, + PublicDashboard, + PublicDashboardShareType, +} from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { getDashboardSceneFor } from '../../../utils/utils'; +import { useShareDrawerContext } from '../../ShareDrawer/ShareDrawerContext'; + +import { EmailSharing } from './EmailShare/EmailSharing'; +import { PublicSharing } from './PublicShare/PublicSharing'; +import ShareAlerts from './ShareAlerts'; +import ShareTypeSelect from './ShareTypeSelect'; + +const selectors = e2eSelectors.pages.ShareDashboardDrawer.ShareExternally; + +export const getAnyOneWithTheLinkShareOption = () => { + return { + label: t('public-dashboard.share-externally.public-share-type-option-label', 'Anyone with the link'), + description: t( + 'public-dashboard.share-externally.public-share-type-option-description', + 'Anyone with the link can access' + ), + value: PublicDashboardShareType.PUBLIC, + icon: 'globe', + }; +}; + +const getOnlySpecificPeopleShareOption = () => ({ + label: t('public-dashboard.share-externally.email-share-type-option-label', 'Only specific people'), + description: t( + 'public-dashboard.share-externally.email-share-type-option-description', + 'Only people with access can open with the link' + ), + value: PublicDashboardShareType.EMAIL, + icon: 'users-alt', +}); + +const getShareExternallyOptions = () => { + return isEmailSharingEnabled() + ? [getOnlySpecificPeopleShareOption(), getAnyOneWithTheLinkShareOption()] + : [getAnyOneWithTheLinkShareOption()]; +}; + +export class ShareExternally extends SceneObjectBase { + static Component = ShareExternallyRenderer; +} + +function ShareExternallyRenderer({ model }: SceneComponentProps) { + const dashboard = getDashboardSceneFor(model); + const { data: publicDashboard, isLoading } = useGetPublicDashboardQuery(dashboard.state.uid!); + const styles = useStyles2(getStyles); + + if (isLoading) { + return ; + } + + return ( +
+ +
+ ); +} + +function ShareExternallyBase({ publicDashboard }: { publicDashboard?: PublicDashboard }) { + const options = getShareExternallyOptions(); + const getShareType = useMemo(() => { + if (publicDashboard && isEmailSharingEnabled()) { + const opt = options.find((opt) => opt.value === publicDashboard?.share)!; + return opt ?? options[0]; + } + + return options[0]; + }, [publicDashboard, options]); + + const [shareType, setShareType] = useState>(getShareType); + + const Config = useMemo(() => { + if (shareType.value === PublicDashboardShareType.EMAIL && isEmailSharingEnabled()) { + return ; + } + + return ; + }, [shareType]); + + return ( + + + + + {Config} + {publicDashboard && ( + <> + + + + )} + + ); +} +function Actions({ publicDashboard }: { publicDashboard: PublicDashboard }) { + const { dashboard } = useShareDrawerContext(); + const [update, { isLoading: isUpdateLoading }] = usePauseOrResumePublicDashboardMutation(); + const [deletePublicDashboard, { isLoading: isDeleteLoading }] = useDeletePublicDashboardMutation(); + const styles = useStyles2(getStyles); + + const isLoading = isUpdateLoading || isDeleteLoading; + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + + function onCopyURL() { + DashboardInteractions.publicDashboardUrlCopied(); + } + + const onPauseOrResumeClick = async () => { + DashboardInteractions.publicDashboardPauseSharingClicked({ + paused: !publicDashboard.isEnabled, + }); + update({ + dashboard: dashboard, + payload: { + ...publicDashboard!, + isEnabled: !publicDashboard.isEnabled, + }, + }); + }; + + const onDeleteClick = () => { + DashboardInteractions.revokePublicDashboardClicked(); + deletePublicDashboard({ + dashboard, + uid: publicDashboard!.uid, + dashboardUid: dashboard.state.uid!, + }); + }; + + return ( + +
+ + generatePublicDashboardUrl(publicDashboard!.accessToken!)} + onClipboardCopy={onCopyURL} + > + Copy external link + + + + +
+ {isLoading && } +
+ ); +} + +const getStyles = (theme: GrafanaTheme2) => ({ + container: css({ + paddingBottom: theme.spacing(2), + }), + actionsContainer: css({ + width: '100%', + }), +}); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareTypeSelect.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareTypeSelect.tsx new file mode 100644 index 00000000000..ad378d3e65b --- /dev/null +++ b/public/app/features/dashboard-scene/sharing/ShareButton/share-externally/ShareTypeSelect.tsx @@ -0,0 +1,106 @@ +import { css } from '@emotion/css'; +import React from 'react'; + +import { SelectableValue, toIconName } from '@grafana/data'; +import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; +import { Icon, Label, Select, Spinner, Stack, Text, useStyles2 } from '@grafana/ui'; +import { contextSrv } from 'app/core/core'; +import { Trans } from 'app/core/internationalization'; +import { + publicDashboardApi, + useUpdatePublicDashboardAccessMutation, +} from 'app/features/dashboard/api/publicDashboardApi'; +import { + isEmailSharingEnabled, + PublicDashboardShareType, +} from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions'; +import { AccessControlAction } from 'app/types'; + +import { useShareDrawerContext } from '../../ShareDrawer/ShareDrawerContext'; + +import { getAnyOneWithTheLinkShareOption } from './ShareExternally'; + +const selectors = e2eSelectors.pages.ShareDashboardDrawer.ShareExternally; +export default function ShareTypeSelect({ + setShareType, + options, + value, +}: { + setShareType: (v: SelectableValue) => void; + value: SelectableValue; + options: Array>; +}) { + const { dashboard } = useShareDrawerContext(); + const styles = useStyles2(getStyles); + + const { data: publicDashboard } = publicDashboardApi.endpoints?.getPublicDashboard.useQueryState( + dashboard.state.uid! + ); + const [updateAccess, { isLoading }] = useUpdatePublicDashboardAccessMutation(); + + const hasWritePermissions = contextSrv.hasPermission(AccessControlAction.DashboardsPublicWrite); + const anyOneWithTheLinkOpt = getAnyOneWithTheLinkShareOption(); + + const onUpdateShareType = (shareType: PublicDashboardShareType) => { + if (!publicDashboard) { + return; + } + + DashboardInteractions.publicDashboardShareTypeChange({ + shareType: shareType === PublicDashboardShareType.EMAIL ? 'email' : 'public', + }); + + const req = { + dashboard, + payload: { + ...publicDashboard!, + share: shareType, + }, + }; + + updateAccess(req); + }; + + return ( +
+ + + {isLoading && } + + + {isEmailSharingEnabled() ? ( +