Skip to content

fix pl.path can't resolve the path started with ~ #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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