Hi All, I've been working on getting my foreman plugin, cert_reaper, finished and have been asked to add a single API route to allow callers to clear puppet certificates based on certificate name.
The source for my plugin can be found at: <goog_557621292> https://github.com/dscoular/cert-reaper/ I was thinking that this should just utilise an HTTP DELETE method, the path to the API's route and a puppet certificate name e.g. DELETE /api/v2/certs/theagent.example.com I had hoped this would just entail adding a line to my plugin's config/routes.rb file and implementing the action in an api controller, however it seems a bit more complex than that. I've tried to strip back to as basic as possible just to see if I could get something to fire my API action but I'm getting nowhere. Could someone please give me a nudge in the right direction? Here are my existing routes: *config/routes.rb* Rails.application.routes.draw do get 'clear_cert', to: 'cert_reaper/hosts#clear_cert' get 'multiple_clear_cert', to: 'cert_reaper/hosts#multiple_clear_cert' post 'submit_multiple_clear_cert', to: 'cert_reaper/hosts#submit_multiple_clear_cert' delete 'certs', to: 'cert_reaper/api/v2/certs#destroy' end The "delete" line just ignores the /api/... path and certname parameter I had wanted and tries to make "DELETE /certs" fire my destroy() method, which I've implemented in the following: *app/controllers/api/v2/certs_controller.rb* module Api module v2 class CertsController < ::Api::v2::BaseController resource_description do resource_id 'certs' api_version 'v2' api_base_url '/api' end api :DELETE, '/certs/:certname/', _('Clear a puppet certificate.') param :certname, :required => true, String, desc: 'Full name of the user' def destroy render :json => { :error => _('Destroy got called with "#{params['certname']}".' }, :status => :precondition_failed end end end end However when I try to make an HTTP DELETE request against /certs/ using postman I get the following error: Routing Error uninitialized constant CertReaper::Api Rails.root: /home/vagrant/foreman My guess is that my route's action module isn't being loaded or recognised. Obviously I'm pretty confused (I'm a ruby/rails/foreman newbie), so any kind words of wisdom nudging me in the right direction would be hugely appreciated. Cheers, Doug -- You received this message because you are subscribed to the Google Groups "foreman-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
