Skip to content

Commit

Permalink
fix(secret): code and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanXin-Chen committed Jul 29, 2024
1 parent f4098c0 commit 76acb11
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
30 changes: 11 additions & 19 deletions apisix/secret/aws.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,27 @@ local function make_request_to_aws(conf,key)

local session_token = env.fetch_by_uri(conf.session_token) or conf.session_token

local credentials = aws_instance:Credentials {
local credentials = aws_instance:Credentials({
accessKeyId = access_key_id,
secretAccessKey = secret_access_key,
sessionToken = session_token,
}
})

local default_endpoint = "https://secretsmanager." .. region .. ".amazonaws.com"
local pre, host, port, _, _ = unpack(http:parse_uri(conf.endpoint_url or default_endpoint))
local endpoint = pre .. "://" .. host

local sm = aws_instance:SecretsManager {
local sm = aws_instance:SecretsManager({
credentials = credentials,
endpoint = endpoint,
region = region,
port = port,
}
})

local res, err = sm:getSecretValue {
local res, err = sm:getSecretValue({
SecretId = key,
VersionStage = "AWSCURRENT",
}
})

if type(res) ~= "table" then
if err then
Expand All @@ -95,17 +95,13 @@ local function make_request_to_aws(conf,key)
if res.status ~= 200 then
local body = res.body
if type(body) == "table" then
local data, err = core.json.encode(body)
if err then
return nil, "invalid status code " .. res.status .. ", " .. err
end

local data = core.json.encode(body)
if data then
return nil, "invalid status code " .. res.status .. ", " .. data
end
end

return nil, "invalid status code received " .. res.status
return nil, "invalid status code " .. res.status
end

local body = res.body
Expand Down Expand Up @@ -147,16 +143,12 @@ local function get(conf,key)
return nil, "failed to retrtive data from aws secret manager: " .. err
end

local data, err = core.json.decode(res)
if not data then
if err then
return nil, "failed to decode result, res: " .. res .. ", " .. err
end

local ret = core.json.decode(res)
if not ret then
return nil, "failed to decode result, res: " .. res
end

return data[sub_key]
return ret[sub_key]
end

_M.get = get
Expand Down
2 changes: 0 additions & 2 deletions ci/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ linux_get_dependencies () {
apt update
apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl libpcre3 libpcre3-dev libldap2-dev
apt-get install -y libyaml-dev
wget https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.gz
tar -xzf expat-2.5.0.tar.gz && cd expat-2.5.0 && ./configure && sudo make install && cd ..
wget https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
}

Expand Down
2 changes: 2 additions & 0 deletions utils/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function install_apisix_runtime() {
chmod +x build-apisix-runtime.sh
./build-apisix-runtime.sh latest
rm build-apisix-runtime.sh
wget https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.gz
tar -xzf expat-2.5.0.tar.gz && cd expat-2.5.0 && ./configure && sudo make install && cd ..
}

# Install LuaRocks
Expand Down

0 comments on commit 76acb11

Please sign in to comment.