1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/lib/omni_auth/data_mapping/base.rb

51 lines
1.3 KiB
Ruby

# frozen_string_literal: true
# Data mapping functions for SSO authentications (through OmniAuth)
module OmniAuth::DataMapping
# Type-dependant mapping functions
module Base
extend ActiveSupport::Concern
included do
def local_sym(mapping)
(mapping.local_model + '.' + mapping.local_field).to_sym
end
def map_transformation(transformation, raw_data)
value = nil
transformation['mapping'].each do |m|
if m['from'] == raw_data
value = m['to']
break
end
end
# if no transformation had set any value, return the raw value
value || raw_data
end
def map_boolean(transformation, raw_data)
return false if raw_data == transformation['false_value']
true if raw_data == transformation['true_value']
end
def map_date(transformation, raw_data)
case transformation['format']
when 'iso8601'
DateTime.iso8601(raw_data)
when 'rfc2822'
DateTime.rfc2822(raw_data)
when 'rfc3339'
DateTime.rfc3339(raw_data)
when 'timestamp-s'
DateTime.strptime(raw_data, '%s')
when 'timestamp-ms'
DateTime.strptime(raw_data, '%Q')
else
DateTime.parse(raw_data)
end
end
end
end
end