mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
fix(import): add import for app and machine keys (#4536)
* fix(import): add import for app and machine keys * fix(export): add review changes * fix(import): Apply suggestions from code review Co-authored-by: Livio Spring <livio.a@gmail.com> * fix(import): add review changes Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -84,6 +84,23 @@ type AuthNKey struct {
|
||||
Type domain.AuthNKeyType
|
||||
}
|
||||
|
||||
type AuthNKeysData struct {
|
||||
SearchResponse
|
||||
AuthNKeysData []*AuthNKeyData
|
||||
}
|
||||
|
||||
type AuthNKeyData struct {
|
||||
ID string
|
||||
CreationDate time.Time
|
||||
ResourceOwner string
|
||||
Sequence uint64
|
||||
|
||||
Expiration time.Time
|
||||
Type domain.AuthNKeyType
|
||||
Identifier string
|
||||
PublicKey []byte
|
||||
}
|
||||
|
||||
type AuthNKeySearchQueries struct {
|
||||
SearchRequest
|
||||
Queries []SearchQuery
|
||||
@@ -122,6 +139,30 @@ func (q *Queries) SearchAuthNKeys(ctx context.Context, queries *AuthNKeySearchQu
|
||||
return authNKeys, err
|
||||
}
|
||||
|
||||
func (q *Queries) SearchAuthNKeysData(ctx context.Context, queries *AuthNKeySearchQueries) (authNKeys *AuthNKeysData, err error) {
|
||||
query, scan := prepareAuthNKeysDataQuery()
|
||||
query = queries.toQuery(query)
|
||||
stmt, args, err := query.Where(
|
||||
sq.Eq{
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-SAg3f", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
rows, err := q.client.QueryContext(ctx, stmt, args...)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-Dbi53", "Errors.Internal")
|
||||
}
|
||||
authNKeys, err = scan(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authNKeys.LatestSequence, err = q.latestSequence(ctx, authNKeyTable)
|
||||
return authNKeys, err
|
||||
}
|
||||
|
||||
func (q *Queries) GetAuthNKeyByID(ctx context.Context, shouldTriggerBulk bool, id string, queries ...SearchQuery) (*AuthNKey, error) {
|
||||
if shouldTriggerBulk {
|
||||
projection.AuthNKeyProjection.Trigger(ctx)
|
||||
@@ -270,3 +311,50 @@ func prepareAuthNKeyPublicKeyQuery() (sq.SelectBuilder, func(row *sql.Row) ([]by
|
||||
return publicKey, nil
|
||||
}
|
||||
}
|
||||
|
||||
func prepareAuthNKeysDataQuery() (sq.SelectBuilder, func(rows *sql.Rows) (*AuthNKeysData, error)) {
|
||||
return sq.Select(
|
||||
AuthNKeyColumnID.identifier(),
|
||||
AuthNKeyColumnCreationDate.identifier(),
|
||||
AuthNKeyColumnResourceOwner.identifier(),
|
||||
AuthNKeyColumnSequence.identifier(),
|
||||
AuthNKeyColumnExpiration.identifier(),
|
||||
AuthNKeyColumnType.identifier(),
|
||||
AuthNKeyColumnIdentifier.identifier(),
|
||||
AuthNKeyColumnPublicKey.identifier(),
|
||||
countColumn.identifier(),
|
||||
).From(authNKeyTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(rows *sql.Rows) (*AuthNKeysData, error) {
|
||||
authNKeys := make([]*AuthNKeyData, 0)
|
||||
var count uint64
|
||||
for rows.Next() {
|
||||
authNKey := new(AuthNKeyData)
|
||||
err := rows.Scan(
|
||||
&authNKey.ID,
|
||||
&authNKey.CreationDate,
|
||||
&authNKey.ResourceOwner,
|
||||
&authNKey.Sequence,
|
||||
&authNKey.Expiration,
|
||||
&authNKey.Type,
|
||||
&authNKey.Identifier,
|
||||
&authNKey.PublicKey,
|
||||
&count,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authNKeys = append(authNKeys, authNKey)
|
||||
}
|
||||
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-Dgfn3", "Errors.Query.CloseRows")
|
||||
}
|
||||
|
||||
return &AuthNKeysData{
|
||||
AuthNKeysData: authNKeys,
|
||||
SearchResponse: SearchResponse{
|
||||
Count: count,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user