Sha256: f3e469ae6f3098986a2521e411cb52775c52073f8cffd5e7c43d39bbcdad04cb

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ImportCommand
      module OpenAPI
        class UpdateServiceOidcConfStep
          include Step

          ##
          # Updates OIDC config
          def call
            # setting required attrs, operation is idempotent
            oidc_settings = {}

            add_flow_settings(oidc_settings)

            return unless oidc_settings.size.positive?

            res = service.update_oidc oidc_settings
            if (errors = res['errors'])
              raise ThreeScaleToolbox::Error, "Service oidc has not been updated. #{errors}"
            end

            puts 'Service oidc updated'
          end

          private

          def add_flow_settings(settings)
            # only applies to oauth2 sec type
            return if security.nil? || security.type != 'oauth2'

            oidc_configuration = {
              standard_flow_enabled: false,
              implicit_flow_enabled: false,
              service_accounts_enabled: false,
              direct_access_grants_enabled: false
            }.merge(flow => true)
            settings.merge!(oidc_configuration)
          end

          def flow
            case (flow_f = security.flow)
            when 'implicit'
              :implicit_flow_enabled
            when 'password'
              :direct_access_grants_enabled
            when 'application'
              :service_accounts_enabled
            when 'accessCode'
              :standard_flow_enabled
            else
              raise ThreeScaleToolbox::Error, "Unexpected security flow field #{flow_f}"
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.9.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
3scale_toolbox-0.8.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb