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.
Instance Method Summary collapse
-
#initialize(values) ⇒ KStor::Model::SecretMeta
constructor
Create new metadata for a secret.
-
#match?(meta) ⇒ Boolean
Match against wildcards.
-
#merge(other) ⇒ Object
Merge metadata.
-
#serialize ⇒ KStor::Crypto::ArmoredHash
Prepare metadata to be written to disk or database.
-
#to_h ⇒ Hash[String, String]
Convert this metadata to a Hash.
Constructor Details
#initialize(values) ⇒ KStor::Model::SecretMeta
Create new metadata for a secret.
Hash param can contains keys for “app”, “database”, “login”, “server” and “url”. Any other key is ignored.
320 321 322 323 324 325 326 |
# File 'lib/kstor/model.rb', line 320 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
303 304 305 |
# File 'lib/kstor/model.rb', line 303 def app @app end |
#database ⇒ Object
Secret is defined for this database
305 306 307 |
# File 'lib/kstor/model.rb', line 305 def database @database end |
#login ⇒ Object
Secret is defined for this login
307 308 309 |
# File 'lib/kstor/model.rb', line 307 def login @login end |
#server ⇒ Object
Secret is related to this server
309 310 311 |
# File 'lib/kstor/model.rb', line 309 def server @server end |
#url ⇒ Object
Secret should be used at this URL
311 312 313 |
# File 'lib/kstor/model.rb', line 311 def url @url end |
Instance Method Details
#match?(meta) ⇒ Boolean
Match against wildcards.
Metadata will be matched against another metadata object with wildcard values. This uses roughly the same rules that shell wildcards (e.g. fnmatch(3) C function).
rubocop:disable Metrics/CyclomaticComplexity
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/kstor/model.rb', line 366 def match?() self_h = to_h other_h = .to_h other_h.each do |k, wildcard| val = self_h[k] return false if val.nil? && !wildcard.nil? && wildcard != '*' 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
Merge metadata.
349 350 351 352 353 |
# File 'lib/kstor/model.rb', line 349 def merge(other) values = to_h.merge(other.to_h) values.reject! { |_, v| v.empty? } self.class.new(values) end |
#serialize ⇒ KStor::Crypto::ArmoredHash
Prepare metadata to be written to disk or database.
341 342 343 |
# File 'lib/kstor/model.rb', line 341 def serialize Crypto::ArmoredHash.from_hash(to_h) end |
#to_h ⇒ Hash[String, String]
Convert this metadata to a Hash.
Empty values will not be included.
333 334 335 336 |
# File 'lib/kstor/model.rb', line 333 def to_h { 'app' => @app, 'database' => @database, 'login' => @login, 'server' => @server, 'url' => @url }.compact end |