Sha256: 7b301c515bb6f36393f7258ef9bac5af5250674690d26db66e18187a29cbe94c

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

require 'fog/proxmox/models/collection'
require 'fog/identity/proxmox/models/permission'

module Fog
  module Identity
    class Proxmox
      # class Permissions authentication
      class Permissions < Fog::Proxmox::Collection
        model Fog::Identity::Proxmox::Permission

        def all(_options = {})
          load_response(service.list_permissions, 'permissions')
        end

        def create(permission_hash)
          groups = permission_hash[:groups]
          users = permission_hash[:users]
          roles = permission_hash[:roles]
          path = permission_hash[:path]
          propagate ||= 1
          permission = new(path: path, propagate: propagate, roleid: roles)
          if groups
            permission.type = 'group'
            permission.ugid = groups
          elsif users
            permission.type = 'user'
            permission.ugid = users
          end
          permission
        end

        def add(permission)
          create(permission).add
        end

        def remove(permission)
          create(permission).remove
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fog-proxmox-0.5.5 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.5.4 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.5.3 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.5.2 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.5.1 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.5.0 lib/fog/identity/proxmox/models/permissions.rb
fog-proxmox-0.4.0 lib/fog/identity/proxmox/models/permissions.rb