lex-onboard 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 945d2252b6dec50ef82d5ff441ef39099c146b0a1dbd7300e1eb9a10238f9bc3
4
- data.tar.gz: 4213f845c3c1211175427ab0f98381c11832640da13556fbc30dcf7264723867
3
+ metadata.gz: 734d7a7131177c63cfa8f5ed51952c7b615ca3dcbae983656dd2e513ba6c0ff3
4
+ data.tar.gz: 0b13588fe6aab4675e595be3b4bcf185aacca1d31670f7727eb407a37b20399b
5
5
  SHA512:
6
- metadata.gz: 966c8d189ef9f44a6c77c44b65eedcf582f4ac9dfca8dd2a6fc61223d48d29c7057aad5633095e08ad5d1bd94d5a3657dc225b5c13110ef36ae247eca3937946
7
- data.tar.gz: 63bece2311db70ff269547be69007c130d302f5c415e1792aeea6e55ef905d77108bd1a2af880ae4b5bda5e67c7b92e1595c5662a0e64ea0eb6c17facd0b46f6
6
+ metadata.gz: 222dfc7792f88731d91cdf2816d43b55b6ace9ac6fefabddfdad3bf7ff6b3ef1434b0d7bf8c850b4542d536811e855c78cb3bcae8a3e3aa2fc1fc6cfe34061e2
7
+ data.tar.gz: 44e0ce419d40ee89ba7f887bcc890550b8f8a557a84d1812751d4d17bd2ccc497a08484625ad9b3b3155bb6662b894071b2ab4d0ebc68e5ec679445c2a08503b
@@ -5,12 +5,13 @@ module Legion
5
5
  module Onboard
6
6
  module Runners
7
7
  module Provision
8
+ extend self
8
9
  include Validator
9
10
 
10
11
  ROLLBACK_ACTIONS = {
11
- vault_namespace: ->(client, askid) { client.delete_namespace(name: askid) },
12
+ vault_namespace: ->(client, askid) { client.delete_namespace(name: askid) },
12
13
  consul_partition: ->(client, askid) { client.delete_partition(name: askid) },
13
- tfe_project: ->(client, askid) { client.delete_project(name: askid) }
14
+ tfe_project: ->(client, askid) { client.delete_project(name: askid) }
14
15
  }.freeze
15
16
 
16
17
  def provision(askid:, tfe_organization: 'terraform.uhg.com', requester_slack_webhook: nil, **)
@@ -18,9 +19,7 @@ module Legion
18
19
  return { status: 'rejected', askid: askid, reason: validation[:reason] } unless validation[:valid]
19
20
 
20
21
  conflicts = check_conflicts(askid: askid)
21
- unless conflicts[:conflicts].empty?
22
- return { status: 'rejected', askid: askid, reason: "conflict in: #{conflicts[:conflicts].join(', ')}" }
23
- end
22
+ return { status: 'rejected', askid: askid, reason: "conflict in: #{conflicts[:conflicts].join(', ')}" } unless conflicts[:conflicts].empty?
24
23
 
25
24
  completed_steps = []
26
25
  steps = []
@@ -52,7 +51,7 @@ module Legion
52
51
  end
53
52
 
54
53
  def rollback(completed_steps, askid:)
55
- completed_steps.reverse.map do |step_name|
54
+ completed_steps.reverse.filter_map do |step_name|
56
55
  action = ROLLBACK_ACTIONS[step_name]
57
56
  next unless action
58
57
 
@@ -60,7 +59,7 @@ module Legion
60
59
  { step: step_name, status: 'rolled_back' }
61
60
  rescue StandardError => e
62
61
  { step: step_name, status: 'rollback_failed', error: e.message }
63
- end.compact
62
+ end
64
63
  end
65
64
 
66
65
  def client_for_step(step_name)
@@ -72,9 +71,7 @@ module Legion
72
71
  end
73
72
 
74
73
  def vault_namespace(askid:)
75
- unless defined?(Legion::Extensions::Vault::Client)
76
- return { step: :vault_namespace, status: 'skipped', reason: 'vault unavailable' }
77
- end
74
+ return { step: :vault_namespace, status: 'skipped', reason: 'vault unavailable' } unless defined?(Legion::Extensions::Vault::Client)
78
75
  return { step: :vault_namespace, status: 'skipped', reason: 'already exists' } if vault_exists?(askid)
79
76
 
80
77
  vault_client.create_namespace(name: askid)
@@ -84,9 +81,7 @@ module Legion
84
81
  end
