fix(projection): add org domain (#2383)

* job queue

* wg improvements

* start handler

* statement

* statements

* imporve handler

* improve statement

* statement in seperate file

* move handlers

* move query/old to query

* handler

* read models

* bulk works

* cleanup

* contrib

* rename readmodel to projection

* rename read_models schema to projections

* rename read_models schema to projections

* search query as func,
bulk iterates as long as new events

* add event sequence less query

* update checks for events between current sequence and sequence of first statement if it has previous sequence 0

* cleanup crdb projection

* refactor projection handler

* start with testing

* tests for handler

* remove todo

* refactor statement: remove table name,
add tests

* improve projection handler shutdown,
no savepoint if noop stmt,
tests for stmt handler

* tests

* start failed events

* seperate branch for contrib

* move statement constructors to crdb pkg

* correct import

* Subscribe for eventtypes (#1800)

* fix: is default (#1737)

* fix: use email as username on global org (#1738)

* fix: use email as username on global org

* Update user_human.go

* Update register_handler.go

* chore(deps): update docusaurus (#1739)

* chore: remove PAT and use GH Token (#1716)

* chore: remove PAT and use GH Token

* fix env

* fix env

* fix env

* md lint

* trigger ci

* change user

* fix GH bug

* replace login part

* chore: add GH Token to sem rel (#1746)

* chore: add GH Token to sem rel

* try branch

* add GH Token

* remove test branch again

* docs: changes acme to acme-caos (#1744)

* changes acme to acme-caos

* Apply suggestions from code review

Co-authored-by: Florian Forster <florian@caos.ch>

Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com>
Co-authored-by: Florian Forster <florian@caos.ch>

* feat: add additional origins on applications (#1691)

* feat: add additional origins on applications

* app additional redirects

* chore(deps-dev): bump @angular/cli from 11.2.8 to 11.2.11 in /console (#1706)

* fix: show org with regex (#1688)

* fix: flag mapping (#1699)

* chore(deps-dev): bump @angular/cli from 11.2.8 to 11.2.11 in /console

Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.2.8 to 11.2.11.
- [Release notes](https://github.com/angular/angular-cli/releases)
- [Commits](https://github.com/angular/angular-cli/compare/v11.2.8...v11.2.11)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump stylelint from 13.10.0 to 13.13.1 in /console (#1703)

* fix: show org with regex (#1688)

* fix: flag mapping (#1699)

* chore(deps-dev): bump stylelint from 13.10.0 to 13.13.1 in /console

Bumps [stylelint](https://github.com/stylelint/stylelint) from 13.10.0 to 13.13.1.
- [Release notes](https://github.com/stylelint/stylelint/releases)
- [Changelog](https://github.com/stylelint/stylelint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/stylelint/stylelint/compare/13.10.0...13.13.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump @types/node from 14.14.37 to 15.0.1 in /console (#1702)

* fix: show org with regex (#1688)

* fix: flag mapping (#1699)

* chore(deps-dev): bump @types/node from 14.14.37 to 15.0.1 in /console

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.37 to 15.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump ts-protoc-gen from 0.14.0 to 0.15.0 in /console (#1701)

* fix: show org with regex (#1688)

* fix: flag mapping (#1699)

* chore(deps): bump ts-protoc-gen from 0.14.0 to 0.15.0 in /console

Bumps [ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) from 0.14.0 to 0.15.0.
- [Release notes](https://github.com/improbable-eng/ts-protoc-gen/releases)
- [Changelog](https://github.com/improbable-eng/ts-protoc-gen/blob/master/CHANGELOG.md)
- [Commits](https://github.com/improbable-eng/ts-protoc-gen/compare/0.14.0...0.15.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump @types/jasmine from 3.6.9 to 3.6.10 in /console (#1682)

Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.6.9 to 3.6.10.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump @types/google-protobuf in /console (#1681)

Bumps [@types/google-protobuf](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/google-protobuf) from 3.7.4 to 3.15.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/google-protobuf)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump grpc from 1.24.5 to 1.24.7 in /console (#1666)

Bumps [grpc](https://github.com/grpc/grpc-node) from 1.24.5 to 1.24.7.
- [Release notes](https://github.com/grpc/grpc-node/releases)
- [Commits](https://github.com/grpc/grpc-node/compare/grpc@1.24.5...grpc@1.24.7)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* lock

* chore(deps-dev): bump @angular/language-service from 11.2.9 to 11.2.12 in /console (#1704)

* fix: show org with regex (#1688)

* fix: flag mapping (#1699)

* chore(deps-dev): bump @angular/language-service in /console

Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.2.9 to 11.2.12.
- [Release notes](https://github.com/angular/angular/releases)
- [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md)
- [Commits](https://github.com/angular/angular/commits/11.2.12/packages/language-service)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* package lock

* downgrade grpc

* downgrade protobuf types

* revert npm packs 🥸

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Silvan <silvan.reusser@gmail.com>

* docs: update run and start section texts (#1745)

* update run and start section texts

* adds showcase

Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com>

* fix: additional origin list (#1753)

* fix: handle api configs in authz handler (#1755)

* fix(console): add model for api keys, fix toast, binding (#1757)

* fix: add model for api keys, fix toast, binding

* show api clientid

* fix: missing patchvalue (#1758)

* feat: refresh token (#1728)

* begin refresh tokens

* refresh tokens

* list and revoke refresh tokens

* handle remove

* tests for refresh tokens

* uniqueness and default expiration

* rename oidc token methods

* cleanup

* migration version

* Update internal/static/i18n/en.yaml

Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>

* fixes

* feat: update oidc pkg for refresh tokens

Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>

* fix: correct json name of clientId in key.json (#1760)

* fix: migration version (#1767)

* start subscription

* eventtypes

* fix(login): links (#1778)

* fix(login): href for help

* fix(login): correct link to tos

* fix: access tokens for service users and refresh token infos (#1779)

* fix: access token for service user

* handle info from refresh request

* uniqueness

* postpone access token uniqueness change

* chore(coc): recommend code of conduct (#1782)

* subscribe for events

* feat(console): refresh toggle out of granttype context (#1785)

* refresh toggle

* disable if not code flow, lint

* lint

* fix: change oidc config order

* accept refresh option within flow

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: refresh token activation (#1795)

* fix: oidc grant type check

* docs: add offline_access scope

* docs: update refresh token status in supported grant types

* fix: update oidc pkg

* fix: check refresh token grant type (#1796)

* configuration structs

* org admins

* failed events

* fixes

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: Florian Forster <florian@caos.ch>
Co-authored-by: mffap <mpa@caos.ch>
Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>

* remove comment

* aggregate reducer

* remove eventtypes

* add protoc-get-validate to mod

* fix transaltion

* upsert

* add gender on org admins,
allow to retry failed stmts after configurable time

* remove if

* sub queries

* fix: tests

* add builder to tests

* new search query

* rename searchquerybuilder to builder

* remove comment from code

* test with multiple queries

* add filters test

* current sequences

* make org and org_admins work again

* add aggregate type to current sequence

* fix(contibute): listing

* add validate module

* fix: search queries

* feat(eventstore): previous aggregate root sequence (#1810)

* feat(eventstore): previous aggregate root sequence

* fix tests

* fix: eventstore v1 test

* add col to all mocked rows

* next try

* fix mig

* rename aggregate root to aggregate type

* update comment

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* small refactorings

* allow update multiple current sequences

* unique log id

* fix migrations

* rename org admin to org owner

* improve error handling and logging

* fix(migration): optimize prev agg root seq

* fix: projection handler test

* fix: sub queries

* small fixes

* additional event types

* correct org owner projection

* fix primary key

* feat(eventstore): jobs for projections (#2026)

* fix: template names in login (#1974)

* fix: template names in login

* fix: error.html

* fix: check for features on mgmt only (#1976)

* fix: add sentry in ui, http and projection handlers (#1977)

* fix: add sentry in ui, http and projection handlers

* fix test

* fix(eventstore): sub queries (#1805)

* sub queries

* fix: tests

* add builder to tests

* new search query

* rename searchquerybuilder to builder

* remove comment from code

* test with multiple queries

* add filters test

* fix(contibute): listing

* add validate module

* fix: search queries

* remove unused event type in query

* ignore query if error in marshal

* go mod tidy

* update privacy policy query

* update queries

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* feat: Extend oidc idp with oauth endpoints (#1980)

* feat: add oauth attributes to oidc idp configuration

* feat: return idpconfig id on create idp

* feat: tests

* feat: descriptions

* feat: docs

* feat: tests

* docs: update to beta 3 (#1984)

* fix: role assertion (#1986)

* fix: enum to display access token role assertion

* improve assertion descriptions

* fix nil pointer

* docs: eventstore (#1982)

* docs: eventstore

* Apply suggestions from code review

Co-authored-by: Florian Forster <florian@caos.ch>

Co-authored-by: Florian Forster <florian@caos.ch>

* fix(sentry): trigger sentry release (#1989)

* feat(send sentry release): send sentry release

* fix(moved step and added releasetag): moved step and added releasetag

* fix: set version for sentry release (#1990)

* feat(send sentry release): send sentry release

* fix(moved step and added releasetag): moved step and added releasetag

* fix(corrected var name): corrected var name

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: log error reason on terminate session (#1973)

* fix: return default language file, if requested lang does not exist for default login texts (#1988)

* fix: return default language file, if requested lang doesnt exists

* feat: read default translation file

* feat: docs

* fix: race condition in auth request unmarshalling (#1993)

* feat: handle ui_locales in login (#1994)

* fix: handle ui_locales in login

* move supportedlanguage func into i18n package

* update oidc pkg

* fix: handle closed channels on unsubscribe (#1995)

* fix: give restore more time (#1997)

* fix: translation file read (#2009)

* feat: translation file read

* feat: readme

* fix: enable idp add button for iam users (#2010)

* fix: filter event_data (#2011)

* feat: Custom message files (#1992)

* feat: add get custom message text to admin api

* feat: read custom message texts from files

* feat: get languages in apis

* feat: get languages in apis

* feat: get languages in apis

* feat: pr feedback

* feat: docs

* feat: merge main

* fix: sms notification (#2013)

* fix: phone verifications

* feat: fix password reset as sms

* fix: phone verification

* fix: grpc status in sentry and validation interceptors (#2012)

* fix: remove oauth endpoints from oidc config proto (#2014)

* try with view

* fix(console): disable sw (#2021)

* fix: disable sw

* angular.json disable sw

* project projections

* fix typos

* customize projections

* customizable projections,
add change date to projects

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Florian Forster <florian@caos.ch>
Co-authored-by: mffap <mpa@caos.ch>
Co-authored-by: Christian Jakob <47860090+thesephirot@users.noreply.github.com>
Co-authored-by: Elio Bischof <eliobischof@gmail.com>

* env file

* typo

* correct users

* correct migration

* fix: merge fail

* fix test

* fix(tests): unordered matcher

* improve currentSequenceMatcher

* correct certs

* correct certs

* add zitadel database on database list

* refctor switch in match

* enable all handlers

* Delete io.env

* cleanup

* add handlers

* rename view to projection

* rename view to projection

* fix type typo

* remove unnecessary logs

* refactor stmts

* simplify interval calculation

* fix tests

* fix unlock test

* fix migration

* migs

* fix(operator): update cockroach and flyway versions (#2138)

* chore(deps): bump k8s.io/apiextensions-apiserver from 0.19.2 to 0.21.3

Bumps [k8s.io/apiextensions-apiserver](https://github.com/kubernetes/apiextensions-apiserver) from 0.19.2 to 0.21.3.
- [Release notes](https://github.com/kubernetes/apiextensions-apiserver/releases)
- [Commits](https://github.com/kubernetes/apiextensions-apiserver/compare/v0.19.2...v0.21.3)

---
updated-dependencies:
- dependency-name: k8s.io/apiextensions-apiserver
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump google.golang.org/api from 0.34.0 to 0.52.0

Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.34.0 to 0.52.0.
- [Release notes](https://github.com/googleapis/google-api-go-client/releases)
- [Changelog](https://github.com/googleapis/google-api-go-client/blob/master/CHANGES.md)
- [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.34.0...v0.52.0)

---
updated-dependencies:
- dependency-name: google.golang.org/api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* start update dependencies

* update mods and otlp

* fix(build): update to go 1.16

* old version for k8s mods

* update k8s versions

* update orbos

* fix(operator): update cockroach and flyway version

* Update images.go

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Stefan Benz <stefan@caos.ch>

* fix import

* fix typo

* fix(migration): add org projection

* fix(projection): correct table for org events in org owners

* better insert stmt

* fix typo

* fix typo

* set max connection lifetime

* set max conns and conn lifetime in eventstore v1

* configure sql connection settings

* add mig for agg type index

* fix replace tab in yaml

* handler interfaces

* subscription

* first try

* handler

* move sql client initialization

* first part implemented

* removed all occurencies of org by id and search orgs

* fix merge issues

* cleanup code

* fix: queries implements orgviewprovider

* cleanup

* refactor text comparison

* remove unused file

* remove unused code

* log

* remove unused code

* remove unused field

* remove unused file

* refactor

* tests for search query

* remove try

* simplify state change mappers

* projection tests

* query functions

* move reusable objects to separate files

* rename domain column to primar_domain

* fix tests

* add current sequence

* remove log prints

* fix tests

* fix: verifier

* fix test

* rename domain col migrations

* simplify search response

* move org domain to query

* cleanup code

* add org id as condition to projection

* add custom column constructors

* fix: org projection table const

* fix: full column name

* feat: text query extension

* fix: tests for query

* number query

* add deprection message

* column in a single place (#2416)

* column in a single place

* use projection for columns

* query column with aliases

* rename methods

* remove unused code

* column

* column for current sequences

* latest sequence

* global counter column

* fix is org unique

* fixes

* fix tests

* error messages

* fix search queries

* migration order

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: Florian Forster <florian@caos.ch>
Co-authored-by: mffap <mpa@caos.ch>
Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Christian Jakob <47860090+thesephirot@users.noreply.github.com>
Co-authored-by: Elio Bischof <eliobischof@gmail.com>
Co-authored-by: Stefan Benz <stefan@caos.ch>
Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
This commit is contained in:
Silvan 2021-10-08 10:24:22 +02:00 committed by GitHub
parent 2e7f174b0e
commit cc0d8b0b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 590 additions and 846 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore/v1/models"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/query"
usr_model "github.com/caos/zitadel/internal/user/model"
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
)
@ -118,14 +119,20 @@ func (s *Server) ListOrgDomains(ctx context.Context, req *mgmt_pb.ListOrgDomains
if err != nil {
return nil, err
}
domains, err := s.org.SearchMyOrgDomains(ctx, queries)
orgIDQuery, err := query.NewOrgDomainOrgIDSearchQuery(authz.GetCtxData(ctx).OrgID)
if err != nil {
return nil, err
}
queries.Queries = append(queries.Queries, orgIDQuery)
domains, err := s.query.SearchOrgDomains(ctx, queries)
if err != nil {
return nil, err
}
return &mgmt_pb.ListOrgDomainsResponse{
Result: org_grpc.DomainsToPb(domains.Result),
Result: org_grpc.DomainsToPb(domains.Domains),
Details: object.ToListDetails(
domains.TotalResult,
domains.Count,
domains.Sequence,
domains.Timestamp,
),

View File

@ -8,20 +8,22 @@ import (
org_grpc "github.com/caos/zitadel/internal/api/grpc/org"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore/v1/models"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/query"
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
)
func ListOrgDomainsRequestToModel(req *mgmt_pb.ListOrgDomainsRequest) (*org_model.OrgDomainSearchRequest, error) {
func ListOrgDomainsRequestToModel(req *mgmt_pb.ListOrgDomainsRequest) (*query.OrgDomainSearchQueries, error) {
offset, limit, asc := object.ListQueryToModel(req.Query)
queries, err := org_grpc.DomainQueriesToModel(req.Queries)
if err != nil {
return nil, err
}
return &org_model.OrgDomainSearchRequest{
Offset: offset,
Limit: limit,
Asc: asc,
return &query.OrgDomainSearchQueries{
SearchRequest: query.SearchRequest{
Offset: offset,
Limit: limit,
Asc: asc,
},
//SortingColumn: //TODO: sorting
Queries: queries,
}, nil

View File

@ -4,7 +4,6 @@ import (
"github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/query"
grant_model "github.com/caos/zitadel/internal/usergrant/model"
org_pb "github.com/caos/zitadel/pkg/grpc/org"
@ -117,8 +116,8 @@ func OrgStateToPb(state domain.OrgState) org_pb.OrgState {
}
}
func DomainQueriesToModel(queries []*org_pb.DomainSearchQuery) (_ []*org_model.OrgDomainSearchQuery, err error) {
q := make([]*org_model.OrgDomainSearchQuery, len(queries))
func DomainQueriesToModel(queries []*org_pb.DomainSearchQuery) (_ []query.SearchQuery, err error) {
q := make([]query.SearchQuery, len(queries))
for i, query := range queries {
q[i], err = DomainQueryToModel(query)
if err != nil {
@ -128,24 +127,16 @@ func DomainQueriesToModel(queries []*org_pb.DomainSearchQuery) (_ []*org_model.O
return q, nil
}
func DomainQueryToModel(query *org_pb.DomainSearchQuery) (*org_model.OrgDomainSearchQuery, error) {
switch q := query.Query.(type) {
func DomainQueryToModel(searchQuery *org_pb.DomainSearchQuery) (query.SearchQuery, error) {
switch q := searchQuery.Query.(type) {
case *org_pb.DomainSearchQuery_DomainNameQuery:
return DomainNameQueryToModel(q.DomainNameQuery)
return query.NewOrgDomainDomainSearchQuery(object.TextMethodToQuery(q.DomainNameQuery.Method), q.DomainNameQuery.Name)
default:
return nil, errors.ThrowInvalidArgument(nil, "ORG-Ags42", "List.Query.Invalid")
}
}
func DomainNameQueryToModel(query *org_pb.DomainNameQuery) (*org_model.OrgDomainSearchQuery, error) {
return &org_model.OrgDomainSearchQuery{
Key: org_model.OrgDomainSearchKeyDomain,
Method: object.TextMethodToModel(query.Method),
Value: query.Name,
}, nil
}
func DomainsToPb(domains []*org_model.OrgDomainView) []*org_pb.Domain {
func DomainsToPb(domains []*query.Domain) []*org_pb.Domain {
d := make([]*org_pb.Domain, len(domains))
for i, domain := range domains {
d[i] = DomainToPb(domain)
@ -153,18 +144,18 @@ func DomainsToPb(domains []*org_model.OrgDomainView) []*org_pb.Domain {
return d
}
func DomainToPb(domain *org_model.OrgDomainView) *org_pb.Domain {
func DomainToPb(d *query.Domain) *org_pb.Domain {
return &org_pb.Domain{
OrgId: domain.OrgID,
DomainName: domain.Domain,
IsVerified: domain.Verified,
IsPrimary: domain.Primary,
ValidationType: DomainValidationTypeFromModel(domain.ValidationType),
OrgId: d.OrgID,
DomainName: d.Domain,
IsVerified: d.IsVerified,
IsPrimary: d.IsPrimary,
ValidationType: DomainValidationTypeFromModel(d.ValidationType),
Details: object.ToViewDetailsPb(
0,
domain.CreationDate,
domain.ChangeDate,
"",
d.Sequence,
d.CreationDate,
d.ChangeDate,
d.OrgID,
),
}
}
@ -180,11 +171,11 @@ func DomainValidationTypeToDomain(validationType org_pb.DomainValidationType) do
}
}
func DomainValidationTypeFromModel(validationType org_model.OrgDomainValidationType) org_pb.DomainValidationType {
func DomainValidationTypeFromModel(validationType domain.OrgDomainValidationType) org_pb.DomainValidationType {
switch validationType {
case org_model.OrgDomainValidationTypeDNS:
case domain.OrgDomainValidationTypeDNS:
return org_pb.DomainValidationType_DOMAIN_VALIDATION_TYPE_DNS
case org_model.OrgDomainValidationTypeHTTP:
case domain.OrgDomainValidationTypeHTTP:
return org_pb.DomainValidationType_DOMAIN_VALIDATION_TYPE_HTTP
default:
return org_pb.DomainValidationType_DOMAIN_VALIDATION_TYPE_UNSPECIFIED

View File

@ -31,7 +31,6 @@ import (
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
org_view "github.com/caos/zitadel/internal/org/repository/view"
"github.com/caos/zitadel/internal/org/repository/view/model"
"github.com/caos/zitadel/internal/telemetry/tracing"
usr_model "github.com/caos/zitadel/internal/user/model"
"github.com/caos/zitadel/internal/user/repository/view"
usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model"
@ -79,31 +78,6 @@ func (repo *OrgRepository) GetMyOrgIamPolicy(ctx context.Context) (*iam_model.Or
return iam_view_model.OrgIAMViewToModel(policy), err
}
func (repo *OrgRepository) SearchMyOrgDomains(ctx context.Context, request *org_model.OrgDomainSearchRequest) (*org_model.OrgDomainSearchResponse, error) {
err := request.EnsureLimit(repo.SearchLimit)
if err != nil {
return nil, err
}
request.Queries = append(request.Queries, &org_model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID})
sequence, sequenceErr := repo.View.GetLatestOrgDomainSequence()
logging.Log("EVENT-SLowp").OnError(sequenceErr).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Warn("could not read latest org domain sequence")
domains, count, err := repo.View.SearchOrgDomains(request)
if err != nil {
return nil, err
}
result := &org_model.OrgDomainSearchResponse{
Offset: request.Offset,
Limit: request.Limit,
TotalResult: uint64(count),
Result: model.OrgDomainsToModel(domains),
}
if sequenceErr == nil {
result.Sequence = sequence.CurrentSequence
result.Timestamp = sequence.LastSuccessfulSpoolerRun
}
return result, nil
}
func (repo *OrgRepository) OrgChanges(ctx context.Context, id string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*org_model.OrgChanges, error) {
changes, err := repo.getOrgChanges(ctx, id, lastSequence, limit, sortAscending, auditLogRetention)
if err != nil {

View File

@ -42,8 +42,6 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
newUserGrant(handler{view, bulkLimit, configs.cycleDuration("UserGrant"), errorCount, es}),
newOrgMember(
handler{view, bulkLimit, configs.cycleDuration("OrgMember"), errorCount, es}),
newOrgDomain(
handler{view, bulkLimit, configs.cycleDuration("OrgDomain"), errorCount, es}),
newUserMembership(
handler{view, bulkLimit, configs.cycleDuration("UserMembership"), errorCount, es}),
newAuthNKeys(

View File

@ -1,138 +0,0 @@
package handler
import (
"github.com/caos/logging"
"github.com/caos/zitadel/internal/eventstore/v1"
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/eventstore/v1/query"
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
org_model "github.com/caos/zitadel/internal/org/repository/view/model"
)
const (
orgDomainTable = "management.org_domains"
)
type OrgDomain struct {
handler
subscription *v1.Subscription
}
func newOrgDomain(handler handler) *OrgDomain {
h := &OrgDomain{
handler: handler,
}
h.subscribe()
return h
}
func (m *OrgDomain) subscribe() {
m.subscription = m.es.Subscribe(m.AggregateTypes()...)
go func() {
for event := range m.subscription.Events {
query.ReduceEvent(m, event)
}
}()
}
func (d *OrgDomain) ViewModel() string {
return orgDomainTable
}
func (d *OrgDomain) Subscription() *v1.Subscription {
return d.subscription
}
func (_ *OrgDomain) AggregateTypes() []es_models.AggregateType {
return []es_models.AggregateType{model.OrgAggregate}
}
func (p *OrgDomain) CurrentSequence() (uint64, error) {
sequence, err := p.view.GetLatestOrgDomainSequence()
if err != nil {
return 0, err
}
return sequence.CurrentSequence, nil
}
func (d *OrgDomain) EventQuery() (*es_models.SearchQuery, error) {
sequence, err := d.view.GetLatestOrgDomainSequence()
if err != nil {
return nil, err
}
return es_models.NewSearchQuery().
AggregateTypeFilter(d.AggregateTypes()...).
LatestSequenceFilter(sequence.CurrentSequence), nil
}
func (d *OrgDomain) Reduce(event *es_models.Event) (err error) {
switch event.AggregateType {
case model.OrgAggregate:
err = d.processOrgDomain(event)
}
return err
}
func (d *OrgDomain) processOrgDomain(event *es_models.Event) (err error) {
domain := new(org_model.OrgDomainView)
switch event.Type {
case model.OrgDomainAdded:
err = domain.AppendEvent(event)
case model.OrgDomainVerified,
model.OrgDomainVerificationAdded:
err = domain.SetData(event)
if err != nil {
return err
}
domain, err = d.view.OrgDomainByOrgIDAndDomain(event.AggregateID, domain.Domain)
if err != nil {
return err
}
err = domain.AppendEvent(event)
case model.OrgDomainPrimarySet:
err = domain.SetData(event)
if err != nil {
return err
}
domain, err = d.view.OrgDomainByOrgIDAndDomain(event.AggregateID, domain.Domain)
if err != nil {
return err
}
existingDomains, err := d.view.OrgDomainsByOrgID(event.AggregateID)
if err != nil {
return err
}
for _, existingDomain := range existingDomains {
existingDomain.Primary = false
}
err = d.view.PutOrgDomains(existingDomains, event)
if err != nil {
return err
}
err = domain.AppendEvent(event)
case model.OrgDomainRemoved:
err = domain.SetData(event)
if err != nil {
return err
}
return d.view.DeleteOrgDomain(event.AggregateID, domain.Domain, event)
default:
return d.view.ProcessedOrgDomainSequence(event)
}
if err != nil {
return err
}
return d.view.PutOrgDomain(domain, event)
}
func (d *OrgDomain) OnError(event *es_models.Event, err error) error {
logging.LogWithFields("SPOOL-us4sj", "id", event.AggregateID).WithError(err).Warn("something went wrong in orgdomain handler")
return spooler.HandleError(event, err, d.view.GetLatestOrgDomainFailedEvent, d.view.ProcessedOrgDomainFailedEvent, d.view.ProcessedOrgDomainSequence, d.errorCountUntilSkip)
}
func (o *OrgDomain) OnSuccess() error {
return spooler.HandleSuccess(o.view.UpdateOrgDomainSpoolerRunTimestamp)
}

View File

@ -1,74 +0,0 @@
package view
import (
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/org/repository/view"
"github.com/caos/zitadel/internal/org/repository/view/model"
"github.com/caos/zitadel/internal/view/repository"
)
const (
orgDomainTable = "management.org_domains"
)
func (v *View) OrgDomainByOrgIDAndDomain(orgID, domain string) (*model.OrgDomainView, error) {
return view.OrgDomainByOrgIDAndDomain(v.Db, orgDomainTable, orgID, domain)
}
func (v *View) OrgDomainsByOrgID(domain string) ([]*model.OrgDomainView, error) {
return view.OrgDomainsByOrgID(v.Db, orgDomainTable, domain)
}
func (v *View) VerifiedOrgDomain(domain string) (*model.OrgDomainView, error) {
return view.VerifiedOrgDomain(v.Db, orgDomainTable, domain)
}
func (v *View) SearchOrgDomains(request *org_model.OrgDomainSearchRequest) ([]*model.OrgDomainView, uint64, error) {
return view.SearchOrgDomains(v.Db, orgDomainTable, request)
}
func (v *View) PutOrgDomain(org *model.OrgDomainView, event *models.Event) error {
err := view.PutOrgDomain(v.Db, orgDomainTable, org)
if err != nil {
return err
}
return v.ProcessedOrgDomainSequence(event)
}
func (v *View) PutOrgDomains(domains []*model.OrgDomainView, event *models.Event) error {
err := view.PutOrgDomains(v.Db, orgDomainTable, domains...)
if err != nil {
return err
}
return v.ProcessedUserSequence(event)
}
func (v *View) DeleteOrgDomain(orgID, domain string, event *models.Event) error {
err := view.DeleteOrgDomain(v.Db, orgDomainTable, orgID, domain)
if err != nil && !errors.IsNotFound(err) {
return err
}
return v.ProcessedOrgDomainSequence(event)
}
func (v *View) GetLatestOrgDomainSequence() (*repository.CurrentSequence, error) {
return v.latestSequence(orgDomainTable)
}
func (v *View) ProcessedOrgDomainSequence(event *models.Event) error {
return v.saveCurrentSequence(orgDomainTable, event)
}
func (v *View) UpdateOrgDomainSpoolerRunTimestamp() error {
return v.updateSpoolerRunSequence(orgDomainTable)
}
func (v *View) GetLatestOrgDomainFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
return v.latestFailedEvent(orgDomainTable, sequence)
}
func (v *View) ProcessedOrgDomainFailedEvent(failedEvent *repository.FailedEvent) error {
return v.saveFailedEvent(failedEvent)
}

View File

@ -16,8 +16,6 @@ type OrgRepository interface {
Languages(ctx context.Context) ([]language.Tag, error)
OrgChanges(ctx context.Context, id string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*org_model.OrgChanges, error)
SearchMyOrgDomains(ctx context.Context, request *org_model.OrgDomainSearchRequest) (*org_model.OrgDomainSearchResponse, error)
SearchMyOrgMembers(ctx context.Context, request *org_model.OrgMemberSearchRequest) (*org_model.OrgMemberSearchResponse, error)
GetOrgMemberRoles() []string

View File

@ -1,61 +0,0 @@
package model
import (
"github.com/caos/zitadel/internal/domain"
caos_errors "github.com/caos/zitadel/internal/errors"
"time"
)
type OrgDomainView struct {
OrgID string
CreationDate time.Time
ChangeDate time.Time
Domain string
Primary bool
Verified bool
ValidationType OrgDomainValidationType
}
type OrgDomainSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn OrgDomainSearchKey
Asc bool
Queries []*OrgDomainSearchQuery
}
type OrgDomainSearchKey int32
const (
OrgDomainSearchKeyUnspecified OrgDomainSearchKey = iota
OrgDomainSearchKeyDomain
OrgDomainSearchKeyOrgID
OrgDomainSearchKeyVerified
OrgDomainSearchKeyPrimary
)
type OrgDomainSearchQuery struct {
Key OrgDomainSearchKey
Method domain.SearchMethod
Value interface{}
}
type OrgDomainSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*OrgDomainView
Sequence uint64
Timestamp time.Time
}
func (r *OrgDomainSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-38fhs", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}

View File

@ -1,79 +0,0 @@
package model
import (
"time"
"github.com/caos/zitadel/internal/domain"
caos_errors "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models"
)
type OrgView struct {
ID string
CreationDate time.Time
ChangeDate time.Time
State OrgState
ResourceOwner string
Sequence uint64
Name string
}
type OrgSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn OrgSearchKey
Asc bool
Queries []*OrgSearchQuery
}
type OrgSearchKey int32
const (
OrgSearchKeyUnspecified OrgSearchKey = iota
OrgSearchKeyOrgID
OrgSearchKeyOrgName
OrgSearchKeyOrgDomain
OrgSearchKeyState
OrgSearchKeyResourceOwner
OrgSearchKeyOrgNameIgnoreCase //used for lowercase search
)
type OrgSearchQuery struct {
Key OrgSearchKey
Method domain.SearchMethod
Value interface{}
}
type OrgSearchResult struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*OrgView
Sequence uint64
Timestamp time.Time
}
func (r *OrgSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-200ds", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}
func OrgViewToOrg(o *OrgView) *Org {
return &Org{
ObjectRoot: models.ObjectRoot{
AggregateID: o.ID,
ChangeDate: o.ChangeDate,
CreationDate: o.CreationDate,
ResourceOwner: o.ResourceOwner,
Sequence: o.Sequence,
},
Name: o.Name,
State: o.State,
}
}

View File

@ -1,113 +0,0 @@
package model
import (
"encoding/json"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
"time"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/errors"
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
org_model "github.com/caos/zitadel/internal/org/model"
)
const (
OrgKeyOrgDomain = "domain"
OrgKeyOrgID = "id"
OrgKeyOrgName = "name"
OrgKeyResourceOwner = "resource_owner"
OrgKeyState = "org_state"
)
type OrgView struct {
ID string `json:"-" gorm:"column:id;primary_key"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
State int32 `json:"-" gorm:"column:org_state"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
Name string `json:"name" gorm:"column:name"`
Domain string `json:"domain" gorm:"column:domain"`
}
func OrgFromModel(org *org_model.OrgView) *OrgView {
return &OrgView{
ChangeDate: org.ChangeDate,
CreationDate: org.CreationDate,
ID: org.ID,
Name: org.Name,
ResourceOwner: org.ResourceOwner,
Sequence: org.Sequence,
State: int32(org.State),
}
}
func OrgToModel(org *OrgView) *org_model.OrgView {
return &org_model.OrgView{
ChangeDate: org.ChangeDate,
CreationDate: org.CreationDate,
ID: org.ID,
Name: org.Name,
ResourceOwner: org.ResourceOwner,
Sequence: org.Sequence,
State: org_model.OrgState(org.State),
}
}
func OrgToDomain(org *OrgView) *domain.Org {
return &domain.Org{
ObjectRoot: es_models.ObjectRoot{
AggregateID: org.ID,
ChangeDate: org.ChangeDate,
CreationDate: org.CreationDate,
Sequence: org.Sequence,
},
Name: org.Name,
PrimaryDomain: org.Domain,
}
}
func OrgsToModel(orgs []*OrgView) []*org_model.OrgView {
modelOrgs := make([]*org_model.OrgView, len(orgs))
for i, org := range orgs {
modelOrgs[i] = OrgToModel(org)
}
return modelOrgs
}
func (o *OrgView) AppendEvent(event *es_models.Event) (err error) {
switch event.Type {
case model.OrgAdded:
o.CreationDate = event.CreationDate
o.State = int32(org_model.OrgStateActive)
o.setRootData(event)
err = o.SetData(event)
case model.OrgChanged:
o.setRootData(event)
err = o.SetData(event)
case model.OrgDeactivated:
o.State = int32(org_model.OrgStateInactive)
case model.OrgReactivated:
o.State = int32(org_model.OrgStateActive)
}
return err
}
func (o *OrgView) setRootData(event *es_models.Event) {
o.ChangeDate = event.CreationDate
o.Sequence = event.Sequence
o.ID = event.AggregateID
o.ResourceOwner = event.ResourceOwner
}
func (o *OrgView) SetData(event *es_models.Event) error {
if err := json.Unmarshal(event.Data, o); err != nil {
logging.Log("VIEW-5W7Op").WithError(err).Error("could not unmarshal event data")
return errors.ThrowInternal(err, "VIEW-HZKME", "Could not unmarshal data")
}
return nil
}

View File

@ -1,94 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/org/model"
es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
)
const (
OrgDomainKeyOrgID = "org_id"
OrgDomainKeyDomain = "domain"
OrgDomainKeyVerified = "verified"
OrgDomainKeyPrimary = "primary_domain"
)
type OrgDomainView struct {
Domain string `json:"domain" gorm:"column:domain;primary_key"`
OrgID string `json:"-" gorm:"column:org_id;primary_key"`
Verified bool `json:"-" gorm:"column:verified"`
Primary bool `json:"-" gorm:"column:primary_domain"`
ValidationType int32 `json:"validationType" gorm:"column:validation_type"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
}
func OrgDomainViewFromModel(domain *model.OrgDomainView) *OrgDomainView {
return &OrgDomainView{
OrgID: domain.OrgID,
Domain: domain.Domain,
Primary: domain.Primary,
Verified: domain.Verified,
ValidationType: int32(domain.ValidationType),
CreationDate: domain.CreationDate,
ChangeDate: domain.ChangeDate,
}
}
func OrgDomainToModel(domain *OrgDomainView) *model.OrgDomainView {
return &model.OrgDomainView{
OrgID: domain.OrgID,
Domain: domain.Domain,
Primary: domain.Primary,
Verified: domain.Verified,
ValidationType: model.OrgDomainValidationType(domain.ValidationType),
CreationDate: domain.CreationDate,
ChangeDate: domain.ChangeDate,
}
}
func OrgDomainsToModel(domain []*OrgDomainView) []*model.OrgDomainView {
result := make([]*model.OrgDomainView, len(domain))
for i, r := range domain {
result[i] = OrgDomainToModel(r)
}
return result
}
func (d *OrgDomainView) AppendEvent(event *models.Event) (err error) {
d.Sequence = event.Sequence
d.ChangeDate = event.CreationDate
switch event.Type {
case es_model.OrgDomainAdded:
d.setRootData(event)
d.CreationDate = event.CreationDate
err = d.SetData(event)
case es_model.OrgDomainVerificationAdded:
err = d.SetData(event)
case es_model.OrgDomainVerified:
d.Verified = true
case es_model.OrgDomainPrimarySet:
d.Primary = true
}
return err
}
func (r *OrgDomainView) setRootData(event *models.Event) {
r.OrgID = event.AggregateID
}
func (r *OrgDomainView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-sj4Sf").WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
}
return nil
}

View File

@ -1,65 +0,0 @@
package model
import (
"github.com/caos/zitadel/internal/domain"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/view/repository"
)
type OrgDomainSearchRequest org_model.OrgDomainSearchRequest
type OrgDomainSearchQuery org_model.OrgDomainSearchQuery
type OrgDomainSearchKey org_model.OrgDomainSearchKey
func (req OrgDomainSearchRequest) GetLimit() uint64 {
return req.Limit
}
func (req OrgDomainSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req OrgDomainSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == org_model.OrgDomainSearchKeyUnspecified {
return nil
}
return OrgDomainSearchKey(req.SortingColumn)
}
func (req OrgDomainSearchRequest) GetAsc() bool {
return req.Asc
}
func (req OrgDomainSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = OrgDomainSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req OrgDomainSearchQuery) GetKey() repository.ColumnKey {
return OrgDomainSearchKey(req.Key)
}
func (req OrgDomainSearchQuery) GetMethod() domain.SearchMethod {
return req.Method
}
func (req OrgDomainSearchQuery) GetValue() interface{} {
return req.Value
}
func (key OrgDomainSearchKey) ToColumnName() string {
switch org_model.OrgDomainSearchKey(key) {
case org_model.OrgDomainSearchKeyDomain:
return OrgDomainKeyDomain
case org_model.OrgDomainSearchKeyOrgID:
return OrgDomainKeyOrgID
case org_model.OrgDomainSearchKeyVerified:
return OrgDomainKeyVerified
case org_model.OrgDomainSearchKeyPrimary:
return OrgDomainKeyPrimary
default:
return ""
}
}

View File

@ -1,69 +0,0 @@
package model
import (
"github.com/caos/zitadel/internal/domain"
usr_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/view/repository"
)
type OrgSearchRequest usr_model.OrgSearchRequest
type OrgSearchQuery usr_model.OrgSearchQuery
type OrgSearchKey usr_model.OrgSearchKey
func (req OrgSearchRequest) GetLimit() uint64 {
return req.Limit
}
func (req OrgSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req OrgSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == usr_model.OrgSearchKeyUnspecified {
return nil
}
return OrgSearchKey(req.SortingColumn)
}
func (req OrgSearchRequest) GetAsc() bool {
return req.Asc
}
func (req OrgSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = OrgSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req OrgSearchQuery) GetKey() repository.ColumnKey {
return OrgSearchKey(req.Key)
}
func (req OrgSearchQuery) GetMethod() domain.SearchMethod {
return req.Method
}
func (req OrgSearchQuery) GetValue() interface{} {
return req.Value
}
func (key OrgSearchKey) ToColumnName() string {
switch usr_model.OrgSearchKey(key) {
case usr_model.OrgSearchKeyOrgDomain:
return OrgKeyOrgDomain
case usr_model.OrgSearchKeyOrgID:
return OrgKeyOrgID
case usr_model.OrgSearchKeyOrgName:
return OrgKeyOrgName
case usr_model.OrgSearchKeyOrgNameIgnoreCase:
return "LOWER(" + OrgKeyOrgName + ")" //used for lowercase search
case usr_model.OrgSearchKeyResourceOwner:
return OrgKeyResourceOwner
case usr_model.OrgSearchKeyState:
return OrgKeyState
default:
return ""
}
}

View File

@ -1,83 +0,0 @@
package view
import (
domain2 "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors"
org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/org/repository/view/model"
"github.com/caos/zitadel/internal/view/repository"
"github.com/jinzhu/gorm"
)
func OrgDomainByOrgIDAndDomain(db *gorm.DB, table, orgID, domain string) (*model.OrgDomainView, error) {
domainView := new(model.OrgDomainView)
orgIDQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyOrgID, Value: orgID, Method: domain2.SearchMethodEquals}
domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: domain2.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, orgIDQuery, domainQuery)
err := query(db, domainView)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gqwfq", "Errors.Org.DomainNotOnOrg")
}
return domainView, err
}
func VerifiedOrgDomain(db *gorm.DB, table, domain string) (*model.OrgDomainView, error) {
domainView := new(model.OrgDomainView)
domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: domain2.SearchMethodEquals}
verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyVerified, Value: true, Method: domain2.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, domainQuery, verifiedQuery)
err := query(db, domainView)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Tew2q", "Errors.Org.DomainNotFound")
}
return domainView, err
}
func SearchOrgDomains(db *gorm.DB, table string, req *org_model.OrgDomainSearchRequest) ([]*model.OrgDomainView, uint64, error) {
members := make([]*model.OrgDomainView, 0)
query := repository.PrepareSearchQuery(table, model.OrgDomainSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
count, err := query(db, &members)
if err != nil {
return nil, 0, err
}
return members, count, nil
}
func OrgDomainsByOrgID(db *gorm.DB, table string, orgID string) ([]*model.OrgDomainView, error) {
domains := make([]*model.OrgDomainView, 0)
queries := []*org_model.OrgDomainSearchQuery{
{
Key: org_model.OrgDomainSearchKeyOrgID,
Value: orgID,
Method: domain2.SearchMethodEquals,
},
}
query := repository.PrepareSearchQuery(table, model.OrgDomainSearchRequest{Queries: queries})
_, err := query(db, &domains)
if err != nil {
return nil, err
}
return domains, nil
}
func PutOrgDomain(db *gorm.DB, table string, domain *model.OrgDomainView) error {
save := repository.PrepareSave(table)
return save(db, domain)
}
func PutOrgDomains(db *gorm.DB, table string, domains ...*model.OrgDomainView) error {
save := repository.PrepareBulkSave(table)
d := make([]interface{}, len(domains))
for i, domain := range domains {
d[i] = domain
}
return save(db, d...)
}
func DeleteOrgDomain(db *gorm.DB, table, orgID, domain string) error {
delete := repository.PrepareDeleteByKeys(table,
repository.Key{Key: model.OrgDomainSearchKey(org_model.OrgDomainSearchKeyDomain), Value: domain},
repository.Key{Key: model.OrgDomainSearchKey(org_model.OrgDomainSearchKeyOrgID), Value: orgID},
)
return delete(db)
}

View File

@ -8,9 +8,8 @@ import (
sq "github.com/Masterminds/squirrel"
"github.com/caos/zitadel/internal/query/projection"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/query/projection"
)
type LatestSequence struct {

View File

@ -7,7 +7,6 @@ import (
"time"
sq "github.com/Masterminds/squirrel"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/query/projection"

View File

@ -0,0 +1,154 @@
package query
import (
"context"
"database/sql"
"time"
sq "github.com/Masterminds/squirrel"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/query/projection"
)
type Domain struct {
CreationDate time.Time
ChangeDate time.Time
Sequence uint64
Domain string
OrgID string
IsVerified bool
IsPrimary bool
ValidationType domain.OrgDomainValidationType
}
type Domains struct {
SearchResponse
Domains []*Domain
}
type OrgDomainSearchQueries struct {
SearchRequest
Queries []SearchQuery
}
func (q *OrgDomainSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
query = q.SearchRequest.toQuery(query)
for _, q := range q.Queries {
query = q.ToQuery(query)
}
return query
}
func NewOrgDomainDomainSearchQuery(method TextComparison, value string) (SearchQuery, error) {
return NewTextQuery(OrgDomainDomainCol, value, method)
}
func NewOrgDomainOrgIDSearchQuery(value string) (SearchQuery, error) {
return NewTextQuery(OrgDomainOrgIDCol, value, TextEquals)
}
func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearchQueries) (domains *Domains, err error) {
query, scan := prepareDomainsQuery()
stmt, args, err := queries.toQuery(query).ToSql()
if err != nil {
return nil, errors.ThrowInvalidArgument(err, "QUERY-ZRfj1", "Errors.Query.SQLStatement")
}
rows, err := q.client.QueryContext(ctx, stmt, args...)
if err != nil {
return nil, errors.ThrowInternal(err, "QUERY-M6mYN", "Errors.Internal")
}
domains, err = scan(rows)
if err != nil {
return nil, err
}
domains.LatestSequence, err = q.latestSequence(ctx, orgDomainsTable)
return domains, err
}
func prepareDomainsQuery() (sq.SelectBuilder, func(*sql.Rows) (*Domains, error)) {
return sq.Select(
OrgDomainCreationDateCol.identifier(),
OrgDomainChangeDateCol.identifier(),
OrgDomainSequenceCol.identifier(),
OrgDomainDomainCol.identifier(),
OrgDomainOrgIDCol.identifier(),
OrgDomainIsVerifiedCol.identifier(),
OrgDomainIsPrimaryCol.identifier(),
OrgDomainValidationTypeCol.identifier(),
countColumn.identifier(),
).From(orgDomainsTable.identifier()).PlaceholderFormat(sq.Dollar),
func(rows *sql.Rows) (*Domains, error) {
domains := make([]*Domain, 0)
var count uint64
for rows.Next() {
domain := new(Domain)
err := rows.Scan(
&domain.CreationDate,
&domain.ChangeDate,
&domain.Sequence,
&domain.Domain,
&domain.OrgID,
&domain.IsVerified,
&domain.IsPrimary,
&domain.ValidationType,
&count,
)
if err != nil {
return nil, err
}
domains = append(domains, domain)
}
if err := rows.Close(); err != nil {
return nil, errors.ThrowInternal(err, "QUERY-rKd6k", "Errors.Query.CloseRows")
}
return &Domains{
Domains: domains,
SearchResponse: SearchResponse{
Count: count,
},
}, nil
}
}
var (
orgDomainsTable = table{
name: projection.OrgDomainTable,
}
OrgDomainCreationDateCol = Column{
name: projection.OrgDomainCreationDateCol,
table: orgDomainsTable,
}
OrgDomainChangeDateCol = Column{
name: projection.OrgDomainChangeDateCol,
table: orgDomainsTable,
}
OrgDomainSequenceCol = Column{
name: projection.OrgDomainSequenceCol,
table: orgDomainsTable,
}
OrgDomainDomainCol = Column{
name: projection.OrgDomainDomainCol,
table: orgDomainsTable,
}
OrgDomainOrgIDCol = Column{
name: projection.OrgDomainOrgIDCol,
table: orgDomainsTable,
}
OrgDomainIsVerifiedCol = Column{
name: projection.OrgDomainIsVerifiedCol,
table: orgDomainsTable,
}
OrgDomainIsPrimaryCol = Column{
name: projection.OrgDomainIsPrimaryCol,
table: orgDomainsTable,
}
OrgDomainValidationTypeCol = Column{
name: projection.OrgDomainValidationTypeCol,
table: orgDomainsTable,
}
)

View File

@ -0,0 +1,180 @@
package projection
import (
"context"
"fmt"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/handler"
"github.com/caos/zitadel/internal/eventstore/handler/crdb"
"github.com/caos/zitadel/internal/repository/org"
)
type OrgDomainProjection struct {
crdb.StatementHandler
}
const (
OrgDomainTable = "zitadel.projections.org_domains"
)
func NewOrgDomainProjection(ctx context.Context, config crdb.StatementHandlerConfig) *OrgDomainProjection {
p := &OrgDomainProjection{}
config.ProjectionName = OrgDomainTable
config.Reducers = p.reducers()
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
return p
}
func (p *OrgDomainProjection) reducers() []handler.AggregateReducer {
return []handler.AggregateReducer{
{
Aggregate: org.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: org.OrgDomainAddedEventType,
Reduce: p.reduceDomainAdded,
},
{
Event: org.OrgDomainVerificationAddedEventType,
Reduce: p.reduceDomainVerificationAdded,
},
{
Event: org.OrgDomainVerifiedEventType,
Reduce: p.reduceDomainVerified,
},
{
Event: org.OrgDomainPrimarySetEventType,
Reduce: p.reducePrimaryDomainSet,
},
{
Event: org.OrgDomainRemovedEventType,
Reduce: p.reduceDomainRemoved,
},
},
},
}
}
const (
OrgDomainCreationDateCol = "creation_date"
OrgDomainChangeDateCol = "change_date"
OrgDomainSequenceCol = "sequence"
OrgDomainDomainCol = "domain"
OrgDomainOrgIDCol = "org_id"
OrgDomainIsVerifiedCol = "is_verified"
OrgDomainIsPrimaryCol = "is_primary"
OrgDomainValidationTypeCol = "validation_type"
)
func (p *OrgDomainProjection) reduceDomainAdded(event eventstore.EventReader) (*handler.Statement, error) {
e, ok := event.(*org.DomainAddedEvent)
if !ok {
logging.LogWithFields("PROJE-6fXKf", "seq", event.Sequence(), "expectedType", org.OrgDomainAddedEventType, "gottenType", fmt.Sprintf("%T", event)).Error("unexpected event type")
return nil, errors.ThrowInvalidArgument(nil, "PROJE-DM2DI", "reduce.wrong.event.type")
}
return crdb.NewCreateStatement(
e,
[]handler.Column{
handler.NewCol(OrgDomainCreationDateCol, e.CreationDate()),
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
handler.NewCol(OrgDomainDomainCol, e.Domain),
handler.NewCol(OrgDomainOrgIDCol, e.Aggregate().ID),
handler.NewCol(OrgDomainIsVerifiedCol, false),
handler.NewCol(OrgDomainIsPrimaryCol, false),
handler.NewCol(OrgDomainValidationTypeCol, domain.OrgDomainValidationTypeUnspecified),
},
), nil
}
func (p *OrgDomainProjection) reduceDomainVerificationAdded(event eventstore.EventReader) (*handler.Statement, error) {
e, ok := event.(*org.DomainVerificationAddedEvent)
if !ok {
logging.LogWithFields("PROJE-2gGSs", "seq", event.Sequence(), "expectedType", org.OrgDomainVerificationAddedEventType, "gottenType", fmt.Sprintf("%T", event)).Error("unexpected event type")
return nil, errors.ThrowInvalidArgument(nil, "PROJE-EBzyu", "reduce.wrong.event.type")
}
return crdb.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
handler.NewCol(OrgDomainValidationTypeCol, e.ValidationType),
},
[]handler.Condition{
handler.NewCond(OrgDomainDomainCol, e.Domain),
handler.NewCond(OrgDomainOrgIDCol, e.Aggregate().ID),
},
), nil
}
func (p *OrgDomainProjection) reduceDomainVerified(event eventstore.EventReader) (*handler.Statement, error) {
e, ok := event.(*org.DomainVerifiedEvent)
if !ok {
logging.LogWithFields("PROJE-aeGCA", "seq", event.Sequence(), "expectedType", org.OrgDomainVerifiedEventType, "gottenType", fmt.Sprintf("%T", event)).Error("unexpected event type")
return nil, errors.ThrowInvalidArgument(nil, "PROJE-3Rvkr", "reduce.wrong.event.type")
}
return crdb.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
handler.NewCol(OrgDomainIsVerifiedCol, true),
},
[]handler.Condition{
handler.NewCond(OrgDomainDomainCol, e.Domain),
handler.NewCond(OrgDomainOrgIDCol, e.Aggregate().ID),
},
), nil
}
func (p *OrgDomainProjection) reducePrimaryDomainSet(event eventstore.EventReader) (*handler.Statement, error) {
e, ok := event.(*org.DomainPrimarySetEvent)
if !ok {
logging.LogWithFields("PROJE-6YjHo", "seq", event.Sequence(), "expectedType", org.OrgDomainPrimarySetEventType, "gottenType", fmt.Sprintf("%T", event)).Error("unexpected event type")
return nil, errors.ThrowInvalidArgument(nil, "PROJE-aIuei", "reduce.wrong.event.type")
}
return crdb.NewMultiStatement(
e,
crdb.AddUpdateStatement(
[]handler.Column{
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
handler.NewCol(OrgDomainIsPrimaryCol, false),
},
[]handler.Condition{
handler.NewCond(OrgDomainOrgIDCol, e.Aggregate().ID),
handler.NewCond(OrgDomainIsPrimaryCol, true),
},
),
crdb.AddUpdateStatement(
[]handler.Column{
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
handler.NewCol(OrgDomainIsPrimaryCol, true),
},
[]handler.Condition{
handler.NewCond(OrgDomainDomainCol, e.Domain),
handler.NewCond(OrgDomainOrgIDCol, e.Aggregate().ID),
},
),
), nil
}
func (p *OrgDomainProjection) reduceDomainRemoved(event eventstore.EventReader) (*handler.Statement, error) {
e, ok := event.(*org.DomainRemovedEvent)
if !ok {
logging.LogWithFields("PROJE-dDnps", "seq", event.Sequence(), "expectedType", org.OrgDomainRemovedEventType, "gottenType", fmt.Sprintf("%T", event)).Error("unexpected event type")
return nil, errors.ThrowInvalidArgument(nil, "PROJE-gh1Mx", "reduce.wrong.event.type")
}
return crdb.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(OrgDomainDomainCol, e.Domain),
handler.NewCond(OrgDomainOrgIDCol, e.Aggregate().ID),
},
), nil
}

View File

@ -0,0 +1,203 @@
package projection
import (
"testing"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/handler"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/repository/org"
)
func TestOrgDomainProjection_reduces(t *testing.T) {
type args struct {
event func(t *testing.T) eventstore.EventReader
}
tests := []struct {
name string
args args
reduce func(event eventstore.EventReader) (*handler.Statement, error)
want wantReduce
}{
{
name: "reduceDomainAdded",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgDomainAddedEventType),
org.AggregateType,
[]byte(`{"domain": "domain.new"}`),
), org.DomainAddedEventMapper),
},
reduce: (&OrgDomainProjection{}).reduceDomainAdded,
want: wantReduce{
projection: OrgDomainTable,
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO zitadel.projections.org_domains (creation_date, change_date, sequence, domain, org_id, is_verified, is_primary, validation_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
expectedArgs: []interface{}{
anyArg{},
anyArg{},
uint64(15),
"domain.new",
"agg-id",
false,
false,
domain.OrgDomainValidationTypeUnspecified,
},
},
},
},
},
},
{
name: "reduceDomainVerificationAdded",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgDomainVerificationAddedEventType),
org.AggregateType,
[]byte(`{"domain": "domain.new", "validationType": 2}`),
), org.DomainVerificationAddedEventMapper),
},
reduce: (&OrgDomainProjection{}).reduceDomainVerificationAdded,
want: wantReduce{
projection: OrgDomainTable,
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.org_domains SET (change_date, sequence, validation_type) = ($1, $2, $3) WHERE (domain = $4) AND (org_id = $5)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
domain.OrgDomainValidationTypeDNS,
"domain.new",
"agg-id",
},
},
},
},
},
},
{
name: "reduceDomainVerified",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgDomainVerifiedEventType),
org.AggregateType,
[]byte(`{"domain": "domain.new"}`),
), org.DomainVerifiedEventMapper),
},
reduce: (&OrgDomainProjection{}).reduceDomainVerified,
want: wantReduce{
projection: OrgDomainTable,
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.org_domains SET (change_date, sequence, is_verified) = ($1, $2, $3) WHERE (domain = $4) AND (org_id = $5)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
true,
"domain.new",
"agg-id",
},
},
},
},
},
},
{
name: "reducePrimaryDomainSet",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgDomainPrimarySetEventType),
org.AggregateType,
[]byte(`{"domain": "domain.new"}`),
), org.DomainPrimarySetEventMapper),
},
reduce: (&OrgDomainProjection{}).reducePrimaryDomainSet,
want: wantReduce{
projection: OrgDomainTable,
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.org_domains SET (change_date, sequence, is_primary) = ($1, $2, $3) WHERE (org_id = $4) AND (is_primary = $5)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
false,
"agg-id",
true,
},
},
{
expectedStmt: "UPDATE zitadel.projections.org_domains SET (change_date, sequence, is_primary) = ($1, $2, $3) WHERE (domain = $4) AND (org_id = $5)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
true,
"domain.new",
"agg-id",
},
},
},
},
},
},
{
name: "reduceDomainRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgDomainRemovedEventType),
org.AggregateType,
[]byte(`{"domain": "domain.new"}`),
), org.DomainRemovedEventMapper),
},
reduce: (&OrgDomainProjection{}).reduceDomainRemoved,
want: wantReduce{
projection: OrgDomainTable,
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM zitadel.projections.org_domains WHERE (domain = $1) AND (org_id = $2)",
expectedArgs: []interface{}{
"domain.new",
"agg-id",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
event := baseEvent(t)
got, err := tt.reduce(event)
if _, ok := err.(errors.InvalidArgument); !ok {
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
}
event = tt.args.event(t)
got, err = tt.reduce(event)
assertReduce(t, got, err, tt.want)
})
}
}

View File

@ -39,6 +39,8 @@ func Start(ctx context.Context, sqlClient *sql.DB, es *eventstore.Eventstore, co
NewProjectProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["projects"]))
NewProjectGrantProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_grants"]))
NewProjectRoleProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_roles"]))
// owner.NewOrgOwnerProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["org_owners"]))
NewOrgDomainProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["org_domains"]))
return nil
}

View File

@ -0,0 +1,13 @@
CREATE TABLE zitadel.projections.org_domains (
creation_date TIMESTAMPTZ,
change_date TIMESTAMPTZ,
sequence BIGINT,
domain TEXT,
org_id TEXT,
is_verified BOOLEAN,
is_primary BOOLEAN,
validation_type SMALLINT,
PRIMARY KEY (org_id, domain)
);