class Jobshop::Generators::DevCertGenerator

Public Instance Methods

cert_file() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 118
def cert_file
  @cert_file ||= File.join(ssl_dir, "#{domain_name}.cert.pem")
end
check_existing_cert() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 29
      def check_existing_cert
        if File.file?(key_file) && File.file?(cert_file)
          say_status :exists, <<~MESSAGE
            Jobshop development key/certificate pair already exists
          MESSAGE

          exit 0
        end
      end
check_pwd() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 15
      def check_pwd
        unless Jobshop::CLI.canary?
          say_status :error, <<~MESSAGE
            This command can only be run from the root of the Jobshop source
          MESSAGE

          exit 0
        end
      end
config_file() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 110
def config_file
  @config_file ||= File.join(ssl_dir, "openssl.conf")
end
domain_name() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 102
def domain_name
  @domain_name ||= "jobshop.test"
end
generate_openssl_conf() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 39
      def generate_openssl_conf
        if !File.file?(config_file)
          <<~`CONFIG`
            cat > "#{config_file}" << EOF
            [req]
            distinguished_name = req_distinguished_name
            x509_extensions = v3_req
            prompt = no

            [req_distinguished_name]
            CN = Jobshop IO Development Environment

            [v3_req]
            keyUsage = keyEncipherment, dataEncipherment
            extendedKeyUsage = serverAuth
            subjectAltName = @alt_names

            [alt_names]
            DNS.1 = #{domain_name}
            DNS.2 = *.#{domain_name}
            DNS.3 = localhost
            IP.1 = 127.0.0.1
            EOF
          CONFIG
        else
          say_status :skip, "#{config_file} already exists..."
        end
      end
key_file() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 114
def key_file
  @key_file ||= File.join(ssl_dir, "#{domain_name}.key.pem")
end
make_dotssl_dir() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 25
def make_dotssl_dir
  FileUtils.mkdir_p(ssl_dir)
end
print_trust_instructions() click to toggle source
run_openssl_cmd() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 68
      def run_openssl_cmd
        <<~`CMD`
          openssl req             \\
          -newkey rsa:2048        \\
          -nodes -x509 -days 365  \\
          -keyout #{key_file}     \\
          -out #{cert_file}       \\
          -config #{config_file}  \\
          2> /dev/null
        CMD

        if $? == 0
          puts <<~MESSAGE
            A self-signed, wildcard SSL key/certificate pair has been generated for #{domain_name}\n
          MESSAGE
        else
          abort <<~MESSAGE
            An error has occured and the key/certificate pair were not generated
          MESSAGE
        end
      end
ssl_dir() click to toggle source
# File lib/generators/jobshop/dev_cert/dev_cert_generator.rb, line 106
def ssl_dir
  @ssl_dir ||= Pathname.pwd.join(".ssl")
end