class AwsRotate::List

Public Class Methods

new(options={}) click to toggle source
Calls superclass method AwsRotate::Base::new
# File lib/aws_rotate/list.rb, line 3
def initialize(options={})
  super
  @lines = IO.readlines(@credentials_path)
end

Public Instance Methods

all_profiles() click to toggle source
# File lib/aws_rotate/list.rb, line 40
def all_profiles
  all_profiles = []
  @lines.each do |line|
    next if line =~ /^\s*#/ # ignore comments

    md = line.match(/\[(.*)\]/)
    all_profiles << md[1] if md
  end
  all_profiles
end
find_profiles(regexp) click to toggle source
# File lib/aws_rotate/list.rb, line 21
def find_profiles(regexp)
  has_key, within_profile, profiles = false, false, []
  all_profiles.each do |profile|
    @lines.each do |line|
      line = line.strip
      within_profile = false if line =~ /^\[/ # on the next profile section, reset flag
      within_profile ||= line == "[#{profile}]" # enable checking
      if within_profile
        has_key = line =~ regexp
        if has_key
          profiles << profile
          break
        end
      end
    end
  end
  profiles
end
profiles() click to toggle source

Only returns profiles that have aws_access_key_id without mfa_serial

# File lib/aws_rotate/list.rb, line 15
def profiles
  iam_profiles = find_profiles(/^aws_access_key_id/)
  mfa_profiles = find_profiles(/^mfa_serial/)
  iam_profiles - mfa_profiles
end
run() click to toggle source
# File lib/aws_rotate/list.rb, line 8
def run
  puts "AWS Profiles:"
  puts profiles
  profiles
end