2022-03-24 16:21:34 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
errs "errors"
|
2022-04-25 08:01:17 +00:00
|
|
|
"strings"
|
2022-03-24 16:21:34 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/query/projection"
|
2022-12-01 08:18:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
2022-03-24 16:21:34 +00:00
|
|
|
)
|
|
|
|
|
2022-06-08 11:46:24 +00:00
|
|
|
const (
|
|
|
|
InstancesFilterTableAlias = "f"
|
|
|
|
)
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
var (
|
|
|
|
instanceTable = table{
|
2022-10-27 06:08:36 +00:00
|
|
|
name: projection.InstanceProjectionTable,
|
|
|
|
instanceIDCol: projection.InstanceColumnID,
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
InstanceColumnID = Column{
|
|
|
|
name: projection.InstanceColumnID,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
InstanceColumnName = Column{
|
|
|
|
name: projection.InstanceColumnName,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
|
|
|
InstanceColumnCreationDate = Column{
|
|
|
|
name: projection.InstanceColumnCreationDate,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-03-24 16:21:34 +00:00
|
|
|
InstanceColumnChangeDate = Column{
|
|
|
|
name: projection.InstanceColumnChangeDate,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
|
|
|
InstanceColumnSequence = Column{
|
|
|
|
name: projection.InstanceColumnSequence,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-06-03 12:30:39 +00:00
|
|
|
InstanceColumnDefaultOrgID = Column{
|
|
|
|
name: projection.InstanceColumnDefaultOrgID,
|
2022-03-24 16:21:34 +00:00
|
|
|
table: instanceTable,
|
|
|
|
}
|
|
|
|
InstanceColumnProjectID = Column{
|
|
|
|
name: projection.InstanceColumnProjectID,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-03-29 09:53:19 +00:00
|
|
|
InstanceColumnConsoleID = Column{
|
|
|
|
name: projection.InstanceColumnConsoleID,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-04-14 12:19:18 +00:00
|
|
|
InstanceColumnConsoleAppID = Column{
|
|
|
|
name: projection.InstanceColumnConsoleAppID,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
2022-03-24 16:21:34 +00:00
|
|
|
InstanceColumnDefaultLanguage = Column{
|
|
|
|
name: projection.InstanceColumnDefaultLanguage,
|
|
|
|
table: instanceTable,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
type Instance struct {
|
2022-04-21 10:37:39 +00:00
|
|
|
ID string
|
|
|
|
ChangeDate time.Time
|
|
|
|
CreationDate time.Time
|
|
|
|
Sequence uint64
|
2022-04-27 15:18:34 +00:00
|
|
|
Name string
|
2022-03-24 16:21:34 +00:00
|
|
|
|
2022-06-03 12:30:39 +00:00
|
|
|
DefaultOrgID string
|
2022-04-25 09:16:36 +00:00
|
|
|
IAMProjectID string
|
|
|
|
ConsoleID string
|
|
|
|
ConsoleAppID string
|
|
|
|
DefaultLang language.Tag
|
2022-04-27 15:18:34 +00:00
|
|
|
Domains []*InstanceDomain
|
2022-04-25 09:16:36 +00:00
|
|
|
host string
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 10:37:39 +00:00
|
|
|
type Instances struct {
|
|
|
|
SearchResponse
|
|
|
|
Instances []*Instance
|
|
|
|
}
|
|
|
|
|
2022-03-29 09:53:19 +00:00
|
|
|
func (i *Instance) InstanceID() string {
|
|
|
|
return i.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) ProjectID() string {
|
|
|
|
return i.IAMProjectID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) ConsoleClientID() string {
|
|
|
|
return i.ConsoleID
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:19:18 +00:00
|
|
|
func (i *Instance) ConsoleApplicationID() string {
|
|
|
|
return i.ConsoleAppID
|
|
|
|
}
|
|
|
|
|
2022-04-12 14:20:17 +00:00
|
|
|
func (i *Instance) RequestedDomain() string {
|
2022-04-25 09:16:36 +00:00
|
|
|
return strings.Split(i.host, ":")[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) RequestedHost() string {
|
|
|
|
return i.host
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) DefaultLanguage() language.Tag {
|
|
|
|
return i.DefaultLang
|
2022-04-12 14:20:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 12:30:39 +00:00
|
|
|
func (i *Instance) DefaultOrganisationID() string {
|
|
|
|
return i.DefaultOrgID
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
type InstanceSearchQueries struct {
|
|
|
|
SearchRequest
|
|
|
|
Queries []SearchQuery
|
|
|
|
}
|
|
|
|
|
2022-04-21 10:37:39 +00:00
|
|
|
func NewInstanceIDsListSearchQuery(ids ...string) (SearchQuery, error) {
|
|
|
|
list := make([]interface{}, len(ids))
|
|
|
|
for i, value := range ids {
|
|
|
|
list[i] = value
|
|
|
|
}
|
|
|
|
return NewListQuery(InstanceColumnID, list, ListIn)
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (q *InstanceSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
|
|
|
query = q.SearchRequest.toQuery(query)
|
|
|
|
for _, q := range q.Queries {
|
|
|
|
query = q.toQuery(query)
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
2022-04-21 10:37:39 +00:00
|
|
|
func (q *Queries) SearchInstances(ctx context.Context, queries *InstanceSearchQueries) (instances *Instances, err error) {
|
2022-12-01 08:18:53 +00:00
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2022-06-08 11:46:24 +00:00
|
|
|
filter, query, scan := prepareInstancesQuery()
|
|
|
|
stmt, args, err := query(queries.toQuery(filter)).ToSql()
|
2022-04-21 10:37:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInvalidArgument(err, "QUERY-M9fow", "Errors.Query.SQLStatement")
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := q.client.QueryContext(ctx, stmt, args...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-3j98f", "Errors.Internal")
|
|
|
|
}
|
|
|
|
instances, err = scan(rows)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return instances, err
|
|
|
|
}
|
|
|
|
|
2022-12-01 08:18:53 +00:00
|
|
|
func (q *Queries) Instance(ctx context.Context, shouldTriggerBulk bool) (_ *Instance, err error) {
|
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
if shouldTriggerBulk {
|
2022-07-22 10:08:39 +00:00
|
|
|
projection.InstanceProjection.Trigger(ctx)
|
2022-06-14 05:51:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 15:18:34 +00:00
|
|
|
stmt, scan := prepareInstanceDomainQuery(authz.GetInstance(ctx).RequestedDomain())
|
2022-03-24 16:21:34 +00:00
|
|
|
query, args, err := stmt.Where(sq.Eq{
|
2022-03-29 09:53:19 +00:00
|
|
|
InstanceColumnID.identifier(): authz.GetInstance(ctx).InstanceID(),
|
2022-03-24 16:21:34 +00:00
|
|
|
}).ToSql()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-d9ngs", "Errors.Query.SQLStatement")
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:18:34 +00:00
|
|
|
row, err := q.client.QueryContext(ctx, query, args...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-03-24 16:21:34 +00:00
|
|
|
return scan(row)
|
|
|
|
}
|
|
|
|
|
2022-12-01 08:18:53 +00:00
|
|
|
func (q *Queries) InstanceByHost(ctx context.Context, host string) (_ authz.Instance, err error) {
|
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2022-04-25 08:01:17 +00:00
|
|
|
stmt, scan := prepareInstanceDomainQuery(host)
|
2022-04-25 09:16:36 +00:00
|
|
|
host = strings.Split(host, ":")[0] //remove possible port
|
2022-03-29 09:53:19 +00:00
|
|
|
query, args, err := stmt.Where(sq.Eq{
|
2022-04-25 09:16:36 +00:00
|
|
|
InstanceDomainDomainCol.identifier(): host,
|
2022-03-29 09:53:19 +00:00
|
|
|
}).ToSql()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-SAfg2", "Errors.Query.SQLStatement")
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:18:34 +00:00
|
|
|
row, err := q.client.QueryContext(ctx, query, args...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-03-29 09:53:19 +00:00
|
|
|
return scan(row)
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (q *Queries) GetDefaultLanguage(ctx context.Context) language.Tag {
|
2022-06-14 05:51:00 +00:00
|
|
|
instance, err := q.Instance(ctx, false)
|
2022-03-24 16:21:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return language.Und
|
|
|
|
}
|
2022-04-25 09:16:36 +00:00
|
|
|
return instance.DefaultLanguage()
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 14:20:17 +00:00
|
|
|
func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Instance, error)) {
|
2022-03-24 16:21:34 +00:00
|
|
|
return sq.Select(
|
|
|
|
InstanceColumnID.identifier(),
|
2022-04-21 10:37:39 +00:00
|
|
|
InstanceColumnCreationDate.identifier(),
|
2022-03-24 16:21:34 +00:00
|
|
|
InstanceColumnChangeDate.identifier(),
|
|
|
|
InstanceColumnSequence.identifier(),
|
2022-06-03 12:30:39 +00:00
|
|
|
InstanceColumnDefaultOrgID.identifier(),
|
2022-03-24 16:21:34 +00:00
|
|
|
InstanceColumnProjectID.identifier(),
|
2022-03-29 09:53:19 +00:00
|
|
|
InstanceColumnConsoleID.identifier(),
|
2022-04-14 12:19:18 +00:00
|
|
|
InstanceColumnConsoleAppID.identifier(),
|
2022-03-24 16:21:34 +00:00
|
|
|
InstanceColumnDefaultLanguage.identifier(),
|
|
|
|
).
|
|
|
|
From(instanceTable.identifier()).PlaceholderFormat(sq.Dollar),
|
|
|
|
func(row *sql.Row) (*Instance, error) {
|
2022-04-25 09:16:36 +00:00
|
|
|
instance := &Instance{host: host}
|
2022-03-24 16:21:34 +00:00
|
|
|
lang := ""
|
|
|
|
err := row.Scan(
|
2022-04-12 14:20:17 +00:00
|
|
|
&instance.ID,
|
2022-04-21 10:37:39 +00:00
|
|
|
&instance.CreationDate,
|
2022-04-12 14:20:17 +00:00
|
|
|
&instance.ChangeDate,
|
|
|
|
&instance.Sequence,
|
2022-06-03 12:30:39 +00:00
|
|
|
&instance.DefaultOrgID,
|
2022-04-12 14:20:17 +00:00
|
|
|
&instance.IAMProjectID,
|
|
|
|
&instance.ConsoleID,
|
2022-04-14 12:19:18 +00:00
|
|
|
&instance.ConsoleAppID,
|
2022-03-24 16:21:34 +00:00
|
|
|
&lang,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
if errs.Is(err, sql.ErrNoRows) {
|
2022-04-27 15:18:34 +00:00
|
|
|
return nil, errors.ThrowNotFound(err, "QUERY-5m09s", "Errors.IAM.NotFound")
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-3j9sf", "Errors.Internal")
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
2022-04-25 09:16:36 +00:00
|
|
|
instance.DefaultLang = language.Make(lang)
|
2022-04-12 14:20:17 +00:00
|
|
|
return instance, nil
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
|
2022-06-08 11:46:24 +00:00
|
|
|
func prepareInstancesQuery() (sq.SelectBuilder, func(sq.SelectBuilder) sq.SelectBuilder, func(*sql.Rows) (*Instances, error)) {
|
|
|
|
instanceFilterTable := instanceTable.setAlias(InstancesFilterTableAlias)
|
|
|
|
instanceFilterIDColumn := InstanceColumnID.setTable(instanceFilterTable)
|
|
|
|
instanceFilterCountColumn := InstancesFilterTableAlias + ".count"
|
2022-04-21 10:37:39 +00:00
|
|
|
return sq.Select(
|
|
|
|
InstanceColumnID.identifier(),
|
|
|
|
countColumn.identifier(),
|
2022-06-08 11:46:24 +00:00
|
|
|
).From(instanceTable.identifier()),
|
|
|
|
func(builder sq.SelectBuilder) sq.SelectBuilder {
|
|
|
|
return sq.Select(
|
|
|
|
instanceFilterCountColumn,
|
|
|
|
instanceFilterIDColumn.identifier(),
|
|
|
|
InstanceColumnCreationDate.identifier(),
|
|
|
|
InstanceColumnChangeDate.identifier(),
|
|
|
|
InstanceColumnSequence.identifier(),
|
|
|
|
InstanceColumnName.identifier(),
|
|
|
|
InstanceColumnDefaultOrgID.identifier(),
|
|
|
|
InstanceColumnProjectID.identifier(),
|
|
|
|
InstanceColumnConsoleID.identifier(),
|
|
|
|
InstanceColumnConsoleAppID.identifier(),
|
|
|
|
InstanceColumnDefaultLanguage.identifier(),
|
|
|
|
InstanceDomainDomainCol.identifier(),
|
|
|
|
InstanceDomainIsPrimaryCol.identifier(),
|
|
|
|
InstanceDomainIsGeneratedCol.identifier(),
|
|
|
|
InstanceDomainCreationDateCol.identifier(),
|
|
|
|
InstanceDomainChangeDateCol.identifier(),
|
|
|
|
InstanceDomainSequenceCol.identifier(),
|
|
|
|
).FromSelect(builder, InstancesFilterTableAlias).
|
|
|
|
LeftJoin(join(InstanceColumnID, instanceFilterIDColumn)).
|
|
|
|
LeftJoin(join(InstanceDomainInstanceIDCol, instanceFilterIDColumn)).
|
|
|
|
PlaceholderFormat(sq.Dollar)
|
|
|
|
},
|
2022-04-21 10:37:39 +00:00
|
|
|
func(rows *sql.Rows) (*Instances, error) {
|
|
|
|
instances := make([]*Instance, 0)
|
2022-06-08 11:46:24 +00:00
|
|
|
var lastInstance *Instance
|
2022-04-21 10:37:39 +00:00
|
|
|
var count uint64
|
|
|
|
for rows.Next() {
|
|
|
|
instance := new(Instance)
|
|
|
|
lang := ""
|
2022-06-08 11:46:24 +00:00
|
|
|
var (
|
|
|
|
domain sql.NullString
|
|
|
|
isPrimary sql.NullBool
|
|
|
|
isGenerated sql.NullBool
|
|
|
|
changeDate sql.NullTime
|
|
|
|
creationDate sql.NullTime
|
|
|
|
sequence sql.NullInt64
|
|
|
|
)
|
2022-04-21 10:37:39 +00:00
|
|
|
err := rows.Scan(
|
2022-06-08 11:46:24 +00:00
|
|
|
&count,
|
2022-04-21 10:37:39 +00:00
|
|
|
&instance.ID,
|
|
|
|
&instance.CreationDate,
|
|
|
|
&instance.ChangeDate,
|
|
|
|
&instance.Sequence,
|
2022-04-27 15:18:34 +00:00
|
|
|
&instance.Name,
|
2022-06-03 12:30:39 +00:00
|
|
|
&instance.DefaultOrgID,
|
2022-04-21 10:37:39 +00:00
|
|
|
&instance.IAMProjectID,
|
|
|
|
&instance.ConsoleID,
|
|
|
|
&instance.ConsoleAppID,
|
|
|
|
&lang,
|
2022-06-08 11:46:24 +00:00
|
|
|
&domain,
|
|
|
|
&isPrimary,
|
|
|
|
&isGenerated,
|
|
|
|
&changeDate,
|
|
|
|
&creationDate,
|
|
|
|
&sequence,
|
2022-04-21 10:37:39 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-06-08 11:46:24 +00:00
|
|
|
if instance.ID == "" || !domain.Valid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
instance.DefaultLang = language.Make(lang)
|
|
|
|
instanceDomain := &InstanceDomain{
|
|
|
|
CreationDate: creationDate.Time,
|
|
|
|
ChangeDate: changeDate.Time,
|
|
|
|
Sequence: uint64(sequence.Int64),
|
|
|
|
Domain: domain.String,
|
|
|
|
IsPrimary: isPrimary.Bool,
|
|
|
|
IsGenerated: isGenerated.Bool,
|
|
|
|
InstanceID: instance.ID,
|
|
|
|
}
|
|
|
|
if lastInstance != nil && instance.ID == lastInstance.ID {
|
|
|
|
lastInstance.Domains = append(lastInstance.Domains, instanceDomain)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lastInstance = instance
|
|
|
|
instance.Domains = append(instance.Domains, instanceDomain)
|
2022-04-21 10:37:39 +00:00
|
|
|
instances = append(instances, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-8nlWW", "Errors.Query.CloseRows")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Instances{
|
|
|
|
Instances: instances,
|
|
|
|
SearchResponse: SearchResponse{
|
|
|
|
Count: count,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 08:01:17 +00:00
|
|
|
|
2022-04-27 15:18:34 +00:00
|
|
|
func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows) (*Instance, error)) {
|
2022-04-25 08:01:17 +00:00
|
|
|
return sq.Select(
|
|
|
|
InstanceColumnID.identifier(),
|
|
|
|
InstanceColumnCreationDate.identifier(),
|
|
|
|
InstanceColumnChangeDate.identifier(),
|
|
|
|
InstanceColumnSequence.identifier(),
|
2022-04-27 15:18:34 +00:00
|
|
|
InstanceColumnName.identifier(),
|
2022-06-03 12:30:39 +00:00
|
|
|
InstanceColumnDefaultOrgID.identifier(),
|
2022-04-25 08:01:17 +00:00
|
|
|
InstanceColumnProjectID.identifier(),
|
|
|
|
InstanceColumnConsoleID.identifier(),
|
|
|
|
InstanceColumnConsoleAppID.identifier(),
|
|
|
|
InstanceColumnDefaultLanguage.identifier(),
|
2022-04-27 15:18:34 +00:00
|
|
|
InstanceDomainDomainCol.identifier(),
|
|
|
|
InstanceDomainIsPrimaryCol.identifier(),
|
|
|
|
InstanceDomainIsGeneratedCol.identifier(),
|
|
|
|
InstanceDomainCreationDateCol.identifier(),
|
|
|
|
InstanceDomainChangeDateCol.identifier(),
|
|
|
|
InstanceDomainSequenceCol.identifier(),
|
2022-04-25 08:01:17 +00:00
|
|
|
).
|
|
|
|
From(instanceTable.identifier()).
|
|
|
|
LeftJoin(join(InstanceDomainInstanceIDCol, InstanceColumnID)).
|
|
|
|
PlaceholderFormat(sq.Dollar),
|
2022-04-27 15:18:34 +00:00
|
|
|
func(rows *sql.Rows) (*Instance, error) {
|
|
|
|
instance := &Instance{
|
|
|
|
host: host,
|
|
|
|
Domains: make([]*InstanceDomain, 0),
|
|
|
|
}
|
2022-04-25 08:01:17 +00:00
|
|
|
lang := ""
|
2022-04-27 15:18:34 +00:00
|
|
|
for rows.Next() {
|
|
|
|
var (
|
|
|
|
domain sql.NullString
|
|
|
|
isPrimary sql.NullBool
|
|
|
|
isGenerated sql.NullBool
|
|
|
|
changeDate sql.NullTime
|
|
|
|
creationDate sql.NullTime
|
2022-06-08 11:46:24 +00:00
|
|
|
sequence sql.NullInt64
|
2022-04-27 15:18:34 +00:00
|
|
|
)
|
|
|
|
err := rows.Scan(
|
|
|
|
&instance.ID,
|
|
|
|
&instance.CreationDate,
|
|
|
|
&instance.ChangeDate,
|
|
|
|
&instance.Sequence,
|
|
|
|
&instance.Name,
|
2022-06-03 12:30:39 +00:00
|
|
|
&instance.DefaultOrgID,
|
2022-04-27 15:18:34 +00:00
|
|
|
&instance.IAMProjectID,
|
|
|
|
&instance.ConsoleID,
|
|
|
|
&instance.ConsoleAppID,
|
|
|
|
&lang,
|
|
|
|
&domain,
|
|
|
|
&isPrimary,
|
|
|
|
&isGenerated,
|
|
|
|
&changeDate,
|
|
|
|
&creationDate,
|
2022-06-08 11:46:24 +00:00
|
|
|
&sequence,
|
2022-04-27 15:18:34 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-d9nw", "Errors.Internal")
|
|
|
|
}
|
|
|
|
if !domain.Valid {
|
|
|
|
continue
|
2022-04-25 08:01:17 +00:00
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
instance.Domains = append(instance.Domains, &InstanceDomain{
|
|
|
|
CreationDate: creationDate.Time,
|
|
|
|
ChangeDate: changeDate.Time,
|
2022-06-08 11:46:24 +00:00
|
|
|
Sequence: uint64(sequence.Int64),
|
2022-04-27 15:18:34 +00:00
|
|
|
Domain: domain.String,
|
|
|
|
IsPrimary: isPrimary.Bool,
|
|
|
|
IsGenerated: isGenerated.Bool,
|
|
|
|
InstanceID: instance.ID,
|
|
|
|
})
|
|
|
|
}
|
2022-08-17 06:07:41 +00:00
|
|
|
if instance.ID == "" {
|
|
|
|
return nil, errors.ThrowNotFound(nil, "QUERY-n0wng", "Errors.IAM.NotFound")
|
|
|
|
}
|
2022-05-03 13:58:38 +00:00
|
|
|
instance.DefaultLang = language.Make(lang)
|
2022-04-27 15:18:34 +00:00
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "QUERY-Dfbe2", "Errors.Query.CloseRows")
|
2022-04-25 08:01:17 +00:00
|
|
|
}
|
|
|
|
return instance, nil
|
|
|
|
}
|
|
|
|
}
|