egi-fedcloud-cloudhound 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d6d1e60e2fbc93b5e6d6747ea4373ffe878d9fc
4
- data.tar.gz: b17621e8590fe41fef073fd3751b200ce49c00ce
3
+ metadata.gz: c4e3b3c827061e35ca49b4ea566f0fa3264b4acd
4
+ data.tar.gz: 033094880617f0c90a25feaa5c4042c862d416a5
5
5
  SHA512:
6
- metadata.gz: 63b816bef03b604dcf574a783480e1bab4a52af61d0cda94fb4f91c0e0fc23946b945ed0f81ee25d6e3860814eb0ea3c1a169966b48bce9fb83aefbc6632e7b9
7
- data.tar.gz: 7a61a4cd04db86768da65fbbdb59f14cb8b41e629e67b9a1c736b202d2cf559afe5bb7ae8ff35d901c1f037357649a25ec5ccf5266e12f00f7e9dadcec22a566
6
+ metadata.gz: 37529d8dcd8fd6c4824ca091db0f959ae8212cc0a20058bc2c62f792db530cbf9b96f1b3c667228a525055466d35f0ab6fdd177e1681e32105f2e3bcfbe1e83b
7
+ data.tar.gz: 9d4e419443d9e6a20210332a7baa4da3fd728e1c021ddb76627d2adaae7e75aa64f410424d18f3730c684103fdff6394c06990f8345734b2a604a8109ce9f1e4
@@ -23,6 +23,8 @@ class EgiFedcloudCloudhound < Thor
23
23
  include Thor::Actions
24
24
 
25
25
  desc "all", "Prints information for all available cloud sites"
26
+ method_option :format, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.format,
27
+ :enum => Egi::Fedcloud::Cloudhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
26
28
  method_option :credentials, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.credentials,
27
29
  :aliases => '-c', :desc => 'PEM file with a personal certificate and private key'
28
30
  method_option :password, :type => :string, :default => nil,
@@ -38,7 +40,8 @@ class EgiFedcloudCloudhound < Thor
38
40
  def all
39
41
  init_log options[:debug]
40
42
 
