Class: ThreeScaleToolbox::Commands::ImportCommand::OpenAPI::UpdatePoliciesStep

Inherits:
Object
  • Object
show all
Includes:
Step
Defined in:
lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb

Instance Attribute Summary

Attributes included from Step

#context

Instance Method Summary collapse

Methods included from Step

#api_spec, #backend_api_host_header, #backend_api_secret_token, #base_path, #build_3scale_operations, #default_credentials_userkey, #initialize, #oidc_issuer_endpoint, #oidc_issuer_type, #operations, #override_private_base_url, #override_private_basepath, #override_public_basepath, #prefix_matching, #private_base_path, #production_public_base_url, #public_base_path, #resource, #service, #service=, #staging_public_base_url, #target_system_name, #threescale_client

Instance Method Details

#callObject

Updates Proxy Policies config



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb', line 10

def call
  # to be idempotent, we must read first
  source_policies_settings = service.policies
  # shallow copy
  # to detect policies_settings changes, should only be updated setting objects
  # do not update in-place, otherwise changes will not be detected
  policies_settings = source_policies_settings.dup

  add_anonymous_access_policy(policies_settings)
  add_rh_sso_keycloak_role_check_policy(policies_settings)
  add_url_rewritting_policy(policies_settings)

  return if source_policies_settings == policies_settings

  res = service.update_policies('policies_config' => policies_settings)
  if res.is_a?(Hash) && (errors = res['errors'])
    raise ThreeScaleToolbox::Error, "Service policies have not been updated. #{errors}"
  end

  puts 'Service policies updated'
end