<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'bobtfish', 'ec2_api.rb'))

Puppet::Type.type(:aws_iam_user).provide(:api, :parent => Puppet_X::Bobtfish::Ec2_api) do
  mk_resource_methods

  def self.new_from_aws(item)
    new(
      :aws_item         => item,
      :name             => item.name,
      :id               => item.id,
      :arn              => item.arn,
      :path             => item.path,
      :groups           => item.groups.map { |g| g.name },
      :ensure           => :present
    )
  end
  def self.instances
    iam.users.collect { |item| new_from_aws(item) }
  end
  def create
    begin
      iam.users.create(resource[:name], :path => resource[:path])
    rescue Exception => e
      fail e
    end
  end
  def destroy
    @property_hash[:aws_item].delete
    @property_hash[:ensure] = :absent
  end
end
<commit_msg>Start trying to set/reset groups<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x', 'bobtfish', 'ec2_api.rb'))
require 'set'

Puppet::Type.type(:aws_iam_user).provide(:api, :parent => Puppet_X::Bobtfish::Ec2_api) do
  mk_resource_methods

  def self.new_from_aws(item)
    new(
      :aws_item         => item,
      :name             => item.name,
      :id               => item.id,
      :arn              => item.arn,
      :path             => item.path,
      :groups           => item.groups.map { |g| g.name },
      :ensure           => :present
    )
  end
  def self.instances
    iam.users.collect { |item| new_from_aws(item) }
  end
  [:arn, :path, :name].each do |ro_method|
    define_method("#{ro_method}=") do |v|
      fail "Cannot manage #{ro_method} is read-only once a user is created"
    end
  end
  def groups=(newgroups)
    groups_to_add = Set.new(newgroups).subtract(@property_hash[:groups]).to_a.map { |name| iam.groups[name] }
    groups_to_remove = Set.new(@property_hash[:groups]).subtract(newgroups).to_a.map { |name| iam.groups[name] }
    puts groups_to_add.inspect
    puts groups_to_remove.inspect
  end
  def create
    begin
      iam.users.create(resource[:name], :path => resource[:path])
    rescue Exception => e
      fail e
    end
  end
  def destroy
    @property_hash[:aws_item].delete
    @property_hash[:ensure] = :absent
  end
end

{'fraction_non_alphanumeric': 0.14719726144629866, 'fraction_numerical': 0.0017115960633290544, 'mean_word_length': 2.4688427299703264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964292', 'n_tokens_mistral': 820, 'n_tokens_neox': 808, 'n_words': 155}