@@ -143,7 +143,7 @@ func (p *Plugin) Exec() error {
143143 if p .StripPrefix != "" {
144144 if err := validateStripPrefix (p .StripPrefix ); err != nil {
145145 log .WithFields (log.Fields {
146- "error" : err ,
146+ "error" : err ,
147147 "pattern" : p .StripPrefix ,
148148 }).Error ("Invalid strip_prefix pattern" )
149149 return err
@@ -322,13 +322,13 @@ func resolveKey(target, srcPath, stripPrefix string) string {
322322 if err != nil {
323323 // Log error but continue with original path
324324 log .WithFields (log.Fields {
325- "error" : err ,
326- "path" : srcPath ,
325+ "error" : err ,
326+ "path" : srcPath ,
327327 "pattern" : stripPrefix ,
328328 }).Warning ("Failed to strip prefix, using original path" )
329329 stripped = srcPath
330330 }
331-
331+
332332 key := filepath .Join (target , stripped )
333333 key = filepath .ToSlash (key )
334334 if ! strings .HasPrefix (key , "/" ) {
@@ -490,7 +490,6 @@ func (p *Plugin) createS3Client() *s3.S3 {
490490 log .Warn ("AWS Key and/or Secret not provided (falling back to ec2 instance profile)" )
491491 }
492492
493-
494493 // Create session with primary credentials
495494 sess , err = session .NewSession (conf )
496495 if err != nil {
@@ -503,8 +502,8 @@ func (p *Plugin) createS3Client() *s3.S3 {
503502 // Handle secondary role assumption if UserRoleArn is provided
504503 if len (p .UserRoleArn ) > 0 {
505504 log .WithField ("UserRoleArn" , p .UserRoleArn ).Info ("Using user role ARN" )
506-
507- // Create credentials using the existing session for role assumption
505+
506+ // Create credentials using the existing session for role assumption
508507 // by assuming the UserRoleArn (with ExternalID when provided)
509508 creds := stscreds .NewCredentials (sess , p .UserRoleArn , func (provider * stscreds.AssumeRoleProvider ) {
510509 if p .UserRoleExternalID != "" {
@@ -539,48 +538,48 @@ func validateStripPrefix(pattern string) error {
539538 if ! strings .HasPrefix (pattern , "/" ) {
540539 return fmt .Errorf ("strip_prefix must start with '/'" )
541540 }
542-
541+
543542 // Check length limit
544543 if len (pattern ) > 256 {
545544 return fmt .Errorf ("strip_prefix pattern too long (max 256 characters)" )
546545 }
547-
546+
548547 // Count wildcards
549548 wildcardCount := strings .Count (pattern , "*" ) + strings .Count (pattern , "?" )
550549 if wildcardCount > 20 {
551550 return fmt .Errorf ("strip_prefix pattern contains too many wildcards (max 20)" )
552551 }
553-
552+
554553 // Check for empty segments
555554 if strings .Contains (pattern , "//" ) {
556555 return fmt .Errorf ("strip_prefix pattern contains empty segment '//'" )
557556 }
558-
557+
559558 // Check for invalid ** usage (must be standalone segment)
560559 parts := strings .Split (pattern , "/" )
561560 for _ , part := range parts {
562561 if strings .Contains (part , "**" ) && part != "**" {
563562 return fmt .Errorf ("'**' must be a standalone directory segment" )
564563 }
565564 }
566-
565+
567566 return nil
568567}
569568
570569// patternToRegex converts shell-style wildcards to regex
571570func patternToRegex (pattern string ) (* regexp.Regexp , error ) {
572571 // Escape special regex characters except our wildcards
573572 escaped := regexp .QuoteMeta (pattern )
574-
575- // Replace escaped wildcards with regex equivalents
573+
574+ // Replace escaped wildcards with regex equivalents
576575 // Order matters: ** must be replaced before *
577- escaped = strings .ReplaceAll (escaped , `\*\*` , "(.+)" ) // ** -> (.+) any depth
578- escaped = strings .ReplaceAll (escaped , `\*` , "([^/]+)" ) // * -> ([^/]+) one segment
579- escaped = strings .ReplaceAll (escaped , `\?` , "([^/])" ) // ? -> ([^/]) one character
580-
576+ escaped = strings .ReplaceAll (escaped , `\*\*` , "(.+)" ) // ** -> (.+) any depth
577+ escaped = strings .ReplaceAll (escaped , `\*` , "([^/]+)" ) // * -> ([^/]+) one segment
578+ escaped = strings .ReplaceAll (escaped , `\?` , "([^/])" ) // ? -> ([^/]) one character
579+
581580 // Anchor at start
582581 escaped = "^" + escaped
583-
582+
584583 return regexp .Compile (escaped )
585584}
586585
@@ -589,12 +588,12 @@ func stripWildcardPrefix(path, pattern string) (string, error) {
589588 if pattern == "" {
590589 return path , nil
591590 }
592-
591+
593592 // Normalize paths
594593 path = filepath .ToSlash (path )
595594 pattern = filepath .ToSlash (pattern )
596-
597- // Handle literal prefix (no wildcards)
595+
596+ // Handle literal prefix (no wildcards)
598597 if ! strings .ContainsAny (pattern , "*?" ) {
599598 stripped := strings .TrimPrefix (path , pattern )
600599 // Validate result for literal prefix
@@ -603,28 +602,28 @@ func stripWildcardPrefix(path, pattern string) (string, error) {
603602 }
604603 return stripped , nil
605604 }
606-
605+
607606 // Convert pattern to regex
608607 re , err := patternToRegex (pattern )
609608 if err != nil {
610609 return path , fmt .Errorf ("invalid pattern: %v" , err )
611610 }
612-
611+
613612 // Find matches
614613 matches := re .FindStringSubmatch (path )
615614 if len (matches ) == 0 {
616615 // No match, return path unchanged
617616 return path , nil
618617 }
619-
618+
620619 // Calculate what to strip (the full match)
621620 fullMatch := matches [0 ]
622621 stripped := strings .TrimPrefix (path , fullMatch )
623-
622+
624623 // Validate result
625624 if stripped == "" || stripped == "/" || strings .TrimPrefix (stripped , "/" ) == "" {
626625 return path , fmt .Errorf ("strip_prefix removes entire path for '%s'" , filepath .Base (path ))
627626 }
628-
627+
629628 return stripped , nil
630629}
0 commit comments