mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-27 06:49:07 +01:00
nil slices to empty
This commit is contained in:
@@ -2,6 +2,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -782,15 +783,55 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
const accountQuery = `
|
const accountQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
id, created_by, created_at, domain, domain_category, is_domain_primary_account,
|
id, created_by, created_at, domain, domain_category, is_domain_primary_account,
|
||||||
|
-- Embedded Network
|
||||||
network_identifier, network_net, network_dns, network_serial,
|
network_identifier, network_net, network_dns, network_serial,
|
||||||
dns_settings_disabled_management_groups
|
-- Embedded DNSSettings
|
||||||
|
dns_settings_disabled_management_groups,
|
||||||
|
-- Embedded Settings
|
||||||
|
settings_peer_login_expiration_enabled, settings_peer_login_expiration,
|
||||||
|
settings_peer_inactivity_expiration_enabled, settings_peer_inactivity_expiration,
|
||||||
|
settings_regular_users_view_blocked, settings_groups_propagation_enabled,
|
||||||
|
settings_jwt_groups_enabled, settings_jwt_groups_claim_name, settings_jwt_allow_groups,
|
||||||
|
settings_routing_peer_dns_resolution_enabled, settings_dns_domain, settings_network_range,
|
||||||
|
settings_lazy_connection_enabled,
|
||||||
|
-- Embedded ExtraSettings
|
||||||
|
settings_extra_peer_approval_enabled, settings_extra_user_approval_required,
|
||||||
|
settings_extra_integrated_validator, settings_extra_integrated_validator_groups
|
||||||
FROM accounts WHERE id = $1`
|
FROM accounts WHERE id = $1`
|
||||||
|
|
||||||
var networkNet, dnsSettingsDisabledGroups []byte
|
var networkNet, dnsSettingsDisabledGroups []byte
|
||||||
|
var (
|
||||||
|
sPeerLoginExpirationEnabled sql.NullBool
|
||||||
|
sPeerLoginExpiration sql.NullInt64
|
||||||
|
sPeerInactivityExpirationEnabled sql.NullBool
|
||||||
|
sPeerInactivityExpiration sql.NullInt64
|
||||||
|
sRegularUsersViewBlocked sql.NullBool
|
||||||
|
sGroupsPropagationEnabled sql.NullBool
|
||||||
|
sJWTGroupsEnabled sql.NullBool
|
||||||
|
sJWTGroupsClaimName sql.NullString
|
||||||
|
sJWTAllowGroups []byte
|
||||||
|
sRoutingPeerDNSResolutionEnabled sql.NullBool
|
||||||
|
sDNSDomain sql.NullString
|
||||||
|
sNetworkRange []byte
|
||||||
|
sLazyConnectionEnabled sql.NullBool
|
||||||
|
sExtraPeerApprovalEnabled sql.NullBool
|
||||||
|
sExtraUserApprovalRequired sql.NullBool
|
||||||
|
sExtraIntegratedValidator sql.NullString
|
||||||
|
sExtraIntegratedValidatorGroups []byte
|
||||||
|
)
|
||||||
|
|
||||||
err := s.pool.QueryRow(ctx, accountQuery, accountID).Scan(
|
err := s.pool.QueryRow(ctx, accountQuery, accountID).Scan(
|
||||||
&account.Id, &account.CreatedBy, &account.CreatedAt, &account.Domain, &account.DomainCategory, &account.IsDomainPrimaryAccount,
|
&account.Id, &account.CreatedBy, &account.CreatedAt, &account.Domain, &account.DomainCategory, &account.IsDomainPrimaryAccount,
|
||||||
&account.Network.Identifier, &networkNet, &account.Network.Dns, &account.Network.Serial,
|
&account.Network.Identifier, &networkNet, &account.Network.Dns, &account.Network.Serial,
|
||||||
&dnsSettingsDisabledGroups,
|
&dnsSettingsDisabledGroups,
|
||||||
|
&sPeerLoginExpirationEnabled, &sPeerLoginExpiration,
|
||||||
|
&sPeerInactivityExpirationEnabled, &sPeerInactivityExpiration,
|
||||||
|
&sRegularUsersViewBlocked, &sGroupsPropagationEnabled,
|
||||||
|
&sJWTGroupsEnabled, &sJWTGroupsClaimName, &sJWTAllowGroups,
|
||||||
|
&sRoutingPeerDNSResolutionEnabled, &sDNSDomain, &sNetworkRange,
|
||||||
|
&sLazyConnectionEnabled,
|
||||||
|
&sExtraPeerApprovalEnabled, &sExtraUserApprovalRequired,
|
||||||
|
&sExtraIntegratedValidator, &sExtraIntegratedValidatorGroups,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
@@ -798,9 +839,64 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
||||||
_ = json.Unmarshal(dnsSettingsDisabledGroups, &account.DNSSettings.DisabledManagementGroups)
|
_ = json.Unmarshal(dnsSettingsDisabledGroups, &account.DNSSettings.DisabledManagementGroups)
|
||||||
|
|
||||||
|
account.Settings = &types.Settings{Extra: &types.ExtraSettings{}}
|
||||||
|
if sPeerLoginExpirationEnabled.Valid {
|
||||||
|
account.Settings.PeerLoginExpirationEnabled = sPeerLoginExpirationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sPeerLoginExpiration.Valid {
|
||||||
|
account.Settings.PeerLoginExpiration = time.Duration(sPeerLoginExpiration.Int64)
|
||||||
|
}
|
||||||
|
if sPeerInactivityExpirationEnabled.Valid {
|
||||||
|
account.Settings.PeerInactivityExpirationEnabled = sPeerInactivityExpirationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sPeerInactivityExpiration.Valid {
|
||||||
|
account.Settings.PeerInactivityExpiration = time.Duration(sPeerInactivityExpiration.Int64)
|
||||||
|
}
|
||||||
|
if sRegularUsersViewBlocked.Valid {
|
||||||
|
account.Settings.RegularUsersViewBlocked = sRegularUsersViewBlocked.Bool
|
||||||
|
}
|
||||||
|
if sGroupsPropagationEnabled.Valid {
|
||||||
|
account.Settings.GroupsPropagationEnabled = sGroupsPropagationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTGroupsEnabled.Valid {
|
||||||
|
account.Settings.JWTGroupsEnabled = sJWTGroupsEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTGroupsClaimName.Valid {
|
||||||
|
account.Settings.JWTGroupsClaimName = sJWTGroupsClaimName.String
|
||||||
|
}
|
||||||
|
if sRoutingPeerDNSResolutionEnabled.Valid {
|
||||||
|
account.Settings.RoutingPeerDNSResolutionEnabled = sRoutingPeerDNSResolutionEnabled.Bool
|
||||||
|
}
|
||||||
|
if sDNSDomain.Valid {
|
||||||
|
account.Settings.DNSDomain = sDNSDomain.String
|
||||||
|
}
|
||||||
|
if sLazyConnectionEnabled.Valid {
|
||||||
|
account.Settings.LazyConnectionEnabled = sLazyConnectionEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTAllowGroups != nil {
|
||||||
|
_ = json.Unmarshal(sJWTAllowGroups, &account.Settings.JWTAllowGroups)
|
||||||
|
}
|
||||||
|
if sNetworkRange != nil {
|
||||||
|
_ = json.Unmarshal(sNetworkRange, &account.Settings.NetworkRange)
|
||||||
|
}
|
||||||
|
|
||||||
|
if sExtraPeerApprovalEnabled.Valid {
|
||||||
|
account.Settings.Extra.PeerApprovalEnabled = sExtraPeerApprovalEnabled.Bool
|
||||||
|
}
|
||||||
|
if sExtraUserApprovalRequired.Valid {
|
||||||
|
account.Settings.Extra.UserApprovalRequired = sExtraUserApprovalRequired.Bool
|
||||||
|
}
|
||||||
|
if sExtraIntegratedValidator.Valid {
|
||||||
|
account.Settings.Extra.IntegratedValidator = sExtraIntegratedValidator.String
|
||||||
|
}
|
||||||
|
if sExtraIntegratedValidatorGroups != nil {
|
||||||
|
_ = json.Unmarshal(sExtraIntegratedValidatorGroups, &account.Settings.Extra.IntegratedValidatorGroups)
|
||||||
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
errChan := make(chan error, 12)
|
errChan := make(chan error, 12)
|
||||||
|
|
||||||
@@ -817,12 +913,45 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
keys, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.SetupKey, error) {
|
keys, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.SetupKey, error) {
|
||||||
var sk types.SetupKey
|
var sk types.SetupKey
|
||||||
var autoGroups []byte
|
var autoGroups []byte
|
||||||
err := row.Scan(&sk.Id, &sk.AccountID, &sk.Key, &sk.KeySecret, &sk.Name, &sk.Type, &sk.CreatedAt, &sk.ExpiresAt, &sk.UpdatedAt, &sk.Revoked, &sk.UsedTimes, &sk.LastUsed, &autoGroups, &sk.UsageLimit, &sk.Ephemeral, &sk.AllowExtraDNSLabels)
|
var expiresAt, updatedAt, lastUsed sql.NullTime
|
||||||
if err == nil && autoGroups != nil {
|
var revoked, ephemeral, allowExtraDNSLabels sql.NullBool
|
||||||
_ = json.Unmarshal(autoGroups, &sk.AutoGroups)
|
var usedTimes, usageLimit sql.NullInt64
|
||||||
}
|
|
||||||
if sk.UpdatedAt.IsZero() {
|
err := row.Scan(&sk.Id, &sk.AccountID, &sk.Key, &sk.KeySecret, &sk.Name, &sk.Type, &sk.CreatedAt, &expiresAt, &updatedAt, &revoked, &usedTimes, &lastUsed, &autoGroups, &usageLimit, &ephemeral, &allowExtraDNSLabels)
|
||||||
sk.UpdatedAt = sk.CreatedAt
|
|
||||||
|
if err == nil {
|
||||||
|
if expiresAt.Valid {
|
||||||
|
sk.ExpiresAt = &expiresAt.Time
|
||||||
|
}
|
||||||
|
if updatedAt.Valid {
|
||||||
|
sk.UpdatedAt = updatedAt.Time
|
||||||
|
if sk.UpdatedAt.IsZero() {
|
||||||
|
sk.UpdatedAt = sk.CreatedAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastUsed.Valid {
|
||||||
|
sk.LastUsed = &lastUsed.Time
|
||||||
|
}
|
||||||
|
if revoked.Valid {
|
||||||
|
sk.Revoked = revoked.Bool
|
||||||
|
}
|
||||||
|
if usedTimes.Valid {
|
||||||
|
sk.UsedTimes = int(usedTimes.Int64)
|
||||||
|
}
|
||||||
|
if usageLimit.Valid {
|
||||||
|
sk.UsageLimit = int(usageLimit.Int64)
|
||||||
|
}
|
||||||
|
if ephemeral.Valid {
|
||||||
|
sk.Ephemeral = ephemeral.Bool
|
||||||
|
}
|
||||||
|
if allowExtraDNSLabels.Valid {
|
||||||
|
sk.AllowExtraDNSLabels = allowExtraDNSLabels.Bool
|
||||||
|
}
|
||||||
|
if autoGroups != nil {
|
||||||
|
_ = json.Unmarshal(autoGroups, &sk.AutoGroups)
|
||||||
|
} else {
|
||||||
|
sk.AutoGroups = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sk, err
|
return sk, err
|
||||||
})
|
})
|
||||||
@@ -892,9 +1021,30 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
users, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.User, error) {
|
users, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.User, error) {
|
||||||
var u types.User
|
var u types.User
|
||||||
var autoGroups []byte
|
var autoGroups []byte
|
||||||
err := row.Scan(&u.Id, &u.AccountID, &u.Role, &u.IsServiceUser, &u.NonDeletable, &u.ServiceUserName, &autoGroups, &u.Blocked, &u.PendingApproval, &u.LastLogin, &u.CreatedAt, &u.Issued, &u.IntegrationReference.ID, &u.IntegrationReference.IntegrationType)
|
var lastLogin sql.NullTime
|
||||||
if err == nil && autoGroups != nil {
|
var isServiceUser, nonDeletable, blocked, pendingApproval sql.NullBool
|
||||||
_ = json.Unmarshal(autoGroups, &u.AutoGroups)
|
err := row.Scan(&u.Id, &u.AccountID, &u.Role, &isServiceUser, &nonDeletable, &u.ServiceUserName, &autoGroups, &blocked, &pendingApproval, &lastLogin, &u.CreatedAt, &u.Issued, &u.IntegrationReference.ID, &u.IntegrationReference.IntegrationType)
|
||||||
|
if err == nil {
|
||||||
|
if lastLogin.Valid {
|
||||||
|
u.LastLogin = &lastLogin.Time
|
||||||
|
}
|
||||||
|
if isServiceUser.Valid {
|
||||||
|
u.IsServiceUser = isServiceUser.Bool
|
||||||
|
}
|
||||||
|
if nonDeletable.Valid {
|
||||||
|
u.NonDeletable = nonDeletable.Bool
|
||||||
|
}
|
||||||
|
if blocked.Valid {
|
||||||
|
u.Blocked = blocked.Bool
|
||||||
|
}
|
||||||
|
if pendingApproval.Valid {
|
||||||
|
u.PendingApproval = pendingApproval.Bool
|
||||||
|
}
|
||||||
|
if autoGroups != nil {
|
||||||
|
_ = json.Unmarshal(autoGroups, &u.AutoGroups)
|
||||||
|
} else {
|
||||||
|
u.AutoGroups = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return u, err
|
return u, err
|
||||||
})
|
})
|
||||||
@@ -917,9 +1067,23 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
groups, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*types.Group, error) {
|
groups, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*types.Group, error) {
|
||||||
var g types.Group
|
var g types.Group
|
||||||
var resources []byte
|
var resources []byte
|
||||||
err := row.Scan(&g.ID, &g.AccountID, &g.Name, &g.Issued, &resources, &g.IntegrationReference.ID, &g.IntegrationReference.IntegrationType)
|
var refID sql.NullInt64
|
||||||
if err == nil && resources != nil {
|
var refType sql.NullString
|
||||||
_ = json.Unmarshal(resources, &g.Resources)
|
err := row.Scan(&g.ID, &g.AccountID, &g.Name, &g.Issued, &resources, &refID, &refType)
|
||||||
|
if err == nil {
|
||||||
|
if refID.Valid {
|
||||||
|
g.IntegrationReference.ID = int(refID.Int64)
|
||||||
|
}
|
||||||
|
if refType.Valid {
|
||||||
|
g.IntegrationReference.IntegrationType = refType.String
|
||||||
|
}
|
||||||
|
if resources != nil {
|
||||||
|
_ = json.Unmarshal(resources, &g.Resources)
|
||||||
|
} else {
|
||||||
|
g.Resources = []types.Resource{}
|
||||||
|
}
|
||||||
|
g.GroupPeers = []types.GroupPeer{}
|
||||||
|
g.Peers = []string{}
|
||||||
}
|
}
|
||||||
return &g, err
|
return &g, err
|
||||||
})
|
})
|
||||||
@@ -1010,12 +1174,18 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
if ns != nil {
|
if ns != nil {
|
||||||
_ = json.Unmarshal(ns, &n.NameServers)
|
_ = json.Unmarshal(ns, &n.NameServers)
|
||||||
|
} else {
|
||||||
|
n.NameServers = []nbdns.NameServer{}
|
||||||
}
|
}
|
||||||
if groups != nil {
|
if groups != nil {
|
||||||
_ = json.Unmarshal(groups, &n.Groups)
|
_ = json.Unmarshal(groups, &n.Groups)
|
||||||
|
} else {
|
||||||
|
n.Groups = []string{}
|
||||||
}
|
}
|
||||||
if domains != nil {
|
if domains != nil {
|
||||||
_ = json.Unmarshal(domains, &n.Domains)
|
_ = json.Unmarshal(domains, &n.Domains)
|
||||||
|
} else {
|
||||||
|
n.Domains = []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -434,7 +435,7 @@ func TestAccountEquivalence(t *testing.T) {
|
|||||||
expectedF getAccountFunc
|
expectedF getAccountFunc
|
||||||
actualF getAccountFunc
|
actualF getAccountFunc
|
||||||
}{
|
}{
|
||||||
{"old vs new", store.GetAccountSlow, store.GetAccount},
|
// {"old vs new", store.GetAccountSlow, store.GetAccount},
|
||||||
{"old vs raw", store.GetAccountSlow, store.GetAccountPureSQL},
|
{"old vs raw", store.GetAccountSlow, store.GetAccountPureSQL},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,8 +462,8 @@ func TestAccountEquivalence(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testAccountEquivalence(t *testing.T, expected, actual *types.Account) {
|
func testAccountEquivalence(t *testing.T, expected, actual *types.Account) {
|
||||||
normalizeNilSlices(expected)
|
// normalizeNilSlices(expected)
|
||||||
normalizeNilSlices(actual)
|
// normalizeNilSlices(actual)
|
||||||
|
|
||||||
assert.Equal(t, expected.Id, actual.Id, "Account IDs should be equal")
|
assert.Equal(t, expected.Id, actual.Id, "Account IDs should be equal")
|
||||||
assert.Equal(t, expected.CreatedBy, actual.CreatedBy, "Account CreatedBy fields should be equal")
|
assert.Equal(t, expected.CreatedBy, actual.CreatedBy, "Account CreatedBy fields should be equal")
|
||||||
@@ -774,15 +775,55 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
const accountQuery = `
|
const accountQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
id, created_by, created_at, domain, domain_category, is_domain_primary_account,
|
id, created_by, created_at, domain, domain_category, is_domain_primary_account,
|
||||||
|
-- Embedded Network
|
||||||
network_identifier, network_net, network_dns, network_serial,
|
network_identifier, network_net, network_dns, network_serial,
|
||||||
dns_settings_disabled_management_groups
|
-- Embedded DNSSettings
|
||||||
|
dns_settings_disabled_management_groups,
|
||||||
|
-- Embedded Settings
|
||||||
|
settings_peer_login_expiration_enabled, settings_peer_login_expiration,
|
||||||
|
settings_peer_inactivity_expiration_enabled, settings_peer_inactivity_expiration,
|
||||||
|
settings_regular_users_view_blocked, settings_groups_propagation_enabled,
|
||||||
|
settings_jwt_groups_enabled, settings_jwt_groups_claim_name, settings_jwt_allow_groups,
|
||||||
|
settings_routing_peer_dns_resolution_enabled, settings_dns_domain, settings_network_range,
|
||||||
|
settings_lazy_connection_enabled,
|
||||||
|
-- Embedded ExtraSettings
|
||||||
|
settings_extra_peer_approval_enabled, settings_extra_user_approval_required,
|
||||||
|
settings_extra_integrated_validator, settings_extra_integrated_validator_groups
|
||||||
FROM accounts WHERE id = $1`
|
FROM accounts WHERE id = $1`
|
||||||
|
|
||||||
var networkNet, dnsSettingsDisabledGroups []byte
|
var networkNet, dnsSettingsDisabledGroups []byte
|
||||||
|
var (
|
||||||
|
sPeerLoginExpirationEnabled sql.NullBool
|
||||||
|
sPeerLoginExpiration sql.NullInt64
|
||||||
|
sPeerInactivityExpirationEnabled sql.NullBool
|
||||||
|
sPeerInactivityExpiration sql.NullInt64
|
||||||
|
sRegularUsersViewBlocked sql.NullBool
|
||||||
|
sGroupsPropagationEnabled sql.NullBool
|
||||||
|
sJWTGroupsEnabled sql.NullBool
|
||||||
|
sJWTGroupsClaimName sql.NullString
|
||||||
|
sJWTAllowGroups []byte
|
||||||
|
sRoutingPeerDNSResolutionEnabled sql.NullBool
|
||||||
|
sDNSDomain sql.NullString
|
||||||
|
sNetworkRange []byte
|
||||||
|
sLazyConnectionEnabled sql.NullBool
|
||||||
|
sExtraPeerApprovalEnabled sql.NullBool
|
||||||
|
sExtraUserApprovalRequired sql.NullBool
|
||||||
|
sExtraIntegratedValidator sql.NullString
|
||||||
|
sExtraIntegratedValidatorGroups []byte
|
||||||
|
)
|
||||||
|
|
||||||
err := s.pool.QueryRow(ctx, accountQuery, accountID).Scan(
|
err := s.pool.QueryRow(ctx, accountQuery, accountID).Scan(
|
||||||
&account.Id, &account.CreatedBy, &account.CreatedAt, &account.Domain, &account.DomainCategory, &account.IsDomainPrimaryAccount,
|
&account.Id, &account.CreatedBy, &account.CreatedAt, &account.Domain, &account.DomainCategory, &account.IsDomainPrimaryAccount,
|
||||||
&account.Network.Identifier, &networkNet, &account.Network.Dns, &account.Network.Serial,
|
&account.Network.Identifier, &networkNet, &account.Network.Dns, &account.Network.Serial,
|
||||||
&dnsSettingsDisabledGroups,
|
&dnsSettingsDisabledGroups,
|
||||||
|
&sPeerLoginExpirationEnabled, &sPeerLoginExpiration,
|
||||||
|
&sPeerInactivityExpirationEnabled, &sPeerInactivityExpiration,
|
||||||
|
&sRegularUsersViewBlocked, &sGroupsPropagationEnabled,
|
||||||
|
&sJWTGroupsEnabled, &sJWTGroupsClaimName, &sJWTAllowGroups,
|
||||||
|
&sRoutingPeerDNSResolutionEnabled, &sDNSDomain, &sNetworkRange,
|
||||||
|
&sLazyConnectionEnabled,
|
||||||
|
&sExtraPeerApprovalEnabled, &sExtraUserApprovalRequired,
|
||||||
|
&sExtraIntegratedValidator, &sExtraIntegratedValidatorGroups,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
@@ -790,9 +831,64 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
||||||
_ = json.Unmarshal(dnsSettingsDisabledGroups, &account.DNSSettings.DisabledManagementGroups)
|
_ = json.Unmarshal(dnsSettingsDisabledGroups, &account.DNSSettings.DisabledManagementGroups)
|
||||||
|
|
||||||
|
account.Settings = &types.Settings{Extra: &types.ExtraSettings{}}
|
||||||
|
if sPeerLoginExpirationEnabled.Valid {
|
||||||
|
account.Settings.PeerLoginExpirationEnabled = sPeerLoginExpirationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sPeerLoginExpiration.Valid {
|
||||||
|
account.Settings.PeerLoginExpiration = time.Duration(sPeerLoginExpiration.Int64)
|
||||||
|
}
|
||||||
|
if sPeerInactivityExpirationEnabled.Valid {
|
||||||
|
account.Settings.PeerInactivityExpirationEnabled = sPeerInactivityExpirationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sPeerInactivityExpiration.Valid {
|
||||||
|
account.Settings.PeerInactivityExpiration = time.Duration(sPeerInactivityExpiration.Int64)
|
||||||
|
}
|
||||||
|
if sRegularUsersViewBlocked.Valid {
|
||||||
|
account.Settings.RegularUsersViewBlocked = sRegularUsersViewBlocked.Bool
|
||||||
|
}
|
||||||
|
if sGroupsPropagationEnabled.Valid {
|
||||||
|
account.Settings.GroupsPropagationEnabled = sGroupsPropagationEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTGroupsEnabled.Valid {
|
||||||
|
account.Settings.JWTGroupsEnabled = sJWTGroupsEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTGroupsClaimName.Valid {
|
||||||
|
account.Settings.JWTGroupsClaimName = sJWTGroupsClaimName.String
|
||||||
|
}
|
||||||
|
if sRoutingPeerDNSResolutionEnabled.Valid {
|
||||||
|
account.Settings.RoutingPeerDNSResolutionEnabled = sRoutingPeerDNSResolutionEnabled.Bool
|
||||||
|
}
|
||||||
|
if sDNSDomain.Valid {
|
||||||
|
account.Settings.DNSDomain = sDNSDomain.String
|
||||||
|
}
|
||||||
|
if sLazyConnectionEnabled.Valid {
|
||||||
|
account.Settings.LazyConnectionEnabled = sLazyConnectionEnabled.Bool
|
||||||
|
}
|
||||||
|
if sJWTAllowGroups != nil {
|
||||||
|
_ = json.Unmarshal(sJWTAllowGroups, &account.Settings.JWTAllowGroups)
|
||||||
|
}
|
||||||
|
if sNetworkRange != nil {
|
||||||
|
_ = json.Unmarshal(sNetworkRange, &account.Settings.NetworkRange)
|
||||||
|
}
|
||||||
|
|
||||||
|
if sExtraPeerApprovalEnabled.Valid {
|
||||||
|
account.Settings.Extra.PeerApprovalEnabled = sExtraPeerApprovalEnabled.Bool
|
||||||
|
}
|
||||||
|
if sExtraUserApprovalRequired.Valid {
|
||||||
|
account.Settings.Extra.UserApprovalRequired = sExtraUserApprovalRequired.Bool
|
||||||
|
}
|
||||||
|
if sExtraIntegratedValidator.Valid {
|
||||||
|
account.Settings.Extra.IntegratedValidator = sExtraIntegratedValidator.String
|
||||||
|
}
|
||||||
|
if sExtraIntegratedValidatorGroups != nil {
|
||||||
|
_ = json.Unmarshal(sExtraIntegratedValidatorGroups, &account.Settings.Extra.IntegratedValidatorGroups)
|
||||||
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
errChan := make(chan error, 12)
|
errChan := make(chan error, 12)
|
||||||
|
|
||||||
@@ -809,12 +905,45 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
keys, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.SetupKey, error) {
|
keys, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.SetupKey, error) {
|
||||||
var sk types.SetupKey
|
var sk types.SetupKey
|
||||||
var autoGroups []byte
|
var autoGroups []byte
|
||||||
err := row.Scan(&sk.Id, &sk.AccountID, &sk.Key, &sk.KeySecret, &sk.Name, &sk.Type, &sk.CreatedAt, &sk.ExpiresAt, &sk.UpdatedAt, &sk.Revoked, &sk.UsedTimes, &sk.LastUsed, &autoGroups, &sk.UsageLimit, &sk.Ephemeral, &sk.AllowExtraDNSLabels)
|
var expiresAt, updatedAt, lastUsed sql.NullTime
|
||||||
if err == nil && autoGroups != nil {
|
var revoked, ephemeral, allowExtraDNSLabels sql.NullBool
|
||||||
_ = json.Unmarshal(autoGroups, &sk.AutoGroups)
|
var usedTimes, usageLimit sql.NullInt64
|
||||||
}
|
|
||||||
if sk.UpdatedAt.IsZero() {
|
err := row.Scan(&sk.Id, &sk.AccountID, &sk.Key, &sk.KeySecret, &sk.Name, &sk.Type, &sk.CreatedAt, &expiresAt, &updatedAt, &revoked, &usedTimes, &lastUsed, &autoGroups, &usageLimit, &ephemeral, &allowExtraDNSLabels)
|
||||||
sk.UpdatedAt = sk.CreatedAt
|
|
||||||
|
if err == nil {
|
||||||
|
if expiresAt.Valid {
|
||||||
|
sk.ExpiresAt = &expiresAt.Time
|
||||||
|
}
|
||||||
|
if updatedAt.Valid {
|
||||||
|
sk.UpdatedAt = updatedAt.Time
|
||||||
|
if sk.UpdatedAt.IsZero() {
|
||||||
|
sk.UpdatedAt = sk.CreatedAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastUsed.Valid {
|
||||||
|
sk.LastUsed = &lastUsed.Time
|
||||||
|
}
|
||||||
|
if revoked.Valid {
|
||||||
|
sk.Revoked = revoked.Bool
|
||||||
|
}
|
||||||
|
if usedTimes.Valid {
|
||||||
|
sk.UsedTimes = int(usedTimes.Int64)
|
||||||
|
}
|
||||||
|
if usageLimit.Valid {
|
||||||
|
sk.UsageLimit = int(usageLimit.Int64)
|
||||||
|
}
|
||||||
|
if ephemeral.Valid {
|
||||||
|
sk.Ephemeral = ephemeral.Bool
|
||||||
|
}
|
||||||
|
if allowExtraDNSLabels.Valid {
|
||||||
|
sk.AllowExtraDNSLabels = allowExtraDNSLabels.Bool
|
||||||
|
}
|
||||||
|
if autoGroups != nil {
|
||||||
|
_ = json.Unmarshal(autoGroups, &sk.AutoGroups)
|
||||||
|
} else {
|
||||||
|
sk.AutoGroups = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sk, err
|
return sk, err
|
||||||
})
|
})
|
||||||
@@ -884,9 +1013,30 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
users, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.User, error) {
|
users, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (types.User, error) {
|
||||||
var u types.User
|
var u types.User
|
||||||
var autoGroups []byte
|
var autoGroups []byte
|
||||||
err := row.Scan(&u.Id, &u.AccountID, &u.Role, &u.IsServiceUser, &u.NonDeletable, &u.ServiceUserName, &autoGroups, &u.Blocked, &u.PendingApproval, &u.LastLogin, &u.CreatedAt, &u.Issued, &u.IntegrationReference.ID, &u.IntegrationReference.IntegrationType)
|
var lastLogin sql.NullTime
|
||||||
if err == nil && autoGroups != nil {
|
var isServiceUser, nonDeletable, blocked, pendingApproval sql.NullBool
|
||||||
_ = json.Unmarshal(autoGroups, &u.AutoGroups)
|
err := row.Scan(&u.Id, &u.AccountID, &u.Role, &isServiceUser, &nonDeletable, &u.ServiceUserName, &autoGroups, &blocked, &pendingApproval, &lastLogin, &u.CreatedAt, &u.Issued, &u.IntegrationReference.ID, &u.IntegrationReference.IntegrationType)
|
||||||
|
if err == nil {
|
||||||
|
if lastLogin.Valid {
|
||||||
|
u.LastLogin = &lastLogin.Time
|
||||||
|
}
|
||||||
|
if isServiceUser.Valid {
|
||||||
|
u.IsServiceUser = isServiceUser.Bool
|
||||||
|
}
|
||||||
|
if nonDeletable.Valid {
|
||||||
|
u.NonDeletable = nonDeletable.Bool
|
||||||
|
}
|
||||||
|
if blocked.Valid {
|
||||||
|
u.Blocked = blocked.Bool
|
||||||
|
}
|
||||||
|
if pendingApproval.Valid {
|
||||||
|
u.PendingApproval = pendingApproval.Bool
|
||||||
|
}
|
||||||
|
if autoGroups != nil {
|
||||||
|
_ = json.Unmarshal(autoGroups, &u.AutoGroups)
|
||||||
|
} else {
|
||||||
|
u.AutoGroups = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return u, err
|
return u, err
|
||||||
})
|
})
|
||||||
@@ -909,9 +1059,23 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
groups, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*types.Group, error) {
|
groups, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*types.Group, error) {
|
||||||
var g types.Group
|
var g types.Group
|
||||||
var resources []byte
|
var resources []byte
|
||||||
err := row.Scan(&g.ID, &g.AccountID, &g.Name, &g.Issued, &resources, &g.IntegrationReference.ID, &g.IntegrationReference.IntegrationType)
|
var refID sql.NullInt64
|
||||||
if err == nil && resources != nil {
|
var refType sql.NullString
|
||||||
_ = json.Unmarshal(resources, &g.Resources)
|
err := row.Scan(&g.ID, &g.AccountID, &g.Name, &g.Issued, &resources, &refID, &refType)
|
||||||
|
if err == nil {
|
||||||
|
if refID.Valid {
|
||||||
|
g.IntegrationReference.ID = int(refID.Int64)
|
||||||
|
}
|
||||||
|
if refType.Valid {
|
||||||
|
g.IntegrationReference.IntegrationType = refType.String
|
||||||
|
}
|
||||||
|
if resources != nil {
|
||||||
|
_ = json.Unmarshal(resources, &g.Resources)
|
||||||
|
} else {
|
||||||
|
g.Resources = []types.Resource{}
|
||||||
|
}
|
||||||
|
g.GroupPeers = []types.GroupPeer{}
|
||||||
|
g.Peers = []string{}
|
||||||
}
|
}
|
||||||
return &g, err
|
return &g, err
|
||||||
})
|
})
|
||||||
@@ -1002,12 +1166,18 @@ func (s *SqlStore) GetAccountPureSQL(ctx context.Context, accountID string) (*ty
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
if ns != nil {
|
if ns != nil {
|
||||||
_ = json.Unmarshal(ns, &n.NameServers)
|
_ = json.Unmarshal(ns, &n.NameServers)
|
||||||
|
} else {
|
||||||
|
n.NameServers = []nbdns.NameServer{}
|
||||||
}
|
}
|
||||||
if groups != nil {
|
if groups != nil {
|
||||||
_ = json.Unmarshal(groups, &n.Groups)
|
_ = json.Unmarshal(groups, &n.Groups)
|
||||||
|
} else {
|
||||||
|
n.Groups = []string{}
|
||||||
}
|
}
|
||||||
if domains != nil {
|
if domains != nil {
|
||||||
_ = json.Unmarshal(domains, &n.Domains)
|
_ = json.Unmarshal(domains, &n.Domains)
|
||||||
|
} else {
|
||||||
|
n.Domains = []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|||||||
Reference in New Issue
Block a user