Class: Kscript::KkWgPassUtils

Inherits:
Base
  • Object
show all
Defined in:
lib/kscript/plugins/kk_wg_pass_utils.rb

Instance Attribute Summary

Attributes inherited from Base

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#human_output?, inherited, #with_error_handling

Constructor Details

#initialize(*args, **opts) ⇒ KkWgPassUtils

Returns a new instance of KkWgPassUtils.



12
13
14
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 12

def initialize(*args, **opts)
  super
end

Class Method Details

.argumentsObject



29
30
31
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 29

def self.arguments
  '[length]'
end

.authorObject



41
42
43
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 41

def self.author
  'kk'
end

.descriptionObject



45
46
47
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 45

def self.description
  'Generate a random password for WireGuard.'
end

.groupObject



37
38
39
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 37

def self.group
  'network'
end

.usageObject



33
34
35
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 33

def self.usage
  "kscript wg_pass [length]\nkscript wg_pass 32"
end

Instance Method Details

#generateObject



23
24
25
26
27
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 23

def generate
  password = Array.new(@length) { rand(33..126).chr }.join
  logger.kinfo('Generated WireGuard password', password: password)
  logger.kinfo(password)
end

#run(*args, **_opts) ⇒ Object



16
17
18
19
20
21
# File 'lib/kscript/plugins/kk_wg_pass_utils.rb', line 16

def run(*args, **_opts)
  with_error_handling do
    @length = (args[0] || 24).to_i
    generate
  end
end