2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-17 12:31:24 +00:00
|
|
|
require 'carrierwave/orm/activerecord'
|
|
|
|
|
2019-03-28 13:17:42 +00:00
|
|
|
class ProjectImportData < ApplicationRecord
|
2017-08-03 12:19:11 +00:00
|
|
|
belongs_to :project, inverse_of: :import_data
|
2016-04-11 09:13:51 +00:00
|
|
|
attr_encrypted :credentials,
|
2018-05-19 13:03:29 +00:00
|
|
|
key: Settings.attr_encrypted_db_key_base,
|
2016-04-11 09:13:51 +00:00
|
|
|
marshal: true,
|
|
|
|
encode: true,
|
2016-05-19 18:55:25 +00:00
|
|
|
mode: :per_attribute_iv_and_salt,
|
2016-06-28 07:55:19 +00:00
|
|
|
insecure_mode: true,
|
2016-05-19 18:55:25 +00:00
|
|
|
algorithm: 'aes-256-cbc'
|
2016-03-03 17:10:06 +00:00
|
|
|
|
2017-07-03 14:01:41 +00:00
|
|
|
serialize :data, JSON # rubocop:disable Cop/ActiveRecordSerialize
|
2015-04-17 12:31:24 +00:00
|
|
|
|
|
|
|
validates :project, presence: true
|
2016-04-01 10:04:41 +00:00
|
|
|
|
2016-04-05 13:41:15 +00:00
|
|
|
before_validation :symbolize_credentials
|
|
|
|
|
|
|
|
def symbolize_credentials
|
2016-04-11 09:13:51 +00:00
|
|
|
# bang doesn't work here - attr_encrypted makes it not to work
|
2016-04-06 08:36:30 +00:00
|
|
|
self.credentials = self.credentials.deep_symbolize_keys unless self.credentials.blank?
|
2016-04-01 10:04:41 +00:00
|
|
|
end
|
2018-12-10 17:09:33 +00:00
|
|
|
|
|
|
|
def merge_data(hash)
|
|
|
|
self.data = data.to_h.merge(hash) unless hash.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_credentials(hash)
|
|
|
|
self.credentials = credentials.to_h.merge(hash) unless hash.empty?
|
|
|
|
end
|
2019-01-14 19:44:36 +00:00
|
|
|
|
|
|
|
def clear_credentials
|
|
|
|
self.credentials = {}
|
|
|
|
end
|
2015-04-17 12:31:24 +00:00
|
|
|
end
|