(ctx context.Context, name string, data []byte)
| 279 | } |
| 280 | |
| 281 | func (h *Host) saveAuthFile(ctx context.Context, name string, data []byte) (string, error) { |
| 282 | authDir := h.resolvedAuthDir() |
| 283 | if authDir == "" { |
| 284 | return "", fmt.Errorf("auth directory is unavailable") |
| 285 | } |
| 286 | dst := filepath.Join(authDir, filepath.Base(name)) |
| 287 | if !filepath.IsAbs(dst) { |
| 288 | if abs, errAbs := filepath.Abs(dst); errAbs == nil { |
| 289 | dst = abs |
| 290 | } |
| 291 | } |
| 292 | auth, errBuild := h.buildAuthFromFileData(dst, data) |
| 293 | if errBuild != nil { |
| 294 | return "", errBuild |
| 295 | } |
| 296 | if errWrite := os.WriteFile(dst, data, 0o600); errWrite != nil { |
| 297 | return "", fmt.Errorf("failed to write auth file: %w", errWrite) |
| 298 | } |
| 299 | if errUpsert := h.upsertAuthRecord(ctx, auth); errUpsert != nil { |
| 300 | return "", errUpsert |
| 301 | } |
| 302 | return dst, nil |
| 303 | } |
| 304 | |
| 305 | func (h *Host) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) { |
| 306 | if strings.TrimSpace(path) == "" { |
no test coverage detected