paraxial 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 70c0596f1eef97562cfcb511a053227074b08349c28081f76fde5e7481085eeb
4
- data.tar.gz: a129cedace488343816f94ad89a712825b9e000de2dffa041f0ba9ab997f18d7
3
+ metadata.gz: ea5f2156685b5204495019d6a72ad0f433326438abfef4e70e26b39ab62bf58b
4
+ data.tar.gz: 4dd855ada83c429df5422b42177af07863041ef94feb14912375df5f8d18e807
5
5
  SHA512:
6
- metadata.gz: 3e67e1dc3fe51b437fc52b6ad026d155b7caea38a9d804e7676d96a2825fcd8833b320dd88f1151c313784eb7b49468c07a6f37275cdbf25bd5d66fda0d00c39
7
- data.tar.gz: 0c93c320b498c22f7feaea3483562da418fe36af99c587652ffa8a19a2da10216b8ec4b131c44096dd6a3fd46a7ded086c161ff035f8b3264868b5e64ae15f3a
6
+ metadata.gz: 5f458988de37e4a6c9c0a8f8e1489b613925faf48d11dc59c1addbcca49acc740292cddae12bd675c25c8c640a2f45133e5ed6d9232c8319f74fe868c2e2396e
7
+ data.tar.gz: 81504558ae7231a7f5f5397f6ca640faf63532c15686d61942d54a306c0d28b865f3e11e8c17973729a1b200c74ad3246f149ca46a53635e91dfa229fe57a998
data/lib/paraxial/cli.rb CHANGED
@@ -4,6 +4,8 @@ require 'net/http'
4
4
  require 'uri'
5
5
  require 'json'
6
6
  require 'time'
7
+ require 'yaml'
8
+ require_relative 'helpers'
7
9
 
8
10
  module Paraxial
9
11
  class CLI < Thor
@@ -16,6 +18,13 @@ module Paraxial
16
18
 
17
19
  def scan
18
20
  puts '[Paraxial] Scan starting...'
21
+ if check_rubocop_configuration
22
+ puts '[Paraxial] .rubocop.yml contains the required paraxial configuration.'
23
+ else
24
+ puts '[Paraxial] .rubocop.yml does not contain the required paraxial configuration.'
25
+ puts '[Paraxial] How to configure: TODO_URL'
26
+ exit
27
+ end
19
28
 
20
29
  if ENV['PARAXIAL_API_KEY'].nil?
21
30
  puts '[Paraxial] Environment variable PARAXIAL_API_KEY not found'
@@ -30,7 +39,7 @@ module Paraxial
30
39
  rubocop = `rubocop --only #{cops} --format json`
31
40
  lockfile = File.read('./Gemfile.lock')
32
41
  api_key = ENV['PARAXIAL_API_KEY']
33
- uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/ruby_scan')
42
+ uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/ruby_scan')
34
43
  headers = { 'Content-Type': 'application/json' }
35
44
 
36
45
  body = { rubocop:, lockfile:, api_key:, timestamp: Paraxial.get_timestamp }
@@ -60,7 +69,7 @@ module Paraxial
60
69
 
61
70
  censored_backend_map['api_key'] = api_key
62
71
  backend_map = censored_backend_map
63
- parax_uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/github_app')
72
+ parax_uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/github_app')
64
73
  github_pr_url = "https://github.com/#{repo_owner}/#{repo_name}/pull/#{pr_number}"
65
74
 
66
75
  rr = Net::HTTP.post(parax_uri, backend_map.to_json, headers)
@@ -75,5 +84,22 @@ module Paraxial
75
84
  end
76
85
  end
77
86
  end
87
+
88
+ private
89
+
90
+ def check_rubocop_configuration
91
+ rubocop_file = File.join(Dir.pwd, '.rubocop.yml')
92
+
93
+ return false unless File.exist?(rubocop_file)
94
+
95
+ config = YAML.load_file(rubocop_file)
96
+ required_key = 'require'
97
+
98
+ if config.is_a?(Hash) && config[required_key].is_a?(Array)
99
+ config[required_key].include?('paraxial')
100
+ else
101
+ false
102
+ end
103
+ end
78
104
  end
79
105
  end
@@ -0,0 +1,7 @@
1
+ module Paraxial
2
+ module Helpers
3
+ def self.get_paraxial_url
4
+ @paraxial_url ||= ENV['PARAXIAL_URL'] || 'https://app.paraxial.io/'
5
+ end
6
+ end
7
+ end
@@ -1,57 +1,66 @@
1
1
  require 'bundler'
2
2
  require 'paraxial'
3
3
  require 'rpatricia'
4
+ require_relative '../helpers'
4
5
 
5
6
  Bundler.setup
6
7
 
7
8
  Rails.application.config.to_prepare do
8
- # Your code here
9
- puts '[Paraxial] Runtime start'
9
+ puts '[Paraxial] Init start'
10
10
  api_key = ENV['PARAXIAL_API_KEY']
11
11
 
12
12
  if api_key.nil?
