Sha256: a6a6b823e64193f401b33452a351a1b9e17605c58176419bd5f2b885a4820303

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 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 [] 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}." }
        []
      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

25 entries across 25 versions & 1 rubygems

Version Path
gemsmith-19.6.0 lib/gemsmith/tools/pusher.rb
gemsmith-19.5.2 lib/gemsmith/tools/pusher.rb
gemsmith-19.5.1 lib/gemsmith/tools/pusher.rb
gemsmith-19.5.0 lib/gemsmith/tools/pusher.rb
gemsmith-19.4.0 lib/gemsmith/tools/pusher.rb