Skip to content
Permalink
Browse files

Allow specifying `exclude` option in a DSL

  • Loading branch information...
sorah committed Sep 21, 2018
1 parent 726b890 commit 03242d080e020a424fe999448723e279e92dc686
Showing with 26 additions and 3 deletions.
  1. +6 −2 lib/miam/client.rb
  2. +5 −1 lib/miam/dsl/context.rb
  3. +15 −0 spec/miam/exclude_spec.rb
@@ -2,7 +2,10 @@ class Miam::Client
include Miam::Logger::Helper

def initialize(options = {})
@options = {:format => :ruby}.merge(options)
@options = {
format: :ruby,
exclude: []
}.merge(options)
aws_config = options.delete(:aws_config) || {}
@iam = Aws::IAM::Client.new(aws_config)
@sts = Aws::STS::Client.new(aws_config)
@@ -58,6 +61,7 @@ def apply(file)

def walk(file)
expected = load_file(file)
@options[:exclude] += expected[:exclude]

actual, group_users, instance_profile_roles = Miam::Exporter.export(@iam, @options)
updated = pre_walk_managed_policies(expected[:policies], actual[:policies])
@@ -539,7 +543,7 @@ def target_matched?(name)
result = true

if @options[:exclude]
result &&= @options[:exclude].all? {|r| name !~ r}
result &&= @options[:exclude].all? {|r| name !~ r }
end

if @options[:target]
@@ -12,7 +12,7 @@ def self.eval(dsl, path, options = {})
def initialize(path, options = {}, &block)
@path = path
@options = options
@result = {:users => {}, :groups => {}, :roles => {}, :instance_profiles => {}, :policies => {}}
@result = {:users => {}, :groups => {}, :roles => {}, :instance_profiles => {}, :policies => {}, :exclude => []}

@context = Hashie::Mash.new(
:path => path,
@@ -41,6 +41,10 @@ def require(file)
end
end

def exclude(pattern)
@result[:exclude] << pattern
end

def user(name, user_options = {}, &block)
name = name.to_s

@@ -234,4 +234,19 @@
expect(updated).to be_falsey
end
end

context 'when specifying exclude option in a DSL' do
let(:exclude_everything) do
<<-RUBY
exclude /.*/
RUBY
end

subject { client(exclude: []) }

it do
updated = apply(subject) { exclude_everything }
expect(updated).to be_falsey
end
end
end

0 comments on commit 03242d0

Please sign in to comment.
You can’t perform that action at this time.