Sha256: fbbcb8052ec6a7f29818835e13a64e59c78ee9eed33d225f06ac19627c155323

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Kaname
  module Adapter
    class Real
      def find_user(name)
        user = Kaname::Resource.users.find_by_name(name)
        {"id" => user.id, "name" => user.name}
      end

      def create_user(name, email)
        password = Kaname::Generator.password
        puts "#{user},#{password}"
        response = Fog::Identity[:openstack].create_user(resource[0], password, diff[2]['email'])
        response.data[:body]["user"]
      end

      def create_user_role(tenant, user_hash, email)
        tenant = Kaname::Resource.tenants.find{|t| t.name == tenant}
        role = Kaname::Resource.roles.find{|r| r.name == role}
        Fog::Identity[:openstack].create_user_role(tenant.id, user_hash["id"], role.id)
      end

      def delete_user(name)
        user = find_user(name)
        Fog::Identity[:openstack].delete_user(user["id"])
      end

      def delete_user_role(tenant, user_hash, role)
        tenant = Kaname::Resource.tenants.find{|t| t.name == tenant}
        role = Kaname::Resource.roles.find{|r| r.name == role}
        Fog::Identity[:openstack].delete_user_role(tenant.id, user_hash["id"], role.id)
      end

      def change_user_role(tenant, user_hash, before_role, after_role)
        delete_user_role(tenant, user_hash, before_role)
        create_user_role(tenant, user_hash, after_role)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kaname-0.1.3 lib/kaname/adapter/real.rb