censu 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -1
  3. data/.rubocop.yml +41 -35
  4. data/README.md +2 -2
  5. data/censys.gemspec +1 -1
  6. data/lib/censu.rb +2 -0
  7. data/lib/censys.rb +2 -0
  8. data/lib/censys/account.rb +23 -0
  9. data/lib/censys/account/quota.rb +17 -0
  10. data/lib/censys/api.rb +11 -2
  11. data/lib/censys/autonomous_system.rb +2 -0
  12. data/lib/censys/certificate.rb +2 -0
  13. data/lib/censys/data.rb +2 -0
  14. data/lib/censys/data/response.rb +2 -0
  15. data/lib/censys/data/result.rb +2 -2
  16. data/lib/censys/data/series.rb +2 -7
  17. data/lib/censys/data/series_list.rb +2 -0
  18. data/lib/censys/document.rb +2 -0
  19. data/lib/censys/document/has_asn.rb +2 -0
  20. data/lib/censys/document/has_http_response.rb +3 -1
  21. data/lib/censys/document/has_location.rb +2 -0
  22. data/lib/censys/document/has_services.rb +2 -0
  23. data/lib/censys/exceptions.rb +7 -10
  24. data/lib/censys/http_response.rb +2 -0
  25. data/lib/censys/ipv4.rb +2 -0
  26. data/lib/censys/location.rb +16 -10
  27. data/lib/censys/report.rb +2 -0
  28. data/lib/censys/report/metadata.rb +2 -0
  29. data/lib/censys/report/response.rb +2 -0
  30. data/lib/censys/search.rb +2 -0
  31. data/lib/censys/search/certificate.rb +2 -0
  32. data/lib/censys/search/ipv4.rb +2 -0
  33. data/lib/censys/search/metadata.rb +2 -0
  34. data/lib/censys/search/response.rb +2 -0
  35. data/lib/censys/search/result.rb +2 -0
  36. data/lib/censys/search/website.rb +2 -0
  37. data/lib/censys/version.rb +3 -2
  38. data/lib/censys/website.rb +2 -0
  39. data/spec/account_spec.rb +15 -0
  40. data/spec/censys_spec.rb +1 -2
  41. data/spec/data_spec.rb +4 -4
  42. data/spec/fixtures/vcr_cassettes/Censys_API/_account/should_return_an_Account.yml +47 -0
  43. data/spec/fixtures/vcr_cassettes/Censys_API/_data/result/{should_return_Result_response.yml → should_return_a_Data_Result.yml} +1 -1
  44. data/spec/fixtures/vcr_cassettes/Censys_API/_data/series/should_return_a_Data_Series.yml +53 -0
  45. data/spec/fixtures/vcr_cassettes/Censys_API/_data/series_list/{should_return_SeriesList_response.yml → should_return_a_Data_SeriesList.yml} +124 -107
  46. data/spec/fixtures/vcr_cassettes/Censys_API/_report/certificates/{should_return_certificate_response.yml → should_return_a_certificate_response.yml} +7 -7
  47. data/spec/fixtures/vcr_cassettes/Censys_API/_report/ipv4/{should_return_ipv4_response.yml → should_return_an_ipv4_response.yml} +10 -10
  48. data/spec/fixtures/vcr_cassettes/Censys_API/_report/websites/{should_return_website_response.yml → should_return_a_website_response.yml} +9 -9
  49. data/spec/fixtures/vcr_cassettes/Censys_API/_search/certificates/should_return_Certificate_response.yml +294 -351
  50. data/spec/fixtures/vcr_cassettes/Censys_API/_search/ipv4/should_return_IPv4_response.yml +396 -544
  51. data/spec/fixtures/vcr_cassettes/Censys_API/_search/websites/should_return_Website_response.yml +71 -71
  52. data/spec/fixtures/vcr_cassettes/Censys_API/_view/certificates/{should_return_Certificate_response.yml → should_return_a_Certificate_response.yml} +65 -68
  53. data/spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_IPv4_response.yml +95 -114
  54. data/spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_an_IPv4_response.yml +156 -0
  55. data/spec/fixtures/vcr_cassettes/Censys_API/_view/websites/{should_return_Website_response.yml → should_return_a_Website_response.yml} +504 -514
  56. data/spec/report_spec.rb +4 -4
  57. data/spec/search_spec.rb +1 -1
  58. data/spec/spec_helper.rb +8 -1
  59. data/spec/view_spec.rb +6 -6
  60. metadata +26 -18
  61. data/spec/fixtures/vcr_cassettes/Censys_API/_data/series/should_return_Series_response.yml +0 -130
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 689085dedc6c546aab344362dafad21976d0d9ad42c3402873b907745cdb41f0
4
- data.tar.gz: b0e0c0eb6a0f03b25289e827834f322ac6293bff8869d09355ed87592a457c13
3
+ metadata.gz: af8770860ef1c212a40039c69c74ab333edac166d8c070e1ccb4adf027caa535
4
+ data.tar.gz: 8b78c15ee59f19dd999ed69488b508be26931cfd6766ff747f8a179088f4d9e7
5
5
  SHA512:
