| 508 | } |
| 509 | |
| 510 | func parseDestinationRuleForFile(conf *configFile, filePath string, kmsEncryptionContext map[string]*string) (*Config, error) { |
| 511 | var rule *creationRule |
| 512 | var dRule *destinationRule |
| 513 | |
| 514 | if len(conf.DestinationRules) > 0 { |
| 515 | for _, r := range conf.DestinationRules { |
| 516 | if r.PathRegex == "" { |
| 517 | dRule = &r |
| 518 | rule = &dRule.RecreationRule |
| 519 | break |
| 520 | } |
| 521 | if r.PathRegex != "" { |
| 522 | if match, _ := regexp.MatchString(r.PathRegex, filePath); match { |
| 523 | dRule = &r |
| 524 | rule = &dRule.RecreationRule |
| 525 | break |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if dRule == nil { |
| 532 | return nil, fmt.Errorf("error loading config: no matching destination found in config") |
| 533 | } |
| 534 | |
| 535 | var dest publish.Destination |
| 536 | destinationCount := 0 |
| 537 | if dRule.S3Bucket != "" { |
| 538 | destinationCount++ |
| 539 | } |
| 540 | if dRule.GCSBucket != "" { |
| 541 | destinationCount++ |
| 542 | } |
| 543 | if dRule.VaultPath != "" { |
| 544 | destinationCount++ |
| 545 | } |
| 546 | |
| 547 | if destinationCount > 1 { |
| 548 | return nil, fmt.Errorf("error loading config: more than one destinations were found in a single destination rule, you can only use one per rule") |
| 549 | } |
| 550 | if dRule.S3Bucket != "" { |
| 551 | dest = publish.NewS3Destination(dRule.S3Bucket, dRule.S3Prefix) |
| 552 | } |
| 553 | if dRule.GCSBucket != "" { |
| 554 | dest = publish.NewGCSDestination(dRule.GCSBucket, dRule.GCSPrefix) |
| 555 | } |
| 556 | if dRule.VaultPath != "" { |
| 557 | dest = publish.NewVaultDestination(dRule.VaultAddress, dRule.VaultPath, dRule.VaultKVMountName, dRule.VaultKVVersion) |
| 558 | } |
| 559 | |
| 560 | config, err := configFromRule(rule, kmsEncryptionContext) |
| 561 | if err != nil { |
| 562 | return nil, err |
| 563 | } |
| 564 | config.Destination = dest |
| 565 | config.OmitExtensions = dRule.OmitExtensions |
| 566 | |
| 567 | return config, nil |