Skip to content

Commit a00e2c7

Browse files
feat: [CI-18487]: Formatting
1 parent 9bbe70a commit a00e2c7

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ func run(c *cli.Context) error {
163163
_ = godotenv.Load(c.String("env-file"))
164164
}
165165

166-
167166
plugin := Plugin{
168167
Endpoint: c.String("endpoint"),
169168
Key: c.String("access-key"),
@@ -193,4 +192,3 @@ func run(c *cli.Context) error {
193192

194193
return plugin.Exec()
195194
}
196-

plugin.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
571570
func 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
}

wildcard_strip_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestStripWildcardPrefix(t *testing.T) {
111111
for _, tt := range tests {
112112
t.Run(tt.name, func(t *testing.T) {
113113
result, err := stripWildcardPrefix(tt.path, tt.pattern)
114-
114+
115115
if tt.expectError {
116116
if err == nil {
117117
t.Errorf("stripWildcardPrefix(%q, %q) expected error, got nil", tt.path, tt.pattern)
@@ -174,7 +174,7 @@ func TestPatternToRegex(t *testing.T) {
174174
if err != nil {
175175
t.Fatalf("patternToRegex(%q) error: %v", tt.pattern, err)
176176
}
177-
177+
178178
matches := re.MatchString(tt.testPath)
179179
if matches != tt.matches {
180180
t.Errorf("patternToRegex(%q).MatchString(%q) = %v, want %v", tt.pattern, tt.testPath, matches, tt.matches)
@@ -236,15 +236,15 @@ func TestResolveKeyWithWildcards(t *testing.T) {
236236
t.Run(tt.name, func(t *testing.T) {
237237
result := resolveKey(tt.target, tt.srcPath, tt.stripPrefix)
238238
if result != tt.expected {
239-
t.Errorf("resolveKey(%q, %q, %q) = %q, want %q",
239+
t.Errorf("resolveKey(%q, %q, %q) = %q, want %q",
240240
tt.target, tt.srcPath, tt.stripPrefix, result, tt.expected)
241241
}
242242
})
243243
}
244244
}
245245

246246
// ===============================
247-
// ERROR HANDLING TESTS
247+
// ERROR HANDLING TESTS
248248
// ===============================
249249

250250
func TestWildcardErrorHandling(t *testing.T) {
@@ -311,13 +311,13 @@ func TestWildcardErrorHandling(t *testing.T) {
311311
func BenchmarkStripWildcardPrefix(b *testing.B) {
312312
path := "/harness/artifacts/build-12345/services/auth/v1.2.3/auth-service.zip"
313313
pattern := "/harness/artifacts/*/services/*/"
314-
314+
315315
// Pre-compile pattern (this would happen once in real usage)
316316
_, err := patternToRegex(pattern)
317317
if err != nil {
318318
b.Fatalf("Failed to compile pattern: %v", err)
319319
}
320-
320+
321321
b.ResetTimer()
322322
for i := 0; i < b.N; i++ {
323323
_, _ = stripWildcardPrefix(path, pattern)

0 commit comments

Comments
 (0)