@@ -13,7 +13,11 @@ type Matcher struct {
1313 // url: "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full"
1414 // or
1515 // string: "user=pqgotest dbname=pqgotest sslmode=verify-full"
16+ //
17+ // Deprecated: Use the ".database" member instead.
1618 ConnString string `yaml:"connstring" json:"connstring"`
19+ // Database is the database configuration.
20+ Database * Database `yaml:"database,omitempty" json:"database,omitempty"`
1721 // A string in <host>:<port> format where <host> can be an empty string.
1822 //
1923 // A Matcher contacts an Indexer to create a VulnerabilityReport.
@@ -36,7 +40,7 @@ type Matcher struct {
3640 // Clair allows for a custom connection pool size. This number will
3741 // directly set how many active sql connections are allowed concurrently.
3842 //
39- // Deprecated: Pool size should be set through the ConnString member .
43+ // Deprecated: Pool size should be set through the database configuration .
4044 // Currently, Clair only uses the "pgxpool" package to connect to the
4145 // database, so see
4246 // https://pkg.go.dev/github.com/jackc/pgx/v4/pgxpool#ParseConfig for more
@@ -51,15 +55,17 @@ type Matcher struct {
5155 // A "true" or "false" value
5256 //
5357 // Whether Matcher nodes handle migrations to their databases.
54- Migrations bool `yaml:"migrations,omitempty" json:"migrations,omitempty"`
58+ //
59+ // Deprecated: Use the ".database.migrations" member instead.
60+ Migrations * bool `yaml:"migrations,omitempty" json:"migrations,omitempty"`
5561 // DisableUpdaters disables the updater's running of matchers.
5662 //
5763 // This should be toggled on if vulnerabilities are being provided by
5864 // another mechanism.
5965 DisableUpdaters bool `yaml:"disable_updaters,omitempty" json:"disable_updaters,omitempty"`
6066}
6167
62- func (m * Matcher ) validate (mode Mode ) ([]Warning , error ) {
68+ func (m * Matcher ) validate (mode Mode ) (ws []Warning , err error ) {
6369 if mode != ComboMode && mode != MatcherMode {
6470 return nil , nil
6571 }
@@ -90,16 +96,30 @@ func (m *Matcher) validate(mode Mode) ([]Warning, error) {
9096 default :
9197 panic ("programmer error" )
9298 }
93- return m .lint ()
99+ if m .ConnString != "" {
100+ ws = append (ws , errConnString )
101+ m .ConnString = ""
102+ if d := m .Database ; d != nil {
103+ d .Name = `postgresql`
104+ d .PostgreSQL = & DatabasePostgreSQL {
105+ DSN : m .ConnString ,
106+ }
107+ d .Migrations = m .Migrations
108+ }
109+ }
110+ lws , err := m .lint ()
111+ return append (ws , lws ... ), err
94112}
95113
96114func (m * Matcher ) lint () (ws []Warning , err error ) {
97- ws , err = checkDSN (m .ConnString )
98- if err != nil {
99- return ws , err
115+ if m .ConnString != "" {
116+ ws = append (ws , errConnString )
100117 }
101- for i := range ws {
102- ws [i ].path = ".connstring"
118+ if m .Database == nil {
119+ ws = append (ws , Warning {
120+ path : ".database" ,
121+ msg : `missing database configuration` ,
122+ })
103123 }
104124
105125 if m .Period < Duration (DefaultMatcherPeriod ) {
0 commit comments