Skip to content

Commit

Permalink
Merge pull request #54 from oreno-tools/feature/security-grgroup-rule…
Browse files Browse the repository at this point in the history
…-output

セキュリティグループの出力に To Port 定義を出力するようにした
  • Loading branch information
inokappa committed Aug 28, 2021
2 parents ffa4ff4 + f43187a commit dee8fff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/furikake/resources/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module SecurityGroup
def report
ingresses, egresses = get_resources
headers = ['ID', 'Group Name', 'Description',
'Port', 'Protocol', 'Source' ]
'From Port', 'To Port', 'Protocol', 'Source' ]
ingress_info = MarkdownTables.make_table(headers, ingresses, is_rows: true, align: 'l')

headers = ['ID', 'Group Name', 'Description',
'Port', 'Protocol', 'Destination' ]
'From Port', 'To Port', 'Protocol', 'Source' ]
egress_info = MarkdownTables.make_table(headers, egresses, is_rows: true, align: 'l')

documents = <<"EOS"
Expand Down Expand Up @@ -40,6 +40,7 @@ def get_resources
ingress << encode_value(sg.group_name)
ingress << encode_value(sg.description || 'N/A')
ingress << (permission.from_port || 'N/A')
ingress << (permission.to_port || 'N/A')
ingress << (permission.ip_protocol == '-1' ? 'ALL' : permission.ip_protocol)

ip_ranges = list_ip_ranges(permission.ip_ranges)
Expand All @@ -50,7 +51,7 @@ def get_resources
source << ip_ranges unless ip_ranges.empty?
source << list_ids unless list_ids.empty?
source << group_pairs unless group_pairs.empty?
ingress << source.join(', ')
ingress << source.join(' <br> ')
ingresses << ingress
end

Expand All @@ -60,6 +61,7 @@ def get_resources
egress << encode_value(sg.group_name)
egress << encode_value(sg.description || 'N/A')
egress << (permission.from_port || 'N/A')
egress << (permission.to_port || 'N/A')
egress << (permission.ip_protocol == '-1' ? 'ALL' : permission.ip_protocol)

ip_ranges = list_ip_ranges(permission.ip_ranges)
Expand All @@ -70,7 +72,7 @@ def get_resources
dest << ip_ranges unless ip_ranges.empty?
dest << list_ids unless list_ids.empty?
dest << group_pairs unless group_pairs.empty?
egress << dest.join(', ')
egress << dest.join('<br>')
egresses << egress
end
end
Expand Down Expand Up @@ -106,9 +108,8 @@ def list_group_pairs(user_id_group_pairs)
end

def encode_value(value)
return ('\\' + value) if value == '-'
return ('\\' + value) if value.index('_') == 0
value
return value unless value.index('_') == 0
'\\' + value
end

module_function :report, :get_resources,
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/security_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

it 'check encode_value (has `dash` pattern)' do
expect = '\\-'
expect = '-'
actual = Furikake::Resources::SecurityGroup.encode_value('-')
expect(expect).to eq(actual)
end
Expand Down

0 comments on commit dee8fff

Please sign in to comment.