Skip to content

Commit

Permalink
fix pl.path can't resolve the path started with ~ (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang authored Jan 15, 2024
1 parent fb70851 commit 893ed35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions spec/03-credentials/08-SharedFileCredentials_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ local origin_read = pl_config.read
local origin_isfile = pl_path.isfile

pl_config.read = function(name, ...)
return hooked_file[name] or origin_read(name, ...)
return hooked_file[pl_path.expanduser(name)] or origin_read(name, ...)
end

pl_path.isfile = function(name)
return hooked_file[name] and true or origin_isfile(name)
return hooked_file[pl_path.expanduser(name)] and true or origin_isfile(name)
end

local function hook_config_file(name, content)
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("SharedFileCredentials_spec", function()
end)

it("gets from config", function()
hook_config_file("~/.aws/config", {
hook_config_file(pl_path.expanduser("~/.aws/config"), {
default = {
aws_access_key_id = "access",
aws_secret_access_key = "secret",
Expand All @@ -58,7 +58,7 @@ describe("SharedFileCredentials_spec", function()
end)

it("gets from credentials", function()
hook_config_file("~/.aws/credentials", {
hook_config_file(pl_path.expanduser("~/.aws/credentials"), {
default = {
aws_access_key_id = "access",
aws_secret_access_key = "secret",
Expand Down
8 changes: 4 additions & 4 deletions src/resty/aws/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ do
-- returns an empty table if the section does not exist
local function load_file(filename, section)
assert(type(filename) == "string", "expected filename to be a string")
if not pl_path.isfile(filename) then
if not pl_path.isfile(pl_path.expanduser(filename)) then
return nil, "not a file: '"..filename.."'"
end

Expand Down Expand Up @@ -228,7 +228,7 @@ end
-- table if the config file does not exist.
-- @return options table as gotten from the configuration file, or nil+err.
function config.load_config()
if not pl_path.isfile(env_vars.AWS_CONFIG_FILE.value) then
if not pl_path.isfile(pl_path.expanduser(env_vars.AWS_CONFIG_FILE.value)) then
-- file doesn't exist
return {}
end
Expand All @@ -243,7 +243,7 @@ end
-- @return credentials table as gotten from the credentials file, or a table
-- with the key, id, and token from the configuration file, table can be empty.
function config.load_credentials()
if pl_path.isfile(env_vars.AWS_SHARED_CREDENTIALS_FILE.value) then
if pl_path.isfile(pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)) then
local creds = config.load_credentials_file(env_vars.AWS_SHARED_CREDENTIALS_FILE.value, env_vars.AWS_PROFILE.value)
if creds then -- ignore error, already logged
return creds
Expand Down Expand Up @@ -279,7 +279,7 @@ end
function config.get_config()
local cfg = config.load_config() or {} -- ignore error, already logged

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

0 comments on commit 893ed35

Please sign in to comment.