Sha256: c6e69c6688371bba64ed7e51c5f763967c4bdf8e9ccab1834b9ea02e07afbca1

Contents?: true

Size: 1.94 KB

Versions: 71

Compression:

Stored size: 1.94 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)
          # Old 'connection' is renamed as service and should be used instead
          prepare_service_value(attributes)
          super
        end

        def ec2_credentials
          requires :id
          service.ec2_credentials(:user => self)
        end

        def save
          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
          requires :name, :tenant_id, :password
          enabled = true if enabled.nil?
          data = service.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 = service.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
          service.delete_user(id)
          true
        end

        def roles(tenant_id = self.tenant_id)
          service.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

71 entries across 71 versions & 7 rubygems

Version Path
fog-1.22.0 lib/fog/openstack/models/identity/user.rb
fog-1.21.0 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/openstack/models/identity/user.rb
cifrado-0.2.1 vendor/fog/lib/fog/openstack/models/identity/user.rb
cifrado-0.2.0 vendor/fog/lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/openstack/models/identity/user.rb
fog-1.20.0 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/openstack/models/identity/user.rb
fog-1.19.0 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/openstack/models/identity/user.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/openstack/models/identity/user.rb