mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
6b3f5b984c
* refactor: switch from opencensus to opentelemetry * tempo works as designed nooooot * fix: log traceids * with grafana agent * fix: http tracing * fix: cleanup files * chore: remove todo * fix: bad test * fix: ignore methods in grpc interceptors * fix: remove test log * clean up * typo * fix(config): configure tracing endpoint * fix(span): add error id to span * feat: metrics package * feat: metrics package * fix: counter * fix: metric * try metrics * fix: coutner metrics * fix: active sessin counter * fix: active sessin counter * fix: change current Sequence table * fix: change current Sequence table * fix: current sequences * fix: spooler div metrics * fix: console view * fix: merge master * fix: Last spool run on search result instead of eventtimestamp * fix: go mod * Update console/src/assets/i18n/de.json Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: pr review * fix: map * update oidc pkg * fix: handlers * fix: value observer * fix: remove fmt * fix: handlers * fix: tests * fix: handler minimum cycle duration 1s * fix(spooler): handler channel buffer * fix interceptors Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com>
133 lines
4.1 KiB
Go
133 lines
4.1 KiB
Go
package view
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
global_model "github.com/caos/zitadel/internal/model"
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
"github.com/caos/zitadel/internal/project/repository/view"
|
|
"github.com/caos/zitadel/internal/project/repository/view/model"
|
|
"github.com/caos/zitadel/internal/view/repository"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
applicationTable = "auth.applications"
|
|
)
|
|
|
|
func (v *View) ApplicationByID(projectID, appID string) (*model.ApplicationView, error) {
|
|
return view.ApplicationByID(v.Db, applicationTable, projectID, appID)
|
|
}
|
|
|
|
func (v *View) ApplicationsByProjectID(projectID string) ([]*model.ApplicationView, error) {
|
|
return view.ApplicationsByProjectID(v.Db, applicationTable, projectID)
|
|
}
|
|
|
|
func (v *View) SearchApplications(request *proj_model.ApplicationSearchRequest) ([]*model.ApplicationView, uint64, error) {
|
|
return view.SearchApplications(v.Db, applicationTable, request)
|
|
}
|
|
|
|
func (v *View) PutApplication(app *model.ApplicationView, eventTimestamp time.Time) error {
|
|
err := view.PutApplication(v.Db, applicationTable, app)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return v.ProcessedApplicationSequence(app.Sequence, eventTimestamp)
|
|
}
|
|
|
|
func (v *View) PutApplications(apps []*model.ApplicationView, sequence uint64, eventTimestamp time.Time) error {
|
|
err := view.PutApplications(v.Db, applicationTable, apps...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return v.ProcessedApplicationSequence(sequence, eventTimestamp)
|
|
}
|
|
|
|
func (v *View) DeleteApplication(appID string, eventSequence uint64, eventTimestamp time.Time) error {
|
|
err := view.DeleteApplication(v.Db, applicationTable, appID)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return v.ProcessedApplicationSequence(eventSequence, eventTimestamp)
|
|
}
|
|
|
|
func (v *View) DeleteApplicationsByProjectID(projectID string) error {
|
|
return view.DeleteApplicationsByProjectID(v.Db, applicationTable, projectID)
|
|
}
|
|
|
|
func (v *View) GetLatestApplicationSequence() (*repository.CurrentSequence, error) {
|
|
return v.latestSequence(applicationTable)
|
|
}
|
|
|
|
func (v *View) ProcessedApplicationSequence(eventSequence uint64, eventTimestamp time.Time) error {
|
|
return v.saveCurrentSequence(applicationTable, eventSequence, eventTimestamp)
|
|
}
|
|
|
|
func (v *View) UpdateApplicationSpoolerRunTimestamp() error {
|
|
return v.updateSpoolerRunSequence(applicationTable)
|
|
}
|
|
|
|
func (v *View) GetLatestApplicationFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
|
return v.latestFailedEvent(applicationTable, sequence)
|
|
}
|
|
|
|
func (v *View) ProcessedApplicationFailedEvent(failedEvent *repository.FailedEvent) error {
|
|
return v.saveFailedEvent(failedEvent)
|
|
}
|
|
|
|
func (v *View) ApplicationByClientID(_ context.Context, clientID string) (*model.ApplicationView, error) {
|
|
return view.ApplicationByOIDCClientID(v.Db, applicationTable, clientID)
|
|
}
|
|
|
|
func (v *View) AppIDsFromProjectByClientID(ctx context.Context, clientID string) ([]string, error) {
|
|
app, err := v.ApplicationByClientID(ctx, clientID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req := &proj_model.ApplicationSearchRequest{
|
|
Queries: []*proj_model.ApplicationSearchQuery{
|
|
{
|
|
Key: proj_model.AppSearchKeyProjectID,
|
|
Method: global_model.SearchMethodEquals,
|
|
Value: app.ProjectID,
|
|
},
|
|
},
|
|
}
|
|
apps, _, err := view.SearchApplications(v.Db, applicationTable, req)
|
|
if err != nil {
|
|
return nil, errors.ThrowPreconditionFailed(err, "VIEW-Gd24q", "cannot find applications")
|
|
}
|
|
ids := make([]string, 0, len(apps))
|
|
for _, app := range apps {
|
|
if !app.IsOIDC {
|
|
continue
|
|
}
|
|
ids = append(ids, app.OIDCClientID)
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
func (v *View) AppIDsFromProjectID(ctx context.Context, projectID string) ([]string, error) {
|
|
req := &proj_model.ApplicationSearchRequest{
|
|
Queries: []*proj_model.ApplicationSearchQuery{
|
|
{
|
|
Key: proj_model.AppSearchKeyProjectID,
|
|
Method: global_model.SearchMethodEquals,
|
|
Value: projectID,
|
|
},
|
|
},
|
|
}
|
|
apps, _, err := view.SearchApplications(v.Db, applicationTable, req)
|
|
if err != nil {
|
|
return nil, errors.ThrowPreconditionFailed(err, "VIEW-Gd24q", "cannot find applications")
|
|
}
|
|
ids := make([]string, 0, len(apps))
|
|
for _, app := range apps {
|
|
if !app.IsOIDC {
|
|
continue
|
|
}
|
|
ids = append(ids, app.OIDCClientID)
|
|
}
|
|
return ids, nil
|
|
}
|