Sha256: 4e822774d0bd11c428c28b83189071c163f79f3fb4fa9b2a7117b4ff52f4a5f9

Contents?: true

Size: 1.49 KB

Versions: 13

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require "dry/monads"
require "rubygems/command_manager"

module Gemsmith
  module Tools
    # Pushes a gem package to remote gem server.
    class Pusher
      include Import[:executor, :logger]
      include Dry::Monads[:result]

      def initialize(command: Gem::CommandManager.new, **)
        super(**)
        @command = command
      end

      def call specification
        command.run ["push", specification.package_path.to_s, *one_time_password]
        Success specification
      rescue Gem::Exception => error
        Failure error.message
      end

      private

      attr_reader :command

      # :reek:TooManyStatements
      def one_time_password
        return Core::EMPTY_ARRAY if check_yubikey.failure?

        executor.capture3(check_yubikey.success, "oath", "accounts", "code", "--single", "RubyGems")
                .then { |stdout, _stderr, status| status.success? ? ["--otp", stdout.chomp] : [] }
      rescue Errno::ENOENT => error
        logger.debug { "Unable to obtain YubiKey One-Time Password. #{error}." }
        Core::EMPTY_ARRAY
      end

      def check_yubikey
        executor.capture3("command", "-v", "ykman")
                .then do |stdout, stderr, status|
                  if status.success?
                    Success stdout.chomp
                  else
                    logger.debug { "Unable to find YubiKey Manager. #{stderr}." }
                    Failure()
                  end
                end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gemsmith-22.10.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.9.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.8.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.7.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.6.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.5.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.4.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.3.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.2.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.1.0 lib/gemsmith/tools/pusher.rb
gemsmith-22.0.0 lib/gemsmith/tools/pusher.rb
gemsmith-21.10.0 lib/gemsmith/tools/pusher.rb
gemsmith-21.9.0 lib/gemsmith/tools/pusher.rb