Class: KStor::Model::SecretMeta

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#appObject

Secret is defined for this application



313
314
315
# File 'lib/kstor/model.rb', line 313

def app
  @app
end

#databaseObject

Secret is defined for this database



315
316
317
# File 'lib/kstor/model.rb', line 315

def database
  @database
end

#loginObject

Secret is defined for this login



317
318
319
# File 'lib/kstor/model.rb', line 317

def 
  @login
end

#serverObject

Secret is related to this server



319
320
321
# File 'lib/kstor/model.rb', line 319

def server
  @server
end

#urlObject

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

Returns:

  • (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?(meta)
  self_h = to_h
  other_h = meta.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

#serializeObject



336
337
338
# File 'lib/kstor/model.rb', line 336

def serialize
  Crypto::ArmoredHash.from_hash(to_h)
end

#to_hObject



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