Class: Net::Openvpn::Generators::Keys::Directory
- Inherits:
-
Object
- Object
- Net::Openvpn::Generators::Keys::Directory
- Defined in:
- lib/net/openvpn/generators/keys/directory.rb
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#generate ⇒ Object
Sets up the directory where keys are to be generated.
-
#initialize(**props) ⇒ Directory
constructor
A new instance of Directory.
Constructor Details
#initialize(**props) ⇒ Directory
Returns a new instance of Directory.
7 8 9 |
# File 'lib/net/openvpn/generators/keys/directory.rb', line 7 def initialize(**props) @props = Openvpn.props.merge props end |
Instance Method Details
#exist? ⇒ Boolean
11 12 13 14 15 |
# File 'lib/net/openvpn/generators/keys/directory.rb', line 11 def exist? File.directory?(@props[:key_dir]) and File.exist?(@props[:key_index]) and File.exist?("#{@props[:key_dir]}/serial") end |
#generate ⇒ Object
Sets up the directory where keys are to be generated. Also creates the serial and index.txt used by the pkitool that comes with easy-rsa
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/net/openvpn/generators/keys/directory.rb', line 20 def generate FileUtils.mkdir_p @props[:key_dir] unless File.directory? @props[:key_dir] FileUtils.cd(@props[:key_dir]) do FileUtils.touch @props[:key_index] File.open("serial", "w") {|f| f.write "01" } end FileUtils.chown_R( @props[:key_dir_owner], @props[:key_dir_group], @props[:key_dir] ) FileUtils.chmod_R( @props[:key_dir_permission], @props[:key_dir] ) end |