模块:Mongo::Crypt::KMS::Validations Private

Overview

该模块是私有 API 的一部分。 您应尽可能避免使用此模块,因为它将来可能会被删除或更改。

此模块包含用于验证 KMS 参数的辅助方法。

类方法摘要折叠

实例方法摘要折叠

类方法详细信息

.validate_tls_options(options) ⇒ Hash

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

验证KMS TLS 选项。

参数:

  • 选项 ( Hash | nil )

    用于连接到 KMS 提供商的 TLS 选项。 哈希键应为 KSM 提供程序名称;值应该是 TLS 连接选项的哈希值。 这些选项相当于 Mongo::Client 的 TLS 连接选项。

返回:

  • (哈希)

    提供的 TLS 选项(如果有效)。

引发:

  • ( ArgumentError )

    如果必需的选项丢失或格式不正确。



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ Mongo/crypt/kms.rb', line 85

def validate_tls_options(选项)
  opts = 选项 || {}
  opts. do |provider, provider_opts|
    if provider_opts[:ssl] == false || opts[:tls] == false
      提高 ArgumentError.new(
        " #{ 提供商} 的 TLS 选项不正确 :需要 TLS "
      )
    end
    %i[
      ssl_verify_certificate
      ssl_verify_hostname
    ]. do |opt|
      来年 除非 provider_opts[opt] == false

      提高 ArgumentError.new(
        " #{ provider } 的 TLS 选项不正确 " +
        '禁止不安全的 TLS 选项, ' +
        " KMS 的#{ opt }不能设置为 false "
      )
    end
  end
  opts
end

实例方法详细信息

# validate_param (key, opts, format_hint, required: true) ⇒ string | nil

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

验证KMS参数是否有效。

参数:

  • key (符号)

    参数名称。

  • opts (哈希)

    哈希应包含键下的参数。

  • 必需 布尔值 (默认为: true

    该参数是否为必填项。 非必需参数可以为零。

返回:

  • ( string | nil )

    string参数值,如果缺少非必需参数,则为 nil。

引发:

  • ( ArgumentError )

    如果必需的选项丢失或格式不正确。



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ Mongo/crypt/kms.rb', line 42

def validate_param(key, opts, format_hint, 必需: true)
   = opts.获取(key)
  return nil if .nil? && !必需

  if .nil?
    提高 ArgumentError.new(
      " #{ key } 选项必须是至少有一个字符的字符串; " \ 'currently have nil ' ) endunless 值。 is_a? ( String ) 引发 ArgumentError。 new (" #{ key } 选项必须是至少有一个字符的字符串; " \ " 当前具有 #{ value } " ) end if 值。空?引发 ArgumentErrornew("The #{key} option must be a String with at least one character; " \
      'it is currently an empty string'
    )
  end
  value
rescue KeyError
  if required
    raise ArgumentError.new(" 指定的KMS提供商程序选项无效: #{ opts }. " +
      format_hint
    )
  end
end