mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	plugins: deprecate errwrap.Wrapf() (#11590)
* plugins/database/redshift: deprecate errwrap.Wrapf() * plugins/database/postgresql: deprecate errwrap.Wrapf() * plugins/database/mysql: deprecate errwrap.Wrapf() * plugins/database/mssql: deprecate errwrap.Wrapf() * plugins/database/mongodb: deprecate errwrap.Wrapf() * plugins/database/influxdb: deprecate errwrap.Wrapf()
This commit is contained in:
		| @@ -7,7 +7,6 @@ import ( | |||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| 	"github.com/hashicorp/vault/sdk/helper/certutil" | 	"github.com/hashicorp/vault/sdk/helper/certutil" | ||||||
| @@ -62,7 +61,7 @@ func (i *influxdbConnectionProducer) Initialize(ctx context.Context, req dbplugi | |||||||
| 	} | 	} | ||||||
| 	i.connectTimeout, err = parseutil.ParseDurationSecond(i.ConnectTimeoutRaw) | 	i.connectTimeout, err = parseutil.ParseDurationSecond(i.ConnectTimeoutRaw) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return dbplugin.InitializeResponse{}, errwrap.Wrapf("invalid connect_timeout: {{err}}", err) | 		return dbplugin.InitializeResponse{}, fmt.Errorf("invalid connect_timeout: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	switch { | 	switch { | ||||||
| @@ -80,11 +79,11 @@ func (i *influxdbConnectionProducer) Initialize(ctx context.Context, req dbplugi | |||||||
| 	case len(i.PemJSON) != 0: | 	case len(i.PemJSON) != 0: | ||||||
| 		parsedCertBundle, err = certutil.ParsePKIJSON([]byte(i.PemJSON)) | 		parsedCertBundle, err = certutil.ParsePKIJSON([]byte(i.PemJSON)) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return dbplugin.InitializeResponse{}, errwrap.Wrapf("could not parse given JSON; it must be in the format of the output of the PKI backend certificate issuing command: {{err}}", err) | 			return dbplugin.InitializeResponse{}, fmt.Errorf("could not parse given JSON; it must be in the format of the output of the PKI backend certificate issuing command: %w", err) | ||||||
| 		} | 		} | ||||||
| 		certBundle, err = parsedCertBundle.ToCertBundle() | 		certBundle, err = parsedCertBundle.ToCertBundle() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return dbplugin.InitializeResponse{}, errwrap.Wrapf("Error marshaling PEM information: {{err}}", err) | 			return dbplugin.InitializeResponse{}, fmt.Errorf("Error marshaling PEM information: %w", err) | ||||||
| 		} | 		} | ||||||
| 		i.certificate = certBundle.Certificate | 		i.certificate = certBundle.Certificate | ||||||
| 		i.privateKey = certBundle.PrivateKey | 		i.privateKey = certBundle.PrivateKey | ||||||
| @@ -94,11 +93,11 @@ func (i *influxdbConnectionProducer) Initialize(ctx context.Context, req dbplugi | |||||||
| 	case len(i.PemBundle) != 0: | 	case len(i.PemBundle) != 0: | ||||||
| 		parsedCertBundle, err = certutil.ParsePEMBundle(i.PemBundle) | 		parsedCertBundle, err = certutil.ParsePEMBundle(i.PemBundle) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return dbplugin.InitializeResponse{}, errwrap.Wrapf("Error parsing the given PEM information: {{err}}", err) | 			return dbplugin.InitializeResponse{}, fmt.Errorf("Error parsing the given PEM information: %w", err) | ||||||
| 		} | 		} | ||||||
| 		certBundle, err = parsedCertBundle.ToCertBundle() | 		certBundle, err = parsedCertBundle.ToCertBundle() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return dbplugin.InitializeResponse{}, errwrap.Wrapf("Error marshaling PEM information: {{err}}", err) | 			return dbplugin.InitializeResponse{}, fmt.Errorf("Error marshaling PEM information: %w", err) | ||||||
| 		} | 		} | ||||||
| 		i.certificate = certBundle.Certificate | 		i.certificate = certBundle.Certificate | ||||||
| 		i.privateKey = certBundle.PrivateKey | 		i.privateKey = certBundle.PrivateKey | ||||||
| @@ -112,7 +111,7 @@ func (i *influxdbConnectionProducer) Initialize(ctx context.Context, req dbplugi | |||||||
|  |  | ||||||
| 	if req.VerifyConnection { | 	if req.VerifyConnection { | ||||||
| 		if _, err := i.Connection(ctx); err != nil { | 		if _, err := i.Connection(ctx); err != nil { | ||||||
| 			return dbplugin.InitializeResponse{}, errwrap.Wrapf("error verifying connection: {{err}}", err) | 			return dbplugin.InitializeResponse{}, fmt.Errorf("error verifying connection: %w", err) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -185,12 +184,12 @@ func (i *influxdbConnectionProducer) createClient() (influx.Client, error) { | |||||||
|  |  | ||||||
| 			parsedCertBundle, err := certBundle.ToParsedCertBundle() | 			parsedCertBundle, err := certBundle.ToParsedCertBundle() | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, errwrap.Wrapf("failed to parse certificate bundle: {{err}}", err) | 				return nil, fmt.Errorf("failed to parse certificate bundle: %w", err) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			tlsConfig, err = parsedCertBundle.GetTLSConfig(certutil.TLSClient) | 			tlsConfig, err = parsedCertBundle.GetTLSConfig(certutil.TLSClient) | ||||||
| 			if err != nil || tlsConfig == nil { | 			if err != nil || tlsConfig == nil { | ||||||
| 				return nil, errwrap.Wrapf(fmt.Sprintf("failed to get TLS configuration: tlsConfig:%#v err:{{err}}", tlsConfig), err) | 				return nil, fmt.Errorf("failed to get TLS configuration: tlsConfig:%#v err:%w", tlsConfig, err) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -214,19 +213,19 @@ func (i *influxdbConnectionProducer) createClient() (influx.Client, error) { | |||||||
|  |  | ||||||
| 	cli, err := influx.NewHTTPClient(clientConfig) | 	cli, err := influx.NewHTTPClient(clientConfig) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errwrap.Wrapf("error creating client: {{err}}", err) | 		return nil, fmt.Errorf("error creating client: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Checking server status | 	// Checking server status | ||||||
| 	_, _, err = cli.Ping(i.connectTimeout) | 	_, _, err = cli.Ping(i.connectTimeout) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errwrap.Wrapf("error checking cluster status: {{err}}", err) | 		return nil, fmt.Errorf("error checking cluster status: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// verifying infos about the connection | 	// verifying infos about the connection | ||||||
| 	isAdmin, err := isUserAdmin(cli, i.Username) | 	isAdmin, err := isUserAdmin(cli, i.Username) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errwrap.Wrapf("error getting if provided username is admin: {{err}}", err) | 		return nil, fmt.Errorf("error getting if provided username is admin: %w", err) | ||||||
| 	} | 	} | ||||||
| 	if !isAdmin { | 	if !isAdmin { | ||||||
| 		return nil, fmt.Errorf("the provided user is not an admin of the influxDB server") | 		return nil, fmt.Errorf("the provided user is not an admin of the influxDB server") | ||||||
|   | |||||||
| @@ -11,7 +11,6 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	"github.com/hashicorp/vault/helper/testhelpers/docker" | 	"github.com/hashicorp/vault/helper/testhelpers/docker" | ||||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||||
| 	dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing" | 	dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing" | ||||||
| @@ -78,12 +77,12 @@ func prepareInfluxdbTestContainer(t *testing.T) (func(), *Config) { | |||||||
| 		}) | 		}) | ||||||
| 		cli, err := influx.NewHTTPClient(c.apiConfig()) | 		cli, err := influx.NewHTTPClient(c.apiConfig()) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errwrap.Wrapf("error creating InfluxDB client: {{err}}", err) | 			return nil, fmt.Errorf("error creating InfluxDB client: %w", err) | ||||||
| 		} | 		} | ||||||
| 		defer cli.Close() | 		defer cli.Close() | ||||||
| 		_, _, err = cli.Ping(1) | 		_, _, err = cli.Ping(1) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errwrap.Wrapf("error checking cluster status: {{err}}", err) | 			return nil, fmt.Errorf("error checking cluster status: %w", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return c, nil | 		return c, nil | ||||||
| @@ -421,20 +420,20 @@ func testCredsExist(address, username, password string) error { | |||||||
| 	} | 	} | ||||||
| 	cli, err := influx.NewHTTPClient(conf) | 	cli, err := influx.NewHTTPClient(conf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errwrap.Wrapf("Error creating InfluxDB Client: ", err) | 		return fmt.Errorf("Error creating InfluxDB Client: %w", err) | ||||||
| 	} | 	} | ||||||
| 	defer cli.Close() | 	defer cli.Close() | ||||||
| 	_, _, err = cli.Ping(1) | 	_, _, err = cli.Ping(1) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errwrap.Wrapf("error checking server ping: {{err}}", err) | 		return fmt.Errorf("error checking server ping: %w", err) | ||||||
| 	} | 	} | ||||||
| 	q := influx.NewQuery("SHOW SERIES ON vault", "", "") | 	q := influx.NewQuery("SHOW SERIES ON vault", "", "") | ||||||
| 	response, err := cli.Query(q) | 	response, err := cli.Query(q) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errwrap.Wrapf("error querying influxdb server: {{err}}", err) | 		return fmt.Errorf("error querying influxdb server: %w", err) | ||||||
| 	} | 	} | ||||||
| 	if response != nil && response.Error() != nil { | 	if response != nil && response.Error() != nil { | ||||||
| 		return errwrap.Wrapf("error using the correct influx database: {{err}}", response.Error()) | 		return fmt.Errorf("error using the correct influx database: %w", response.Error()) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,7 +10,6 @@ import ( | |||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/dbutil" | 	"github.com/hashicorp/vault/sdk/database/helper/dbutil" | ||||||
| 	"github.com/mitchellh/mapstructure" | 	"github.com/mitchellh/mapstructure" | ||||||
| @@ -193,7 +192,7 @@ func (c *mongoDBConnectionProducer) getWriteConcern() (opts *options.ClientOptio | |||||||
| 	concern := &writeConcern{} | 	concern := &writeConcern{} | ||||||
| 	err = json.Unmarshal([]byte(input), concern) | 	err = json.Unmarshal([]byte(input), concern) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errwrap.Wrapf("error unmarshalling write_concern: {{err}}", err) | 		return nil, fmt.Errorf("error unmarshalling write_concern: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Translate write concern to mongo options | 	// Translate write concern to mongo options | ||||||
|   | |||||||
| @@ -8,7 +8,6 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	_ "github.com/denisenkom/go-mssqldb" | 	_ "github.com/denisenkom/go-mssqldb" | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	multierror "github.com/hashicorp/go-multierror" | 	multierror "github.com/hashicorp/go-multierror" | ||||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| @@ -279,10 +278,10 @@ func (m *MSSQL) revokeUserDefault(ctx context.Context, username string) error { | |||||||
|  |  | ||||||
| 	// can't drop if not all database users are dropped | 	// can't drop if not all database users are dropped | ||||||
| 	if rows.Err() != nil { | 	if rows.Err() != nil { | ||||||
| 		return errwrap.Wrapf("could not generate sql statements for all rows: {{err}}", rows.Err()) | 		return fmt.Errorf("could not generate sql statements for all rows: %w", rows.Err()) | ||||||
| 	} | 	} | ||||||
| 	if lastStmtError != nil { | 	if lastStmtError != nil { | ||||||
| 		return errwrap.Wrapf("could not perform all sql statements: {{err}}", lastStmtError) | 		return fmt.Errorf("could not perform all sql statements: %w", lastStmtError) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Drop this login | 	// Drop this login | ||||||
|   | |||||||
| @@ -11,7 +11,6 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/go-sql-driver/mysql" | 	"github.com/go-sql-driver/mysql" | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	"github.com/hashicorp/go-uuid" | 	"github.com/hashicorp/go-uuid" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/dbutil" | 	"github.com/hashicorp/vault/sdk/database/helper/dbutil" | ||||||
| @@ -88,7 +87,7 @@ func (c *mySQLConnectionProducer) Init(ctx context.Context, conf map[string]inte | |||||||
|  |  | ||||||
| 	c.maxConnectionLifetime, err = parseutil.ParseDurationSecond(c.MaxConnectionLifetimeRaw) | 	c.maxConnectionLifetime, err = parseutil.ParseDurationSecond(c.MaxConnectionLifetimeRaw) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errwrap.Wrapf("invalid max_connection_lifetime: {{err}}", err) | 		return nil, fmt.Errorf("invalid max_connection_lifetime: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	tlsConfig, err := c.getTLSAuth() | 	tlsConfig, err := c.getTLSAuth() | ||||||
| @@ -113,11 +112,11 @@ func (c *mySQLConnectionProducer) Init(ctx context.Context, conf map[string]inte | |||||||
|  |  | ||||||
| 	if verifyConnection { | 	if verifyConnection { | ||||||
| 		if _, err := c.Connection(ctx); err != nil { | 		if _, err := c.Connection(ctx); err != nil { | ||||||
| 			return nil, errwrap.Wrapf("error verifying connection: {{err}}", err) | 			return nil, fmt.Errorf("error verifying connection: %w", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if err := c.db.PingContext(ctx); err != nil { | 		if err := c.db.PingContext(ctx); err != nil { | ||||||
| 			return nil, errwrap.Wrapf("error verifying connection: {{err}}", err) | 			return nil, fmt.Errorf("error verifying connection: %w", err) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ import ( | |||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	"github.com/hashicorp/go-multierror" | 	"github.com/hashicorp/go-multierror" | ||||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| @@ -445,10 +444,10 @@ func (p *PostgreSQL) defaultDeleteUser(ctx context.Context, username string) err | |||||||
|  |  | ||||||
| 	// can't drop if not all privileges are revoked | 	// can't drop if not all privileges are revoked | ||||||
| 	if rows.Err() != nil { | 	if rows.Err() != nil { | ||||||
| 		return errwrap.Wrapf("could not generate revocation statements for all rows: {{err}}", rows.Err()) | 		return fmt.Errorf("could not generate revocation statements for all rows: %w", rows.Err()) | ||||||
| 	} | 	} | ||||||
| 	if lastStmtError != nil { | 	if lastStmtError != nil { | ||||||
| 		return errwrap.Wrapf("could not perform all revocation statements: {{err}}", lastStmtError) | 		return fmt.Errorf("could not perform all revocation statements: %w", lastStmtError) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Drop this user | 	// Drop this user | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/hashicorp/errwrap" |  | ||||||
| 	"github.com/hashicorp/go-multierror" | 	"github.com/hashicorp/go-multierror" | ||||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||||
| 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | 	"github.com/hashicorp/vault/sdk/database/helper/connutil" | ||||||
| @@ -446,10 +445,10 @@ $$;`) | |||||||
|  |  | ||||||
| 	// can't drop if not all privileges are revoked | 	// can't drop if not all privileges are revoked | ||||||
| 	if rows.Err() != nil { | 	if rows.Err() != nil { | ||||||
| 		return dbplugin.DeleteUserResponse{}, errwrap.Wrapf("could not generate revocation statements for all rows: {{err}}", rows.Err()) | 		return dbplugin.DeleteUserResponse{}, fmt.Errorf("could not generate revocation statements for all rows: %w", rows.Err()) | ||||||
| 	} | 	} | ||||||
| 	if lastStmtError != nil { | 	if lastStmtError != nil { | ||||||
| 		return dbplugin.DeleteUserResponse{}, errwrap.Wrapf("could not perform all revocation statements: {{err}}", lastStmtError) | 		return dbplugin.DeleteUserResponse{}, fmt.Errorf("could not perform all revocation statements: %w", lastStmtError) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Drop this user | 	// Drop this user | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Lars Lehtonen
					Lars Lehtonen