Skip to content

Replace periods underscore kong2tf#1756

Merged
harshadixit12 merged 3 commits intomainfrom
replace-periods-underscore-kong2tf
Sep 12, 2025
Merged

Replace periods underscore kong2tf#1756
harshadixit12 merged 3 commits intomainfrom
replace-periods-underscore-kong2tf

Conversation

@mheap
Copy link
Member

@mheap mheap commented Sep 11, 2025

Resolves #1752

@mheap mheap requested a review from harshadixit12 September 11, 2025 12:41
@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.94%. Comparing base (d48b55b) to head (40b4b33).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
kong2tf/generate_resource.go 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1756      +/-   ##
==========================================
+ Coverage   32.85%   32.94%   +0.08%     
==========================================
  Files          73       73              
  Lines        8053     8068      +15     
==========================================
+ Hits         2646     2658      +12     
- Misses       5243     5245       +2     
- Partials      164      165       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}

// slugify converts a string into a slug using underscores
func slugify(input string) string {
Copy link
Contributor

@harshadixit12 harshadixit12 Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still allow characters like @, # to go through, but terraform does not allow in resource names.
Kong allows these in the entity names though.

What if we do something like this using unicode package -

Suggested change
func slugify(input string) string {
func keepRuneUnicode(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' || r == '-' {
return r
}
return '_'
}
func slugify(input string) string {
slug := strings.Map(keepRuneUnicode, input)
// Remove any consecutive underscores
for strings.Contains(slug, "__") {
slug = strings.ReplaceAll(slug, "__", "_")
}
// Trim leading and trailing underscores
slug = strings.Trim(slug, "_")
return slug
}

This would replace all disallowed characters with _

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me. Can you commit + add any additional test cases you think are important?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll do 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll do 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added tests and this change in 40b4b33, will merge if looks good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@harshadixit12 harshadixit12 merged commit 8e4e308 into main Sep 12, 2025
47 of 55 checks passed
@harshadixit12 harshadixit12 deleted the replace-periods-underscore-kong2tf branch September 12, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kong2tf bug when using a .

3 participants