Class: ForemanSalt::SmartProxies::SaltKeys
- Inherits:
-
Object
- Object
- ForemanSalt::SmartProxies::SaltKeys
- Defined in:
- app/services/foreman_salt/smart_proxies/salt_keys.rb
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#smart_proxy_id ⇒ Object
readonly
Returns the value of attribute smart_proxy_id.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #accept ⇒ Object
- #delete ⇒ Object
-
#initialize(opts) ⇒ SaltKeys
constructor
A new instance of SaltKeys.
- #reject ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts) ⇒ SaltKeys
Returns a new instance of SaltKeys.
6 7 8 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 6 def initialize(opts) @name, @state, @fingerprint, @smart_proxy_id = opts.flatten end |
Instance Attribute Details
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
4 5 6 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 4 def fingerprint @fingerprint end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 4 def name @name end |
#smart_proxy_id ⇒ Object (readonly)
Returns the value of attribute smart_proxy_id.
4 5 6 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 4 def smart_proxy_id @smart_proxy_id end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 4 def state @state end |
Class Method Details
.all(proxy) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 11 def all(proxy) raise ::Foreman::Exception, N_('Must specify a Smart Proxy to use') if proxy.nil? unless (keys = Rails.cache.read("saltkeys_#{proxy.id}")) api = ProxyAPI::Salt.new(url: proxy.url) keys = api.key_list.map do |name, properties| new([name.strip, properties['state'], properties['fingerprint'], proxy.id]) end.compact Rails.cache.write("saltkeys_#{proxy.id}", keys, expires_in: 1.minute) if Rails.env.production? end keys end |
.find(proxy, name) ⇒ Object
25 26 27 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 25 def find(proxy, name) all(proxy).find { |c| c.name == name } end |
.find_by_state(proxy, state) ⇒ Object
29 30 31 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 29 def find_by_state(proxy, state) all(proxy).select { |c| c.state == state } end |
Instance Method Details
#<=>(other) ⇒ Object
60 61 62 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 60 def <=>(other) name <=> other.name end |
#accept ⇒ Object
34 35 36 37 38 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 34 def accept proxy = SmartProxy.find(smart_proxy_id) Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production? ProxyAPI::Salt.new(url: proxy.url).key_accept name end |
#delete ⇒ Object
46 47 48 49 50 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 46 def delete proxy = SmartProxy.find(smart_proxy_id) Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production? ProxyAPI::Salt.new(url: proxy.url).key_delete name end |
#reject ⇒ Object
40 41 42 43 44 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 40 def reject proxy = SmartProxy.find(smart_proxy_id) Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production? ProxyAPI::Salt.new(url: proxy.url).key_reject name end |
#to_param ⇒ Object
52 53 54 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 52 def to_param name end |
#to_s ⇒ Object
56 57 58 |
# File 'app/services/foreman_salt/smart_proxies/salt_keys.rb', line 56 def to_s name end |