MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / LoadConfig

Function LoadConfig

cmd/login.go:551–595  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

549}
550
551func LoadConfig() (*Config, error) {
552 if envToken := os.Getenv("TNR_API_TOKEN"); envToken != "" {
553 config := &Config{
554 APIURL: DefaultAPIURL,
555 Token: envToken,
556 }
557 if projectConfig := loadProjectConfig(); projectConfig != nil && projectConfig.APIURL != "" {
558 config.APIURL = projectConfig.APIURL
559 }
560 if envAPIURL := os.Getenv("TNR_API_URL"); envAPIURL != "" {
561 config.APIURL = envAPIURL
562 }
563 return config, nil
564 }
565
566 configDir, err := utils.ThunderDir()
567 if err != nil {
568 return nil, err
569 }
570
571 configPath := filepath.Join(configDir, "cli_config.json")
572 data, err := os.ReadFile(configPath)
573 if err != nil {
574 return nil, err
575 }
576
577 var config Config
578 if err := json.Unmarshal(data, &config); err != nil {
579 return nil, err
580 }
581
582 if config.APIURL == "" {
583 config.APIURL = DefaultAPIURL
584 }
585
586 if projectConfig := loadProjectConfig(); projectConfig != nil && projectConfig.APIURL != "" {
587 config.APIURL = projectConfig.APIURL
588 }
589
590 if envAPIURL := os.Getenv("TNR_API_URL"); envAPIURL != "" {
591 config.APIURL = envAPIURL
592 }
593
594 return &config, nil
595}
596
597// logoutCmd represents the logout command
598var logoutCmd = &cobra.Command{

Callers 7

initSentryFunction · 0.92
getAuthenticatedClientFunction · 0.85
TestLoadConfigFunction · 0.85
runSCPFunction · 0.85
runLoginFunction · 0.85
kickoffSubscriptionCheckFunction · 0.85

Calls 3

ThunderDirFunction · 0.92
loadProjectConfigFunction · 0.85
ReadFileMethod · 0.65

Tested by 2

TestLoadConfigFunction · 0.68