From 7120d2e0c4350102627ba34902ca0bdffcda17d3 Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Mon, 20 May 2024 11:40:18 +0300 Subject: [PATCH] less diff with helper --- pkg/sdk/snowflakesql/bool.go | 5 +++++ pkg/sdk/users.go | 24 ++++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkg/sdk/snowflakesql/bool.go b/pkg/sdk/snowflakesql/bool.go index c58cbb284c..0a4eda633c 100644 --- a/pkg/sdk/snowflakesql/bool.go +++ b/pkg/sdk/snowflakesql/bool.go @@ -91,3 +91,8 @@ func (n Bool) Value() (driver.Value, error) { } return n.Bool, nil } + +// BoolValue returns either the default bool (false) if the Bool.Valid != true, of the underlying Bool.Value. +func (n Bool) BoolValue() bool { + return n.Valid && n.Bool +} diff --git a/pkg/sdk/users.go b/pkg/sdk/users.go index 2e371063b1..e037fa3534 100644 --- a/pkg/sdk/users.go +++ b/pkg/sdk/users.go @@ -95,12 +95,18 @@ func (row userDBRow) convert() *User { Name: row.Name, CreatedOn: row.CreatedOn, LoginName: row.LoginName, + Disabled: row.Disabled.BoolValue(), + MustChangePassword: row.MustChangePassword.BoolValue(), + SnowflakeLock: row.SnowflakeLock.BoolValue(), DefaultNamespace: row.DefaultNamespace, DefaultRole: row.DefaultRole, DefaultSecondaryRoles: row.DefaultSecondaryRoles, + ExtAuthnDuo: row.ExtAuthnDuo.BoolValue(), ExtAuthnUid: row.ExtAuthnUid, MinsToBypassMfa: row.MinsToBypassMfa, Owner: row.Owner, + HasPassword: row.HasPassword.BoolValue(), + HasRsaPublicKey: row.HasRsaPublicKey.BoolValue(), } if row.DisplayName.Valid { user.DisplayName = row.DisplayName.String @@ -123,21 +129,9 @@ func (row userDBRow) convert() *User { if row.Comment.Valid { user.Comment = row.Comment.String } - if row.Disabled.Valid { - user.Disabled = row.Disabled.Bool - } - if row.MustChangePassword.Valid { - user.MustChangePassword = row.MustChangePassword.Bool - } - if row.SnowflakeLock.Valid { - user.SnowflakeLock = row.SnowflakeLock.Bool - } if row.DefaultWarehouse.Valid { user.DefaultWarehouse = row.DefaultWarehouse.String } - if row.ExtAuthnDuo.Valid { - user.ExtAuthnDuo = row.ExtAuthnDuo.Bool - } if row.LastSuccessLogin.Valid { user.LastSuccessLogin = row.LastSuccessLogin.Time } @@ -147,12 +141,6 @@ func (row userDBRow) convert() *User { if row.LockedUntilTime.Valid { user.LockedUntilTime = row.LockedUntilTime.Time } - if row.HasPassword.Valid { - user.HasPassword = row.HasPassword.Bool - } - if row.HasRsaPublicKey.Valid { - user.HasRsaPublicKey = row.HasRsaPublicKey.Bool - } return user }