Class: SimplyGenius::Atmos::Plugins::LockDetection

Inherits:
OutputFilter
  • Object
show all
Defined in:
lib/simplygenius/atmos/plugins/lock_detection.rb

Instance Attribute Summary

Attributes inherited from OutputFilter

#context

Instance Method Summary collapse

Methods inherited from OutputFilter

#initialize

Methods included from UI

#agree, #ask, #choose, color_enabled, color_enabled=, #display, #error, #notify, #say, #warn

Constructor Details

This class inherits a constructor from SimplyGenius::Atmos::Plugins::OutputFilter

Instance Method Details

#closeObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/simplygenius/atmos/plugins/lock_detection.rb', line 21

def close
  if @lock_detected && @lock_id.present?
    clear_lock = agree("Terraform lock detected, would you like to clear it? ") {|q| q.default = 'n' }
    if clear_lock
      logger.info "Clearing terraform lock with id: #{@lock_id}"
      te = TerraformExecutor.new(process_env: context[:process_env])
      te.run("force-unlock", "-force", @lock_id)
    end
  end
end

#filter(data, flushing: false) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/simplygenius/atmos/plugins/lock_detection.rb', line 11

def filter(data, flushing: false)
  if data =~ /^[\e\[\dm\s]*Lock Info:[\e\[\dm\s]*$/
    @lock_detected = true
  end
  if data =~ /^[\e\[\dm\s]*ID:\s*([a-f0-9\-]+)[\e\[\dm\s]*$/
    @lock_id = $1
  end
  data
end