Junie: TOTP flow update and db migrations.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -45,6 +47,7 @@ This command requires authentication with a username and token.`,
|
||||
},
|
||||
}
|
||||
|
||||
// nolint:gochecknoinits // This is a standard pattern in Cobra applications
|
||||
func init() {
|
||||
rootCmd.AddCommand(databaseCmd)
|
||||
databaseCmd.AddCommand(getCredentialsCmd)
|
||||
@@ -68,7 +71,12 @@ func getCredentials() {
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/v1/database/credentials?username=%s", serverAddr, dbUsername)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
// Create a context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
logger.Fatalf("Failed to create request: %v", err)
|
||||
}
|
||||
@@ -89,7 +97,7 @@ func getCredentials() {
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
var errResp ErrorResponse
|
||||
if err := json.Unmarshal(body, &errResp); err == nil {
|
||||
if unmarshalErr := json.Unmarshal(body, &errResp); unmarshalErr == nil {
|
||||
logger.Fatalf("Error: %s", errResp.Error)
|
||||
} else {
|
||||
logger.Fatalf("Error: %s", resp.Status)
|
||||
@@ -97,8 +105,8 @@ func getCredentials() {
|
||||
}
|
||||
|
||||
var creds DatabaseCredentials
|
||||
if err := json.Unmarshal(body, &creds); err != nil {
|
||||
logger.Fatalf("Failed to parse response: %v", err)
|
||||
if unmarshalErr := json.Unmarshal(body, &creds); unmarshalErr != nil {
|
||||
logger.Fatalf("Failed to parse response: %v", unmarshalErr)
|
||||
}
|
||||
|
||||
fmt.Println("Database Credentials:")
|
||||
@@ -107,4 +115,4 @@ func getCredentials() {
|
||||
fmt.Printf("Name: %s\n", creds.Name)
|
||||
fmt.Printf("User: %s\n", creds.User)
|
||||
fmt.Printf("Password: %s\n", creds.Password)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user