MCPcopy Create free account
hub / github.com/Mister-leo/fssh / LoadMode

Function LoadMode

internal/auth/auth.go:81–110  ·  view source on GitHub ↗

LoadMode 加载当前认证模式 读取 ~/.fssh/auth_mode.json,如果不存在则根据 Keychain 自动检测

()

Source from the content-addressed store, hash-verified

79// LoadMode 加载当前认证模式
80// 读取 ~/.fssh/auth_mode.json,如果不存在则根据 Keychain 自动检测
81func LoadMode() (AuthMode, error) {
82 path := modeConfigPath()
83
84 data, err := os.ReadFile(path)
85 if err != nil {
86 if errors.Is(err, os.ErrNotExist) {
87 // 文件不存在,尝试自动检测
88 // 如果 Keychain 中有 master key,默认使用 Touch ID
89 exists, _ := keychain.MasterKeyExists()
90 if exists {
91 return ModeTouchID, nil
92 }
93 // 否则默认使用 OTP
94 return ModeOTP, nil
95 }
96 return "", fmt.Errorf("读取认证模式配置失败: %w", err)
97 }
98
99 var cfg modeConfig
100 if err := json.Unmarshal(data, &cfg); err != nil {
101 return "", fmt.Errorf("解析认证模式配置失败: %w", err)
102 }
103
104 // 验证版本
105 if cfg.Version != "fssh-auth/v1" {
106 return "", fmt.Errorf("不支持的认证模式配置版本: %s", cfg.Version)
107 }
108
109 return cfg.Mode, nil
110}
111
112// SaveMode 保存认证模式
113func SaveMode(mode AuthMode) error {

Callers 1

GetAuthProviderFunction · 0.85

Calls 2

MasterKeyExistsFunction · 0.92
modeConfigPathFunction · 0.85

Tested by

no test coverage detected