Class: KStor::Model::SecretMeta
- Inherits:
-
Object
- Object
- KStor::Model::SecretMeta
- Defined in:
- lib/kstor/model.rb
Overview
Metadata for a secret.
This is not a “real” model object: just a helper class to convert metadata to and from database.
Instance Attribute Summary collapse
-
#app ⇒ Object
Secret is defined for this application.
-
#database ⇒ Object
Secret is defined for this database.
-
#login ⇒ Object
Secret is defined for this login.
-
#server ⇒ Object
Secret is related to this server.
-
#url ⇒ Object
Secret should be used at this URL.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(values) ⇒ SecretMeta
constructor
A new instance of SecretMeta.
- #match?(meta) ⇒ Boolean
- #merge(other) ⇒ Object
- #serialize ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(values) ⇒ SecretMeta
Returns a new instance of SecretMeta.
323 324 325 326 327 328 329 |
# File 'lib/kstor/model.rb', line 323 def initialize(values) @app = values['app'] @database = values['database'] @login = values['login'] @server = values['server'] @url = values['url'] end |
Instance Attribute Details
#app ⇒ Object
Secret is defined for this application
313 314 315 |
# File 'lib/kstor/model.rb', line 313 def app @app end |
#database ⇒ Object
Secret is defined for this database
315 316 317 |
# File 'lib/kstor/model.rb', line 315 def database @database end |
#login ⇒ Object
Secret is defined for this login
317 318 319 |
# File 'lib/kstor/model.rb', line 317 def login @login end |
#server ⇒ Object
Secret is related to this server
319 320 321 |
# File 'lib/kstor/model.rb', line 319 def server @server end |
#url ⇒ Object
Secret should be used at this URL
321 322 323 |
# File 'lib/kstor/model.rb', line 321 def url @url end |
Class Method Details
.load(armored_hash) ⇒ Object
346 347 348 |
# File 'lib/kstor/model.rb', line 346 def self.load(armored_hash) new(armored_hash.to_hash) end |
Instance Method Details
#match?(meta) ⇒ Boolean
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/kstor/model.rb', line 350 def match?() self_h = to_h other_h = .to_h other_h.each do |k, wildcard| val = self_h[k] next if val.nil? next if wildcard.nil? key_matched = File.fnmatch?( wildcard, val, File::FNM_CASEFOLD | File::FNM_DOTMATCH ) return false unless key_matched end true end |
#merge(other) ⇒ Object
340 341 342 343 344 |
# File 'lib/kstor/model.rb', line 340 def merge(other) values = to_h.merge(other.to_h) values.reject! { |_, v| v.empty? } self.class.new(values) end |
#serialize ⇒ Object
336 337 338 |
# File 'lib/kstor/model.rb', line 336 def serialize Crypto::ArmoredHash.from_hash(to_h) end |
#to_h ⇒ Object
331 332 333 334 |
# File 'lib/kstor/model.rb', line 331 def to_h { 'app' => @app, 'database' => @database, 'login' => @login, 'server' => @server, 'url' => @url }.compact end |