@@ -17,8 +17,8 @@ import (
1717 "golang.org/x/term"
1818
1919 "github.com/timescale/tiger-cli/internal/tiger/api"
20+ "github.com/timescale/tiger-cli/internal/tiger/common"
2021 "github.com/timescale/tiger-cli/internal/tiger/config"
21- "github.com/timescale/tiger-cli/internal/tiger/password"
2222 "github.com/timescale/tiger-cli/internal/tiger/util"
2323)
2424
@@ -84,7 +84,7 @@ Examples:
8484 return err
8585 }
8686
87- details , err := password .GetConnectionDetails (service , password .ConnectionDetailsOptions {
87+ details , err := common .GetConnectionDetails (service , common .ConnectionDetailsOptions {
8888 Pooled : dbConnectionStringPooled ,
8989 Role : dbConnectionStringRole ,
9090 WithPassword : dbConnectionStringWithPassword ,
@@ -170,7 +170,7 @@ Examples:
170170 return fmt .Errorf ("psql client not found. Please install PostgreSQL client tools" )
171171 }
172172
173- details , err := password .GetConnectionDetails (service , password .ConnectionDetailsOptions {
173+ details , err := common .GetConnectionDetails (service , common .ConnectionDetailsOptions {
174174 Pooled : dbConnectPooled ,
175175 Role : dbConnectRole ,
176176 })
@@ -234,26 +234,26 @@ Examples:
234234 RunE : func (cmd * cobra.Command , args []string ) error {
235235 service , err := getServiceDetails (cmd , args )
236236 if err != nil {
237- return exitWithCode ( ExitInvalidParameters , err )
237+ return common . ExitWithCode ( common . ExitInvalidParameters , err )
238238 }
239239
240240 // Build connection string for testing with password (if available)
241- details , err := password .GetConnectionDetails (service , password .ConnectionDetailsOptions {
241+ details , err := common .GetConnectionDetails (service , common .ConnectionDetailsOptions {
242242 Pooled : dbTestConnectionPooled ,
243243 Role : dbTestConnectionRole ,
244244 WithPassword : true ,
245245 })
246246 if err != nil {
247- return exitWithCode ( ExitInvalidParameters , fmt .Errorf ("failed to build connection string: %w" , err ))
247+ return common . ExitWithCode ( common . ExitInvalidParameters , fmt .Errorf ("failed to build connection string: %w" , err ))
248248 }
249249
250250 if dbTestConnectionPooled && ! details .IsPooler {
251- return exitWithCode ( ExitInvalidParameters , fmt .Errorf ("connection pooler not available for this service" ))
251+ return common . ExitWithCode ( common . ExitInvalidParameters , fmt .Errorf ("connection pooler not available for this service" ))
252252 }
253253
254254 // Validate timeout (Cobra handles parsing automatically)
255255 if dbTestConnectionTimeout < 0 {
256- return exitWithCode ( ExitInvalidParameters , fmt .Errorf ("timeout must be positive or zero, got %v" , dbTestConnectionTimeout ))
256+ return common . ExitWithCode ( common . ExitInvalidParameters , fmt .Errorf ("timeout must be positive or zero, got %v" , dbTestConnectionTimeout ))
257257 }
258258
259259 // Test the connection
@@ -344,7 +344,7 @@ Examples:
344344 }
345345
346346 // Save password using configured storage
347- storage := password .GetPasswordStorage ()
347+ storage := common .GetPasswordStorage ()
348348 if err := storage .Save (service , passwordToSave , dbSavePasswordRole ); err != nil {
349349 return fmt .Errorf ("failed to save password: %w" , err )
350350 }
@@ -674,7 +674,7 @@ PostgreSQL Configuration Parameters That May Be Set:
674674 }
675675
676676 // Build connection string
677- details , err := password .GetConnectionDetails (service , password .ConnectionDetailsOptions {
677+ details , err := common .GetConnectionDetails (service , common .ConnectionDetailsOptions {
678678 Pooled : false ,
679679 Role : "tsdbadmin" , // Use admin role to create new roles
680680 WithPassword : true ,
@@ -699,7 +699,7 @@ PostgreSQL Configuration Parameters That May Be Set:
699699 }
700700
701701 // Save password to storage with the new role name
702- result , err := password .SavePasswordWithResult (service , rolePassword , roleName )
702+ result , err := common .SavePasswordWithResult (service , rolePassword , roleName )
703703 if err != nil {
704704 fmt .Fprintf (cmd .ErrOrStderr (), "⚠️ Warning: %s\n " , result .Message )
705705 } else if ! result .Success {
@@ -771,7 +771,7 @@ func getServiceDetails(cmd *cobra.Command, args []string) (api.Service, error) {
771771 // Get API key and project ID for authentication
772772 apiKey , projectID , err := getCredentialsForDB ()
773773 if err != nil {
774- return api.Service {}, exitWithCode ( ExitAuthenticationError , fmt .Errorf ("authentication required: %w. Please run 'tiger auth login'" , err ))
774+ return api.Service {}, common . ExitWithCode ( common . ExitAuthenticationError , fmt .Errorf ("authentication required: %w. Please run 'tiger auth login'" , err ))
775775 }
776776
777777 // Create API client
@@ -791,7 +791,7 @@ func getServiceDetails(cmd *cobra.Command, args []string) (api.Service, error) {
791791
792792 // Handle API response
793793 if resp .StatusCode () != 200 {
794- return api.Service {}, exitWithErrorFromStatusCode (resp .StatusCode (), resp .JSON4XX )
794+ return api.Service {}, common . ExitWithErrorFromStatusCode (resp .StatusCode (), resp .JSON4XX )
795795 }
796796
797797 if resp .JSON200 == nil {
@@ -847,8 +847,8 @@ func buildPsqlCommand(connectionString, psqlPath string, additionalFlags []strin
847847
848848 // Only set PGPASSWORD for keyring storage method
849849 // pgpass storage relies on psql automatically reading ~/.pgpass file
850- storage := password .GetPasswordStorage ()
851- if _ , isKeyring := storage .(* password .KeyringStorage ); isKeyring {
850+ storage := common .GetPasswordStorage ()
851+ if _ , isKeyring := storage .(* common .KeyringStorage ); isKeyring {
852852 if password , err := storage .Get (service , role ); err == nil && password != "" {
853853 // Set PGPASSWORD environment variable for psql when using keyring
854854 psqlCmd .Env = append (os .Environ (), "PGPASSWORD=" + password )
@@ -876,17 +876,17 @@ func testDatabaseConnection(ctx context.Context, connectionString string, timeou
876876 // Determine the appropriate exit code based on error type
877877 if isContextDeadlineExceeded (err ) {
878878 fmt .Fprintf (cmd .ErrOrStderr (), "Connection timeout after %v\n " , timeout )
879- return exitWithCode ( ExitTimeout , err ) // Connection timeout
879+ return common . ExitWithCode ( common . ExitTimeout , err ) // Connection timeout
880880 }
881881
882882 // Check if it's a connection rejection vs unreachable
883883 if isConnectionRejected (err ) {
884884 fmt .Fprintf (cmd .ErrOrStderr (), "Connection rejected: %v\n " , err )
885- return exitWithCode ( ExitGeneralError , err ) // Server is rejecting connections
885+ return common . ExitWithCode ( common . ExitGeneralError , err ) // Server is rejecting connections
886886 }
887887
888888 fmt .Fprintf (cmd .ErrOrStderr (), "Connection failed: %v\n " , err )
889- return exitWithCode (2 , err ) // No response to connection attempt
889+ return common . ExitWithCode (2 , err ) // No response to connection attempt
890890 }
891891 defer conn .Close (ctx )
892892
@@ -896,17 +896,17 @@ func testDatabaseConnection(ctx context.Context, connectionString string, timeou
896896 // Determine the appropriate exit code based on error type
897897 if isContextDeadlineExceeded (err ) {
898898 fmt .Fprintf (cmd .ErrOrStderr (), "Connection timeout after %v\n " , timeout )
899- return exitWithCode ( ExitTimeout , err ) // Connection timeout
899+ return common . ExitWithCode ( common . ExitTimeout , err ) // Connection timeout
900900 }
901901
902902 // Check if it's a connection rejection vs unreachable
903903 if isConnectionRejected (err ) {
904904 fmt .Fprintf (cmd .ErrOrStderr (), "Connection rejected: %v\n " , err )
905- return exitWithCode ( ExitGeneralError , err ) // Server is rejecting connections
905+ return common . ExitWithCode ( common . ExitGeneralError , err ) // Server is rejecting connections
906906 }
907907
908908 fmt .Fprintf (cmd .ErrOrStderr (), "Connection failed: %v\n " , err )
909- return exitWithCode (2 , err ) // No response to connection attempt
909+ return common . ExitWithCode (2 , err ) // No response to connection attempt
910910 }
911911
912912 // Connection successful
0 commit comments