Module: GeoEngineer::ApiGatewayHelpers::ClassMethods

Defined in:
lib/geoengineer/resources/api_gateway/helpers.rb

Overview

Class Methods

Instance Method Summary collapse

Instance Method Details

#__fetch_remote_rest_api_resources_for_rest_api(provider, rr) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 49

def __fetch_remote_rest_api_resources_for_rest_api(provider, rr)
  _client(provider).get_resources({
                                    rest_api_id: rr[:_terraform_id]
                                  })['items'].map(&:to_h).map do |res|
    next nil unless res[:path_part] # default resource has no path_part
    res[:_terraform_id] = res[:id]
    res[:_geo_id]       = "#{rr[:_geo_id]}::#{res[:path_part]}"
    res
  end.compact
end

#_client(provider) ⇒ Object

Helper Client



23
24
25
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 23

def _client(provider)
  AwsClients.api_gateway(provider)
end

#_fetch_integration(provider, rr, res, meth) ⇒ Object

Integration



86
87
88
89
90
91
92
93
94
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 86

def _fetch_integration(provider, rr, res, meth)
  return _client(provider).get_integration({
                                             rest_api_id: rr[:_terraform_id],
                                             resource_id: res[:_terraform_id],
                                             http_method: meth
                                           }).to_h
rescue Aws::APIGateway::Errors::NotFoundException
  return nil
end

#_fetch_method(provider, rr, res, meth) ⇒ Object

Method



97
98
99
100
101
102
103
104
105
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 97

def _fetch_method(provider, rr, res, meth)
  return _client(provider).get_method({
                                        rest_api_id: rr[:_terraform_id],
                                        resource_id: res[:_terraform_id],
                                        http_method: meth
                                      }).to_h
rescue Aws::APIGateway::Errors::NotFoundException
  return nil
end

#_fetch_remote_rest_api_resources_for_rest_api(provider, rr) ⇒ Object

Resources



61
62
63
64
65
66
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 61

def _fetch_remote_rest_api_resources_for_rest_api(provider, rr)
  cache = GeoEngineer::ApiGatewayHelpers._rest_api_resource_cache[provider] ||= {}
  return cache[rr[:_terraform_id]] if cache[rr[:_terraform_id]]

  cache[rr[:_terraform_id]] = __fetch_remote_rest_api_resources_for_rest_api(provider, rr)
end

#_fetch_remote_rest_apis(provider) ⇒ Object

Rest API



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 28

def _fetch_remote_rest_apis(provider)
  cache = GeoEngineer::ApiGatewayHelpers._rest_api_cache
  return cache[provider] if cache[provider]

  ret = _client(provider).get_rest_apis['items'].map(&:to_h).map do |rr|
    rr[:_terraform_id]    = rr[:id]
    rr[:_geo_id]          = rr[:name]
    rr[:root_resource_id] = _root_resource_id(provider, rr)
    rr
  end.compact
  cache[provider] = ret
  ret
end

#_remote_rest_api_resource(provider) ⇒ Object

Combination Methods



69
70
71
72
73
74
75
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 69

def _remote_rest_api_resource(provider)
  _fetch_remote_rest_apis(provider).map do |rr|
    _fetch_remote_rest_api_resources_for_rest_api(provider, rr).map do |res|
      yield rr, res
    end
  end
end

#_remote_rest_api_resource_method(provider) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 77

def _remote_rest_api_resource_method(provider)
  _remote_rest_api_resource(provider) do |rr, res|
    (res[:resource_methods] || {}).keys.map do |meth|
      yield rr, res, meth
    end
  end
end

#_root_resource_id(provider, rr) ⇒ Object



42
43
44
45
46
47
# File 'lib/geoengineer/resources/api_gateway/helpers.rb', line 42

def _root_resource_id(provider, rr)
  _client(provider).get_resources({ rest_api_id: rr[:id] })['items'].map do |res|
    return res.id if res.path == '/'
  end
  nil
end