smart_proxy_ansible 2.1.0 → 2.1.1

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: ce925932dfc2ddf578d2ae15b293ee1a223b8808
4
- data.tar.gz: 54f6dd7b4d48229be33aef44b7445d8284a7d734
3
+ metadata.gz: 572320552523c1629bda9d963a16fd07d189f14a
4
+ data.tar.gz: 92d4fee5cbafedd4fc52b0921ca4f470374837f1
5
5
  SHA512:
6
- metadata.gz: a88b68d82b25d7baeff478651fdf159c512be92262d2c7c5ed5af5ed204915043ab08dbe3d7b3200a7261226f0ece19f2e803be10d3e25e105caa3f6d46bc97e
7
- data.tar.gz: 0c57bf4282a7f4e9699b9108e3e89817a2e2ded17ef448d8d51ae5eeede0a93d8947673d3df034d775fee2238fdb5c2fc40a707c1acc77aa5044953c062c0e97
6
+ metadata.gz: f9faca4cd728399491dd3a8edba30dc214d710ed237d12c95e5abaed7a58eccdc35ad79a2c894b8eeea1fc1723b2b05ed857eef8add79c102a51e4de2a7cb571
7
+ data.tar.gz: 3c908550293b98400efb727cd89e5f55537ff6b1616a364c78635dccb7fff8540a19845bba583547d3c637207192d91149a03dde215fa7df1334de8d897b70da
@@ -4,6 +4,8 @@ module Proxy
4
4
  # please keep the actual implementation of the endpoints outside
5
5
  # of this class.
6
6
  class Api < Sinatra::Base
7
+ include ::Proxy::Log
8
+
7
9
  get '/roles' do
8
10
  RolesReader.list_roles.to_json
9
11
  end
@@ -11,13 +13,23 @@ module Proxy
11
13
  get '/roles/variables' do
12
14
  variables = {}
13
15
  RolesReader.list_roles.each do |role_name|
14
- variables[role_name] = extract_variables(role_name)[role_name]
16
+ begin
17
+ variables[role_name] = extract_variables(role_name)[role_name]
18
+ rescue ReadVariablesException => e
19
+ # skip what cannot be parsed
20
+ logger.error e
21
+ end
15
22
  end
16
23
  variables.to_json
17
24
  end
18
25
 
19
26
  get '/roles/:role_name/variables' do |role_name|
20
- extract_variables(role_name).to_json
27
+ begin
28
+ extract_variables(role_name).to_json
29
+ rescue ReadVariablesException => e
30
+ logger.error e
31
+ {}.to_json
32
+ end
21
33
  end
22
34
 
23
35
  private
@@ -36,5 +36,6 @@ module Proxy
36
36
 
37
37
  class ReadConfigFileException < Proxy::Ansible::Exception; end
38
38
  class ReadRolesException < Proxy::Ansible::Exception; end
39
+ class ReadVariablesException < Proxy::Ansible::Exception; end
39
40
  end
40
41
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Proxy
2
4
  module Ansible
3
5
  # Implements the logic needed to read the roles and associated information
@@ -6,26 +8,16 @@ module Proxy
6
8
  def extract_variables(role_path)
7
9
  role_files = Dir.glob("#{role_path}/defaults/**/*.yml") +
8
10
  Dir.glob("#{role_path}/defaults/**/*.yaml")
9
- # not anything matching item, }}, {{, ansible_hostname or 'if'
10
- variables = role_files.map do |role_file|
11
- candidates = File.read(role_file)
12
- .scan(/{{(.*?)}}/).select do |param|
13
- param.first.scan(/item/) == [] && param.first.scan(/if/) == []
14
- end.flatten
15
- # Sometimes inside the {{ }} there's a OR condition. In such a case,
16
- # let's split and choose possible variables (variables cannot
17
- # contain parenthesis)
18
-
19
- candidates.map do |variable|
20
- variable.split('|').map(&:strip).select do |var|
21
- !var.include?('(') && # variables are not parenthesis
22
- !var.include?('[') && # variables are not arrays
23
- !var.include?('.') && # variables are not objects
24
- !var.include?("'") # variables are not plain strings
25
- end
26
- end unless candidates.nil?
27
- end.compact.flatten.uniq.map(&:strip)
28
- variables
11
+ role_files.flat_map do |role_file|
12
+ loaded_yaml = {}
13
+ begin
14
+ loaded_yaml = YAML.load_file(role_file)
15
+ rescue Psych::SyntaxError
16
+ raise ReadVariablesException.new "#{role_file} is not YAML file"
17
+ end
18
+ raise ReadVariablesException.new "Could not parse YAML file: #{role_file}" unless loaded_yaml.is_a? Hash
19
+ loaded_yaml.keys
20
+ end
29
21
  end
30
22
  end
31
23
  end
@@ -2,6 +2,6 @@ module Proxy
2
2
  # Version, this allows the proxy and other plugins know
3
3
  # what version of the Ansible plugin is running
4
4
  module Ansible
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-06 00:00:00.000000000 Z
12
+ date: 2019-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler