Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First foray into switching V3 to ActionController
- Switched ProcessController - Tests work (mostly) - Lots to do still [#98146936] Signed-off-by: Zach Robinson <zrobinson@pivotal.io>
- Loading branch information
Showing
16 changed files
with
725 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'rails' | ||
require 'action_controller' | ||
|
||
module VCAP | ||
module CloudController | ||
module RestController | ||
class ApplicationCC < ::Rails::Application | ||
config.middleware.delete 'ActionDispatch::Session::CookieStore' | ||
config.middleware.delete 'ActionDispatch::Cookies' | ||
config.middleware.delete 'ActionDispatch::Flash' | ||
end | ||
|
||
module V3ErrorsHelper | ||
def invalid_param!(message) | ||
raise VCAP::Errors::ApiError.new_from_details('BadQueryParameter', message) | ||
end | ||
|
||
def unprocessable!(message) | ||
raise VCAP::Errors::ApiError.new_from_details('UnprocessableEntity', message) | ||
end | ||
|
||
def unauthorized! | ||
raise VCAP::Errors::ApiError.new_from_details('NotAuthorized') | ||
end | ||
end | ||
|
||
class BaseControllerV3 < ::ActionController::Base | ||
include VCAP::CloudController | ||
include VCAP::CloudController::RestController::V3ErrorsHelper | ||
|
||
wrap_parameters :body, format: [:json] | ||
|
||
before_filter :set_current_user | ||
before_filter :check_read_permissions!, only: [:index, :show] | ||
before_filter :check_write_permissions!, except: [:index, :show] | ||
|
||
def query_params | ||
request.query_parameters.with_indifferent_access | ||
end | ||
|
||
# include VCAP::Errors | ||
# include VCAP::RestAPI | ||
# include Messages | ||
# include Routes | ||
# extend Forwardable | ||
|
||
def check_read_permissions! | ||
read_scope = SecurityContext.scopes.include?('cloud_controller.read') | ||
raise VCAP::Errors::ApiError.new_from_details('NotAuthorized') if !roles.admin? && !read_scope | ||
end | ||
|
||
def check_write_permissions! | ||
write_scope = SecurityContext.scopes.include?('cloud_controller.write') | ||
raise VCAP::Errors::ApiError.new_from_details('NotAuthorized') if !roles.admin? && !write_scope | ||
end | ||
|
||
def set_current_user | ||
auth_token = request.headers['HTTP_AUTHORIZATION'] | ||
token_decoder = VCAP::UaaTokenDecoder.new(Config.config[:uaa]) | ||
VCAP::CloudController::Security::SecurityContextConfigurer.new(token_decoder).configure(auth_token) | ||
end | ||
|
||
def roles | ||
VCAP::CloudController::SecurityContext.roles | ||
end | ||
|
||
def current_user | ||
VCAP::CloudController::SecurityContext.current_user | ||
end | ||
|
||
def current_user_email | ||
VCAP::CloudController::SecurityContext.current_user_email | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Rails.application.configure do | ||
# Settings specified here will take precedence over those in config/application.rb. | ||
|
||
# In the development environment your application's code is reloaded on | ||
# every request. This slows down response time but is perfect for development | ||
# since you don't have to restart the web server when you make code changes. | ||
config.cache_classes = false | ||
|
||
# Do not eager load code on boot. | ||
config.eager_load = false | ||
|
||
# Show full error reports and disable caching. | ||
config.consider_all_requests_local = true | ||
config.action_controller.perform_caching = false | ||
|
||
# Print deprecation notices to the Rails logger. | ||
config.active_support.deprecation = :log | ||
|
||
# Debug mode disables concatenation and preprocessing of assets. | ||
# This option may cause significant delays in view rendering with a large | ||
# number of complex assets. | ||
config.assets.debug = true | ||
|
||
# Asset digests allow you to set far-future HTTP expiration dates on all assets, | ||
# yet still be able to expire them through the digest params. | ||
config.assets.digest = true | ||
|
||
# Adds additional error checking when serving assets at runtime. | ||
# Checks for improperly declared sprockets dependencies. | ||
# Raises helpful error messages. | ||
config.assets.raise_runtime_errors = true | ||
|
||
# Raises error for missing translations | ||
# config.action_view.raise_on_missing_translations = true | ||
end |
Oops, something went wrong.