File: get_policy.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (52 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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