6
- metadata.gz: 1db979e480c89463f6218b9ce05df6e8e13f30fe74a87dabf414943bc9e8f07e52afb1ab07274c1814ac27f2713231529165304e1c8ae2e319066e97de8af535
7
- data.tar.gz: 98e8fde7d80fba0033d882ff5f65d387982c3113875c1bc4a10ec377c0940fd3d2625279384af2431f2ea3c2ebce024a0dea7be2e41352ef106c5b99fc33d80c
6
+ metadata.gz: a032559c4b00a88f655afc64b17fa3bcf9b4f445c826539b473c6e202f3c2583e8290a77c46077069cd4944c04ba91abb721c62a4f4ceae403dd058a9e97d0e8
7
+ data.tar.gz: b8f51ba142b1d75c286f9fba9ea3fe209d99cc9d55d983293bd0296d6c8734dec0560284e9d3627e95ed908701b53788344a6d12fb14a02b93600236df9a19c6
data/.rspec CHANGED
@@ -1 +1,3 @@
1
- --colour --format documentation
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -1,141 +1,148 @@
1
1
  # Relaxed.Ruby.Style
2
2
  ## Version 2.2
3
3
 
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+
4
7
  Style/Alias:
5
8
  Enabled: false
6
- StyleGuide: http://relaxed.ruby.style/#stylealias
9
+ StyleGuide: https://relaxed.ruby.style/#stylealias
7
10
 
8
11
  Style/AsciiComments:
9
12
  Enabled: false
10
- StyleGuide: http://relaxed.ruby.style/#styleasciicomments
13
+ StyleGuide: https://relaxed.ruby.style/#styleasciicomments
11
14
 
12
15
  Style/BeginBlock:
13
16
  Enabled: false
14
- StyleGuide: http://relaxed.ruby.style/#stylebeginblock
17
+ StyleGuide: https://relaxed.ruby.style/#stylebeginblock
15
18
 
16
19
  Style/BlockDelimiters:
17
20
  Enabled: false
18
- StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
21
+ StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
19
22
 
20
23
  Style/CommentAnnotation:
21
24
  Enabled: false
22
- StyleGuide: http://relaxed.ruby.style/#stylecommentannotation
25
+ StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
23
26
 
24
27
  Style/Documentation:
25
28
  Enabled: false
26
- StyleGuide: http://relaxed.ruby.style/#styledocumentation
29
+ StyleGuide: https://relaxed.ruby.style/#styledocumentation
27
30
 
28
31
  Layout/DotPosition:
29
32
  Enabled: false
30
- StyleGuide: http://relaxed.ruby.style/#layoutdotposition
33
+ StyleGuide: https://relaxed.ruby.style/#layoutdotposition
31
34
 
32
35
  Style/DoubleNegation:
33
36
  Enabled: false
34
- StyleGuide: http://relaxed.ruby.style/#styledoublenegation
37
+ StyleGuide: https://relaxed.ruby.style/#styledoublenegation
35
38
 
36
39
  Style/EndBlock:
37
40
  Enabled: false
38
- StyleGuide: http://relaxed.ruby.style/#styleendblock
41
+ StyleGuide: https://relaxed.ruby.style/#styleendblock
39
42
 
40
43
  Style/FormatString:
41
44
  Enabled: false
42
- StyleGuide: http://relaxed.ruby.style/#styleformatstring
45
+ StyleGuide: https://relaxed.ruby.style/#styleformatstring
43
46
 
44
47
  Style/IfUnlessModifier:
45
48
  Enabled: false
46
- StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
49
+ StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
47
50
 
48
51
  Style/Lambda:
49
52
  Enabled: false
50
- StyleGuide: http://relaxed.ruby.style/#stylelambda
53
+ StyleGuide: https://relaxed.ruby.style/#stylelambda
51
54
 
52
55
  Style/ModuleFunction:
