Module: Cyclid::API::Organizations::Configs
- Defined in:
- app/cyclid/controllers/organizations/config.rb
Overview
API endpoints for Organization specific configuration
Organizations collapse
-
#GET(/organizations/: organization/configs) ⇒ Object
Get the list of plugins which support per-organization configurations.
-
#GET(/organizations/: organization/configs/:type/:plugin) ⇒ Object
Get the current configuration for the given plugin.
-
#PUT(/organizations/: organization/configs/:type/:plugin) ⇒ 200, 404
Update the plugin configuration.
Class Method Summary collapse
-
.registered(app) ⇒ Object
Sinatra callback.
Class Method Details
.registered(app) ⇒ Object
Sinatra callback
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/cyclid/controllers/organizations/config.rb', line 70 def self.registered(app) include Errors::HTTPErrors include Constants::JobStatus # Return a list of plugins which have configs app.get do (params[:name], Operations::READ) configs = [] Cyclid.plugins.all.each do |plugin| configs << { type: plugin.human_name, name: plugin.name } \ if plugin.config? end return configs.to_json end # Get the current configuration for the given plugin. app.get '/:type/:plugin' do (params[:name], Operations::READ) org = Organization.find_by(name: params[:name]) halt_with_json_response(404, INVALID_ORG, 'organization does not exist') \ if org.nil? Cyclid.logger.debug "type=#{params[:type]} plugin=#{params[:plugin]}" # Find the plugin plugin = Cyclid.plugins.find(params[:plugin], params[:type]) halt_with_json_response(404, INVALID_PLUGIN, 'plugin does not exist') \ if plugin.nil? # Ask the plugin for the current config for this organization. This # will include the config schema under the 'schema' attribute. begin config = plugin.get_config(org) halt_with_json_response(404, INVALID_PLUGIN_CONFIG, 'failed to get plugin config') \ if config.nil? rescue StandardError => ex halt_with_json_response(404, \ INVALID_PLUGIN_CONFIG, \ "failed to get plugin config: #{ex}") \ if config.nil? end return config.to_json end # Update the plugin configuration app.put '/:type/:plugin' do (params[:name], Operations::ADMIN) payload = parse_request_body Cyclid.logger.debug payload org = Organization.find_by(name: params[:name]) halt_with_json_response(404, INVALID_ORG, 'organization does not exist') \ if org.nil? # Find the plugin plugin = Cyclid.plugins.find(params[:plugin], params[:type]) halt_with_json_response(404, INVALID_PLUGIN, 'plugin does not exist') \ if plugin.nil? # Ask the plugin for the current config for this organization. This # will include the config schema under the 'schema' attribute. begin plugin.set_config(payload, org) rescue StandardError => ex halt_with_json_response(404, \ INVALID_PLUGIN_CONFIG, \ "failed to set plugin config: #{ex}") \ end end end |
Instance Method Details
#GET(/organizations/: organization/configs) ⇒ Object
Get the list of plugins which support per-organization configurations.
|
# File 'app/cyclid/controllers/organizations/config.rb', line 28
|
#GET(/organizations/: organization/configs/:type/:plugin) ⇒ Object
Get the current configuration for the given plugin.
|
# File 'app/cyclid/controllers/organizations/config.rb', line 36
|
#PUT(/organizations/: organization/configs/:type/:plugin) ⇒ 200, 404
Update the plugin configuration
|
# File 'app/cyclid/controllers/organizations/config.rb', line 54
|