Sha256: aef67ef39a396b5f48250fa61a0160033d9a9bd8dc84b3dd973c67429d75fcc9

Contents?: true

Size: 1.93 KB

Versions: 20

Compression:

Stored size: 1.93 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

20 entries across 20 versions & 4 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/openstack/models/identity/user.rb
fog-1.30.0 lib/fog/openstack/models/identity/user.rb
fog-1.29.0 lib/fog/openstack/models/identity/user.rb
fog-1.28.0 lib/fog/openstack/models/identity/user.rb
fog-1.27.0 lib/fog/openstack/models/identity/user.rb
fog-1.26.0 lib/fog/openstack/models/identity/user.rb
fog-1.25.0 lib/fog/openstack/models/identity/user.rb
nsidc-fog-1.24.1 lib/fog/openstack/models/identity/user.rb
fog-1.24.0 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.11 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.10 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.9 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.8 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.7 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.6 lib/fog/openstack/models/identity/user.rb
fog-1.23.0 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.4 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.3 lib/fog/openstack/models/identity/user.rb
ns-fog-1.22.2 lib/fog/openstack/models/identity/user.rb
fog-1.22.1 lib/fog/openstack/models/identity/user.rb