Class: Belt::CLI::BackupConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/belt/cli/backup_config.rb

Defined Under Namespace

Classes: BackupDSL, ConfigDSL, ConfigEvaluator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBackupConfig

Returns a new instance of BackupConfig.



23
24
25
26
27
28
# File 'lib/belt/cli/backup_config.rb', line 23

def initialize
  @dynamodb_tables = nil # nil = not configured, :all = all tables, Array = specific tables
  @cognito_exports = []  # e.g. [:users, :pool_config]
  @s3_buckets = []       # e.g. [:legal_documents]
  @retention = { snapshots: 90, cognito: 10, s3: 10 }
end

Instance Attribute Details

#cognito_exportsObject (readonly)

Returns the value of attribute cognito_exports.



6
7
8
# File 'lib/belt/cli/backup_config.rb', line 6

def cognito_exports
  @cognito_exports
end

#dynamodb_tablesObject (readonly)

Returns the value of attribute dynamodb_tables.



6
7
8
# File 'lib/belt/cli/backup_config.rb', line 6

def dynamodb_tables
  @dynamodb_tables
end

#retentionObject (readonly)

Returns the value of attribute retention.



6
7
8
# File 'lib/belt/cli/backup_config.rb', line 6

def retention
  @retention
end

#s3_bucketsObject (readonly)

Returns the value of attribute s3_buckets.



6
7
8
# File 'lib/belt/cli/backup_config.rb', line 6

def s3_buckets
  @s3_buckets
end

Class Method Details

.load(env, infra_dir: nil) ⇒ Object

Load backup config from infrastructure//belt.rb Returns nil if no config file exists or backups aren't configured



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/belt/cli/backup_config.rb', line 10

def self.load(env, infra_dir: nil)
  infra_dir ||= 'infrastructure'
  config_file = File.join(infra_dir, env, 'belt.rb')
  return nil unless File.exist?(config_file)

  config = new
  evaluator = ConfigEvaluator.new(config)
  evaluator.evaluate(File.read(config_file), config_file)

  # Return nil if no backups were configured
  config.any? ? config : nil
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/belt/cli/backup_config.rb', line 38

def any?
  dynamodb? || cognito? || @s3_buckets.any?
end

#cognito?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/belt/cli/backup_config.rb', line 34

def cognito?
  @cognito_exports.any?
end

#dynamodb?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/belt/cli/backup_config.rb', line 30

def dynamodb?
  !@dynamodb_tables.nil?
end