grafana/pkg
Oleg Gaidarenko d88fdc86fc Auth: Do not search for the user twice (#18366)
* Auth: Do not search for the user twice

Previously `initContextWithBasicAuth` did not use `LoginUserQuery`, doing
`GetUserByLoginQuery` only i.e. looking user in DB only, things changed when
this function started to check LDAP provider via `LoginUserQuery` (#6940),
however, this request was placed after `GetUserByLoginQuery`, so we first
looking in DB then in the LDAP - if LDAP user hasn't logged in we will
not find it in DB, so `LoginUserQuery` will never be reached.

`LoginUserQuery` request already performs `GetUserByLoginQuery`
request in correct sequence. So we can just remove redundant request.

* Correct sequence execution during authentification &
  introduce tests for it

* Move basic auth tests to separate test file, since main test file already
  pretty large

* Introduce `testing.go` for the middleware module

* Remove redundant test helper function

* Make handler names more explicit

Ref 5777f65d05
Fixes #18329

* Auth: address review comment
2019-08-03 21:50:05 +02:00
..
api Navigation: Fixed double settings menus (#18349) 2019-08-02 14:02:59 +02:00
bus Codestyle: Fix govet issues (#17178) 2019-06-04 22:00:05 +02:00
cmd cli: fix for recognizing when in dev mode. (#18334) 2019-08-02 09:38:41 +02:00
components datasource: testdata - add predicatable csv wave scenario (#18183) 2019-07-18 13:36:22 -04:00
events feat(signup): progress on new sign up and email verification flow, #2353 2015-08-28 15:14:24 +02:00
extensions SAML: Configuration defaults, examples and dependencies (#17954) 2019-07-05 11:27:14 +01:00
infra Instrumentation: Add failed notifications metric (#18089) 2019-07-24 11:43:24 +02:00
login LDAP: finishing touches (#17945) 2019-07-05 17:49:00 +03:00
middleware Auth: Do not search for the user twice (#18366) 2019-08-03 21:50:05 +02:00
models SQLStore: use bool pointer instead of string (#18111) 2019-07-17 06:24:56 +03:00
plugins CLI: Allow installing custom binary plugins (#17551) 2019-07-29 10:44:58 +02:00
registry add functionality to override service in registry 2018-10-30 13:37:30 +01:00
services Alerting: Also include configured AlertRuleTags in Webhooks (#18233) 2019-08-03 17:00:40 +02:00
setting Auth: saml enabled check. (#17960) 2019-07-05 16:39:52 +02:00
tsdb Plugin: AzureMonitor - Reapply MetricNamespace support (#17282) 2019-07-20 01:43:52 +02:00
util CLI: Add command to migrate all datasources to use encrypted password fields (#17118) 2019-05-27 10:47:21 +02:00
ARCHITECTURE.md Codestyle: add guidelines for removing the m alias for models (#17890) 2019-07-03 11:36:01 +03:00
README.md Docs upgrading deps (#17657) 2019-07-02 09:43:25 +02:00
STYLEGUIDE.md Build: use golangci-lint as a make command (#17739) 2019-07-02 16:06:59 +03:00

Grafana backend codebase

The code styleguide and brief description of the architecture

On going refactorings.

These issues are not something we want to address all at once but something we will improve over time. Since Grafana is released at a regular schedule the prefer approuch is to do this in batches. Not only is it easier to review, it also reduces the risk of conflicts when cherry-picking fixes from master to release branches. Changes that spawn multiple locations are therefore prefered in the end of the release cycle since we make fewer patch releases in the end of the cycle.

Global state

Global state makes testing and debugging software harder and its something we want to avoid when possible. Unfortunately, there is quite a lot of global state in Grafana. The way we want to migrate away from this is to use the inject package to wire up all dependencies either in pkg/cmd/grafana-server/main.go or self registering using registry.RegisterService ex https://github.com/grafana/grafana/blob/master/pkg/services/cleanup/cleanup.go#L25

Reduce the use of the init() function

Should only be used to register services/implementations.

Settings refactoring

The plan is to move all settings to from package level vars in settings package to the setting.Cfg struct. To access the settings services/components can inject this setting.Cfg struct.

Cfg struct Injection example

Reduce the use of Goconvey

We want to migrated away from using Goconvey and use stdlib testing as its the most common approuch in the GO community and we think it will make it easier for new contributors. Read more about how we want to write tests in the ARCHITECTURE.MD docs.

Sqlstore refactoring

The sqlstore handlers all use a global xorm engine variable. This should be refactored to use the Sqlstore instance.

Avoid global HTTP Handler functions

HTTP handlers should be refactored to so the handler methods are on the HttpServer instance or a more detailed handler struct. E.g (AuthHandler). This way they get access to HttpServer service dependencies (& Cfg object) and can avoid global state

Date comparison

Newly introduced date columns in the database should be stored as epochs if date comparison is required. This permits to have a unifed approach for comparing dates against all the supported databases instead of handling seperately each one of them. In addition to this, by comparing epochs error pruning transformations from/to other time zones are no more needed.

Dependency management

Documented in UPDRAGING_DEPENDENCIES.md.