@@ -2,16 +2,16 @@ package main
22
33import (
44 "context"
5- "crypto/rsa"
6- "crypto/x509"
7- "encoding/pem"
85 "fmt"
96 "net/url"
107 "os"
118 "regexp"
129 "strconv"
1310 "strings"
1411 "time"
12+ "crypto/rsa"
13+ "crypto/x509"
14+ "encoding/pem"
1515
1616 _ "github.com/ClickHouse/clickhouse-go/v2" // register the ClickHouse driver
1717 "github.com/cenkalti/backoff"
@@ -401,32 +401,32 @@ func (j *Job) updateConnections() {
401401 level .Error (j .log ).Log ("msg" , "Failed to parse Snowflake URL" , "url" , conn , "err" , err )
402402 continue
403403 }
404-
404+
405405 queryParams := u .Query ()
406406 privateKeyPath := os .ExpandEnv (queryParams .Get ("private_key_file" ))
407-
407+
408408 cfg := & gosnowflake.Config {
409409 Account : u .Host ,
410410 User : u .User .Username (),
411411 Role : queryParams .Get ("role" ),
412412 Database : queryParams .Get ("database" ),
413413 Schema : queryParams .Get ("schema" ),
414414 }
415-
415+
416416 if privateKeyPath != "" {
417417 // RSA key auth
418418 keyBytes , err := os .ReadFile (privateKeyPath )
419419 if err != nil {
420420 level .Error (j .log ).Log ("msg" , "Failed to read private key file" , "path" , privateKeyPath , "err" , err )
421421 continue
422422 }
423-
423+
424424 keyBlock , _ := pem .Decode (keyBytes )
425425 if keyBlock == nil {
426426 level .Error (j .log ).Log ("msg" , "Failed to decode PEM block" , "path" , privateKeyPath )
427427 continue
428428 }
429-
429+
430430 var privateKey * rsa.PrivateKey
431431 if parsedKey , err := x509 .ParsePKCS8PrivateKey (keyBlock .Bytes ); err == nil {
432432 privateKey , _ = parsedKey .(* rsa.PrivateKey )
@@ -436,16 +436,16 @@ func (j *Job) updateConnections() {
436436 level .Error (j .log ).Log ("msg" , "Failed to parse private key" , "err" , err )
437437 continue
438438 }
439-
439+
440440 cfg .Authenticator = gosnowflake .AuthTypeJwt
441441 cfg .PrivateKey = privateKey
442-
442+
443443 dsn , err := gosnowflake .DSN (cfg )
444444 if err != nil {
445445 level .Error (j .log ).Log ("msg" , "Failed to create Snowflake DSN with RSA" , "err" , err )
446446 continue
447447 }
448-
448+
449449 newConn .snowflakeConfig = cfg
450450 newConn .snowflakeDSN = dsn
451451 newConn .host = u .Host
@@ -460,20 +460,20 @@ func (j *Job) updateConnections() {
460460 cfg .Port = port
461461 }
462462 }
463-
463+
464464 dsn , err := gosnowflake .DSN (cfg )
465465 if err != nil {
466466 level .Error (j .log ).Log ("msg" , "Failed to create Snowflake DSN with password" , "err" , err )
467467 continue
468468 }
469-
469+
470470 newConn .conn , err = sqlx .Open ("snowflake" , dsn )
471471 if err != nil {
472472 level .Error (j .log ).Log ("msg" , "Failed to open Snowflake connection" , "err" , err )
473473 continue
474474 }
475475 }
476-
476+
477477 j .conns = append (j .conns , newConn )
478478 continue
479479 }
@@ -651,21 +651,21 @@ func (c *connection) connect(job *Job) error {
651651 }
652652 c .tokenExpirationTime = time .Now ().Add (time .Hour )
653653 }
654-
654+
655655 db , err := sqlx .Open ("snowflake" , c .snowflakeDSN )
656656 if err != nil {
657657 return fmt .Errorf ("failed to open Snowflake connection: %w (host: %s)" , err , c .host )
658658 }
659-
659+
660660 db .SetMaxOpenConns (1 )
661661 db .SetMaxIdleConns (0 )
662662 db .SetConnMaxLifetime (30 * time .Minute )
663-
663+
664664 if err := db .Ping (); err != nil {
665665 db .Close ()
666666 return fmt .Errorf ("failed to ping Snowflake: %w (host: %s)" , err , c .host )
667667 }
668-
668+
669669 c .conn = db
670670 return nil
671671 }
0 commit comments