diff --git a/src/resty/aws/credentials/CredentialProviderChain.lua b/src/resty/aws/credentials/CredentialProviderChain.lua index f54bd05..034755c 100644 --- a/src/resty/aws/credentials/CredentialProviderChain.lua +++ b/src/resty/aws/credentials/CredentialProviderChain.lua @@ -11,7 +11,10 @@ CredentialProviderChain.__index = CredentialProviderChain local aws_config = require("resty.aws.config") -CredentialProviderChain.defaultProviders = {} do +CredentialProviderChain.defaultProviders = {} + + +local function initialize() -- while not everything is implemented this will load what we do have without -- failing on what is missing. Will auto pick up newly added classes afterwards. local function add_if_exists(name, opts) @@ -41,6 +44,8 @@ CredentialProviderChain.defaultProviders = {} do else add_if_exists("EC2MetadataCredentials") end + + initialize = nil end --- Constructor, inherits from `Credentials`. @@ -65,6 +70,11 @@ end -- @param opt options table, additional fields to the `Credentials` class: -- @param opt.providers array of `Credentials` objects or functions (functions must return a `Credentials` object) function CredentialProviderChain:new(opts) + if initialize then + initialize() + initialize = nil + end + local self = Super:new(opts) -- override 'self' to be the new object/class setmetatable(self, CredentialProviderChain) diff --git a/src/resty/aws/credentials/RemoteCredentials.lua b/src/resty/aws/credentials/RemoteCredentials.lua index ecc1859..a3a7ac1 100644 --- a/src/resty/aws/credentials/RemoteCredentials.lua +++ b/src/resty/aws/credentials/RemoteCredentials.lua @@ -15,9 +15,11 @@ local http = require "resty.luasocket.http" local json = require "cjson" -local FullUri do - -- construct the URL +local FullUri + +local function initialize() + -- construct the URL local function makeset(t) for i = 1, #t do t[t[i]] = true @@ -73,8 +75,9 @@ local FullUri do FullUri.port = FullUri.port or ({ http = 80, https = 443 })[FullUri.scheme] end -end + initialize = nil +end -- Create class @@ -96,6 +99,10 @@ end -- updates credentials. -- @return success, or nil+err function RemoteCredentials:refresh() + if initialize then + initialize() + end + if not FullUri then return nil, "No URI environment variables found for RemoteCredentials" end