lib/kms_encrypted.rb in kms_encrypted-0.2.0 vs lib/kms_encrypted.rb in kms_encrypted-0.3.0

- old
+ new

@@ -1,69 +1,39 @@ # dependencies require "active_support" -begin - # aws-sdk v3 - require "aws-sdk-kms" -rescue LoadError - begin - # aws-sdk v2 - require "aws-sdk" - rescue LoadError - # do nothing - end -end - -begin - require "google/apis/cloudkms_v1" -rescue LoadError - # do nothing -end - # modules require "kms_encrypted/log_subscriber" require "kms_encrypted/model" require "kms_encrypted/version" module KmsEncrypted class << self - attr_writer :kms_client + attr_writer :aws_client + attr_writer :google_client + attr_writer :vault_client - def kms_client - @kms_client ||= Aws::KMS::Client.new(client_options) + def aws_client + @aws_client ||= Aws::KMS::Client.new( + retry_limit: 2, + http_open_timeout: 2, + http_read_timeout: 2 + ) end - alias_method :kms, :kms_client - # deprecated, use kms_client instead - attr_reader :client_options - - # deprecated, use kms_client instead - def client_options=(value) - @client_options = value - @kms_client = nil + def google_client + @google_client ||= begin + require "google/apis/cloudkms_v1" + client = ::Google::Apis::CloudkmsV1::CloudKMSService.new + client.authorization = ::Google::Auth.get_application_default( + "https://www.googleapis.com/auth/cloud-platform" + ) + client + end end - end - # deprecated, use kms_client instead - self.client_options = { - retry_limit: 2, - http_open_timeout: 2, - http_read_timeout: 2 - } - - module Google - class << self - attr_writer :kms_client - - def kms_client - @kms_client ||= begin - client = ::Google::Apis::CloudkmsV1::CloudKMSService.new - client.authorization = ::Google::Auth.get_application_default( - "https://www.googleapis.com/auth/cloud-platform" - ) - client - end - end + def vault_client + @vault_client ||= ::Vault end end end ActiveSupport.on_load(:active_record) do