connresolve

package
v0.511.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

Application Connection Resolution Module

Shared Transport Connection Resolution path that stops before open.

Files

File Responsibility
doc.go Package boundary for ready-to-open connection configuration
resolve.go Resolve: password, TLS shape, timeout, port default, catalog bind
catalog.go MySQL/TiDB catalog alias binding shared by Audit and Query Access
classify.go Connection Failure Class mapping for later opener errors
port.go PostgreSQL omitted-port default
resolve_test.go Resolve seam cases
catalog_test.go Catalog alias and conflict cases
classify_test.go Failure class cases
port_test.go PostgreSQL omitted-port cases

Exports

  • Resolve() / Request / Config / Error / Options
  • BindMySQLTiDBCatalog() / ErrCatalogConflict
  • Classify() / FailureClass and class constants
  • ApplyPostgreSQLDefaultPort()

Dependencies

  • Upstream: internal/application/auditmeta, internal/application/queryaccess, internal/application/online, internal/interfaces/cli, internal/interfaces/mcp
  • Downstream: Go standard library

Update Rule

  • If members/interfaces/dependencies change, update this file in the same change.

Documentation

Overview

Package connresolve turns caller connection input into a ready-to-open configuration. input: dialect plus MySQL/TiDB database, connection schema, and request default catalog hints output: one catalog and one qualifier, or ErrCatalogConflict pos: shared MySQL/TiDB catalog-alias rule for metadata-aware Audit and Online Query Access note: if this file changes, update this header and module README.md.

Package connresolve turns caller connection input into a ready-to-open configuration. input: connection, TLS, timeout, and authentication errors from later openers output: a Connection Failure Class with no host, DSN, driver text, or credential pos: shared classification for Transport Connection Resolution; surfaces map class to their own words note: if this file changes, update this header and module README.md.

Package connresolve turns caller connection input into a ready-to-open configuration. input: dialect, catalog hints, omitted-port flags, and raw connection/TLS/authentication errors output: MySQL/TiDB catalog binding, PostgreSQL omitted-port default, and Connection Failure Class pos: application Transport Connection Resolution path that stops before open note: if this file changes, update this header and module README.md.

Package connresolve turns caller connection input into a ready-to-open configuration. input: requested dialect, configured port, and whether the caller set the port explicitly output: 5432 when PostgreSQL is explicit and the port was omitted pos: shared PostgreSQL omitted-port default before open note: if this file changes, update this header and module README.md.

Package connresolve turns caller connection input into a ready-to-open configuration. input: host, socket, user, password sources, TLS files, timeout, dialect, and catalog hints output: a Config ready for auditmeta.Prepare or online.OpenSession, or an Error with FailureClass pos: Transport Connection Resolution entry that stops before open note: if this file changes, update this header and module README.md.

Index

Constants

View Source
const (
	CodeSocketTCPConflict    = "socket_tcp_conflict"
	CodeTLSMode              = "tls_mode"
	CodeTLSCARequiresEnabled = "tls_ca_requires_enabled"
	CodeTLSRequiresHost      = "tls_requires_host"
	CodeTLSRequiresUser      = "tls_requires_user"
	CodeTLSNoSocket          = "tls_no_socket"
	CodeTLSCAPath            = "tls_ca_path"
	CodeTLSCARead            = "tls_ca_read"
	CodeTLSCAPEM             = "tls_ca_pem"
	CodeTimeout              = "timeout"
	CodePasswordSource       = "password_source"
	CodePasswordLookup       = "password_lookup"
	CodeCatalogConflict      = "catalog_conflict"
)

Variables

View Source
var ErrCatalogConflict = errors.New("MySQL/TiDB database, schema, and default schema must match when set; use one catalog value")

ErrCatalogConflict indicates MySQL/TiDB catalog hints disagree.

Functions

func ApplyPostgreSQLDefaultPort

func ApplyPostgreSQLDefaultPort(dialect string, port int, portExplicit bool) int

ApplyPostgreSQLDefaultPort returns 5432 when dialect is postgresql and the caller did not set a port. Other dialects keep the configured port.

func BindMySQLTiDBCatalog

func BindMySQLTiDBCatalog(dialect, database, connectionSchema, requestedSchema string) (string, string, error)

BindMySQLTiDBCatalog canonicalizes MySQL/TiDB database, connection schema, and request default hints into one catalog and one qualifier. Non-MySQL/TiDB dialects return the database and requested schema unchanged.

Types

type Config

type Config struct {
	Host           string
	Port           int
	User           string
	Socket         string
	Database       string
	Schema         string
	Qualifier      string
	Dialect        string
	Password       string
	ConnectTimeout time.Duration
	TLSMode        string
	CACert         *x509.CertPool
}

Config is ready-to-open connection configuration. It does not hold a live handle.

func Resolve

func Resolve(req Request, opts Options) (Config, error)

Resolve validates input, resolves password and TLS, applies the PostgreSQL omitted-port default, and binds MySQL/TiDB catalog aliases. It does not open.

type Error

type Error struct {
	Class FailureClass
	Code  string
	// contains filtered or unexported fields
}

Error is a Transport Connection Resolution failure with a Connection Failure Class.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FailureClass

type FailureClass string

FailureClass is a Connection Failure Class. It is not a user-facing sentence.

const (
	ClassNone             FailureClass = ""
	ClassValidation       FailureClass = "validation"
	ClassAuthentication   FailureClass = "authentication"
	ClassRefused          FailureClass = "refused"
	ClassTimeout          FailureClass = "timeout"
	ClassTLSHostname      FailureClass = "tls_hostname"
	ClassTLSUnknownCA     FailureClass = "tls_unknown_ca"
	ClassTLSNotOffered    FailureClass = "tls_not_offered"
	ClassTLSCertificate   FailureClass = "tls_certificate"
	ClassTLSHandshake     FailureClass = "tls_handshake"
	ClassConnectionFailed FailureClass = "connection_failed"
)

func Classify

func Classify(err error) FailureClass

Classify maps an opener or network error to a Connection Failure Class.

type Options

type Options struct {
	LookupEnv func(string) (string, bool)
	ReadFile  func(string) ([]byte, error)
}

Options substitutes env and file access in tests.

type Request

type Request struct {
	Host            string
	Port            int
	PortExplicit    bool
	User            string
	Socket          string
	Database        string
	Schema          string
	RequestedSchema string
	Dialect         string
	DialectExplicit bool
	Password        string
	PasswordEnv     string
	PasswordFile    string
	ConnectTimeout  string
	TLSMode         string
	TLSCAFile       string
}

Request is caller connection input before open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL