Sha256: dcfd02dff00e59a2117f14b3f9512256ae669a4e5c044c5fa33e719d94ceefc8

Contents?: true

Size: 1.29 KB

Versions: 17

Compression:

Stored size: 1.29 KB

Contents

require 'fog/openstack/models/model'

module Fog
  module Identity
    class OpenStack
      class V2
        class Role < Fog::OpenStack::Model
          identity :id
          attribute :name

          def save
            requires :name
            data = service.create_role(name)
            merge_attributes(data.body['role'])
            true
          end

          def destroy
            requires :id
            service.delete_role(id)
            true
          end

          def add_to_user(user, tenant)
            add_remove_to_user(user, tenant, :add)
          end

          def remove_to_user(user, tenant)
            add_remove_to_user(user, tenant, :remove)
          end

          private
          def add_remove_to_user(user, tenant, ops)
            requires :id
            user_id = get_id(user)
            tenant_id = get_id(tenant)
            case ops
              when :add
                service.create_user_role(tenant_id, user_id, id).status == 200
              when :remove
                service.delete_user_role(tenant_id, user_id, id).status == 204
            end
          end

          def get_id(_)
            _.is_a?(String) ? _ : _.id
          end
        end # class Role
      end # class V2
    end # class OpenStack
  end # module Identity
end # module Fog

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
fog-openstack-0.1.10 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.9 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.8 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.7 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.6 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.5 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.4 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.3 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.2 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.1 lib/fog/openstack/models/identity_v2/role.rb
fog-openstack-0.1.0 lib/fog/openstack/models/identity_v2/role.rb
fog-1.37.0 lib/fog/openstack/models/identity_v2/role.rb
fog-1.36.0 lib/fog/openstack/models/identity_v2/role.rb
fog-1.35.0 lib/fog/openstack/models/identity_v2/role.rb
fog-2.0.0.pre.0 lib/fog/openstack/models/identity_v2/role.rb
fog-1.34.0 lib/fog/openstack/models/identity_v2/role.rb
fog-1.33.0 lib/fog/openstack/models/identity_v2/role.rb