diff options
Diffstat (limited to 'qa/qa/runtime/application_settings.rb')
-rw-r--r-- | qa/qa/runtime/application_settings.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/qa/qa/runtime/application_settings.rb b/qa/qa/runtime/application_settings.rb index 55a5ae9d06c..5aeab922a12 100644 --- a/qa/qa/runtime/application_settings.rb +++ b/qa/qa/runtime/application_settings.rb @@ -2,6 +2,8 @@ module QA module Runtime + # TODO: Ideally this should be changed to a normal class due to now being able to override what api client is used + # class ApplicationSettings class << self include Support::API @@ -13,26 +15,30 @@ module QA # #set({ allow_local_requests_from_web_hooks_and_services: true }) # #set(allow_local_requests_from_web_hooks_and_services: true) # https://docs.gitlab.com/ee/api/settings.html - def set_application_settings(**application_settings) - @original_application_settings = get_application_settings + def set_application_settings(api_client: admin_api_client, **application_settings) + @original_application_settings = get_application_settings(api_client: api_client) QA::Runtime::Logger.info("Setting application settings: #{application_settings}") r = put(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url, **application_settings) - raise "Couldn't set application settings #{application_settings.inspect}" unless r.code == QA::Support::API::HTTP_STATUS_OK + return if r.code == QA::Support::API::HTTP_STATUS_OK + + raise "Couldn't set application settings #{application_settings.inspect}" end - def get_application_settings + def get_application_settings(api_client: admin_api_client) parse_body(get(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url)) end + # TODO: This class probably needs to be refactored because this method relies on original settings to have been + # populated sometime in the past and there is no guarantee original settings instance variable is still valid def restore_application_settings(*application_settings_keys) set_application_settings(**@original_application_settings.slice(*application_settings_keys)) end private - def api_client - @api_client ||= Runtime::API::Client.as_admin + def admin_api_client + @admin_api_client ||= Runtime::API::Client.as_admin rescue API::Client::AuthorizationError => e raise "Administrator access is required to set application settings. #{e.message}" end |