From b52f20826cef37e438d72448e3067e253d07423e Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Thu, 13 Sep 2018 11:42:04 +0000 Subject: [PATCH 1/3] Auto corrected by following Ruby Space --- lib/fgt_rest_api/ext/ipsec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fgt_rest_api/ext/ipsec.rb b/lib/fgt_rest_api/ext/ipsec.rb index b031e1c..a612bb2 100644 --- a/lib/fgt_rest_api/ext/ipsec.rb +++ b/lib/fgt_rest_api/ext/ipsec.rb @@ -22,11 +22,11 @@ def ipsec_tunnel_children end def ipsec_incoming_bytes(tunnel_parent) - ipsec_tunnels.select { |t| t['parent'] == tunnel_parent || t['name'] == tunnel_parent }.map { |t2| t2['incoming_bytes'] }.inject(0){|sum,x| sum + x } + ipsec_tunnels.select { |t| t['parent'] == tunnel_parent || t['name'] == tunnel_parent }.map { |t2| t2['incoming_bytes'] }.inject(0) { |sum, x| sum + x } end def ipsec_outgoing_bytes(tunnel_parent) - ipsec_tunnels.select { |t| t['parent'] == tunnel_parent || t['name'] == tunnel_parent }.map { |t2| t2['outgoing_bytes'] }.inject(0){|sum,x| sum + x } + ipsec_tunnels.select { |t| t['parent'] == tunnel_parent || t['name'] == tunnel_parent }.map { |t2| t2['outgoing_bytes'] }.inject(0) { |sum, x| sum + x } end end end From 32114f9744e75e9207aa19f5cd1b783f559ae811 Mon Sep 17 00:00:00 2001 From: Stefan Feurle Date: Tue, 25 Sep 2018 16:31:23 +0200 Subject: [PATCH 2/3] added basic ssl-tunnel interface --- Gemfile.lock | 4 ++-- lib/fgt_rest_api/ext/ssl.rb | 10 ++++++++++ lib/fgt_rest_api/version.rb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 lib/fgt_rest_api/ext/ssl.rb diff --git a/Gemfile.lock b/Gemfile.lock index 070648b..90e2e07 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - fgt_rest_api (0.1.4) + fgt_rest_api (0.1.5) httpclient netaddr @@ -22,4 +22,4 @@ DEPENDENCIES rake (~> 10.0) BUNDLED WITH - 1.16.1 + 1.16.4 diff --git a/lib/fgt_rest_api/ext/ssl.rb b/lib/fgt_rest_api/ext/ssl.rb new file mode 100644 index 0000000..ff921e0 --- /dev/null +++ b/lib/fgt_rest_api/ext/ssl.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module FGT + class RestApi + def ssl_tunnels(tunnel_name = nil) + options = tunnel_name.yield_self { |t| t.nil? ? {} : { tunnel: tunnel_name } } + monitor_get('vpn/ssl/select', options).results.uniq + end + end +end diff --git a/lib/fgt_rest_api/version.rb b/lib/fgt_rest_api/version.rb index 731442d..2d55af5 100644 --- a/lib/fgt_rest_api/version.rb +++ b/lib/fgt_rest_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FgtRestApi - VERSION = '0.1.5' + VERSION = '0.1.6' end From f4044ebacfc281c0dac779e8a365f8f430515e57 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Thu, 29 Aug 2019 04:36:03 +0000 Subject: [PATCH 3/3] Auto corrected by following Lint Ruby EmptyLine --- bin/fgt_policy2xlsx.rb | 1 + lib/fgt_rest_api/ext/policy_and_object.rb | 2 ++ lib/fgt_rest_api/fc_hash.rb | 4 ++++ lib/fgt_rest_api/rest_api.rb | 3 +++ 4 files changed, 10 insertions(+) diff --git a/bin/fgt_policy2xlsx.rb b/bin/fgt_policy2xlsx.rb index 8a11e28..b628b84 100755 --- a/bin/fgt_policy2xlsx.rb +++ b/bin/fgt_policy2xlsx.rb @@ -107,6 +107,7 @@ def add_row( add_obj_xlsxreference(object) unless object.nil? @cell.y_incr return @sheet.ws.add_row(@headers, styles: styles, types: types, widths: widths) if row.nil? + @sheet.ws.add_row(row, styles: styles, types: types, widths: widths) end diff --git a/lib/fgt_rest_api/ext/policy_and_object.rb b/lib/fgt_rest_api/ext/policy_and_object.rb index 9311f93..879268b 100644 --- a/lib/fgt_rest_api/ext/policy_and_object.rb +++ b/lib/fgt_rest_api/ext/policy_and_object.rb @@ -20,6 +20,7 @@ class RestApi def clear_cache_var(ivar) return nil unless instance_variable_defined?(ivar) && @inst_var_refreshable.include?(ivar) + remove_instance_variable(ivar) @inst_var_refreshable.tap { |a| a.delete(ivar) } end @@ -77,6 +78,7 @@ def find_group_for_object(object, vdom = use_vdom) groups.each do |group| grouped_groups = find_group_for_object(group[:name], vdom) next if grouped_groups.empty? + groups += grouped_groups end groups.flatten.uniq.compact diff --git a/lib/fgt_rest_api/fc_hash.rb b/lib/fgt_rest_api/fc_hash.rb index b754f35..3ebbb5f 100644 --- a/lib/fgt_rest_api/fc_hash.rb +++ b/lib/fgt_rest_api/fc_hash.rb @@ -4,6 +4,7 @@ module FGT class FCHash < ::Hash def []=(key, value) raise(ArgumentError, "key needs start with downcase letter: >>#{key}<<") unless key[0] == key[0].downcase + if key.is_a?(String) super(key, value) elsif key.is_a?(Symbol) @@ -16,6 +17,7 @@ def []=(key, value) def [](key) raise(ArgumentError, "key needs start with downcase: >>#{key}<<") unless key.to_s[0] == key.to_s[0].downcase + if key.is_a?(String) super(key) elsif key.is_a?(Symbol) @@ -36,6 +38,7 @@ def attribute_methods(key, value) def getter_method(key) method_name = key.to_s.tr('-', '_') return true if respond_to?(method_name.to_sym) + define_singleton_method(method_name) do begin fetch(key) @@ -48,6 +51,7 @@ def getter_method(key) def setter_method(key) method_name = key.to_s.tr('-', '_') + '=' return true if respond_to?(method_name.to_sym) + define_singleton_method(method_name) { |v| store(key, v) } end end diff --git a/lib/fgt_rest_api/rest_api.rb b/lib/fgt_rest_api/rest_api.rb index cbd4e59..4d15f75 100644 --- a/lib/fgt_rest_api/rest_api.rb +++ b/lib/fgt_rest_api/rest_api.rb @@ -72,6 +72,7 @@ def proxy=(pxy) %w[get post].each do |request_method| define_method('monitor_' + request_method) do |path, params = {}| raise(SafeModeActiveError) if request_method != 'get' && safe_mode + url_path = "api/#{api_version}/monitor/#{path.gsub(/\/*$/, '')}/" params[:vdom] = use_vdom unless params.key?(:vdom) request(request_method, url_path, params) @@ -91,6 +92,7 @@ def proxy=(pxy) def memoize_results(key) (@inst_var_refreshable || @inst_var_refreshable = Set.new) << key return instance_variable_get(key) if instance_variable_defined?(key) + instance_variable_set(key, yield) end @@ -122,6 +124,7 @@ def cmdb(request_method: 'get', path:, name:, mkey: '', child_name: '', child_mk raise(CMDBMKeyError) unless /^[^\/]*$/.match?(mkey) raise(CMDBChildNameError) unless /^[^\/]*$/.match?(child_name) raise(CMDBChildMKeyError) unless /^[^\/]*$/.match?(child_mkey) + url_path = "api/#{api_version}/cmdb/#{path}/#{name}/" unless mkey.empty? url_path += "#{mkey}/"