Sha256: e18b07d0a3f3473663782889076d5f3f60a15c0911920a4801e540b8af3c0410

Contents?: true

Size: 876 Bytes

Versions: 6

Compression:

Stored size: 876 Bytes

Contents

module LearnOpen
  class GitSSHConnector
    attr_reader :ssh_connection, :environment

    GIT_SSH_USER = 'git'

    def self.call(git_server:, environment:)
      self.new(git_server: git_server, environment: environment).call
    end

    def initialize(git_server:, environment:)
      @ssh_connection = LearnOpen.ssh_adapter.new(user: GIT_SSH_USER, hostname: git_server)
      @environment = environment
    end

    def call
      if managed_environment? && ssh_unauthenticated?
        upload_ssh_keys!
      end

      ssh_authenticated?
    end

    def upload_ssh_keys!
      LearnOpen.learn_web_client.add_ssh_key(key: ssh_connection.public_key)
    end

    def managed_environment?
      environment.managed?
    end

    def ssh_unauthenticated?
      !ssh_authenticated?
    end

    def ssh_authenticated?
      ssh_connection.authenticated?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
learn-open-1.2.28 lib/learn_open/services/git_ssh_connector.rb
learn-open-1.2.27 lib/learn_open/services/git_ssh_connector.rb
learn-open-1.2.26 lib/learn_open/services/git_ssh_connector.rb
learn-open-1.2.24 lib/learn_open/services/git_ssh_connector.rb
learn-open-1.2.23 lib/learn_open/services/git_ssh_connector.rb
learn-open-1.2.22 lib/learn_open/services/git_ssh_connector.rb