Class: Api::V2::SccAccountsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V2::SccAccountsController
- Includes:
- Api::Version2, Foreman::Controller::AutoCompleteSearch
- Defined in:
- app/controllers/api/v2/scc_accounts_controller.rb
Instance Method Summary collapse
- #bulk_subscribe ⇒ Object
- #bulk_subscribe_with_repos ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #sync ⇒ Object
- #test_connection ⇒ Object
- #update ⇒ Object
Instance Method Details
#bulk_subscribe ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 119 def bulk_subscribe respond_to do |format| if params[:scc_subscribe_product_ids].count > 0 # we need to pass two parameters to the product subscribe task, # the product itself and an array of repo ids # if the id array is empty, all repositories will be subscribed to scc_products = @scc_account.scc_products.where(:id => params[:scc_subscribe_product_ids]) subscribe_task = ForemanTasks.async_task(::Actions::BulkAction, ::Actions::SccManager::SubscribeProduct, scc_products, {}) format.json { render json: subscribe_task.to_json, status: :ok } else format.json { render json: { error: 'No Product selected' }, status: :expectation_failed } end end rescue ::Foreman::Exception => e render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity rescue ForemanTasks::Lock::LockConflict => e render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity end |
#bulk_subscribe_with_repos ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 152 def bulk_subscribe_with_repos respond_to do |format| # if we want to subscribe to specific repos, we need to pass the product and the # corresponding repository ids instead of scc products only if params[:scc_product_data].count > 0 scc_products = @scc_account.scc_products.where(:id => params[:scc_product_data].pluck(:scc_product_id)) if scc_products.empty? format.json { render json: { error: _('The selected products cannot be found for this SCC account.') }, status: :unprocessable_entity } else action_args = params[:scc_product_data].map { |p| { p['scc_product_id'] => p['repository_list'] } }.inject(:merge) subscribe_task = ForemanTasks.async_task(::Actions::BulkAction, ::Actions::SccManager::SubscribeProduct, scc_products, action_args) format.json { render json: subscribe_task.to_json, status: :ok } end else format.json { render json: { error: 'No Product selected' }, status: :expectation_failed } end end rescue ::Foreman::Exception => e render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity rescue ForemanTasks::Lock::LockConflict => e render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity end |
#create ⇒ Object
52 53 54 55 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 52 def create @scc_account = resource_class.new(scc_account_params) process_response @scc_account.save_with_logic! end |
#destroy ⇒ Object
70 71 72 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 70 def destroy process_response @scc_account.destroy end |
#index ⇒ Object
18 19 20 21 22 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 18 def index scope = resource_scope scope = scope.where(:organization => params[:organization_id]) if params[:organization_id].present? @scc_accounts = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page], :per_page => params[:per_page]) end |
#show ⇒ Object
26 27 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 26 def show end |
#sync ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 104 def sync sync_task = ForemanTasks.async_task(::Actions::SccManager::Sync, @scc_account) synced = @scc_account.update! sync_task: sync_task respond_to do |format| format.json { render json: sync_task.to_json } if synced end rescue ::Foreman::Exception => e render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity rescue ForemanTasks::Lock::LockConflict => e render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity end |
#test_connection ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 80 def test_connection if params[:id].present? find_resource begin local_scc_account_params = scc_account_params rescue ActionController::ParameterMissing local_scc_account_params = {} end @scc_account.login = local_scc_account_params[:login] unless local_scc_account_params[:login].empty? @scc_account.password = local_scc_account_params[:password] unless local_scc_account_params[:password].empty? else @scc_account = resource_class.new(scc_account_params) end respond_to do |format| if @scc_account.test_connection format.json { render json: { 'success' => true }.to_json, status: :ok } else format.json { render json: { 'success' => false, 'error' => 'Test failed. Check your credentials.' }.to_json, status: :not_found } end end end |
#update ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/controllers/api/v2/scc_accounts_controller.rb', line 60 def update if params[:scc_account].present? process_response @scc_account.update(scc_account_params) else render json: { error: 'No input data provided for changing the SCC account.', status: :expectation_failed } end end |