Class: Lamma::CLI::Rollback

Inherits:
Object
  • Object
show all
Includes:
SharedHelpers
Defined in:
lib/lamma/cli/rollback.rb

Constant Summary

Constants included from SharedHelpers

SharedHelpers::DEFAULT_PROFILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SharedHelpers

#ini_config, #ini_credentials, #region_or_raise, #search_conf_path

Constructor Details

#initialize(options, thor) ⇒ Rollback

Returns a new instance of Rollback.



14
15
16
17
18
# File 'lib/lamma/cli/rollback.rb', line 14

def initialize(options, thor)
  @options = options
  @thor = thor
  @conf_path = search_conf_path(options['conf_path'] || Lamma::DEFAULT_CONF_PATH)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/lamma/cli/rollback.rb', line 12

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/lamma/cli/rollback.rb', line 12

def path
  @path
end

#thorObject (readonly)

Returns the value of attribute thor.



12
13
14
# File 'lib/lamma/cli/rollback.rb', line 12

def thor
  @thor
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lamma/cli/rollback.rb', line 20

def run
  unless File.exist?(@conf_path)
    abort("Config file #{@conf_path} is missing.")
  end

  f = Lamma::Function.new(@conf_path)

  unless f.remote_exist?
    abort("Remote function #{f.name} doesn't seem to be exists. You have to create or deploy it first")
  end

  unless options['alias']
    abort("You can't rollback with alias (-a) option.")
  end

  a = Lamma::Alias.new(f, options['alias'])

  unless a.remote_exist?
    abort("Alias #{a.name} doesn't exist. You have to deploy the function first.")
  end

  la = Lamma::Alias.new(f, "#{options['alias']}_#{Lamma::LAST_DEPLOY_SUFFIX}")

  unless la.remote_exist?
    abort("Alias #{la.name} doesn't exist. You have to deploy the function first.")
  end

  v = a.remote_version
  lv = la.remote_version

  if v == lv
    abort("Aliases #{a.name} and #{la.name} indicates same version #{v}. Deploy it first?")
  end

  a.version = lv

  Lamma.logger.info("Updating alias configuration")
  a.update
end