Skip to content

Commit

Permalink
make all parts of connection string configurable; test with cockroach…
Browse files Browse the repository at this point in the history
…db 21.1.8
  • Loading branch information
JorritSalverda committed Sep 7, 2021
1 parent e6ce5b2 commit 19f2c8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 5 additions & 4 deletions .estafette.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ version:
semver:
major: 1
minor: 0
patch: 4
patch: 5
labelTemplate: '{{branch}}-{{auto}}'
releaseBranch: 1.0.4
releaseBranch: 1.0.5

stages:
build-lint-and-package:
Expand Down Expand Up @@ -63,7 +63,7 @@ stages:
test-migration-against-cockroachdb:
services:
- name: estafette-ci-db-public
image: cockroachdb/cockroach:v21.1.7
image: cockroachdb/cockroach:v21.1.8
env:
COCKROACH_SKIP_ENABLING_DIAGNOSTIC_REPORTING: "true"
readiness:
Expand Down Expand Up @@ -219,4 +219,5 @@ releases:
repoBranch: main

create-github-release:
image: extensions/github-release:dev
image: extensions/github-release:dev
ignoreMissingMilestone: true
10 changes: 6 additions & 4 deletions cockroachDBClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ type cockroachDBClientImpl struct {
cockroachHost string
cockroachInsecure bool
sslMode string
cockroachCertificateDir string
certificateAuthorityPath string
certificatePath string
certificateKeyPath string
cockroachPort int
cockroachUser string
cockroachPassword string
databaseConnection *sql.DB
}

// NewCockroachDBClient returns a new cockroach.DBClient
func NewCockroachDBClient(cockroachConnectionString, cockroachDatabase, cockroachHost string, cockroachInsecure bool, sslMode, cockroachCertificateDir, certificateAuthorityPath string, cockroachPort int, cockroachUser, cockroachPassword string) (cockroachDBClient DBClient) {
func NewCockroachDBClient(cockroachConnectionString, cockroachDatabase, cockroachHost string, cockroachInsecure bool, sslMode, certificateAuthorityPath, certificatePath, certificateKeyPath string, cockroachPort int, cockroachUser, cockroachPassword string) (cockroachDBClient DBClient) {

cockroachDBClient = &cockroachDBClientImpl{
databaseDriver: "postgres",
Expand All @@ -45,7 +46,8 @@ func NewCockroachDBClient(cockroachConnectionString, cockroachDatabase, cockroac
cockroachHost: cockroachHost,
cockroachInsecure: cockroachInsecure,
sslMode: sslMode,
cockroachCertificateDir: cockroachCertificateDir,
certificatePath: certificatePath,
certificateKeyPath: certificateKeyPath,
certificateAuthorityPath: certificateAuthorityPath,
cockroachPort: cockroachPort,
cockroachUser: cockroachUser,
Expand Down Expand Up @@ -73,7 +75,7 @@ func (dbc *cockroachDBClientImpl) Connect() (err error) {
if dbc.cockroachInsecure {
dataSourceName = fmt.Sprintf("postgresql://%v@%v:%v/%v?sslmode=disable", userAndPassword, dbc.cockroachHost, dbc.cockroachPort, dbc.cockroachDatabase)
} else {
dataSourceName = fmt.Sprintf("postgresql://%v@%v:%v/%v?sslmode=%v&sslrootcert=%v&sslcert=%v/cert&sslkey=%v/key", userAndPassword, dbc.cockroachHost, dbc.cockroachPort, dbc.cockroachDatabase, dbc.sslMode, dbc.certificateAuthorityPath, dbc.cockroachCertificateDir, dbc.cockroachCertificateDir)
dataSourceName = fmt.Sprintf("postgresql://%v@%v:%v/%v?sslmode=%v&sslrootcert=%v&sslcert=%v&sslkey=%v", userAndPassword, dbc.cockroachHost, dbc.cockroachPort, dbc.cockroachDatabase, dbc.sslMode, dbc.certificateAuthorityPath, dbc.certificatePath, dbc.certificateKeyPath)
}
}

Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ var (
cockroachDatabase = kingpin.Flag("cockroach-database", "CockroachDB database.").Default("defaultdb").OverrideDefaultFromEnvar("COCKROACH_DATABASE").String()
cockroachHost = kingpin.Flag("cockroach-host", "CockroachDB host.").Default("estafette-ci-db-public").OverrideDefaultFromEnvar("COCKROACH_HOST").String()
cockroachInsecure = kingpin.Flag("cockroach-insecure", "CockroachDB insecure connection.").Default("false").OverrideDefaultFromEnvar("COCKROACH_INSECURE").Bool()
cockroachCertificateDir = kingpin.Flag("cockroach-certs-dir", "CockroachDB certificate directory.").Default("/cockroach-certs").OverrideDefaultFromEnvar("COCKROACH_CERTS_DIR").String()
cockroachPort = kingpin.Flag("cockroach-port", "CockroachDB port.").Default("26257").OverrideDefaultFromEnvar("COCKROACH_PORT").Int()
cockroachUser = kingpin.Flag("cockroach-user", "CockroachDB user.").Default("root").OverrideDefaultFromEnvar("COCKROACH_USER").String()
cockroachPassword = kingpin.Flag("cockroach-password", "CockroachDB password.").Envar("COCKROACH_PASSWORD").String()
cockroachConnectionString = kingpin.Flag("cockroach-connection-string", "CockroachDB connection string.").Envar("COCKROACH_CONNECTION_STRING").String()
sslMode = kingpin.Flag("ssl-mode", "SSL Mode used to connect to cockroachdb.").Default("verify-full").OverrideDefaultFromEnvar("SSL_MODE").String()
certificateAuthorityPath = kingpin.Flag("ca-path", "Path to certificate authority (CA) public certificate.").Default("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt").OverrideDefaultFromEnvar("CA_PATH").String()
certificateAuthorityPath = kingpin.Flag("ssl-ca-path", "Path to certificate authority (CA) public certificate.").Default("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt").OverrideDefaultFromEnvar("SSL_CA_PATH").String()
certificatePath = kingpin.Flag("ssl-cert-path", "Path to public certificate.").Default("/cockroach-certs/cert").OverrideDefaultFromEnvar("SSL_CERT_PATH").String()
certificateKeyPath = kingpin.Flag("ssl-key-path", "Path to certificate key.").Default("/cockroach-certs/key").OverrideDefaultFromEnvar("SSL_KEY_PATH").String()
waitSeconds = kingpin.Flag("wait-seconds", "Seconds to wait before executin.").Default("0").OverrideDefaultFromEnvar("WAIT_SECONDS").Int()
)

Expand All @@ -47,7 +48,7 @@ func main() {
}

// set up database and update schema
cockroachDBClient := NewCockroachDBClient(*cockroachConnectionString, *cockroachDatabase, *cockroachHost, *cockroachInsecure, *sslMode, *cockroachCertificateDir, *certificateAuthorityPath, *cockroachPort, *cockroachUser, *cockroachPassword)
cockroachDBClient := NewCockroachDBClient(*cockroachConnectionString, *cockroachDatabase, *cockroachHost, *cockroachInsecure, *sslMode, *certificateAuthorityPath, *certificatePath, *certificateKeyPath, *cockroachPort, *cockroachUser, *cockroachPassword)
err := cockroachDBClient.Connect()
if err != nil {
log.Warn().Err(err).Msg("Failed connecting to database")
Expand Down

0 comments on commit 19f2c8d

Please sign in to comment.