Sha256: 6e5672bf28f8a4b17490a9c22b5097ed11699bb3c37ea7a40ccac0f305b6c4c0

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

require 'ostruct'

module ForemanSalt
  module Api
    module V2
      class SaltAutosignController < ::ForemanSalt::Api::V2::BaseController
        before_filter :find_proxy, :setup_proxy

        api :GET, '/salt_autosign/:smart_proxy_id', N_('List all autosign records')
        param :smart_proxy_id, :identifier_dottable, :required => true
        def index
          @salt_autosigns = all_autosign
        end

        api :POST, '/salt_autosign/:smart_proxy_id', N_('Create an autosign record')
        param :smart_proxy_id, :identifier_dottable, :required => true
        param :record, String, :required => true, :desc => N_('Autosign record')
        def create
          @api.autosign_create params[:record]
          @salt_autosign = { :record => params[:record] }
        end

        api :DELETE, '/salt_autosign/:smart_proxy_id/:record', N_('Delete an autosign record')
        param :smart_proxy_id, :identifier_dottable, :required => true
        param :record, String, :required => true, :desc => N_('Autosign record')
        def destroy
          @api.autosign_remove params[:record]
          render :json => { root_node_name => _('Record deleted.') }
        end

        def metadata_total
          @total ||= all_autosign.count
        end

        def metadata_subtotal
          metadata_total
        end

        def metadata_page
          1
        end

        def metadata_per_page
          metadata_total
        end

        private

        def all_autosign
          @_autosigns ||= @api.autosign_list.map { |record| OpenStruct.new(:record => record) }
        end

        def find_proxy
          @proxy = ::SmartProxy.find(params[:smart_proxy_id])
          not_found unless @proxy
        end

        def setup_proxy
          @api = ProxyAPI::Salt.new(:url => @proxy.url)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreman_salt-4.0.1 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-4.0.0 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-3.0.2 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-3.0.1 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-3.0.0 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-2.1.0 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-2.0.2 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-2.0.1 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb
foreman_salt-2.0.0 app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb