class SFRest::Update

Drive updates on the Site Factory

Public Class Methods

new(conn) click to toggle source

@param [SFRest::Connection] conn

# File lib/sfrest/update.rb, line 7
def initialize(conn)
  @conn = conn
end

Public Instance Methods

list_vcs_refs(type = 'sites', stack_id = 1) click to toggle source

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
modify_status(site_creation, site_duplication, domain_management, bulk_operations) click to toggle source

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
multi_stack?() click to toggle source
# File lib/sfrest/update.rb, line 99
def multi_stack?
  @multi_stack ||= @conn.codebase.list['stacks'].size > 1
end
pause_update() click to toggle source

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
resume_update() click to toggle source

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
start_update(ref) click to toggle source

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
status_info() click to toggle source

Gets the status information.

# File lib/sfrest/update.rb, line 12
def status_info
  current_path = '/api/v1/status'
  @conn.get(current_path)
end
update(datum) click to toggle source

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
update_list() click to toggle source

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
update_progress(update_id) click to toggle source

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
update_version() click to toggle source

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
v2_endpoint?() click to toggle source

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
validate_request(datum) click to toggle source
# 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