1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/requests/lambda/get_policy.rb
2015-06-23 09:53:53 -03:00

52 lines
1.7 KiB
Ruby

module Fog
module AWS
class Lambda
class Real
require 'fog/aws/parsers/lambda/base'
# Returns the access policy, containing a list of permissions granted via the AddPermission API, associated with the specified bucket.
# http://docs.aws.amazon.com/lambda/latest/dg/API_GetPolicy.html
# ==== Parameters
# * FunctionName <~String> - Function name whose access policy you want to retrieve.
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'Policy' <~Hash> - The access policy associated with the specified function.
def get_policy(params={})
function_name = params.delete('FunctionName')
request({
:method => 'GET',
:path => "/functions/#{function_name}/versions/HEAD/policy",
:parser => Fog::AWS::Parsers::Lambda::Base.new
}.merge(params))
end
end
class Mock
def get_policy(params={})
response = Excon::Response.new
function = self.get_function_configuration(params).body
function_arn = function['FunctionArn']
statements = self.data[:permissions][function_arn] || []
if statements.empty?
message = "ResourceNotFoundException => "
message << "The resource you requested does not exist."
raise Fog::AWS::Lambda::Error, message
end
policy = {
'Version' => '2012-10-17',
'Statement' => statements,
'Id' => 'default'
}
response.status = 200
response.body = { 'Policy' => policy }
response
end
end
end
end
end