class Caco::Postgres::HbaSet
Constants
- TypeHost
- TypeLocal
- ValidMethods
- ValidTypes
Public Instance Methods
append_value(ctx, input:, type:, database:, user:, method:, **)
click to toggle source
# File lib/caco/postgres/hba_set.rb, line 44 def append_value(ctx, input:, type:, database:, user:, method:, **) after_type_size = 8 - type.size > 0 ? (8 - type.size) : 1 after_type_spaces = " " * after_type_size after_db_size = 16 - database.size > 0 ? (16 - database.size) : 1 after_db_spaces = " " * after_db_size after_user_size = 16 - user.size > 0 ? (16 - user.size) : 1 after_user_spaces = " " * after_user_size network_size = ctx[:network].size rescue 0 after_network_size = 24 - network_size > 0 ? 24 - network_size : 1 after_network_spaces = " " * after_network_size if type == 'local' input << "#{type}#{after_type_spaces}#{database}#{after_db_spaces}#{user}#{after_user_spaces}#{after_network_spaces}#{method}\n" else input << "#{type}#{after_type_spaces}#{database}#{after_db_spaces}#{user}#{after_user_spaces}#{ctx[:network]}#{after_network_spaces}#{method}\n" end ctx[:content] = input end
check_if_network_value_is_needed(ctx, type:, **)
click to toggle source
# File lib/caco/postgres/hba_set.rb, line 38 def check_if_network_value_is_needed(ctx, type:, **) return true if type == 'local' return true if ctx[:network] raise MissingNetworkValue.new("You need to enter a value for network when #{type} is specified") end
check_method_is_valid(ctx, method:, **)
click to toggle source
# File lib/caco/postgres/hba_set.rb, line 28 def check_method_is_valid(ctx, method:, **) raise InvalidMethod.new("`#{method}' is not a valid method") unless ValidMethods.include?(method) true end
check_type_is_valid(ctx, type:, **)
click to toggle source
# File lib/caco/postgres/hba_set.rb, line 23 def check_type_is_valid(ctx, type:, **) raise InvalidType.new("`#{type}' is not a valid type") unless ValidTypes.include?(type) true end
check_value_exist(ctx, input:, type:, database:, user:, method:, **)
click to toggle source
# File lib/caco/postgres/hba_set.rb, line 33 def check_value_exist(ctx, input:, type:, database:, user:, method:, **) return input.match?(/^#{type}\s+#{database}\s+#{user}\s+#{method}$/) if type == 'local' input.match?(/^#{type}\s+#{database}\s+#{user}\s+#{ctx[:network]}\s+#{method}$/) end