Sha256: a9e1fdd71c7b7aae3df769b4e55a871775b7961fdeff464524364a2037107d9b

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 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

            logger.info 'Service oidc updated'
          end

          private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb