appcanary 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 284939affc1454e5a6d28abe108b4c9949288c2e
4
- data.tar.gz: 59b656003a5ac8a4533377757197d79d25ca1784
3
+ metadata.gz: 76000ce63fdd1ce397b93e7a4152e1b591c1017f
4
+ data.tar.gz: '0984f418130bed51fe3b0038b92a1a1c35d561ea'
5
5
  SHA512:
6
- metadata.gz: 201fd68b7ef60153da6d237043726f558c04ad23fcc430f1090def068ce5880c2982b1f5307d26feb6396121fd5415233675b9628e2a8a22a84e74c18f4b407f
7
- data.tar.gz: a3f711c3e6997fe909af3225404472f7f4e27499b5daff2710a83e07e11292a1fd69788a2f639565aeacf5977c2c1af77d8a89b36e586c4871b68333dc530bb7
6
+ metadata.gz: 84cdae3c74b1b9bd1bbdf1cf16a3201a9205a2a95440e75fb68e8b607cd6e33bbdbd25294875e678298ed99d795462a1f02f80332e1fc263d4617e052377b524
7
+ data.tar.gz: e2daded1e92c193d4e1536fea763fd9308ea5c0a1194ef1f5295a989a8be86615771e7990c0b8ab18924e52b492ac53a7862dd872fe5be18e8bd4c75d665223f
@@ -1,77 +1,109 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
3
+ require "rubygems"
4
4
  require "appcanary"
5
5
  require "optparse"
6
6
 
7
7
  class AppcanaryCLI
8
8
  class << self
9
- def api_key_opt(opts)
9
+ TOP_LEVEL_HELP = <<-HELP
10
+ Usage: appcanary check|update [options]
11
+
12
+ Subcommands are:
13
+ check - Check your gem bundle for vulnerabilities
14
+ update - Update an Appcanary monitor
15
+
16
+ See "appcanary COMMAND --help" for more information about a specific command.
17
+ HELP
18
+
19
+ REQUIRED_PARAMS = {
20
+ api_key: "Must provide an API key.",
21
+ gemfile_lock_path: "Must provide a path to a Gemfile.lock",
22
+ monitor_name: "Must provide a monitor name"
23
+ }
24
+
25
+ REQUIRED = { "check" => [:api_key, :gemfile_lock_path],
26
+ "update" => [:api_key, :gemfile_lock_path, :monitor_name] }
27
+
28
+ def api_key_opt(opts, vals)
10
29
  opts.on("-a", "--api-key API_KEY", :REQUIRED,
11
- "Your Appcanary API key. Find it at https://appcanary.com/settings") do |ak|
30
+ "Your Appcanary API key. Required; find it at https://appcanary.com/settings") do |ak|
31
+ vals[:api_key] = ak
12
32
  Appcanary.api_key = ak
13
33
  end
14
34
  end
15
35
 
16
- def gemfile_lock_opt(opts)
17
- opts.on("-g", "--gemfile-lock GEMFILE_LOCK", :OPTIONAL,
18
- "Path to the Gemfile.lock to ship to Appcanary") do |gl|
36
+ def gemfile_lock_opt(opts, vals)
37
+ opts.on("-g", "--gemfile-lock GEMFILE_LOCK", :REQUIRED,
38
+ "Path to the Gemfile.lock to ship to Appcanary. Required.") do |gl|
39
+ vals[:gemfile_lock_path] = gl
19
40
  Appcanary.gemfile_lock_path = gl
20
41
  end
21
42
  end
22
43
 
23
- def base_uri_opt(opts)
44
+ def base_uri_opt(opts, vals)
24
45
  opts.on("-b", "--base-uri BASE_URI", :OPTIONAL,
25
46
  "The URL for the Appcanary endpoint to use.") do |bu|
26
47
  Appcanary.base_uri = bu
27
48
  end
28
49
  end
29
50
 
30
- def monitor_name_opt(opts)
51
+ def monitor_name_opt(opts, vals)
31
52
  opts.on("-m", "--monitor-name MONITOR_NAME", :REQUIRED,
32
- "The name of the Appcanary monitor to update.") do |mn|
53
+ "The name of the Appcanary monitor to update. Required.") do |mn|
54
+ vals[:monitor_name] = mn
33
55
  Appcanary.monitor_name = mn
34
56
  end
35
57
  end
36
58
 
37
- def parse
38
- top_level_help = <<-HELP
39
- Subcommands are:
40
- check - Check your gem bundle for vulnerabilities
41
- update - Update an Appcanary monitor
42
-
43
- See "appcanary COMMAND --help" for more information about a specific command.
44
- HELP
45
-
46
- common = OptionParser.new do |opts|
47
- opts.banner = "Usage: appcanary check|update [options]"
48
- opts.separator ""
49
- opts.separator top_level_help
59
+ def print_help(banner, msg=nil)
60
+ if msg
61
+ puts "#{msg}\n\n"
50
62
  end
51
63
 
64
+ puts banner
65
+ exit
66
+ end
67
+
68
+ def parse(args)
69
+ command = args.first
70
+ values = {}
71
+
52
72
  subcommands = {
53
73
  "update" => OptionParser.new do |opts|
54
74
  opts.banner = "Usage: update [options]"
55
- api_key_opt(opts)
56
- base_uri_opt(opts)
57
- gemfile_lock_opt(opts)
58
- monitor_name_opt(opts)
75
+ api_key_opt(opts, values)
76
+ base_uri_opt(opts, values)
77
+ gemfile_lock_opt(opts, values)
78
+ monitor_name_opt(opts, values)
59
79
  end,
60
80
  "check" => OptionParser.new do |opts|
61
81
  opts.banner = "Usage: check [options]"
62
- api_key_opt(opts)
63
- base_uri_opt(opts)
64
- gemfile_lock_opt(opts)
82
+ api_key_opt(opts, values)
83
+ base_uri_opt(opts, values)
84
+ gemfile_lock_opt(opts, values)
65
85
  end
66
86
  }
67
87
 
68
- common.order!
69
-
70
- command = ARGV.shift
71
88
  if command.nil?
72
- puts "No subcommand found -- try appcanary --help"
73
- else
74
- subcommands[command].order!
89
+ print_help TOP_LEVEL_HELP
90
+ elsif subcommands[command].nil?
91
+ print_help TOP_LEVEL_HELP,
92
+ "Sorry, I don't know '#{command}'."
93
+ else
94
+ subcmd = subcommands[command]
95
+
96
+ begin
97
+ opt = subcmd.parse(args[1..-1])
98
+ rescue => e
99
+ print_help subcmd.help, e
100
+ end
101
+
102
+ if values.empty?
103
+ print_help subcmd.help
104
+ elsif missing = REQUIRED[command].find { |flag| !values.keys.include?(flag) }
105
+ print_help subcmd.help, REQUIRED_PARAMS[missing]
106
+ end
75
107
  end
76
108
 
77
109
  command
@@ -91,9 +123,9 @@ def run_check
91
123
  end
92
124
 
93
125
  def run_appcanary_command
94
- case AppcanaryCLI.parse
126
+ case AppcanaryCLI.parse(ARGV)
95
127
  when "update"
96
- Appcanary.update_monitor!
128
+ puts Appcanary.update_monitor!
97
129
  when "check"
98
130
  run_check
99
131
  end
@@ -3,6 +3,8 @@ require "net/http/post/multipart"
3
3
  require "json"
4
4
 
5
5
  module Appcanary
6
+ require 'securerandom'
7
+
6
8
  class ServiceError < RuntimeError
7
9
  end
8
10
 
@@ -1,3 +1,3 @@
1
1
  module Appcanary
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appcanary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - J Irving
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-06 00:00:00.000000000 Z
12
+ date: 2017-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.5.1
142
+ rubygems_version: 2.5.2
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Check your dependencies against Appcanary's database.