processCAFlag reads CA file content and stores it as PEM if value is a file path
(opt *confOpt)
| 540 | |
| 541 | // processCAFlag reads CA file content and stores it as PEM if value is a file path |
| 542 | func processCAFlag(opt *confOpt) error { |
| 543 | value := viper.GetString(opt.viperKey) |
| 544 | if value == "" { |
| 545 | return nil |
| 546 | } |
| 547 | |
| 548 | // If it's a file path, read and store PEM content directly |
| 549 | if _, err := os.Stat(value); err == nil { |
| 550 | content, err := os.ReadFile(value) |
| 551 | if err != nil { |
| 552 | return fmt.Errorf("failed to read CA file %s: %w", value, err) |
| 553 | } |
| 554 | |
| 555 | // Store PEM content directly |
| 556 | viper.Set(opt.viperKey, string(content)) |
| 557 | } |
| 558 | |
| 559 | return nil |
| 560 | } |