Skip to content

Commit 893ed35

Browse files
authored
fix pl.path can't resolve the path started with ~ (#94)
1 parent fb70851 commit 893ed35

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

spec/03-credentials/08-SharedFileCredentials_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ local origin_read = pl_config.read
88
local origin_isfile = pl_path.isfile
99

1010
pl_config.read = function(name, ...)
11-
return hooked_file[name] or origin_read(name, ...)
11+
return hooked_file[pl_path.expanduser(name)] or origin_read(name, ...)
1212
end
1313

1414
pl_path.isfile = function(name)
15-
return hooked_file[name] and true or origin_isfile(name)
15+
return hooked_file[pl_path.expanduser(name)] and true or origin_isfile(name)
1616
end
1717

1818
local function hook_config_file(name, content)
@@ -40,7 +40,7 @@ describe("SharedFileCredentials_spec", function()
4040
end)
4141

4242
it("gets from config", function()
43-
hook_config_file("~/.aws/config", {
43+
hook_config_file(pl_path.expanduser("~/.aws/config"), {
4444
default = {
4545
aws_access_key_id = "access",
4646
aws_secret_access_key = "secret",
@@ -58,7 +58,7 @@ describe("SharedFileCredentials_spec", function()
5858
end)
5959

6060
it("gets from credentials", function()
61-
hook_config_file("~/.aws/credentials", {
61+
hook_config_file(pl_path.expanduser("~/.aws/credentials"), {
6262
default = {
6363
aws_access_key_id = "access",
6464
aws_secret_access_key = "secret",

src/resty/aws/config.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ do
169169
-- returns an empty table if the section does not exist
170170
local function load_file(filename, section)
171171
assert(type(filename) == "string", "expected filename to be a string")
172-
if not pl_path.isfile(filename) then
172+
if not pl_path.isfile(pl_path.expanduser(filename)) then
173173
return nil, "not a file: '"..filename.."'"
174174
end
175175

@@ -228,7 +228,7 @@ end
228228
-- table if the config file does not exist.
229229
-- @return options table as gotten from the configuration file, or nil+err.
230230
function config.load_config()
231-
if not pl_path.isfile(env_vars.AWS_CONFIG_FILE.value) then
231+
if not pl_path.isfile(pl_path.expanduser(env_vars.AWS_CONFIG_FILE.value)) then
232232
-- file doesn't exist
233233
return {}
234234
end
@@ -243,7 +243,7 @@ end
243243
-- @return credentials table as gotten from the credentials file, or a table
244244
-- with the key, id, and token from the configuration file, table can be empty.
245245
function config.load_credentials()
246-
if pl_path.isfile(env_vars.AWS_SHARED_CREDENTIALS_FILE.value) then
246+
if pl_path.isfile(pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)) then
247247
local creds = config.load_credentials_file(env_vars.AWS_SHARED_CREDENTIALS_FILE.value, env_vars.AWS_PROFILE.value)
248248
if creds then -- ignore error, already logged
249249
return creds
@@ -279,7 +279,7 @@ end
279279
function config.get_config()
280280
local cfg = config.load_config() or {} -- ignore error, already logged
281281

282-
if pl_path.isfile(env_vars.AWS_SHARED_CREDENTIALS_FILE.value) then
282+
if pl_path.isfile(pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)) then
283283
-- there is a creds file, so override creds with creds file
284284
local creds = config.load_credentials_file(
285285
env_vars.AWS_SHARED_CREDENTIALS_FILE.value, env_vars.AWS_PROFILE.value) -- ignore error, already logged

0 commit comments

Comments
 (0)