mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-25 10:40:02 +08:00
* Add periodic import of database objects from supported databases. A single implementation is included: for Postgres, along with necessary changes. Also refactors SQLAdminClient interface to accept cert expiry instead of pulling that information from `tlsca.Identity`. * fix logging, imports * add missing license * review feedback - several minor changes - apply import rules for all registered object fetchers using wrapper type - refactor DAC to use object fetcher - adjust tests * add comment and missing log call * support config overrides through unstable env vars, including disabling the service entirely * refactoring and minor changes - be more specific about required API for ObjectFetcherConfig - measure scan time - bump default scan interval - call StopImporter from stopDatabase to fix issue with dynamic db resource updates - add comments * Refactor `connectAsAdmin`, add `withDefaultDatabase()` method for clarity of implementation. * Reduce surface area for fetcher config * make the not-implemented case less noisy by skipping the error * lint fix * decrease verbosity of reporting for unsupported configurations * make `reason` field private * move `unregisterObjectFetcher` to tests * avoid exceedingly long lines with log calls * correct formatting leftover from slog conversion * tighten logic around disabled importer if the scan interval is zero or less, the importer becomes disabled, which avoids panic from interval.New(). add some tests and comments for clarity. * drop unused method
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
// Teleport
|
|
// Copyright (C) 2024 Gravitational, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package objects
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/gravitational/trace"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestIsErrFetcherDisabled(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
expectedMatch bool
|
|
expectedReason string
|
|
}{
|
|
{
|
|
name: "nil err",
|
|
err: nil,
|
|
expectedMatch: false,
|
|
expectedReason: "",
|
|
},
|
|
{
|
|
name: "err not ErrFetcherDisabled",
|
|
err: errors.New("some other reason"),
|
|
expectedMatch: false,
|
|
expectedReason: "",
|
|
},
|
|
{
|
|
name: "ErrFetcherDisabled with empty reason",
|
|
err: NewErrFetcherDisabled(""),
|
|
expectedMatch: true,
|
|
expectedReason: "",
|
|
},
|
|
{
|
|
name: "ErrFetcherDisabled bare",
|
|
err: NewErrFetcherDisabled("dummy"),
|
|
expectedMatch: true,
|
|
expectedReason: "dummy",
|
|
},
|
|
{
|
|
name: "ErrFetcherDisabled wrapped",
|
|
err: trace.Wrap(NewErrFetcherDisabled("dummy reason")),
|
|
expectedMatch: true,
|
|
expectedReason: "dummy reason",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
match, reason := IsErrFetcherDisabled(tc.err)
|
|
require.Equal(t, tc.expectedMatch, match)
|
|
require.Equal(t, tc.expectedReason, reason)
|
|
})
|
|
}
|
|
}
|