Class: SimplyGenius::Atmos::Otp

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport, Singleton
Defined in:
lib/simplygenius/atmos/otp.rb

Instance Method Summary collapse

Constructor Details

#initializeOtp

Returns a new instance of Otp.



12
13
14
15
16
17
18
19
20
# File 'lib/simplygenius/atmos/otp.rb', line 12

def initialize
  @secret_file = Atmos.config["atmos.otp.secret_file"] || "~/.atmos.yml"
  @secret_file = File.expand_path(@secret_file)
  yml_hash = YAML.load_file(@secret_file) rescue Hash.new
  @secret_store = SettingsHash.new(yml_hash)
  @secret_store[Atmos.config[:org]] ||= {}
  @secret_store[Atmos.config[:org]][:otp] ||= {}
  @scoped_secret_store = @secret_store[Atmos.config[:org]][:otp]
end

Instance Method Details

#add(name, secret) ⇒ Object



22
23
24
25
26
# File 'lib/simplygenius/atmos/otp.rb', line 22

def add(name, secret)
  old = @scoped_secret_store[name]
  logger.info "Replacing OTP secret #{name}=#{old}" if old
  @scoped_secret_store[name] = secret
end

#generate(name) ⇒ Object



39
40
41
# File 'lib/simplygenius/atmos/otp.rb', line 39

def generate(name)
  otp(name).try(:now)
end

#remove(name) ⇒ Object



28
29
30
31
32
# File 'lib/simplygenius/atmos/otp.rb', line 28

def remove(name)
  old = @scoped_secret_store.delete(name)
  @otp.try(:delete, name)
  logger.info "Removed OTP secret #{name}=#{old}" if old
end

#saveObject



34
35
36
37
# File 'lib/simplygenius/atmos/otp.rb', line 34

def save
  File.write(@secret_file, YAML.dump(@secret_store.to_hash))
  File.chmod(0600, @secret_file)
end