Skip to content
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

fix(*): patch expanduser to be more friendly to OpenResty environment #111

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions spec/03-credentials/08-SharedFileCredentials_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local pl_path = require "pl.path"
local pl_config = require "pl.config"
local tbl_clear = require "table.clear"
local restore = require "spec.helpers"

local hooked_file = {}

Expand All @@ -24,12 +25,15 @@
local SharedFileCredentials_spec

before_each(function()
-- make ci happy
restore.setenv("HOME", "/home/ci-test")
windmgc marked this conversation as resolved.
Show resolved Hide resolved
local _ = require("resty.aws.config").global -- load config before anything else

SharedFileCredentials_spec = require "resty.aws.credentials.SharedFileCredentials"
end)

after_each(function()
restore()
tbl_clear(hooked_file)
end)

Expand Down
17 changes: 13 additions & 4 deletions src/resty/aws/config.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--- Load AWS configuration.
--
-- This is based of [Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
Expand Down Expand Up @@ -178,7 +178,13 @@
-- 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(pl_path.expanduser(filename)) then

local expanded_path, err = pl_path.expanduser(filename)
if not expanded_path then
return nil, "failed expanding path '"..filename.."': "..tostring(err)
end

if not pl_path.isfile(expanded_path) then
return nil, "not a file: '"..filename.."'"
end

Expand Down Expand Up @@ -237,7 +243,8 @@
-- 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(pl_path.expanduser(env_vars.AWS_CONFIG_FILE.value)) then
local expanded_path = pl_path.expanduser(env_vars.AWS_CONFIG_FILE.value)
if not (expanded_path and pl_path.isfile(expanded_path)) then
-- file doesn't exist
return {}
end
Expand All @@ -252,7 +259,8 @@
-- @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(pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)) then
local expanded_path = pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)
if expanded_path and pl_path.isfile(expanded_path) 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 @@ -288,7 +296,8 @@
function config.get_config()
local cfg = config.load_config() or {} -- ignore error, already logged

if pl_path.isfile(pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)) then
local expanded_path = pl_path.expanduser(env_vars.AWS_SHARED_CREDENTIALS_FILE.value)
if expanded_path and pl_path.isfile(expanded_path) 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
Loading