Sha256: b9bd7ae284e88913c9e577f1bc8ca64ab51d4796332c21f9e2ffaac729b5cc1b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module AwsRotate
  class List < Base
    def initialize(options={})
      super
      @lines = IO.readlines(@credentials_path)
    end

    def run
      puts "AWS Profiles:"
      puts profiles
      profiles
    end

    # Only returns profiles that have aws_access_key_id associated
    def profiles
      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 =~ /^aws_access_key_id/
            if has_key
              profiles << profile
              break
            end
          end
        end
      end
      profiles
    end

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws-rotate-0.3.0 lib/aws_rotate/list.rb