Add.initialize()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
# frozen_string_literal: true
2
3
require_relative '../../../../action'
4
require_relative '../../../../helper/ssh_methods'
5
6
module AMA
7
  module Chef
8
    module User
9
      class Action
10
        module Account
11
          module PrivateKey
12
            module Remote
13
              class Add < Action
14
                include Helper::SSHMethods
15
16
                attr_accessor :account
17
                attr_accessor :private_key
18
                attr_accessor :remote
19
20
                # @param [AMA::Chef::User::Model::Account] account
21
                # @param [AMA::Chef::User::Model::PrivateKey] private_key
22
                # @param [AMA::Chef::User::Model::PrivateKey::Remote] remote
23
                def initialize(account, private_key, remote)
24
                  @account = account
25
                  @private_key = private_key
26
                  @remote = remote
27
                end
28
29
                def apply(resource_factory)
30
                  path = "#{ssh_directory(@account.id)}/#{@private_key.id}"
31
                  options = @remote.options.merge('IdentityFile' => path)
32
                  account = @account
33
                  key = @private_key
34
                  remote = @remote
35
                  name = "#{account.id}:#{key.owner}:#{key.id}:#{remote.id}"
36
                  resource_factory.ssh_config name do
37
                    user account.id.to_s
38
                    host remote.id.to_s
39
                    options options
40
                  end
41
                end
42
              end
43
            end
44
          end
45
        end
46
      end
47
    end
48
  end
49
end
50