Sha256: e59ccecc379dd13e552335689eb2b8d805eb82a12746a164fb27fb2170f11e4e

Contents?: true

Size: 1.21 KB

Versions: 18

Compression:

Stored size: 1.21 KB

Contents

require "hanami/utils/blank"
require "securerandom"

module Hanami
  class CLI
    module Commands
      module Generate
        # @since 1.1.0
        # @api private
        class Secret < Command
          requires "environment"

          desc "Generate session secret"

          argument :app, desc: "The application name (eg. `web`)"

          example [
            "    # Prints secret (eg. `#{Project.app_sessions_secret}`)",
            "web # Prints session secret (eg. `WEB_SESSIONS_SECRET=#{Project.app_sessions_secret}`)"
          ]

          # @since 1.1.0
          # @api private
          def call(app: nil, **options)
            context = Context.new(app: app, options: options)

            generate_secret(context)
          end

          private

          # @since 1.1.0
          # @api private
          def generate_secret(context)
            secret = project.app_sessions_secret

            if Hanami::Utils::Blank.blank?(context.app)
              puts secret
            else
              puts "Set the following environment variable to provide the secret token:"
              puts %(#{context.app.upcase}_SESSIONS_SECRET="#{secret}")
            end
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hanami-1.3.5 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.4 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.3 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.2 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.0 lib/hanami/cli/commands/generate/secret.rb
hanami-1.3.0.beta1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.2.0 lib/hanami/cli/commands/generate/secret.rb
hanami-1.2.0.rc2 lib/hanami/cli/commands/generate/secret.rb
hanami-1.2.0.rc1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.2.0.beta2 lib/hanami/cli/commands/generate/secret.rb
hanami-1.2.0.beta1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.0 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.0.rc1 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.0.beta3 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.0.beta2 lib/hanami/cli/commands/generate/secret.rb
hanami-1.1.0.beta1 lib/hanami/cli/commands/generate/secret.rb