13
- puts '[Paraxial] PARAXIAL_API_KEY key not set, agent not started'
14
- elsif ENV['PARAXIAL_URL'].nil?
15
- puts '[Paraxial] PARAXIAL_URL key not set, agent not started'
13
+ puts '[Paraxial] Init PARAXIAL_API_KEY key not set, agent not started'
16
14
  elsif Rails.env.test?
17
- puts '[Paraxial] Test environment detected, agent not started'
15
+ puts '[Paraxial] Init Test environment detected, agent not started'
18
16
  else
19
- deps_and_licenses = []
20
- Bundler.load.specs.each do |spec|
21
- # Print the gem name and license
22
- h = { name: spec.name, version: spec.version.to_s, description: Paraxial.trim_dep(spec.description),
23
- license: spec.license || 'None' }
24
- deps_and_licenses << h
25
- end
26
- deps_and_licenses << { name: 'ruby', version: RUBY_VERSION, description: 'The Ruby Programming Language',
27
- license: 'Ruby' }
28
- uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/ruby_app_lic')
29
- headers = { 'Content-Type': 'application/json' }
17
+ begin
18
+ puts '[Paraxial] Init config valid, agent starting'
19
+ deps_and_licenses = []
20
+ Bundler.load.specs.each do |spec|
21
+ # Print the gem name and license
22
+ h = { name: spec.name, version: spec.version.to_s, description: Paraxial.trim_dep(spec.description),
23
+ license: spec.license || 'None' }
24
+ deps_and_licenses << h
25
+ end
26
+ deps_and_licenses << { name: 'ruby', version: RUBY_VERSION, description: 'The Ruby Programming Language',
27
+ license: 'Ruby' }
28
+ uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/ruby_app_lic')
29
+ headers = { 'Content-Type': 'application/json' }
30
30
 
31
- body = { app_lic: deps_and_licenses, api_key:, timestamp: Paraxial.get_timestamp }
32
- Thread.new do
33
- Net::HTTP.post(uri, body.to_json, headers)
34
- end
31
+ body = { app_lic: deps_and_licenses, api_key:, timestamp: Paraxial.get_timestamp }
32
+ cloud_uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/cloud_ip_list')
33
+ response = Net::HTTP.get(cloud_uri)
35
34
 
36
- cloud_uri = URI.parse(ENV['PARAXIAL_URL'] + '/api/cloud_ip_list')
37
- response = Net::HTTP.get(cloud_uri)
35
+ Thread.new do
36
+ Net::HTTP.post(uri, body.to_json, headers)
37
+ end
38
38
 
39
- # https://github.com/jkitching/rpatricia
40
- pt_v4 = Patricia.new
41
- pt_v6 = Patricia.new(:AF_INET6)
42
- cloud_list = JSON.parse(response)
43
- cloud_list.each do |k, v|
44
- if k.include?('::')
45
- pt_v6.add(k, v)
46
- else
47
- pt_v4.add(k, v)
39
+ # https://github.com/jkitching/rpatricia
40
+ pt_v4 = Patricia.new
41
+ pt_v6 = Patricia.new(:AF_INET6)
42
+ cloud_list = JSON.parse(response)
43
+ cloud_list.each do |k, v|
44
+ if k.include?('::')
45
+ pt_v6.add(k, v)
46
+ else
47
+ pt_v4.add(k, v)
48
+ end
48
49
  end
50
+ # puts '[Paraxial] pt_v4.num_nodes'
51
+ # puts pt_v4.num_nodes
52
+ # puts 'pt_v6.num_nodes'
53
+ # puts pt_v6.num_nodes
54
+ PARAXIAL_IPV4 = pt_v4
55
+ PARAXIAL_IPV6 = pt_v6
56
+ rescue Errno::ECONNREFUSED => _e
57
+ puts '[Paraxial] Init HTTP request failed, check configuration'
58
+ PARAXIAL_IPV4 = Patricia.new
59
+ PARAXIAL_IPV6 = Patricia.new(:AF_INET6)
60
+ rescue StandardError => _e
61
+ puts '[Paraxial] Init error, check configuration'
62
+ PARAXIAL_IPV4 = Patricia.new
63
+ PARAXIAL_IPV6 = Patricia.new(:AF_INET6)
49
64
  end
50
- # puts '[Paraxial] pt_v4.num_nodes'
51
- # puts pt_v4.num_nodes
52
- # puts 'pt_v6.num_nodes'
53
- # puts pt_v6.num_nodes
54
- PARAXIAL_IPV4 = pt_v4
55
- PARAXIAL_IPV6 = pt_v6
56
65
  end
57
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paraxial
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraxial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lubas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -82,6 +82,7 @@ files:
82
82
  - lib/paraxial.rb
83
83
  - lib/paraxial/cli.rb
84
84
  - lib/paraxial/engine.rb
85
+ - lib/paraxial/helpers.rb
85
86
  - lib/paraxial/initializers/startup.rb
86
87
  - lib/paraxial/version.rb
87
88
  - lib/rubocop/cop/paraxial/constantize.rb