From fd29b8b484cccb67b3ccd285480879215960c489 Mon Sep 17 00:00:00 2001 From: Philipp Defner Date: Mon, 22 Sep 2025 18:15:40 +0200 Subject: [PATCH] go fmt --- job.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/job.go b/job.go index 44e2bd06..ca798e6f 100644 --- a/job.go +++ b/job.go @@ -2,6 +2,9 @@ package main import ( "context" + "crypto/rsa" + "crypto/x509" + "encoding/pem" "fmt" "net/url" "os" @@ -9,9 +12,6 @@ import ( "strconv" "strings" "time" - "crypto/rsa" - "crypto/x509" - "encoding/pem" _ "github.com/ClickHouse/clickhouse-go/v2" // register the ClickHouse driver "github.com/cenkalti/backoff" @@ -401,10 +401,10 @@ func (j *Job) updateConnections() { level.Error(j.log).Log("msg", "Failed to parse Snowflake URL", "url", conn, "err", err) continue } - + queryParams := u.Query() privateKeyPath := os.ExpandEnv(queryParams.Get("private_key_file")) - + cfg := &gosnowflake.Config{ Account: u.Host, User: u.User.Username(), @@ -412,7 +412,7 @@ func (j *Job) updateConnections() { Database: queryParams.Get("database"), Schema: queryParams.Get("schema"), } - + if privateKeyPath != "" { // RSA key auth keyBytes, err := os.ReadFile(privateKeyPath) @@ -420,13 +420,13 @@ func (j *Job) updateConnections() { level.Error(j.log).Log("msg", "Failed to read private key file", "path", privateKeyPath, "err", err) continue } - + keyBlock, _ := pem.Decode(keyBytes) if keyBlock == nil { level.Error(j.log).Log("msg", "Failed to decode PEM block", "path", privateKeyPath) continue } - + var privateKey *rsa.PrivateKey if parsedKey, err := x509.ParsePKCS8PrivateKey(keyBlock.Bytes); err == nil { privateKey, _ = parsedKey.(*rsa.PrivateKey) @@ -436,16 +436,16 @@ func (j *Job) updateConnections() { level.Error(j.log).Log("msg", "Failed to parse private key", "err", err) continue } - + cfg.Authenticator = gosnowflake.AuthTypeJwt cfg.PrivateKey = privateKey - + dsn, err := gosnowflake.DSN(cfg) if err != nil { level.Error(j.log).Log("msg", "Failed to create Snowflake DSN with RSA", "err", err) continue } - + newConn.snowflakeConfig = cfg newConn.snowflakeDSN = dsn newConn.host = u.Host @@ -460,20 +460,20 @@ func (j *Job) updateConnections() { cfg.Port = port } } - + dsn, err := gosnowflake.DSN(cfg) if err != nil { level.Error(j.log).Log("msg", "Failed to create Snowflake DSN with password", "err", err) continue } - + newConn.conn, err = sqlx.Open("snowflake", dsn) if err != nil { level.Error(j.log).Log("msg", "Failed to open Snowflake connection", "err", err) continue } } - + j.conns = append(j.conns, newConn) continue } @@ -651,21 +651,21 @@ func (c *connection) connect(job *Job) error { } c.tokenExpirationTime = time.Now().Add(time.Hour) } - + db, err := sqlx.Open("snowflake", c.snowflakeDSN) if err != nil { return fmt.Errorf("failed to open Snowflake connection: %w (host: %s)", err, c.host) } - + db.SetMaxOpenConns(1) db.SetMaxIdleConns(0) db.SetConnMaxLifetime(30 * time.Minute) - + if err := db.Ping(); err != nil { db.Close() return fmt.Errorf("failed to ping Snowflake: %w (host: %s)", err, c.host) } - + c.conn = db return nil }