File: get_function.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 (74 lines) | stat: -rw-r--r-- 2,532 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Fog
  module AWS
    class Lambda
      class Real
        require 'fog/aws/parsers/lambda/base'

        # Returns the configuration information of the Lambda function.
        # http://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html
        # ==== Parameters
        # * FunctionName <~String> - Lambda function name.
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'Code' <~Hash> - object for the Lambda function location.
        #     * 'Configuration' <~Hash> - function metadata description.
        def get_function(params={})
          function_name = params.delete('FunctionName')
          request({
            :method  => 'GET',
            :path    => "/functions/#{function_name}/versions/HEAD",
            :parser  => Fog::AWS::Parsers::Lambda::Base.new
          }.merge(params))
        end
      end

      class Mock
        def get_function(params={})
          response = Excon::Response.new
          response.status = 200
          response.body = ''

          unless function_id = params.delete('FunctionName')
            raise Fog::AWS::Lambda::Error, 'Function name cannot be blank.'
          end

          if function_id.match(/^arn:aws:lambda:.+:function:.+/)
            function = self.data[:functions][function_id]
          else
            search_function = Hash[
              self.data[:functions].select do |f,v|
                v['FunctionName'].eql?(function_id)
              end
            ]
            function = search_function.values.first
          end

          msg = 'The resource you requested does not exist.'
          raise Fog::AWS::Lambda::Error, msg if (function.nil? || function.empty?)

          location = "https://awslambda-#{self.region}-tasks.s3-#{self.region}"
          location << ".amazonaws.com/snapshot/#{self.account_id}/"
          location << "#{function['FunctionName']}-#{UUID.uuid}"
          location << '?x-amz-security-token='
          location << Fog::Mock.random_base64(718)
          location << "&AWSAccessKeyId=#{self.aws_access_key_id}"
          location << "&Expires=#{Time.now.to_i + 60*10}"
          location << '&Signature='
          location << Fog::Mock.random_base64(28)

          body = {
            'Code' => {
              'Location'       => location,
              'RepositoryType' => 'S3'
            },
            'Configuration' => function
          }
          response.body = body

          response
        end
      end
    end
  end
end