class SFRest::Update
Drive updates on the Site
Factory
Public Class Methods
@param [SFRest::Connection] conn
# File lib/sfrest/update.rb, line 7 def initialize(conn) @conn = conn end
Public Instance Methods
Lists vcs refs.
# File lib/sfrest/update.rb, line 28 def list_vcs_refs(type = 'sites', stack_id = 1) current_path = "/api/v1/vcs?type=#{type}&stack_id=#{stack_id}" @conn.get(current_path) end
Modifies the status information.
# File lib/sfrest/update.rb, line 18 def modify_status(site_creation, site_duplication, domain_management, bulk_operations) current_path = '/api/v1/status' payload = { 'site_creation' => site_creation, 'site_duplication' => site_duplication, 'domain_management' => domain_management, 'bulk_operations' => bulk_operations }.to_json @conn.put(current_path, payload) end
# File lib/sfrest/update.rb, line 99 def multi_stack? @multi_stack ||= @conn.codebase.list['stacks'].size > 1 end
Pauses current update.
# File lib/sfrest/update.rb, line 79 def pause_update current_path = '/api/v1/update/pause' payload = { 'pause' => true }.to_json @conn.post(current_path, payload) end
Resumes current update.
# File lib/sfrest/update.rb, line 86 def resume_update current_path = '/api/v1/update/pause' payload = { 'pause' => false }.to_json @conn.post(current_path, payload) end
Starts an update.
# File lib/sfrest/update.rb, line 34 def start_update(ref) if update_version == 'v2' raise InvalidApiVersion, 'There is more than one codebase use sfrest.update.update directly.' end update_data = { scope: 'sites', sites_type: 'code, db', sites_ref: ref } update(update_data) end
Gets the status information.
# File lib/sfrest/update.rb, line 12 def status_info current_path = '/api/v1/status' @conn.get(current_path) end
Starts an update. The rest api supports the following scope: sites|factory|both (defaults to 'sites') start_time: sites_type: code|code, db| code, db, registry (defaults to 'code, db') factory_type: code|code, db (defaults to 'code, db') sites_ref: factory_ref: This method does not filter or validate so that it can be used for negative cases. (missing data)
# File lib/sfrest/update.rb, line 52 def update(datum) validate_request datum current_path = "/api/#{update_version}/update" payload = datum.to_json @conn.post(current_path, payload) end
Gets the list of updates.
# File lib/sfrest/update.rb, line 67 def update_list current_path = '/api/v1/update' @conn.get(current_path) end
Gets the progress of an update by id.
# File lib/sfrest/update.rb, line 73 def update_progress(update_id) current_path = "/api/v1/update/#{update_id}/status" @conn.get(current_path) end
Determines the api version to use for updates. it is possible for there to be two codebases and not have a v2 endpoint.
# File lib/sfrest/update.rb, line 95 def update_version multi_stack? && v2_endpoint? ? 'v2' : 'v1' end
Determines if the v2 endpoint exists. A factory with the endpoint will raise an SFRest::BadRequestError
A factory without the endpoint will raise SFRest::InvalidResponse
# File lib/sfrest/update.rb, line 106 def v2_endpoint? return @has_v2_endpoint unless @has_v2_endpoint.nil? begin @conn.post '/api/v2/update', '{}' rescue SFRest::BadRequestError @has_v2_endpoint = true rescue SFRest::InvalidResponse => e return @has_v2_endpoint = false if e.message =~ /Invalid data, status 404/ raise e end end
# File lib/sfrest/update.rb, line 59 def validate_request(datum) v1_keys = %i[scope sites_ref factory_ref sites_type factory_type db_update_arguments] v2_keys = %i[sites factory] key_overlap = binding.local_variable_get("#{update_version}_keys") & datum.keys raise InvalidDataError, "An invalid stucture was passed to the #{update_version} endpoint" if key_overlap.empty? end