53
56
  Enabled: false
54
- StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
57
+ StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
55
58
 
56
59
  Style/MultilineBlockChain:
57
60
  Enabled: false
58
- StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
61
+ StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
59
62
 
60
63
  Style/NegatedIf:
61
64
  Enabled: false
62
- StyleGuide: http://relaxed.ruby.style/#stylenegatedif
65
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedif
63
66
 
64
67
  Style/NegatedWhile:
65
68
  Enabled: false
66
- StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
69
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
67
70
 
68
71
  Style/ParallelAssignment:
69
72
  Enabled: false
70
- StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
73
+ StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
71
74
 
72
75
  Style/PercentLiteralDelimiters:
73
76
  Enabled: false
74
- StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
77
+ StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
75
78
 
76
79
  Style/PerlBackrefs:
77
80
  Enabled: false
78
- StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
81
+ StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
79
82
 
80
83
  Style/Semicolon:
81
84
  Enabled: false
82
- StyleGuide: http://relaxed.ruby.style/#stylesemicolon
85
+ StyleGuide: https://relaxed.ruby.style/#stylesemicolon
83
86
 
84
87
  Style/SignalException:
85
88
  Enabled: false
86
- StyleGuide: http://relaxed.ruby.style/#stylesignalexception
89
+ StyleGuide: https://relaxed.ruby.style/#stylesignalexception
87
90
 
88
91
  Style/SingleLineBlockParams:
89
92
  Enabled: false
90
- StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
93
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
91
94
 
92
95
  Style/SingleLineMethods:
93
96
  Enabled: false
94
- StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
97
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
95
98
 
96
99
  Layout/SpaceBeforeBlockBraces:
97
100
  Enabled: false
98
- StyleGuide: http://relaxed.ruby.style/#layoutspacebeforeblockbraces
101
+ StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
99
102
 
100
103
  Layout/SpaceInsideParens:
101
104
  Enabled: false
102
- StyleGuide: http://relaxed.ruby.style/#layoutspaceinsideparens
105
+ StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
103
106
 
104
107
  Style/SpecialGlobalVars:
105
108
  Enabled: false
106
- StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
109
+ StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
107
110
 
108
111
  Style/StringLiterals:
109
112
  Enabled: false
110
- StyleGuide: http://relaxed.ruby.style/#stylestringliterals
113
+ StyleGuide: https://relaxed.ruby.style/#stylestringliterals
111
114
 
112
115
  Style/TrailingCommaInArguments:
113
116
  Enabled: false
114
- StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarguments
117
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
115
118
 
116
119
  Style/TrailingCommaInArrayLiteral:
117
120
  Enabled: false
118
- StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarrayliteral
121
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
119
122
 
120
123
  Style/TrailingCommaInHashLiteral:
121
124
  Enabled: false
122
- StyleGuide: http://relaxed.ruby.style/#styletrailingcommainhashliteral
125
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
126
+
127
+ Style/SymbolArray:
128
+ Enabled: false
129
+ StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
123
130
 
124
131
  Style/WhileUntilModifier:
125
132
  Enabled: false
126
- StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
133
+ StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
127
134
 
128
135
  Style/WordArray:
129
136
  Enabled: false
130
- StyleGuide: http://relaxed.ruby.style/#stylewordarray
137
+ StyleGuide: https://relaxed.ruby.style/#stylewordarray
131
138
 
132
139
  Lint/AmbiguousRegexpLiteral:
133
140
  Enabled: false
134
- StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
141
+ StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
135
142
 
136
143
  Lint/AssignmentInCondition:
137
144
  Enabled: false
138
- StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
145
+ StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
139
146
 
140
147
  Metrics/AbcSize:
141
148
  Enabled: false
@@ -163,4 +170,3 @@ Metrics/ParameterLists:
163
170
 
164
171
  Metrics/PerceivedComplexity:
165
172
  Enabled: false
166
-
data/README.md CHANGED
@@ -20,7 +20,7 @@ require 'censys'
20
20
  api = Censys::API.new(uid, secret)
21
21
  ```
22
22
 
23
- Initialize the API using `$CENSYS_ID` and `$CENSYS_SECRET` environment variables:
23
+ Initialize the API by using `$CENSYS_ID` and `$CENSYS_SECRET` environment variables:
24
24
 
25
25
  ```ruby
26
26
  api = Censys::API.new
@@ -96,7 +96,7 @@ end
96
96
 
97
97
  ## Requirements
98
98
 
