Sha256: 3349b9cf7506f000a1ccba85e1da79bb9f7892e90470c4745aa3374bfe1d613c

Contents?: true

Size: 1.76 KB

Versions: 13

Compression:

Stored size: 1.76 KB

Contents

require 'fog/core/model'

module Fog
  module Identity
    class OpenStack
      class User < Fog::Model
        identity :id

        attribute :email
        attribute :enabled
        attribute :name
        attribute :tenant_id, :aliases => 'tenantId'
        attribute :password

        attr_accessor :email, :name, :tenant_id, :enabled, :password

        def initialize(attributes)
          @connection = attributes[:connection]
          super
        end

        def save
          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
          requires :name, :tenant_id, :password
          enabled = true if enabled.nil?
          data = connection.create_user(name, password, email, tenant_id, enabled)
          merge_attributes(data.body['user'])
          true
        end

        def update(options = {})
          requires :id
          options.merge('id' => id)
          response = connection.update_user(id, options)
          true
        end

        def update_password(password)
          update({'password' => password, 'url' => "/users/#{id}/OS-KSADM/password"})
        end

        def update_tenant(tenant)
          tenant = tenant.id if tenant.class != String
          update({:tenantId => tenant, 'url' => "/users/#{id}/OS-KSADM/tenant"})
        end

        def update_enabled(enabled)
          update({:enabled => enabled, 'url' => "/users/#{id}/OS-KSADM/enabled"})
        end

        def destroy
          requires :id
          connection.delete_user(id)
          true
        end

        def roles(tenant_id = self.tenant_id)
          connection.list_roles_for_user_on_tenant(tenant_id, self.id).body['roles']
        end
      end # class User
    end # class OpenStack
  end # module Identity
end # module Fog

Version data entries

13 entries across 13 versions & 7 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/openstack/models/identity/user.rb
fog-nirvanix-1.8.1 lib/fog/openstack/models/identity/user.rb
fog-parser-fix-1.6.1 lib/fog/openstack/models/identity/user.rb
fog-test-again-1.6.0 lib/fog/openstack/models/identity/user.rb
fog-parser-fix-1.6.0 lib/fog/openstack/models/identity/user.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/openstack/models/identity/user.rb
fog-sgonyea-1.8.1 lib/fog/openstack/models/identity/user.rb
fog-1.8.0 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/openstack/models/identity/user.rb
fog-1.7.0 lib/fog/openstack/models/identity/user.rb
fog-1.6.0 lib/fog/openstack/models/identity/user.rb
fog-1.5.0 lib/fog/openstack/models/identity/user.rb
fog-1.4.0 lib/fog/openstack/models/identity/user.rb