85
82
 
86
83
  def consul_partition(askid:)
87
- unless defined?(Legion::Extensions::Consul::Client)
88
- return { step: :consul_partition, status: 'skipped', reason: 'consul unavailable' }
89
- end
84
+ return { step: :consul_partition, status: 'skipped', reason: 'consul unavailable' } unless defined?(Legion::Extensions::Consul::Client)
90
85
  return { step: :consul_partition, status: 'skipped', reason: 'already exists' } if consul_exists?(askid)
91
86
 
92
87
  consul_client.create_partition(name: askid)
@@ -96,9 +91,7 @@ module Legion
96
91
  end
97
92
 
98
93
  def tfe_project(askid:, organization:)
99
- unless defined?(Legion::Extensions::Tfe::Client)
100
- return { step: :tfe_project, status: 'skipped', reason: 'tfe unavailable' }
101
- end
94
+ return { step: :tfe_project, status: 'skipped', reason: 'tfe unavailable' } unless defined?(Legion::Extensions::Tfe::Client)
102
95
  return { step: :tfe_project, status: 'skipped', reason: 'already exists' } if tfe_exists?(askid)
103
96
 
104
97
  tfe_client.create_project(organization: organization, name: askid)
@@ -120,12 +113,12 @@ module Legion
120
113
  end
121
114
 
122
115
  def notify_requester(askid:, webhook: nil)
123
- return true unless webhook && defined?(Legion::Extensions::Slack::Client)
116
+ return true unless webhook && defined?(Legion::Extensions::Slack::Client) # rubocop:disable Legion/Extension/RunnerReturnHash
124
117
 
125
118
  Legion::Extensions::Slack::Client.new.send_webhook(
126
119
  webhook: webhook, message: "Onboarding complete for #{askid}"
127
120
  )
128
- rescue StandardError
121
+ rescue StandardError => _e
129
122
  true
130
123
  end
131
124
  end
@@ -5,6 +5,8 @@ module Legion
5
5
  module Onboard
6
6
  module Runners
7
7
  module Validator
8
+ extend self
9
+
8
10
  ASKID_PATTERN = /\A[a-z0-9]([a-z0-9-]*[a-z0-9])?\z/
9
11
  MAX_ASKID_LENGTH = 63
10
12
 
@@ -13,7 +15,7 @@ module Legion
13
15
  return { valid: false, reason: "askid exceeds #{MAX_ASKID_LENGTH} characters" } if askid.length > MAX_ASKID_LENGTH
14
16
 
15
17
  unless askid.match?(ASKID_PATTERN)
16
- return { valid: false,
18
+ return { valid: false,
17
19
  reason: 'askid format invalid — must be lowercase alphanumeric with hyphens' }
18
20
  end
19
21
 
@@ -32,26 +34,26 @@ module Legion
32
34
  private
33
35
 
34
36
  def vault_exists?(askid)
35
- return false unless defined?(Legion::Extensions::Vault::Client)
37
+ return false unless defined?(Legion::Extensions::Vault::Client) # rubocop:disable Legion/Extension/RunnerReturnHash
36
38
 
37
39
  Legion::Extensions::Vault::Client.new.list_namespaces[:namespaces]&.include?(askid)
38
- rescue StandardError
40
+ rescue StandardError => _e
39
41
  false
40
42
  end
41
43
 
42
44
  def consul_exists?(askid)
43
- return false unless defined?(Legion::Extensions::Consul::Client)
45
+ return false unless defined?(Legion::Extensions::Consul::Client) # rubocop:disable Legion/Extension/RunnerReturnHash
44
46
 
45
47
  Legion::Extensions::Consul::Client.new.list_partitions[:partitions]&.any? { |p| p[:name] == askid }
46
- rescue StandardError
48
+ rescue StandardError => _e
47
49
  false
48
50
  end
49
51
 
50
52
  def tfe_exists?(askid)
51
- return false unless defined?(Legion::Extensions::Tfe::Client)
53
+ return false unless defined?(Legion::Extensions::Tfe::Client) # rubocop:disable Legion/Extension/RunnerReturnHash
52
54
 
53
55
  Legion::Extensions::Tfe::Client.new.list_projects[:projects]&.any? { |p| p[:name] == askid }
54
- rescue StandardError
56
+ rescue StandardError => _e
55
57
  false
56
58
  end
57
59
  end
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Onboard
6
- VERSION = '0.2.0'
6
+ VERSION = '0.2.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-onboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity