Class: Caco::Postgres::HbaSet
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- Caco::Postgres::HbaSet
show all
- Defined in:
- lib/caco/postgres/hba_set.rb
Defined Under Namespace
Classes: InvalidMethod, InvalidType, MissingNetworkValue
Constant Summary
collapse
- ValidTypes =
%w( local host hostssl hostnossl )
- ValidMethods =
%w( trust reject md5 password scram-sha-256 gss sspi ident peer pam ldap radius or cert )
- TypeLocal =
Class.new(Trailblazer::Activity::Signal)
- TypeHost =
Class.new(Trailblazer::Activity::Signal)
Instance Method Summary
collapse
-
#append_value(ctx, input:, type:, database:, user:, method:) ⇒ Object
-
#check_if_network_value_is_needed(ctx, type:) ⇒ Object
-
#check_method_is_valid(ctx, method:) ⇒ Object
-
#check_type_is_valid(ctx, type:) ⇒ Object
-
#check_value_exist(ctx, input:, type:, database:, user:, method:) ⇒ Object
Instance Method Details
#append_value(ctx, input:, type:, database:, user:, method:) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# 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:) ⇒ Object
38
39
40
41
42
|
# 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:) ⇒ Object
28
29
30
31
|
# 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:) ⇒ Object
23
24
25
26
|
# 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:) ⇒ Object
33
34
35
36
|
# 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
|