99
- * [ruby] >= 2.4
99
+ - Ruby 2.4 / 2.5
100
100
 
101
101
  ## Install
102
102
 
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'censys/version'
4
4
 
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/api'
2
4
  require 'censys/version'
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/api'
2
4
  require 'censys/version'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'censys/account/quota'
4
+
5
+ module Censys
6
+ class Account
7
+ attr_reader :api_id
8
+ attr_reader :email
9
+ attr_reader :first_login
10
+ attr_reader :last_login
11
+ attr_reader :login
12
+ attr_reader :quota
13
+
14
+ def initialize(attributes)
15
+ @api_id = attributes["api_id"]
16
+ @email = attributes["email"]
17
+ @first_login = attributes["first_login"]
18
+ @last_login = attributes["last_login"]
19
+ @login = attributes["login"]
20
+ @quota = Quota.new(attributes["quota"])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Censys
4
+ class Account
5
+ class Quota
6
+ attr_reader :used
7
+ attr_reader :resets_at
8
+ attr_reader :allowance
9
+
10
+ def initialize(attributes)
11
+ @used = attributes["used"]
12
+ @resets_at = attributes["resets_at"]
13
+ @allowance = attributes["allowance"]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/exceptions'
2
4
  require 'censys/search'
3
5
  require 'censys/report'
@@ -5,6 +7,7 @@ require 'censys/ipv4'
5
7
  require 'censys/website'
6
8
  require 'censys/certificate'
7
9
  require 'censys/data'
10
+ require 'censys/account'
8
11
 
9
12
  require 'net/https'
10
13
  require 'json'
@@ -12,8 +15,8 @@ require 'json'
12
15
  module Censys
13
16
  class API
14
17
  VERSION = 1
15
- HOST = 'www.censys.io'.freeze
16
- URL = "https://#{HOST}/api/v#{VERSION}".freeze
18
+ HOST = 'www.censys.io'
19
+ URL = "https://#{HOST}/api/v#{VERSION}"
17
20
 
18
21
  class Resource
19
22
  def initialize(type, api)
@@ -188,6 +191,12 @@ module Censys
188
191
  end
189
192
  end
190
193
 
194
+ def account
195
+ get("/account") do |response|
196
+ Account.new(response)
197
+ end
198
+ end
199
+
191
200
  private
192
201
 
193
202
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
4
  class AutonomousSystem
3
5
  # @return [String]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  module Censys
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/data/response'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/data/result'
2
4
  require 'censys/data/series_list'
3
5
  require 'censys/data/series'
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  module Censys
4
6
  module Data
5
7
  class Result
6
8
  attr_reader :id
7
-
8
9
  attr_reader :files
9
-
10
10
  attr_reader :timestamp
11
11
 
12
12
  def initialize(attributes)
@@ -1,20 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
4
  module Data
3
5
  class Series
4
6
  attr_reader :id
5
-
6
7
  attr_reader :port
7
-
8
8
  attr_reader :protocol
9
-
10
9
  attr_reader :subprotocol
11
-
12
10
  attr_reader :destination
13
-
14
11
  attr_reader :name
15
-
16
12
  attr_reader :description
17
-
18
13
  attr_reader :results
19
14
 
20
15
  def initialize(attributes)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
4
  module Data
3
5
  class SeriesList
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
4
  class Document
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/autonomous_system'
2
4
 
3
5
  module Censys
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/http_response'
2
4
 
3
5
  module Censys
@@ -9,7 +11,7 @@ module Censys
9
11
  # @return [HTTPResponse]
10
12
  #
11
13
  def http_response
12
- @http_reponse ||= HTTPResponse.new(@attributes.dig("80", "http"))
14
+ @http_response ||= HTTPResponse.new(@attributes.dig("80", "http"))
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'censys/location'
2
4
 
3
5
  module Censys
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
4
  class Document
3
5
  module HasServices
@@ -1,16 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Censys
2
- class ResponseError < RuntimeError
3
- end
4
+ class ResponseError < StandardError; end
4
5
 
5
- class AuthenticationError < ResponseError
6
- end
6
+ class AuthenticationError < ResponseError; end
7
7
 
8
- class NotFound < ResponseError
9
- end
8
+ class NotFound < ResponseError; end
10
9
 
11
- class RateLimited < ResponseError
12
- end
10
+ class RateLimited < ResponseError; end
13
11
 
14
- class InternalServerError < ResponseError
15
- end
12
+ class InternalServerError < ResponseError; end
16
13
  end