Module: ThreeScaleToolbox::CRD::ProductSerializer

Included in:
Entities::Service
Defined in:
lib/3scale_toolbox/crds/product_dump.rb

Instance Method Summary collapse

Instance Method Details

#appkey_authentication_to_crObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 96

def appkey_authentication_to_cr
  {
    'appKeyAppID' => {
      'appID' => cached_proxy['auth_app_id'],
      'appKey' => cached_proxy['auth_app_key'],
      'credentials' => cached_proxy['credentials_location'],
      'security' => security_to_cr,
      'gatewayResponse' => gateway_response_to_cr
    }
  }
end

#authentication_to_crObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 72

def authentication_to_cr
  case backend_version
  when '1'
    userkey_authentication_to_cr
  when '2'
    appkey_authentication_to_cr
  when 'oidc'
    oidc_authentication_to_cr
  else
    raise ThreeScaleToolbox::Error, "Unknown backend_version: #{backend_version}"
  end
end

#cr_nameObject



38
39
40
41
42
43
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 38

def cr_name
  # Should be DNS1123 subdomain name
  # TODO run validation for DNS1123
  # https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
  "#{system_name.gsub(/[^[a-zA-Z0-9\-\.]]/, '.')}.#{Helper.random_lowercase_name}"
end

#deployment_to_crObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 45

def deployment_to_cr
  case deployment_option
  when 'hosted'
    hosted_deployment_to_cr
  when 'self_managed'
    self_managed_deployment_to_cr
  else
    raise ThreeScaleToolbox::Error, "Unknown deployment option: #{deployment_option}"
  end
end

#gateway_response_to_crObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 139

def gateway_response_to_cr
  {
    'errorStatusAuthFailed' => cached_proxy['error_status_auth_failed'],
    'errorHeadersAuthFailed' => cached_proxy['error_headers_auth_failed'],
    'errorAuthFailed' => cached_proxy['error_auth_failed'],
    'errorStatusAuthMissing' => cached_proxy['error_status_auth_missing'],
    'errorHeadersAuthMissing' => cached_proxy['error_headers_auth_missing'],
    'errorAuthMissing' => cached_proxy['error_auth_missing'],
    'errorStatusNoMatch' => cached_proxy['error_status_no_match'],
    'errorHeadersNoMatch' => cached_proxy['error_headers_no_match'],
    'errorNoMatch' => cached_proxy['error_no_match'],
    'errorStatusLimitsExceeded' => cached_proxy['error_status_limits_exceeded'],
    'errorHeadersLimitsExceeded' => cached_proxy['error_headers_limits_exceeded'],
    'errorLimitsExceeded' => cached_proxy['error_limits_exceeded']
  }
end

#hosted_deployment_to_crObject



56
57
58
59
60
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 56

def hosted_deployment_to_cr
  {
    'apicastHosted' => { 'authentication' => authentication_to_cr }
  }
end

#oidc_authentication_to_crObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 108

def oidc_authentication_to_cr
  {
    'oidc' => {
      'issuerType' => cached_proxy['oidc_issuer_type'],
      'issuerEndpoint' => cached_proxy['oidc_issuer_endpoint'],
      'jwtClaimWithClientID' => cached_proxy['jwt_claim_with_client_id'],
      'jwtClaimWithClientIDType' => cached_proxy['jwt_claim_with_client_id_type'],
      'authenticationFlow' => oidc_flow_to_cr,
      'credentials' => cached_proxy['credentials_location'],
      'security' => security_to_cr,
      'gatewayResponse' => gateway_response_to_cr
    }
  }
end

#oidc_flow_to_crObject



123
124
125
126
127
128
129
130
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 123

def oidc_flow_to_cr
  {
    'standardFlowEnabled' => cached_oidc['standard_flow_enabled'],
    'implicitFlowEnabled' => cached_oidc['implicit_flow_enabled'],
    'serviceAccountsEnabled' => cached_oidc['service_accounts_enabled'],
    'directAccessGrantsEnabled' => cached_oidc['direct_access_grants_enabled']
  }
end

#security_to_crObject



132
133
134
135
136
137
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 132

def security_to_cr
  {
    'hostHeader' => cached_proxy['hostname_rewrite'],
    'secretToken' => cached_proxy['secret_token']
  }
end

#self_managed_deployment_to_crObject



62
63
64
65
66
67
68
69
70
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 62

def self_managed_deployment_to_cr
  {
    'apicastSelfManaged' => {
      'authentication' => authentication_to_cr,
      'stagingPublicBaseURL' => cached_proxy['sandbox_endpoint'],
      'productionPublicBaseURL' => cached_proxy['endpoint']
    }
  }
end

#to_crObject



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
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 4

def to_cr
  {
    'apiVersion' => 'capabilities.3scale.net/v1beta1',
    'kind' => 'Product',
    'metadata' => {
      'annotations' => {
        '3scale_toolbox_created_at' => Time.now.utc.iso8601,
        '3scale_toolbox_version' => ThreeScaleToolbox::VERSION
      },
      'name' => cr_name
    },
    'spec' => {
      'name' => name,
      'systemName' => system_name,
      'description' => description,
      'mappingRules' => mapping_rules.map(&:to_cr),
      'metrics' => metrics.each_with_object({}) do |metric, hash|
        hash[metric.system_name] = metric.to_cr
      end,
      'methods' => methods.each_with_object({}) do |method, hash|
        hash[method.system_name] = method.to_cr
      end,
      'policies' => policies,
      'applicationPlans' => plans.each_with_object({}) do |app_plan, hash|
        hash[app_plan.system_name] = app_plan.to_cr
      end,
      'backendUsages' => backend_usage_list.each_with_object({}) do |backend_usage, hash|
        hash[backend_usage.backend.system_name] = backend_usage.to_cr
      end,
      'deployment' => deployment_to_cr
    }
  }
end

#userkey_authentication_to_crObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/3scale_toolbox/crds/product_dump.rb', line 85

def userkey_authentication_to_cr
  {
    'userkey' => {
      'authUserKey' => cached_proxy['auth_user_key'],
      'credentials' => cached_proxy['credentials_location'],
      'security' => security_to_cr,
      'gatewayResponse' => gateway_response_to_cr
    }
  }
end