41
- $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.as_table(
43
+ $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.send(
44
+ "as_#{options[:format]}",
42
45
  Egi::Fedcloud::Cloudhound::Extractor.find_all(
43
46
  options
44
47
  )
@@ -46,6 +49,8 @@ class EgiFedcloudCloudhound < Thor
46
49
  end
47
50
 
48
51
  desc "ip IP_ADDRESS", "Prints information based on the provided IP address or IP address range"
52
+ method_option :format, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.format,
53
+ :enum => Egi::Fedcloud::Cloudhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
49
54
  method_option :credentials, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.credentials,
50
55
  :aliases => '-c', :desc => 'PEM file with a personal certificate and private key'
51
56
  method_option :password, :type => :string, :default => nil,
@@ -61,7 +66,8 @@ class EgiFedcloudCloudhound < Thor
61
66
  def ip(ip_address)
62
67
  init_log options[:debug]
63
68
 
64
- $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.as_table(
69
+ $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.send(
70
+ "as_#{options[:format]}",
65
71
  Egi::Fedcloud::Cloudhound::Extractor.find_by_ip(
66
72
  ip_address,
67
73
  options
@@ -70,6 +76,8 @@ class EgiFedcloudCloudhound < Thor
70
76
  end
71
77
 
72
78
  desc "appuri URI", "Prints information based on the provided Appliance MPURI"
79
+ method_option :format, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.format,
80
+ :enum => Egi::Fedcloud::Cloudhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
73
81
  method_option :credentials, :type => :string, :default => Egi::Fedcloud::Cloudhound::Settings.credentials,
74
82
  :aliases => '-c', :desc => 'PEM file with a personal certificate and private key'
75
83
  method_option :password, :type => :string, :default => nil,
@@ -85,7 +93,8 @@ class EgiFedcloudCloudhound < Thor
85
93
  def appuri(uri)
86
94
  init_log options[:debug]
87
95
 
88
- $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.as_table(
96
+ $stdout.puts Egi::Fedcloud::Cloudhound::Formatter.send(
97
+ "as_#{options[:format]}",
89
98
  Egi::Fedcloud::Cloudhound::Extractor.find_by_appuri(
90
99
  uri,
91
100
  options
@@ -107,7 +116,7 @@ class EgiFedcloudCloudhound < Thor
107
116
  # @return [Egi::Fedcloud::Cloudhound::Log] logger instance for additional configuration
108
117
  def init_log(debug = false)
109
118
  logger = Egi::Fedcloud::Cloudhound::Log.new(STDERR)
110
- logger.level = debug ? Egi::Fedcloud::Cloudhound::Log::DEBUG : Egi::Fedcloud::Cloudhound::Log::ERROR
119
+ logger.level = debug ? Egi::Fedcloud::Cloudhound::Log::DEBUG : Egi::Fedcloud::Cloudhound::Log::WARN
111
120
  logger
112
121
  end
113
122
  end
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  production:
3
+ format: table
3
4
  credentials: "<%= ENV['HOME'] %>/.globus/usercred.pem"
4
5
  ca_path: '/etc/grid-security/certificates'
5
6
  gocdb_base_url: 'https://goc.egi.eu'
@@ -7,6 +8,7 @@ production:
7
8
  debug: false
8
9
 
9
10
  development:
11
+ format: table
10
12
  credentials: "<%= ENV['HOME'] %>/.globus/usercred.pem"
11
13
  ca_path: '/etc/grid-security/certificates'
12
14
  gocdb_base_url: 'https://goc.egi.eu'
@@ -14,6 +16,7 @@ development:
14
16
  debug: true
15
17
 
16
18
  test:
19
+ format: table
17
20
  credentials: "<%= ENV['HOME'] %>/.globus/testcred.pem"
18
21
  ca_path: '/etc/grid-security/certificates'
19
22
  gocdb_base_url: 'http://localhost/goc'
@@ -3,10 +3,14 @@ require 'terminal-table'
3
3
  #
4
4
  class Egi::Fedcloud::Cloudhound::Formatter
5
5
 
6
+ FORMATS = %w(table json plain).freeze
7
+
6
8
  class << self
7
9
  #
8
10
  def as_table(data = [])
9
11
  Egi::Fedcloud::Cloudhound::Log.debug "[#{self}] Transforming #{data.inspect} into a table"
12
+
13
+ data ||= []
10
14
  table = Terminal::Table.new
11
15
 
12
16
  table.add_row [' >>> Site Name <<< ', ' >>> NGI Name <<< ', ' >>> CSIRT Contact(s) <<< ']
@@ -21,7 +25,26 @@ class Egi::Fedcloud::Cloudhound::Formatter
21
25
 
22
26
  #
23
27
  def as_json(data = [])
24
- data ? JSON.generate(data) : '{}'
28
+ Egi::Fedcloud::Cloudhound::Log.debug "[#{self}] Transforming #{data.inspect} into a JSON document"
29
+ return '{}' if data.blank?
30
+
31
+ JSON.generate(data)
32
+ end
33
+
34
+ #
35
+ def as_plain(data = [])
36
+ Egi::Fedcloud::Cloudhound::Log.debug "[#{self}] Transforming #{data.inspect} into plain text"
37
+ return '' if data.blank?
38
+
39
+ plain = []
40
+ data.each do |site|
41
+ Egi::Fedcloud::Cloudhound::Log.warn "[#{self}] #{site[:name]} doesn't " \
42
+ "have a CSIRT e-mail!" if site[:csirt].blank?
43
+ next if site[:csirt].blank?
44
+ plain << "#{site[:name]} <#{site[:csirt]}>"
45
+ end
46
+
47
+ plain.join ', '
25
48
  end
26
49
  end
27
50
 
@@ -16,7 +16,7 @@ class Egi::Fedcloud::Cloudhound::GocdbSite
16
16
  @ngi = self.class.extract_text(element.locate('ROC'))
17
17
 
18
18
  Egi::Fedcloud::Cloudhound::Log.debug "[#{self.class}] Extracting IP ranges for site #{@name}"
19
- @ip_ranges = self.class.extract_ranges(self.class.extract_text(element.locate('SITE_IP')))
19
+ @ip_ranges = self.class.extract_ranges(self.class.extract_text(element.locate('SITE_IP')), @name)
20
20
  end
21
21
 
22
22
  #
@@ -44,7 +44,7 @@ class Egi::Fedcloud::Cloudhound::GocdbSite
44
44
 
45
45
  class << self
46
46
  #
47
- def extract_ranges(text_ranges)
47
+ def extract_ranges(text_ranges, site_name)
48
48
  ranges = text_ranges.split(/[,;]/).reject { |el| el.blank? || !el.include?('/') || INVALID_RANGES.include?(el) }
49
49
 
50
50
  Egi::Fedcloud::Cloudhound::Log.debug "[#{self}] -- Ranges: #{ranges.inspect}"
@@ -52,7 +52,8 @@ class Egi::Fedcloud::Cloudhound::GocdbSite
52
52
  begin
53
53
  IPAddr.new(range)
54
54
  rescue
55
- Egi::Fedcloud::Cloudhound::Log.warn "[#{self}] -- Invalid range #{range.inspect}"
55
+ Egi::Fedcloud::Cloudhound::Log.warn "[#{self}] Invalid IP range #{range.inspect} " \
56
+ "for site #{site_name}"
56
57
  nil
57
58
  end
58
59
  end
@@ -2,7 +2,7 @@ module Egi
2
2
  module Fedcloud
3
3
  module Cloudhound
4
4
  # Versioning constant
5
- VERSION = "0.0.2" unless defined?(::Egi::Fedcloud::Cloudhound::VERSION)
5
+ VERSION = "0.0.3" unless defined?(::Egi::Fedcloud::Cloudhound::VERSION)
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egi-fedcloud-cloudhound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  version: '0'
273
273
  requirements: []
274
274
  rubyforge_project:
275
- rubygems_version: 2.2.2
275
+ rubygems_version: 2.4.4
276
276
  signing_key:
277
277
  specification_version: 4
278
278
  summary: A proof-of-concept utility for locating cloud sites and corresponding CSIRT/CERT