Class: Jets::CLI::Curl::Adapter::Lambda
- Defined in:
- lib/jets/cli/curl/adapter/lambda.rb
Instance Method Summary collapse
- #api_id ⇒ Object
- #aws_region ⇒ Object
- #body ⇒ Object
- #convert ⇒ Object
- #cookies ⇒ Object
- #default_headers ⇒ Object
- #default_host ⇒ Object
- #headers ⇒ Object
- #headers_option ⇒ Object
- #host ⇒ Object
- #http_method ⇒ Object
-
#parse_query_string(raw_query_string) ⇒ Object
AWS Lambda 2.0 Behavior docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html.
- #path ⇒ Object
- #raw_query_string ⇒ Object
- #request_context ⇒ Object
- #uri ⇒ Object
- #user_agent ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Jets::CLI::Curl::Adapter::Base
Instance Method Details
#api_id ⇒ Object
100 101 102 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 100 def api_id "dummy" end |
#aws_region ⇒ Object
104 105 106 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 104 def aws_region Jets.aws.region end |
#body ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 23 def body data = @options[:data] return unless data if data.starts_with?("@") file = data[1..] file = "#{Jets.root}/#{file}" unless file.starts_with?("/") IO.read(file) # IE: @data.json else data end end |
#convert ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 5 def convert { version: "2.0", routeKey: "$default", rawPath: path, rawQueryString: raw_query_string, cookies: , body: body, headers: headers, requestContext: request_context, isBase64Encoded: false }.delete_if { |k, v| v.nil? }.to_json end |
#cookies ⇒ Object
19 20 21 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 19 def Cookies::Parser.new(@options[:cookie]).parse if @options[:cookie] end |
#default_headers ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 39 def default_headers { host: host, "x-forwarded-proto": "https", "x-forwarded-port": "443", "x-forwarded-for": "127.0.0.1", "user-agent": "jets curl (#{Jets::VERSION})" } end |
#default_host ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 62 def default_host host = uri.host if host && (host.include?("amazonaws.com") || host.include?(".aws")) host else "#{api_id}.lambda-url.#{aws_region}.on.aws" end end |
#headers ⇒ Object
35 36 37 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 35 def headers default_headers.merge(headers_option) end |
#headers_option ⇒ Object
49 50 51 52 53 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 49 def headers_option headers = @options[:headers] || {} headers["user-agent"] = user_agent if user_agent headers.transform_keys(&:downcase).transform_values(&:strip) end |
#host ⇒ Object
55 56 57 58 59 60 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 55 def host return default_host unless @options[:headers] deleted_host = @options[:headers].delete("Host")&.strip host = @options[:headers][:host] || deleted_host host || default_host end |
#http_method ⇒ Object
108 109 110 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 108 def http_method @options[:request] || "GET" end |
#parse_query_string(raw_query_string) ⇒ Object
AWS Lambda 2.0 Behavior docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 126 def parse_query_string(raw_query_string) query_params = {} raw_query_string.split("&").each do |param| key, value = param.split("=") key = key.to_sym if query_params.key?(key) query_params[key] += ",#{value}" else query_params[key] = value end end query_params.transform_values! { |value| value.include?(",") ? value.split(",") : value } end |
#path ⇒ Object
116 117 118 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 116 def path uri.path end |
#raw_query_string ⇒ Object
120 121 122 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 120 def raw_query_string uri.query end |
#request_context ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 78 def request_context now = Time.now.utc { accountId: "anonymous", apiId: api_id, domainName: host, domainPrefix: api_id, http: { method: http_method, path: path, protocol: "HTTP/1.1", sourceIp: "127.0.0.1", userAgent: user_agent }, requestId: "3fca3afe-2fb7-4e93-ac3b-949519408c39", routeKey: "$default", stage: "$default", time: now.strftime("%d/%b/%Y:%H:%M:%S %z"), timeEpoch: now.to_i } end |
#uri ⇒ Object
112 113 114 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 112 def uri URI.parse(@options[:path]) end |
#user_agent ⇒ Object
71 72 73 74 75 |
# File 'lib/jets/cli/curl/adapter/lambda.rb', line 71 def user_agent return unless @options[:headers] deleted_user_agent = @options[:headers].delete("User-Agent")&.strip @options[:headers]["user-agent"] || deleted_user_agent end |