Class: SimplyGenius::Atmos::Commands::Otp

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/simplygenius/atmos/commands/otp.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UI

#agree, #ask, #choose, color_enabled, color_enabled=, #display, #error, #notify, #say, #warn

Class Method Details

.descriptionObject



11
12
13
# File 'lib/simplygenius/atmos/commands/otp.rb', line 11

def self.description
  "Generates an otp token for the given user"
end

Instance Method Details

#executeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/simplygenius/atmos/commands/otp.rb', line 29

def execute
  code = nil
  if secret
    Atmos::Otp.instance.add(name, secret)
    code = Atmos::Otp.instance.generate(name)
    Atmos::Otp.instance.save
  else
    code = Atmos::Otp.instance.generate(name)
  end

  if code.nil?
    signal_usage_error <<~EOF
      No otp secret has been setup for #{name}
      Use the -m flag to 'atmos user create' to create/activate one
      or associate an existing secret with 'atmos otp -s <secret> <name>'
    EOF
  else
    puts code
  end

  if clipboard?
    Clipboard.copy(code)
  end
end