Skip to content

fix(region_config): fix configure endpoint bug in getRegionPrefix#129

Merged
windmgc merged 2 commits into
mainfrom
fix-cn-region-sts-endpoint
Aug 21, 2024
Merged

fix(region_config): fix configure endpoint bug in getRegionPrefix#129
windmgc merged 2 commits into
mainfrom
fix-cn-region-sts-endpoint

Conversation

@windmgc
Copy link
Copy Markdown
Member

@windmgc windmgc commented Aug 15, 2024

Summary

This PR fixes a bug inside generateRegionPrefix that caused some service endpoint in specific region is not getting configured correctly.

local function generateRegionPrefix(region)
if not region then
return nil, "no region given"
end
local parts = split(region, "-", true)
if #parts < 3 then
return nil, "not a valid region, only 2 parts; "..region
end
parts[#parts] = "*"
return table.concat(parts, "-")
end

This code originates from the JS code here:

function generateRegionPrefix(region) {
  if (!region) return null;
  var parts = region.split('-');
  if (parts.length < 3) return null;
  return parts.slice(0, parts.length - 2).join('-') + '-*';
}

There is a bug in our Lua code, that parts.slice(0, parts.length - 2).join('-') + '-*' is fetching the [0, #parts-2) items from the region parts and concatenating with another asterisk. But our SDK is just replacing the last item in the array with an asterisk, which equals fetching [0, #parts-2] and concatenating with another asterisk. (Here I'm using an index starting with 0 to clarify the difference). This caused different results when we generated region prefixes: a region cn-north-1 will result in cn-* in the JS function and cn-north-* in the Lua function.

The PR fixes it and lets the region_config_data apply correctly.

Issue

FTI-6159 mentioned an issue caused by this bug, which happens inside cn-north-1 that is expected to apply the cn-*/* endpoint config. The bug caused a mismatch and endpoint config cannot be applied correctly. This bug would also influence other regions like us-isob-east-1

@windmgc windmgc requested a review from Tieske August 15, 2024 08:52
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 15, 2024

Luacheck Report

2 tests   2 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 93d3c6b.

♻️ This comment has been updated with latest results.

Comment thread src/resty/aws/init.lua Outdated
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.

4 participants