class RdsRotateDbSnapshots::OptionsParser

Attributes

options[R]
script_name[R]
time_periods[R]

Public Class Methods

new(script_name: nil, cli: false) click to toggle source
# File lib/rds_rotate_db_snapshots/options_parser.rb, line 12
def initialize(script_name: nil, cli: false)
  @script_name = script_name
  @options = {
    aws_access_key: ENV.fetch("AWS_ACCESS_KEY_ID", nil),
    aws_secret_access_key: ENV.fetch("AWS_SECRET_ACCESS_KEY", nil),
    aws_session_token: ENV.fetch("AWS_SESSION_TOKEN", nil),
    aws_region: ENV.fetch("AWS_REGION", nil),
    pattern: nil,
    by_tags: nil,
    dry_run: false,
    backoff_limit: 15,
    create_snapshot: nil
  }
  @time_periods = {
    hourly: { seconds: 60 * 60, format: '%Y-%m-%d-%H', keep: 0, keeping: {} },
    daily: { seconds: 24 * 60 * 60, format: '%Y-%m-%d', keep: 0, keeping: {} },
    weekly: { seconds: 7 * 24 * 60 * 60, format: '%Y-%W', keep: 0, keeping: {} },
    monthly: { seconds: 30 * 24 * 60 * 60, format: '%Y-%m', keep: 0, keeping: {} },
    yearly: { seconds: 12 * 30 * 24 * 60 * 60, format: '%Y', keep: 0, keeping: {} }
  }
  @cli = cli
  init_cli_parser if cli?
end

Public Instance Methods

parse!() click to toggle source
# File lib/rds_rotate_db_snapshots/options_parser.rb, line 36
def parse!
  @parser.parse!
  @options.merge(time_periods: @time_periods)
end

Private Instance Methods

cli?() click to toggle source
# File lib/rds_rotate_db_snapshots/options_parser.rb, line 43
def cli?
  !!@cli
end
init_cli_parser() click to toggle source
# File lib/rds_rotate_db_snapshots/options_parser.rb, line 47
def init_cli_parser
  @parser ||= OptionParser.new do |o|
    banner_opts o
    aws_opts o
    snapshot_create_opts o
    time_period_opts o
    extra_opts o
    not_supported_opts o
  end
end