ryo 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,37 +4,62 @@ module Ryo
4
4
  class CLI < Thor
5
5
  desc "dir URL", "Discover directories and files belong to a given URL"
6
6
  def dir(url)
7
- hash = discover(url, dir: true)
7
+ hash = run_discovery(url, dir: true)
8
8
  puts hash.to_json
9
9
  end
10
10
 
11
11
  desc "subdomain URL", "Discover subdomains of a given URL"
12
12
  def subdomain(url)
13
- hash = discover(url, subdomain: true)
13
+ hash = run_discovery(url, subdomain: true)
14
14
  puts hash.to_json
15
15
  end
16
16
 
17
17
  desc "tech URL", "Discover used technolgies of a given URL"
18
18
  def tech(url)
19
- hash = discover(url, tech: true)
19
+ hash = run_discovery(url, tech: true)
20
20
  puts hash.to_json
21
21
  end
22
22
 
23
23
  desc "whois URL", "Discover whois information of a given URL"
24
24
  def whois(url)
25
- hash = discover(url, whois: true)
25
+ hash = run_discovery(url, whois: true)
26
+ puts hash.to_json
27
+ end
28
+
29
+ desc "discover URL", "Run discovery plugin(s) against a given URL"
30
+ method_option :dir, type: :boolean, default: false
31
+ method_option :subdomain, type: :boolean, default: false
32
+ method_option :tech, type: :boolean, default: false
33
+ method_option :whois, type: :boolean, default: false
34
+ def discovery(url)
35
+ hash = run_discovery(url, options)
26
36
  puts hash.to_json
27
37
  end
28
38
 
29
39
  desc "all URL", "Run all discovery plugins against a given URL"
30
40
  def all(url)
31
- hash = discover(url, all: true)
41
+ hash = run_discovery(url, all: true)
32
42
  puts hash.to_json
33
43
  end
34
44
 
35
45
  no_commands do
36
- def discover(url, options)
46
+ def validate_url(url)
47
+ uri = URI.parse(url)
48
+ raise InvalidURLError unless %w(http https).include?(uri.scheme)
49
+ end
50
+
51
+ def validate_options(options)
52
+ raise InvalidOptionsError unless options.any? { |_, v| v }
53
+ end
54
+
55
+ def run_discovery(url, options)
56
+ validate_url(url)
57
+ validate_options(options)
37
58
  Ryo.discover url, options
59
+ rescue InvalidURLError => _
60
+ { error: "Please input a valid URL" }
61
+ rescue InvalidOptionsError => _
62
+ { error: "Please input at least one option" }
38
63
  rescue StandardError => e
39
64
  { error: "Warning: #{e}" }
40
65
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ryo
2
4
  class NotFoundError < StandardError; end
3
- end
5
+ class InvalidURLError < StandardError; end
6
+ class InvalidOptionsError < StandardError; end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ryo
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ryo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki