mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
refactor: rename package errors to zerrors (#7039)
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
z_db "github.com/zitadel/zitadel/internal/database"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type database struct {
|
||||
@@ -41,18 +41,18 @@ func (d *database) ReadKeys() (crypto.Keys, error) {
|
||||
From(EncryptionKeysTable).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowInternal(err, "", "unable to read keys")
|
||||
return nil, zerrors.ThrowInternal(err, "", "unable to read keys")
|
||||
}
|
||||
err = d.client.Query(func(rows *sql.Rows) error {
|
||||
for rows.Next() {
|
||||
var id, encryptionKey string
|
||||
err = rows.Scan(&id, &encryptionKey)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to read keys")
|
||||
return zerrors.ThrowInternal(err, "", "unable to read keys")
|
||||
}
|
||||
key, err := d.decrypt(encryptionKey, d.masterKey)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to decrypt key")
|
||||
return zerrors.ThrowInternal(err, "", "unable to decrypt key")
|
||||
}
|
||||
keys[id] = key
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (d *database) ReadKeys() (crypto.Keys, error) {
|
||||
}, stmt, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowInternal(err, "", "unable to read keys")
|
||||
return nil, zerrors.ThrowInternal(err, "", "unable to read keys")
|
||||
}
|
||||
|
||||
return keys, nil
|
||||
@@ -73,23 +73,23 @@ func (d *database) ReadKey(id string) (_ *crypto.Key, err error) {
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowInternal(err, "", "unable to read key")
|
||||
return nil, zerrors.ThrowInternal(err, "", "unable to read key")
|
||||
}
|
||||
var key string
|
||||
err = d.client.QueryRow(func(row *sql.Row) error {
|
||||
var encryptionKey string
|
||||
err = row.Scan(&encryptionKey)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to read key")
|
||||
return zerrors.ThrowInternal(err, "", "unable to read key")
|
||||
}
|
||||
key, err = d.decrypt(encryptionKey, d.masterKey)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to decrypt key")
|
||||
return zerrors.ThrowInternal(err, "", "unable to decrypt key")
|
||||
}
|
||||
return nil
|
||||
}, stmt, args...)
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowInternal(err, "", "unable to read key")
|
||||
return nil, zerrors.ThrowInternal(err, "", "unable to read key")
|
||||
}
|
||||
|
||||
return &crypto.Key{
|
||||
@@ -104,33 +104,33 @@ func (d *database) CreateKeys(keys ...*crypto.Key) error {
|
||||
for _, key := range keys {
|
||||
encryptionKey, err := d.encrypt(key.Value, d.masterKey)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to encrypt key")
|
||||
return zerrors.ThrowInternal(err, "", "unable to encrypt key")
|
||||
}
|
||||
insert = insert.Values(key.ID, encryptionKey)
|
||||
}
|
||||
stmt, args, err := insert.ToSql()
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to insert new keys")
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
tx, err := d.client.Begin()
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to insert new keys")
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
_, err = tx.Exec(stmt, args...)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return caos_errs.ThrowInternal(err, "", "unable to insert new keys")
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "", "unable to insert new keys")
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkMasterKeyLength(masterKey string) error {
|
||||
if length := len([]byte(masterKey)); length != 32 {
|
||||
return caos_errs.ThrowInternalf(nil, "", "masterkey must be 32 bytes, but is %d", length)
|
||||
return zerrors.ThrowInternalf(nil, "", "masterkey must be 32 bytes, but is %d", length)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
z_db "github.com/zitadel/zitadel/internal/database"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func Test_database_ReadKeys(t *testing.T) {
|
||||
@@ -62,7 +62,7 @@ func Test_database_ReadKeys(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -187,7 +187,7 @@ func Test_database_ReadKey(t *testing.T) {
|
||||
id: "id1",
|
||||
},
|
||||
res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -212,7 +212,7 @@ func Test_database_ReadKey(t *testing.T) {
|
||||
id: "id1",
|
||||
},
|
||||
res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -303,7 +303,7 @@ func Test_database_CreateKeys(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -422,7 +422,7 @@ func Test_checkMasterKeyLength(t *testing.T) {
|
||||
args{
|
||||
masterKey: "",
|
||||
},
|
||||
caos_errs.IsInternal,
|
||||
zerrors.IsInternal,
|
||||
},
|
||||
{
|
||||
"valid length",
|
||||
|
Reference in New Issue
Block a user