Skip to content

Commit 40d1fb4

Browse files
committed
feat: centralize devenv pods operations through manager API with new CLI configuration and list options.
1 parent a06127f commit 40d1fb4

File tree

20 files changed

+289
-435
lines changed

20 files changed

+289
-435
lines changed

cmd/devenv/auth.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/nauticalab/devenv-engine/internal/manager"
8+
"github.com/nauticalab/devenv-engine/internal/manager/auth"
9+
"github.com/nauticalab/devenv-engine/internal/manager/client"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -20,13 +21,24 @@ var authListCmd = &cobra.Command{
2021
Short: "List current authentication information",
2122
Long: `Display the current authentication information, including the authenticated user and their developer identity.`,
2223
Run: func(cmd *cobra.Command, args []string) {
24+
// Load configuration
25+
config, err := LoadCLIConfig()
26+
if err != nil {
27+
fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err)
28+
os.Exit(1)
29+
}
30+
31+
if config.ManagerURL == "" {
32+
fmt.Fprintf(os.Stderr, "Error: manager URL is required. Set DEVEN_MANAGER_URL env var or configure in ~/.devenv/config.yaml\n")
33+
os.Exit(1)
34+
}
35+
2336
// Create manager client
24-
client := manager.NewClient(manager.ClientConfig{
25-
BaseURL: os.Getenv("DEVEN_MANAGER_URL"),
26-
})
37+
authProvider := auth.NewK8sSAProvider(nil, "", "", "")
38+
c := client.NewClient(config.ManagerURL, authProvider)
2739

2840
// Get identity
29-
whoami, err := client.WhoAmI(context.Background())
41+
whoami, err := c.WhoAmI(context.Background())
3042
if err != nil {
3143
fmt.Printf("Error getting authentication info: %v\n", err)
3244
os.Exit(1)
@@ -42,9 +54,6 @@ var authListCmd = &cobra.Command{
4254
}
4355

4456
func init() {
45-
// Add auth command to root
46-
rootCmd.AddCommand(authCmd)
47-
4857
// Add subcommands
4958
authCmd.AddCommand(authListCmd)
5059
}

cmd/devenv/config.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"gopkg.in/yaml.v3"
9+
)
10+
11+
// CLIConfig represents the configuration for the CLI
12+
type CLIConfig struct {
13+
ManagerURL string `yaml:"managerURL"`
14+
}
15+
16+
// LoadCLIConfig loads configuration from multiple sources in order of precedence:
17+
// 1. Flags (handled by caller)
18+
// 2. Environment variables
19+
// 3. Config file (~/.devenv/config.yaml)
20+
func LoadCLIConfig() (*CLIConfig, error) {
21+
config := &CLIConfig{}
22+
23+
// 1. Load from config file
24+
homeDir, err := os.UserHomeDir()
25+
if err == nil {
26+
configPath := filepath.Join(homeDir, ".devenv", "config.yaml")
27+
if _, err := os.Stat(configPath); err == nil {
28+
data, err := os.ReadFile(configPath)
29+
if err == nil {
30+
if err := yaml.Unmarshal(data, config); err != nil {
31+
return nil, fmt.Errorf("failed to parse config file %s: %w", configPath, err)
32+
}
33+
}
34+
}
35+
}
36+
37+
// 2. Load from environment variables (override config file)
38+
if envURL := os.Getenv("DEVEN_MANAGER_URL"); envURL != "" {
39+
config.ManagerURL = envURL
40+
}
41+
42+
return config, nil
43+
}

0 commit comments

Comments
 (0)