(authIndex string)
| 234 | } |
| 235 | |
| 236 | func (h *Host) authPhysicalJSONByIndex(authIndex string) (*coreauth.Auth, []byte, error) { |
| 237 | auth, errGet := h.authByIndex(authIndex) |
| 238 | if errGet != nil { |
| 239 | return nil, nil, errGet |
| 240 | } |
| 241 | path := strings.TrimSpace(authAttribute(auth, "path")) |
| 242 | if path == "" { |
| 243 | return nil, nil, fmt.Errorf("auth file path not found for auth_index %s", authIndex) |
| 244 | } |
| 245 | data, errRead := os.ReadFile(path) |
| 246 | if errRead != nil { |
| 247 | if os.IsNotExist(errRead) { |
| 248 | return nil, nil, fmt.Errorf("auth file not found for auth_index %s", authIndex) |
| 249 | } |
| 250 | return nil, nil, fmt.Errorf("failed to read auth file: %w", errRead) |
| 251 | } |
| 252 | if len(bytesTrimSpace(data)) == 0 { |
| 253 | return nil, nil, fmt.Errorf("auth file is empty for auth_index %s", authIndex) |
| 254 | } |
| 255 | var metadata map[string]any |
| 256 | if errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil { |
| 257 | return nil, nil, fmt.Errorf("invalid auth file for auth_index %s: %w", authIndex, errUnmarshal) |
| 258 | } |
| 259 | return auth, data, nil |
| 260 | } |
| 261 | |
| 262 | func validateHostAuthSaveRequest(req pluginapi.HostAuthSaveRequest) (string, []byte, error) { |
| 263 | name := strings.TrimSpace(req.Name) |
no test coverage detected