Sha256: 6f4b4000b3b3bb75c07ecfdec50be6277e3d477f999636d87a8ddbbfa585c04c

Contents?: true

Size: 1.85 KB

Versions: 25

Compression:

Stored size: 1.85 KB

Contents

require 'fog/openstack/models/model'

module Fog
  module Identity
    class OpenStack
      class V2
        class User < Fog::OpenStack::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 ec2_credentials
            requires :id
            service.ec2_credentials(:user => self)
          end

          def save
            raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
            requires :name
            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)
            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)
            if tenant_id
              service.list_roles_for_user_on_tenant(tenant_id, id).body['roles']
            else
              []
            end
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 23 versions & 3 rubygems

Version Path
fog-openstack-0.1.31 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.10 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.1.30 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.1.29 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.9 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.1.28 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.8 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.7 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.6 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.5 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.4 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.3 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.2 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.3.0 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.2.4 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.2.3 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.2.2 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.2.1 lib/fog/identity/openstack/v2/models/user.rb
fog-openstack-0.2.0 lib/fog/identity/openstack/v2/models/user.rb
fog-zj-0.1.28 lib/fog/identity/openstack/v2/models/user.rb