|
1
|
|
|
# frozen_string_literal: true |
|
2
|
|
|
|
|
3
|
|
|
# rubocop:disable Metrics/LineLength |
|
4
|
|
|
|
|
5
|
|
|
require_relative '../../../action/account/private_key/remote/add' |
|
6
|
|
|
require_relative '../../../action/account/private_key/remote/remove' |
|
7
|
|
|
require_relative '../../../action/account/private_key/remote/purge' |
|
8
|
|
|
|
|
9
|
|
|
module AMA |
|
10
|
|
|
module Chef |
|
11
|
|
|
module User |
|
12
|
|
|
class Planner |
|
13
|
|
|
class Account |
|
14
|
|
|
class PrivateKey |
|
15
|
|
|
# This planner creates actions altering private key remotes |
|
16
|
|
|
class Remote |
|
17
|
|
|
# @param [AMA::Chef::User::Model::Account] account |
|
18
|
|
|
# @param [AMA::Chef::User::Model::PrivateKey] private_key |
|
19
|
|
|
# @param [Hash{Symbol, AMA::Chef::User::Model::PrivateKey::Remote}] current_state |
|
20
|
|
|
# @param [Hash{Symbol, AMA::Chef::User::Model::PrivateKey::Remote}] desired_state |
|
21
|
|
|
def plan(account, private_key, current_state, desired_state) |
|
22
|
|
|
current_state ||= {} |
|
23
|
|
|
desired_state ||= {} |
|
24
|
|
|
actions = (current_state.keys | desired_state.keys).map do |key| |
|
25
|
|
|
current = current_state[key] |
|
26
|
|
|
desired = desired_state[key] |
|
27
|
|
|
process(account, private_key, current, desired) |
|
28
|
|
|
end |
|
29
|
|
|
if desired_state.empty? |
|
30
|
|
|
actions.push(ns::Purge.new(account, private_key)) |
|
31
|
|
|
end |
|
32
|
|
|
actions |
|
33
|
|
|
end |
|
34
|
|
|
|
|
35
|
|
|
private |
|
36
|
|
|
|
|
37
|
|
|
# @param [AMA::Chef::User::Model::Account] account |
|
38
|
|
|
# @param [AMA::Chef::User::Model::PrivateKey] private_key |
|
39
|
|
|
# @param [AMA::Chef::User::Model::PrivateKey::Remote] current_state |
|
40
|
|
|
# @param [AMA::Chef::User::Model::PrivateKey::Remote] desired_state |
|
41
|
|
|
def process(account, private_key, current_state, desired_state) |
|
42
|
|
|
if desired_state.nil? |
|
43
|
|
|
ns::Remove.new(account, private_key, current_state) |
|
44
|
|
|
else |
|
45
|
|
|
ns::Add.new(account, private_key, desired_state) |
|
46
|
|
|
end |
|
47
|
|
|
end |
|
48
|
|
|
|
|
49
|
|
|
def ns |
|
50
|
|
|
::AMA::Chef::User::Action::Account::PrivateKey::Remote |
|
51
|
|
|
end |
|
52
|
|
|
end |
|
53
|
|
|
end |
|
54
|
|
|
end |
|
55
|
|
|
end |
|
56
|
|
|
end |
|
57
|
|
|
end |
|
58
|
|
|
end |
|
59
|
|
|
|